Skip to content

Commit 20f24ec

Browse files
committed
format samples
1 parent 2e03b5e commit 20f24ec

File tree

613 files changed

+3732
-2924
lines changed

Some content is hidden

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

613 files changed

+3732
-2924
lines changed

packages/lit-dev-content/samples/_check-code-helpers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {PostDoc} from 'postdoc-lib';
22

3-
export const installCodeChecker = async (checkCode: () => Promise<{passed: boolean, message?: string}>) => {
3+
export const installCodeChecker = async (
4+
checkCode: () => Promise<{passed: boolean; message?: string}>,
5+
) => {
46
const postDoc = new PostDoc({
57
messageTarget: window.top!,
68
messageReceiver: window,
@@ -15,9 +17,9 @@ export const installCodeChecker = async (checkCode: () => Promise<{passed: boole
1517
postDoc.postMessage({status, message});
1618
break;
1719
}
18-
}
20+
},
1921
});
2022

2123
await postDoc.handshake;
2224
postDoc.postMessage({status: 'READY'});
23-
}
25+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<script type="module" src="./my-element.js"></script>
22

3-
<my-element></my-element>
3+
<my-element></my-element>
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { html, LitElement, css } from 'lit';
2-
import { customElement } from 'lit/decorators.js';
1+
import {html, LitElement, css} from 'lit';
2+
import {customElement} from 'lit/decorators.js';
33

44
@customElement('my-element')
55
export class MyElement extends LitElement {
66
render() {
7-
return html`<p>I'm blue</p><div>I'm red</div>`;
7+
return html`<p>I'm blue</p>
8+
<div>I'm red</div>`;
89
}
910

1011
static styles = css`
@@ -15,4 +16,4 @@ export class MyElement extends LitElement {
1516
color: red;
1617
}
1718
`;
18-
}
19+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<script type="module" src="./my-element.js"></script>
22

3-
<my-element></my-element>
3+
<my-element></my-element>
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
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';
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';
44

55
@customElement('input-or-textfield')
66
export class MyElement extends LitElement {
77
// attribute is false because this is a value that can't be serialized to an
88
// HTML attribute
9-
@property({ attribute: false }) tagLiteral: StaticValue|null = null;
9+
@property({attribute: false}) tagLiteral: StaticValue | null = null;
1010
@property() value = '';
1111

1212
render() {
1313
return html`
14-
${
15-
staticHTML`
14+
${staticHTML`
1615
<${this.tagLiteral}
1716
@input=${this.#onInput}
1817
.value=${this.value}></${this.tagLiteral}>
19-
`
20-
}
21-
<div>
22-
The value of the input is: ${this.value}
23-
</div>
18+
`}
19+
<div>The value of the input is: ${this.value}</div>
2420
`;
2521
}
2622

2723
#onInput(e: InputEvent) {
28-
this.value = (e.target as (HTMLInputElement | HTMLTextAreaElement)).value;
24+
this.value = (e.target as HTMLInputElement | HTMLTextAreaElement).value;
2925
}
3026
}
Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { css, html, LitElement } from 'lit';
2-
import { customElement, state } from 'lit/decorators.js';
3-
import { literal } from 'lit/static-html.js';
1+
import {css, html, LitElement} from 'lit';
2+
import {customElement, state} from 'lit/decorators.js';
3+
import {literal} from 'lit/static-html.js';
44
import './input-or-textfield.js';
55

66
@customElement('my-element')
@@ -14,37 +14,49 @@ export class MyElement extends LitElement {
1414
<div>
1515
<label>
1616
<input
17-
type="radio"
18-
name="selection"
19-
@change=${this.#onChange}
20-
value="input"
21-
checked>
17+
type="radio"
18+
name="selection"
19+
@change=${this.#onChange}
20+
value="input"
21+
checked
22+
/>
2223
input
2324
</label>
2425
</div>
2526
<div>
2627
<label>
2728
<input
28-
type="radio"
29-
name="selection"
30-
@change=${this.#onChange}
31-
value="textarea">
29+
type="radio"
30+
name="selection"
31+
@change=${this.#onChange}
32+
value="textarea"
33+
/>
3234
textarea
3335
</label>
3436
</div>
3537
</fieldset>
3638
<!-- /* playground-fold-end */ -->
3739
<input-or-textfield
38-
value="this is the default value"
39-
.tagLiteral=${this.tagLiteral}>
40+
value="this is the default value"
41+
.tagLiteral=${this.tagLiteral}
42+
>
4043
</input-or-textfield>
4144
`;
4245
}
4346

4447
#onChange(e: InputEvent) {
4548
const target = e.target as HTMLInputElement;
46-
this.tagLiteral = target.value === 'input' ? literal`input` : literal`textarea`;
49+
this.tagLiteral =
50+
target.value === 'input' ? literal`input` : literal`textarea`;
4751
}
4852

49-
static styles = css`/* playground-fold */:host { font-family: sans-serif; } :host > * { margin-block: .5em; }/* playground-fold-end */`;
53+
static styles = css`
54+
/* playground-fold */
55+
:host {
56+
font-family: sans-serif;
57+
}
58+
:host > * {
59+
margin-block: 0.5em;
60+
} /* playground-fold-end */
61+
`;
5062
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<script type="module" src="./my-element.js"></script>
22

3-
<my-element></my-element>
3+
<my-element></my-element>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { html, LitElement, css } from 'lit';
2-
import { customElement, state } from 'lit/decorators.js';
3-
import { classMap } from 'lit/directives/class-map.js';
1+
import {html, LitElement, css} from 'lit';
2+
import {customElement, state} from 'lit/decorators.js';
3+
import {classMap} from 'lit/directives/class-map.js';
44

55
@customElement('my-element')
66
export class MyElement extends LitElement {
7-
@state() counter = 0
7+
@state() counter = 0;
88

99
firstUpdated() {
10-
setInterval(() => this.counter += 1 , 1000);
10+
setInterval(() => (this.counter += 1), 1000);
1111
}
1212

1313
render() {
1414
const classes = {
1515
red: this.counter % 2 === 0,
16-
blue: this.counter % 2 === 1
16+
blue: this.counter % 2 === 1,
1717
};
1818
return html`<p class=${classMap(classes)}>Hello!</p>`;
1919
}
@@ -26,4 +26,4 @@ export class MyElement extends LitElement {
2626
color: blue;
2727
}
2828
`;
29-
}
29+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<script type="module" src="./my-element.js"></script>
22

3-
<my-element></my-element>
3+
<my-element></my-element>

packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/my-element.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { html, LitElement } from 'lit';
2-
import { customElement, state } from 'lit/decorators.js';
1+
import {html, LitElement} from 'lit';
2+
import {customElement, state} from 'lit/decorators.js';
33

44
@customElement('my-element')
55
export class MyElement extends LitElement {
@@ -14,13 +14,18 @@ export class MyElement extends LitElement {
1414

1515
return html`
1616
<button
17-
@click=${() => {this.someBoolean = !this.someBoolean}}>
17+
@click=${() => {
18+
this.someBoolean = !this.someBoolean;
19+
}}
20+
>
1821
Toggle template
1922
</button>
2023
<div>This is an inline ternary conditional</div>
21-
${this.someBoolean ? html`<p>Some other text</p>` : html`<p>Some text</p>`}
24+
${this.someBoolean
25+
? html`<p>Some other text</p>`
26+
: html`<p>Some text</p>`}
2227
<div>This is a variable conditional</div>
2328
${someText}
2429
`;
2530
}
26-
}
31+
}

0 commit comments

Comments
 (0)