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+
}
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { html, LitElement } from 'lit';
2-
import { customElement } from 'lit/decorators.js';
3-
import { trustedStyles, type CSSStyleSheet } from './trusted-stringified-css-source.js';
1+
import {html, LitElement} from 'lit';
2+
import {customElement} from 'lit/decorators.js';
3+
import {
4+
trustedStyles,
5+
type CSSStyleSheet,
6+
} from './trusted-stringified-css-source.js';
47

58
// Use constructable stylesheets on TRUSTED CSS strings to use them in a LitElement
69
const styles = new CSSStyleSheet();
@@ -11,10 +14,6 @@ const styles = new CSSStyleSheet();
1114
export class MyElement extends LitElement {
1215
static styles = styles;
1316
render() {
14-
return html`
15-
<div>
16-
This should be red!
17-
</div>
18-
`;
17+
return html` <div>This should be red!</div> `;
1918
}
2019
}

packages/lit-dev-content/samples/articles/lit-cheat-sheet/constructable-stylesheets/trusted-stringified-css-source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const trustedStyles = `
55
`;
66

77
// This may be needed for some older versions of TS
8-
export type CSSStyleSheet = typeof globalThis['CSSStyleSheet'] & {
8+
export type CSSStyleSheet = (typeof globalThis)['CSSStyleSheet'] & {
99
replaceSync(cssText: string): void;
1010
replace(cssText: string): void;
1111
};

packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
</div>
2222
<div>
2323
<my-element></my-element>
24-
</div>
24+
</div>

packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/my-element.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 {
@@ -15,4 +15,4 @@ export class MyElement extends LitElement {
1515
render() {
1616
return html`<p part="paragraph">This is in a shadow root!</p>`;
1717
}
18-
}
18+
}
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 array='1,"2",3,4,"5"'></my-element>
3+
<my-element array='1,"2",3,4,"5"'></my-element>

packages/lit-dev-content/samples/articles/lit-cheat-sheet/custom-attribute-converter/my-element.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { html, LitElement } from 'lit';
2-
import { customElement, property, state } from 'lit/decorators.js';import {ComplexAttributeConverter} from 'lit';
1+
import {html, LitElement} from 'lit';
2+
import {customElement, property, state} from 'lit/decorators.js';
3+
import {ComplexAttributeConverter} from 'lit';
34

45
/**
56
* Bidirectionally converts an array from an attribute to a property of the
@@ -17,17 +18,15 @@ export const arrayConverter: ComplexAttributeConverter<Array<unknown>> = {
1718
} catch {
1819
return [];
1920
}
20-
}
21+
},
2122
};
2223

2324
@customElement('my-element')
2425
export class MyElement extends LitElement {
25-
@property({ converter: arrayConverter, reflect: true })
26-
array: Array<number|string> = [];
26+
@property({converter: arrayConverter, reflect: true})
27+
array: Array<number | string> = [];
2728

2829
render() {
29-
return this.array.map((item) =>
30-
html`<div>${typeof item}: ${item}</div>`
31-
);
30+
return this.array.map((item) => html`<div>${typeof item}: ${item}</div>`);
3231
}
33-
}
32+
}

packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/game-player.ts

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

44
export type ScoreEvent = CustomEvent<number>;
55

@@ -13,6 +13,8 @@ export class GamePlayer extends LitElement {
1313
}
1414

1515
handleScore(points: number) {
16-
this.dispatchEvent(new CustomEvent('score', { detail: points, bubbles: true }));
16+
this.dispatchEvent(
17+
new CustomEvent('score', {detail: points, bubbles: true}),
18+
);
1719
}
18-
}
20+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<script type="module" src="./score-board.js"></script>
22

3-
<score-board></score-board>
3+
<score-board></score-board>
Lines changed: 9 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
import './game-player.js';
44
import type {ScoreEvent} from './game-player.js';
55

@@ -12,9 +12,13 @@ export class ScoreBoard extends LitElement {
1212
return html`
1313
<h1>${this.playerOneScore} - ${this.playerTwoScore}</h1>
1414
<h2>Player 1</h2>
15-
<game-player @score=${(e: ScoreEvent) => this.playerOneScore += e.detail}></game-player>
15+
<game-player
16+
@score=${(e: ScoreEvent) => (this.playerOneScore += e.detail)}
17+
></game-player>
1618
<h2>Player 2</h2>
17-
<game-player @score=${(e: ScoreEvent) => this.playerTwoScore += e.detail}></game-player>
19+
<game-player
20+
@score=${(e: ScoreEvent) => (this.playerTwoScore += e.detail)}
21+
></game-player>
1822
`;
1923
}
20-
}
24+
}

0 commit comments

Comments
 (0)