Skip to content

Commit ba0e081

Browse files
committed
[article] Create a lit cheat sheet
1 parent 42d1ed5 commit ba0e081

File tree

175 files changed

+3758
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+3758
-35
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lit-dev-content/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,15 @@
180180
"rollup-plugin-minify-html-literals": "^1.2.6",
181181
"rollup-plugin-summary": "^1.2.3",
182182
"rollup-plugin-terser": "^7.0.2",
183+
"signal-utils": "^0.21.1",
183184
"slugify": "^1.3.6"
184185
},
185186
"dependencies": {
186187
"@lit-labs/context": "^0.4.1",
187188
"@lit-labs/motion": "^1.0.1",
188189
"@lit-labs/react": "^1.0.8",
189-
"@lit-labs/task": "^3.0.2",
190190
"@lit-labs/signals": "^0.1.1",
191+
"@lit-labs/task": "^3.0.2",
191192
"@lit/context": "^1.1.0",
192193
"@lit/localize": "^0.10.0",
193194
"@lit/react": "^1.0.0 || 1.0.0-pre.0",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<my-element></my-element>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { html, LitElement, css } from 'lit';
2+
import { customElement } from 'lit/decorators.js';
3+
4+
@customElement('my-element')
5+
export class MyElement extends LitElement {
6+
render() {
7+
return html`<p>I'm blue</p><div>I'm red</div>`;
8+
}
9+
10+
static styles = css`
11+
p {
12+
color: blue;
13+
}
14+
div {
15+
color: red;
16+
}
17+
`;
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "/samples/v3-base.json",
3+
"files": {
4+
"my-element.ts": {},
5+
"index.html": {}
6+
},
7+
"previewHeight": "100px"
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<my-element></my-element>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { html, LitElement } from 'lit';
2+
import { customElement, property } from 'lit/decorators.js';
3+
import { html as staticHTML, StaticValue } from 'lit/static-html.js';
4+
5+
@customElement('input-or-textfield')
6+
export class MyElement extends LitElement {
7+
// attribute is false because this is a value that can't be serialized to an
8+
// HTML attribute
9+
@property({ attribute: false }) tagLiteral: StaticValue|null = null;
10+
@property() value = '';
11+
12+
render() {
13+
return html`
14+
${
15+
staticHTML`
16+
<${this.tagLiteral}
17+
@input=${this.#onInput}
18+
.value=${this.value}></${this.tagLiteral}>
19+
`
20+
}
21+
<div>
22+
The value of the input is: ${this.value}
23+
</div>
24+
`;
25+
}
26+
27+
#onInput(e: InputEvent) {
28+
this.value = (e.target as (HTMLInputElement | HTMLTextAreaElement)).value;
29+
}
30+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { css, html, LitElement } from 'lit';
2+
import { customElement, state } from 'lit/decorators.js';
3+
import { literal } from 'lit/static-html.js';
4+
import './input-or-textfield.js';
5+
6+
@customElement('my-element')
7+
export class MyElement extends LitElement {
8+
@state() tagLiteral = literal`input`;
9+
render() {
10+
return html`
11+
<!-- /* playground-fold */ -->
12+
<fieldset>
13+
<legend>Choose a tag to render:</legend>
14+
<div>
15+
<label>
16+
<input
17+
type="radio"
18+
name="selection"
19+
@change=${this.#onChange}
20+
value="input"
21+
checked>
22+
input
23+
</label>
24+
</div>
25+
<div>
26+
<label>
27+
<input
28+
type="radio"
29+
name="selection"
30+
@change=${this.#onChange}
31+
value="textarea">
32+
textarea
33+
</label>
34+
</div>
35+
</fieldset>
36+
<!-- /* playground-fold-end */ -->
37+
<input-or-textfield
38+
value="this is the default value"
39+
.tagLiteral=${this.tagLiteral}>
40+
</input-or-textfield>
41+
`;
42+
}
43+
44+
#onChange(e: InputEvent) {
45+
const target = e.target as HTMLInputElement;
46+
this.tagLiteral = target.value === 'input' ? literal`input` : literal`textarea`;
47+
}
48+
49+
static styles = css`/* playground-fold */:host { font-family: sans-serif; } :host > * { margin-block: .5em; }/* playground-fold-end */`;
50+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "/samples/v3-base.json",
3+
"files": {
4+
"input-or-textfield.ts": {},
5+
"my-element.ts": {},
6+
"index.html": {}
7+
},
8+
"previewHeight": "175px"
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<my-element></my-element>

0 commit comments

Comments
 (0)