From 18538bf065683746f0eb791c733d4507fe6546da Mon Sep 17 00:00:00 2001 From: Elliott Marquez <5981958+e111077@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:34:30 -0700 Subject: [PATCH] [WIP] lit cheat sheet --- .../lit-cheat-sheet/add-styles/index.html | 3 + .../lit-cheat-sheet/add-styles/my-element.ts | 18 + .../lit-cheat-sheet/add-styles/project.json | 8 + .../lit-cheat-sheet/classes/index.html | 3 + .../lit-cheat-sheet/classes/my-element.ts | 29 ++ .../lit-cheat-sheet/classes/project.json | 8 + .../lit-cheat-sheet/conditionals/index.html | 3 + .../conditionals/my-element.ts | 26 + .../lit-cheat-sheet/conditionals/project.json | 8 + .../css-shadow-parts/index.html | 24 + .../css-shadow-parts/my-element.ts | 18 + .../css-shadow-parts/project.json | 8 + .../lit-cheat-sheet/data-up/game-player.ts | 18 + .../lit-cheat-sheet/data-up/index.html | 3 + .../lit-cheat-sheet/data-up/project.json | 9 + .../lit-cheat-sheet/data-up/score-board.ts | 20 + .../lit-cheat-sheet/define/hello-world.ts | 9 + .../lit-cheat-sheet/define/index.html | 3 + .../lit-cheat-sheet/define/project.json | 8 + .../event-listeners/index.html | 3 + .../event-listeners/my-element.ts | 47 ++ .../event-listeners/project.json | 8 + .../export-part/another-element.ts | 12 + .../lit-cheat-sheet/export-part/index.html | 12 + .../lit-cheat-sheet/export-part/my-element.ts | 10 + .../lit-cheat-sheet/export-part/project.json | 9 + .../lit-cheat-sheet/expressions/index.html | 3 + .../lit-cheat-sheet/expressions/my-element.ts | 62 +++ .../lit-cheat-sheet/expressions/project.json | 8 + .../host-global-listeners/index.html | 3 + .../host-global-listeners/my-element.ts | 55 ++ .../host-global-listeners/project.json | 8 + .../import/another-component.ts | 9 + .../lit-cheat-sheet/import/hello-world.ts | 10 + .../lit-cheat-sheet/import/index.html | 3 + .../lit-cheat-sheet/import/project.json | 9 + .../inheriting-custom-props/index.html | 21 + .../inheriting-custom-props/my-element.ts | 17 + .../inheriting-custom-props/project.json | 8 + .../lit-cheat-sheet/pass-data-down/id-card.ts | 20 + .../lit-cheat-sheet/pass-data-down/index.html | 3 + .../pass-data-down/my-wallet.ts | 12 + .../pass-data-down/project.json | 9 + .../lit-cheat-sheet/render-lists/index.html | 3 + .../render-lists/my-element.ts | 25 + .../lit-cheat-sheet/render-lists/project.json | 8 + .../lit-cheat-sheet/repeat/index.html | 3 + .../lit-cheat-sheet/repeat/my-element.ts | 38 ++ .../lit-cheat-sheet/repeat/project.json | 8 + .../lit-cheat-sheet/scope-styles/index.html | 4 + .../scope-styles/my-element.ts | 15 + .../lit-cheat-sheet/scope-styles/project.json | 8 + .../shadow-root-options/index.html | 3 + .../shadow-root-options/my-element.ts | 28 + .../shadow-root-options/project.json | 8 + .../share-styles-import/another-element.ts | 14 + .../share-styles-import/index.html | 5 + .../share-styles-import/my-element.ts | 19 + .../share-styles-import/project.json | 11 + .../share-styles-import/shared-styles.ts | 17 + .../turn-off-shadow-dom/index.html | 7 + .../turn-off-shadow-dom/my-element.ts | 16 + .../turn-off-shadow-dom/project.json | 8 + .../update-complete/index.html | 3 + .../update-complete/my-element.ts | 34 ++ .../update-complete/project.json | 8 + .../lit-cheat-sheet/virtualizer/index.html | 3 + .../lit-cheat-sheet/virtualizer/my-element.ts | 23 + .../lit-cheat-sheet/virtualizer/project.json | 8 + .../site/_includes/articles.html | 1 + .../site/articles/article/lit-cheat-sheet.md | 488 ++++++++++++++++++ packages/lit-dev-content/site/css/docs.css | 4 +- .../site/images/articles/lit_cheat_sheet.jpg | Bin 0 -> 12249 bytes .../images/articles/lit_cheat_sheet_2x.jpg | Bin 0 -> 21484 bytes .../src/components/litdev-example.ts | 69 ++- packages/lit-dev-server/src/server.ts | 10 + .../src/playground-plugin/plugin.ts | 36 +- 77 files changed, 1494 insertions(+), 28 deletions(-) create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/game-player.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/score-board.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/hello-world.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/another-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/another-component.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/hello-world.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/id-card.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/my-wallet.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/another-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/shared-styles.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/project.json create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/index.html create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/my-element.ts create mode 100644 packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/project.json create mode 100644 packages/lit-dev-content/site/articles/article/lit-cheat-sheet.md create mode 100644 packages/lit-dev-content/site/images/articles/lit_cheat_sheet.jpg create mode 100644 packages/lit-dev-content/site/images/articles/lit_cheat_sheet_2x.jpg diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/my-element.ts new file mode 100644 index 000000000..9fc3fecd0 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/my-element.ts @@ -0,0 +1,18 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + render() { + return html`

I'm blue

I'm red
`; + } + + static styles = css` + p { + color: blue; + } + div { + color: red; + } + `; +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/project.json new file mode 100644 index 000000000..816404c3d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/add-styles/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "100px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/my-element.ts new file mode 100644 index 000000000..e31973473 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/my-element.ts @@ -0,0 +1,29 @@ +import { html, LitElement, css } from 'lit'; +import { customElement, state } from 'lit/decorators.js'; +import { classMap } from 'lit/directives/class-map.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + @state() counter = 0 + + firstUpdated() { + setInterval(() => this.counter += 1 , 1000); + } + + render() { + const classes = { + red: this.counter % 2 === 0, + blue: this.counter % 2 === 1 + }; + return html`

Hello!

`; + } + + static styles = css` + .red { + color: red; + } + .blue { + color: blue; + } + `; +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/project.json new file mode 100644 index 000000000..816404c3d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/classes/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "100px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/my-element.ts new file mode 100644 index 000000000..860091f41 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/my-element.ts @@ -0,0 +1,26 @@ +import { html, LitElement } from 'lit'; +import { customElement, state } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + @state() private someBoolean = false; + + render() { + let someText = html`

Some text

`; + + if (this.someBoolean) { + someText = html`

Some other text

`; + } + + return html` + +
This is an inline ternary conditional
+ ${this.someBoolean ? html`

Some other text

` : html`

Some text

`} +
This is a variable conditional
+ ${someText} + `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/project.json new file mode 100644 index 000000000..9c791c2a3 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/conditionals/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "200px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/index.html new file mode 100644 index 000000000..63ef6c4b2 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/index.html @@ -0,0 +1,24 @@ + + + +
+ +
+
+ +
\ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/my-element.ts new file mode 100644 index 000000000..6fac25d2d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/my-element.ts @@ -0,0 +1,18 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + static styles = css` + p { + color: blue; + border: 1px solid black; + padding: 4px; + margin-block: 4px; + } + `; + + render() { + return html`

This is in a shadow root!

`; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/project.json new file mode 100644 index 000000000..875a71aaf --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/css-shadow-parts/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "120px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/game-player.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/game-player.ts new file mode 100644 index 000000000..fdfdab6a8 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/game-player.ts @@ -0,0 +1,18 @@ +import { html, LitElement } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +export type ScoreEvent = CustomEvent; + +@customElement('game-player') +export class GamePlayer extends LitElement { + render() { + return html` + + + `; + } + + handleScore(points: number) { + this.dispatchEvent(new CustomEvent('score', { detail: points, bubbles: true })); + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/index.html new file mode 100644 index 000000000..0e004d712 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/project.json new file mode 100644 index 000000000..9ccb50497 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/project.json @@ -0,0 +1,9 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "score-board.ts": {}, + "game-player.ts": {}, + "index.html": {} + }, + "previewHeight": "250px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/score-board.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/score-board.ts new file mode 100644 index 000000000..6a8d3dd36 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/data-up/score-board.ts @@ -0,0 +1,20 @@ +import { html, LitElement } from 'lit'; +import { customElement, state } from 'lit/decorators.js'; +import './game-player.js'; +import type {ScoreEvent} from './game-player.js'; + +@customElement('score-board') +export class ScoreBoard extends LitElement { + @state() playerOneScore = 0; + @state() playerTwoScore = 0; + + render() { + return html` +

${this.playerOneScore} - ${this.playerTwoScore}

+

Player 1

+ this.playerOneScore += e.detail}> +

Player 2

+ this.playerTwoScore += e.detail}> + `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/hello-world.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/hello-world.ts new file mode 100644 index 000000000..b4f5ba4d5 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/hello-world.ts @@ -0,0 +1,9 @@ +import { html, LitElement } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('hello-world') +export class HelloWorld extends LitElement { + render() { + return html`

Hello, world!

`; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/index.html new file mode 100644 index 000000000..c53974764 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/project.json new file mode 100644 index 000000000..6430bb8e9 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/define/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "hello-world.ts": {}, + "index.html": {} + }, + "previewHeight": "100px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/my-element.ts new file mode 100644 index 000000000..4d0219b83 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/my-element.ts @@ -0,0 +1,47 @@ +import { html, LitElement } from 'lit'; +import { customElement, query, state } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + @state() inputValue = ''; + @state() hasError = false; + @query('input') inputEl!: HTMLInputElement; + + render() { + return html` + +
+ + + + ${this.hasError ? html`Only positive numbers are allowed` : ''} +
${this.inputValue}
+
+ `; + } + + onInput(e: InputEvent) { + this.inputValue = (e.target as HTMLInputElement).value; + if (!this.inputValue.match(/^[0-9]+$/)) { + this.inputEl.dispatchEvent(new Event('number-error', {bubbles: true})); + return; + } + + this.inputEl.dispatchEvent(new Event('number-success', {bubbles: true})); + } + + onClick() { + this.inputValue = ''; + this.inputEl.focus(); + } + + onNumberError() { + this.hasError = true; + } + + onNumberSuccess() { + this.hasError = false; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/project.json new file mode 100644 index 000000000..9936a8af2 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/event-listeners/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "170px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/another-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/another-element.ts new file mode 100644 index 000000000..05456dd5d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/another-element.ts @@ -0,0 +1,12 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('another-element') +export class AnotherElement extends LitElement { + render() { + return html` +
Part 1
+
Part 2
+ `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/index.html new file mode 100644 index 000000000..09a583b4e --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/index.html @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/my-element.ts new file mode 100644 index 000000000..f13ab63c8 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/my-element.ts @@ -0,0 +1,10 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import './another-element.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + render() { + return html``; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/project.json new file mode 100644 index 000000000..911c75617 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/export-part/project.json @@ -0,0 +1,9 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "another-element.ts": {}, + "index.html": {} + }, + "previewHeight": "120px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/my-element.ts new file mode 100644 index 000000000..b2d40febd --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/my-element.ts @@ -0,0 +1,62 @@ +import { css, html, LitElement, PropertyValues } from 'lit'; +import { customElement, query, state } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + @state() htmlText = ''; + @state() disabled = false; + @state() label = 'label'; + @state() value = 'value'; + @query('input') inputEl!: HTMLElement; + + render() { + return html` + +
+ Renders to: +
${this.htmlText}
+
+ +
+ + + +
+ + `; + } + + updated(changed: PropertyValues) { + /* playground-fold */ + super.updated(changed); + this.htmlText = this.inputEl.outerHTML; + /* playground-fold-end */ + } + + static styles = css` + /* playground-fold */ + label { + display: block; + } + /* playground-fold-end */ + `; +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/project.json new file mode 100644 index 000000000..9936a8af2 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/expressions/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "170px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/my-element.ts new file mode 100644 index 000000000..47bc9b474 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/my-element.ts @@ -0,0 +1,55 @@ +import { html, LitElement, isServer } from 'lit'; +import { customElement, state } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + @state() focusedWithin = false; + @state() clickedOutside = false; + + render() { + return html` + + ${this.focusedWithin ? html`

Something in this component was focused

` : ''} + ${this.clickedOutside ? html`

Something was clicked OUTSIDE this component

` : ''} + `; + } + + connectedCallback(): void { + super.connectedCallback(); + + // Only want to do this in the browser since the server doesn't have the + // concept of events or document. + if (!isServer) { + document.addEventListener('click', this.onDocumentClick); + this.addEventListener('focusin', this.onFocusin); + this.addEventListener('focusout', this.onFocusout); + } + } + + disconnectedCallback() { + super.disconnectedCallback(); + + if (!isServer) { + // clean up to prevent memory leaks + document.removeEventListener('click', this.onDocumentClick); + // Garbage should also take care of removing these, but it's good practice + this.removeEventListener('focusin', this.onFocusin); + this.removeEventListener('focusout', this.onFocusout); + } + } + + // Should be an arrow function and not a class method to ensure `this` is + // bound correctly. + private onFocusin = () => { + this.focusedWithin = true; + }; + + private onFocusout = () => { + this.focusedWithin = false; + }; + + private onDocumentClick = (e: MouseEvent) => { + const path = e.composedPath(); + this.clickedOutside = !path.includes(this); + }; +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/project.json new file mode 100644 index 000000000..875a71aaf --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/host-global-listeners/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "120px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/another-component.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/another-component.ts new file mode 100644 index 000000000..375269012 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/another-component.ts @@ -0,0 +1,9 @@ +import { html, LitElement } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('another-component') +export class AnotherComponent extends LitElement { + render() { + return html`(I'm another component.)`; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/hello-world.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/hello-world.ts new file mode 100644 index 000000000..de5f2dccf --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/hello-world.ts @@ -0,0 +1,10 @@ +import { html, LitElement } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import './another-component.js' + +@customElement('hello-world') +export class HelloWorld extends LitElement { + render() { + return html`Hello, world! `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/index.html new file mode 100644 index 000000000..c53974764 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/project.json new file mode 100644 index 000000000..58dfe19ca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/import/project.json @@ -0,0 +1,9 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "hello-world.ts": {}, + "another-component.ts": {}, + "index.html": {} + }, + "previewHeight": "100px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/index.html new file mode 100644 index 000000000..5b273eb5d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/index.html @@ -0,0 +1,21 @@ + + + +
+ +
+
+ +
\ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/my-element.ts new file mode 100644 index 000000000..f6ed8d2d6 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/my-element.ts @@ -0,0 +1,17 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + static styles = css` + p { + color: var(--sys-color-on-background, blue); + border: 1px solid var(--sys-color-outline, black); + padding: var(--comp-my-element-padding, 4px); + margin-block: var(--comp-my-element-margin, 4px); + } + `; + render() { + return html`

This is in a shadow root!

`; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/project.json new file mode 100644 index 000000000..875a71aaf --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/inheriting-custom-props/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "120px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/id-card.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/id-card.ts new file mode 100644 index 000000000..b7a427e95 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/id-card.ts @@ -0,0 +1,20 @@ +import { html, LitElement } from 'lit'; +import { customElement, property } from 'lit/decorators.js'; + +@customElement('id-card') +export class IdCard extends LitElement { + @property() name = ''; + @property({ type: Number }) age = 0; + @property({ type: Boolean }) programmer = false; + + render() { + return html` +

${this.name}

+

Age: ${this.age}

+ + `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/index.html new file mode 100644 index 000000000..d5f0f24d5 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/my-wallet.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/my-wallet.ts new file mode 100644 index 000000000..0159d6911 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/my-wallet.ts @@ -0,0 +1,12 @@ +import { html, LitElement } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import './id-card.js'; + +@customElement('my-wallet') +export class MyWallet extends LitElement { + render() { + return html` + + `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/project.json new file mode 100644 index 000000000..c8faab7cf --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/pass-data-down/project.json @@ -0,0 +1,9 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-wallet.ts": {}, + "id-card.ts": {}, + "index.html": {} + }, + "previewHeight": "170px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/my-element.ts new file mode 100644 index 000000000..3e87d606a --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/my-element.ts @@ -0,0 +1,25 @@ +import {LitElement, html} from 'lit'; +import {customElement} from 'lit/decorators.js'; +import { map } from 'lit/directives/map.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + names = ['Chandler', 'Phoebe', 'Joey', 'Monica', 'Rachel', 'Ross']; + items = new Set(['Apple', 'Banana', 'Grape', 'Orange', 'Lime']) + + render() { + return html` +

A list of names that include the letter "e" (rendering an Array)

+ + +

My unique fruits (rendering a Set)

+ + `; + } +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/project.json new file mode 100644 index 000000000..00842cd85 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/render-lists/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "300px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/my-element.ts new file mode 100644 index 000000000..449c3537e --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/my-element.ts @@ -0,0 +1,38 @@ +import {LitElement, html} from 'lit'; +import {customElement, state} from 'lit/decorators.js'; +import {repeat} from 'lit/directives/repeat.js'; + +@customElement('my-element') +class MyElement extends LitElement { + @state() + tasks = [ + { id: 'a', label: 'Learn Lit'}, + { id: 'b', label: 'Feed the cat'}, + { id: 'c', label: 'Go for a walk'}, + { id: 'd', label: 'Take a nap'}, + ]; + + render() { + return html` +

Things to do today:

+ + + + `; + } + + private _sort(dir: number) { + this.tasks.sort((a, b) => a.label.localeCompare(b.label) * dir); + this.requestUpdate(); + } +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/project.json new file mode 100644 index 000000000..89b03c57f --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/repeat/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "180px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/index.html new file mode 100644 index 000000000..f22bdd0aa --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/index.html @@ -0,0 +1,4 @@ + + + +

I'm also a p, but I'm not blue.

\ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/my-element.ts new file mode 100644 index 000000000..65dae1c97 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/my-element.ts @@ -0,0 +1,15 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + render() { + return html`

I'm blue

`; + } + + static styles = css` + p { + color: blue; + } + `; +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/project.json new file mode 100644 index 000000000..816404c3d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/scope-styles/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "100px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/my-element.ts new file mode 100644 index 000000000..fd5901705 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/my-element.ts @@ -0,0 +1,28 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + static override shadowRootOptions = { + ...LitElement.shadowRootOptions, + delegatesFocus: true, + }; + + render() { + return html` +

+ Calling focus on this element will focus the first focusable element in + its shadow root thanks to delegatesFocus: true. Just try + clicking on this text and see how the input is focused instead. +

+ + `; + } + + static styles = css` + code { + background-color: #f4f4f4; + padding: 0.2em 0.4em; + } + `; +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/project.json new file mode 100644 index 000000000..816404c3d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/shadow-root-options/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "100px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/another-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/another-element.ts new file mode 100644 index 000000000..8da15f22c --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/another-element.ts @@ -0,0 +1,14 @@ +import { html, LitElement } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import {sharedStyles} from './shared-styles.js'; + +@customElement('another-element') +export class AnotherElement extends LitElement { + static styles = sharedStyles + + render() { + return html` + This <code> element shares styles with the <my-element> element. + `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/index.html new file mode 100644 index 000000000..239e0f7ef --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/index.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/my-element.ts new file mode 100644 index 000000000..a16e97136 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/my-element.ts @@ -0,0 +1,19 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import {sharedStyles} from './shared-styles.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + static styles = [sharedStyles, css` + p code { + background-color: #faff00; + } + `] + + render() { + return html` + This <code> element shares styles with the <another-element> element. +

I am overriding the <code> element in this <p> tag.

+ `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/project.json new file mode 100644 index 000000000..1b3c94174 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/project.json @@ -0,0 +1,11 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "another-element.ts": {}, + "shared-styles.ts": {}, + "index.html": {} + }, + "previewHeight": "150px" +} + diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/shared-styles.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/shared-styles.ts new file mode 100644 index 000000000..1bf46d01b --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/share-styles-import/shared-styles.ts @@ -0,0 +1,17 @@ +import { css } from 'lit'; + +export const sharedStyles = css` + :host { + display: block; + border: 1px solid black; + padding: 8px; + margin-block: 4px; + } + + code { + font-family: monospace; + background-color: #f4f4f4; + padding: 2px; + border-radius: 3px; + } +`; \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/index.html new file mode 100644 index 000000000..fb0358064 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/index.html @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/my-element.ts new file mode 100644 index 000000000..60aee491b --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/my-element.ts @@ -0,0 +1,16 @@ +import { html, LitElement, css } from 'lit'; +import { customElement } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + override createRenderRoot() { + return this; + } + + render() { + return html` +

This is not rendered in a shadow root

+

Styles from index.html will leak in and static styles do not apply

+ `; + } +} \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/project.json new file mode 100644 index 000000000..816404c3d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/turn-off-shadow-dom/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "100px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/my-element.ts new file mode 100644 index 000000000..9a1cddb7d --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/my-element.ts @@ -0,0 +1,34 @@ +import { css, html, LitElement } from 'lit'; +import { customElement, query, state } from 'lit/decorators.js'; +import {styleMap} from 'lit/directives/style-map.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + @state() width = 1000; + @state() sizeInfo = ''; + @query('#text') textEl!: HTMLElement; + + private async updateSize() { + this.width = Math.random() * 900; + + // Wait for the updateComplete promise to resolve before measuring the text. + await this.updateComplete; + const rect = this.textEl.getBoundingClientRect(); + this.sizeInfo = `The width and height of the text is ${rect.width} x ${rect.height} pixels.`; + } + + render() { + return html` + +

${this.sizeInfo}

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ `; + } + + static styles = css` + #text { + max-width: 100%; + border: 1px solid black; + } + `; +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/project.json new file mode 100644 index 000000000..00842cd85 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/update-complete/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "300px" +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/index.html b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/index.html new file mode 100644 index 000000000..57a0c9aca --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/index.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/my-element.ts b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/my-element.ts new file mode 100644 index 000000000..8161cfaaf --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/my-element.ts @@ -0,0 +1,23 @@ +import {LitElement, html} from 'lit'; +import {customElement} from 'lit/decorators.js'; +import '@lit-labs/virtualizer'; + +@customElement('my-element') +export class MyItems extends LitElement { + data = new Array(10000).fill('').map((i, n) => ({text: `Item ${n}`})); + + render() { + return html` + + `; + } +} diff --git a/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/project.json b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/project.json new file mode 100644 index 000000000..00842cd85 --- /dev/null +++ b/packages/lit-dev-content/samples/articles/lit-cheat-sheet/virtualizer/project.json @@ -0,0 +1,8 @@ +{ + "extends": "/samples/v3-base.json", + "files": { + "my-element.ts": {}, + "index.html": {} + }, + "previewHeight": "300px" +} diff --git a/packages/lit-dev-content/site/_includes/articles.html b/packages/lit-dev-content/site/_includes/articles.html index 3beccf0fb..66c4b431b 100644 --- a/packages/lit-dev-content/site/_includes/articles.html +++ b/packages/lit-dev-content/site/_includes/articles.html @@ -15,6 +15,7 @@ + {% endblock %} {% block content %} diff --git a/packages/lit-dev-content/site/articles/article/lit-cheat-sheet.md b/packages/lit-dev-content/site/articles/article/lit-cheat-sheet.md new file mode 100644 index 000000000..750ee3090 --- /dev/null +++ b/packages/lit-dev-content/site/articles/article/lit-cheat-sheet.md @@ -0,0 +1,488 @@ +--- +title: The Lit Cheat Sheet +publishDate: 2024-05-10 +lastUpdated: 2024-05-10 +summary: A quick reference for the basics of Lit +thumbnail: /images/articles/lit_cheat_sheet +tags: + - web-components + - web-components +eleventyNavigation: + parent: Articles + key: The Lit Cheat Sheet + order: 1 +author: + - elliott-marquez +preloadTsWorker: true +--- + +Do you need a quick reference for the basics of Lit? Look no further! This cheat +sheet will help you get started with, or just remember, the features of Lit. + +If you are coming from another framework, you might also want to supplement this +article with [Component Party](https://component-party.dev/) which compares +basic concepts across different frameworks. Just make sure that Lit is selected +at the top of the page! + +{% aside "positive" "no-header" %} + +Use the Table of Contents to jump to a specific section! + +{% endaside %} + +## Component Definition + +### Defining a Component + +`LitElement` is the base class for all Lit components. + +@customElementcustomElements.define is where you associate the name of your component with the class definition / logic of that component. + +`render()` is the method where you define your component's template using a tagged template literal with `html`. + +Write your HTML in the `html` tagged template literal. + +{% playground-ide "articles/lit-cheat-sheet/define", true %} + + +{% aside "info" %} + +Important rules: + +Components are global HTML elements, you currently can't have more than one with the same name on a page. + +Components must have dashes in their name (defined using @customElementcustomElements.define). + +{% endaside %} + + +**Related Documentation & Topics:** + +- [Defining a Component](/docs/components/defining/) +- [LitElement](/docs/api/LitElement/) +- [`@customElement`](/docs/api/decorators/#customElement) +- [`customElements.define`](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) +- [Rendering](/docs/components/rendering/) +- [How to build your first Lit component](https://www.youtube.com/watch?v=QBa1_QQnRcs) (Video) +- [How to style your Lit elements](https://www.youtube.com/watch?v=Xt7blcyuw5s) + +### Import a component + +To use a component, import the file with it's definition. + +{% playground-ide "articles/lit-cheat-sheet/import", true %} + +**Related Documentation & Topics:** + +- [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) (external) +- [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) (external) +- [JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) (external) +- [`@customElement`](/docs/api/decorators/#customElement) +- [`customElements.define`](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) (external) +- [Local dev servers (bare module specifiers)](/docs/tools/development/#devserver) + +## Templating + +### Render HTML + +Use the `html` tagged template literal to define your component's template. + +{% playground-ide "articles/lit-cheat-sheet/define", true %} + +**Related Documentation & Topics:** + +- [Templates Overview](/docs/templates/overview/) +- [Rendering](/docs/components/rendering/) + +### Conditionals + +Use standard JavaScript conditional expressions in your template to conditionally render content. + +{% playground-ide "articles/lit-cheat-sheet/conditionals", true %} + +**Related Documentation & Topics:** + +- [Conditionals](/docs/templates/conditionals/) +- [Expressions](/docs/templates/expressions/) + +### Attribute and Property Expressions (Binding syntax) + +Lit-html has three types of built-in expressions to set attributes or properties on elements: + +- Property expressions `.prop=${value}` +- Attribute expressions `attr=${value}` +- Boolean attribute expressions `?attr=${value}` + +{% playground-ide "articles/lit-cheat-sheet/expressions", true %} + +**Related Documentation & Topics:** + +- [Expressions](/docs/templates/expressions/) +- [Expressions – Attribute Expressions](/docs/templates/expressions/#attribute-expressions) +- [Expressions – Property Expressions](/docs/templates/expressions/#property-expressions) + +### Event Listener Expressions + +Lit-html has a built-in event listener expression to add event listeners to elements. + +{% playground-ide "articles/lit-cheat-sheet/event-listeners", true %} + +**Related Documentation & Topics:** + +- [Expressions](/docs/templates/expressions/) +- [Expressions – Event listener expressions](/docs/templates/expressions/#event-listener-expressions) +- [Events](/docs/components/events/) +- [Event communication between web components](https://www.youtube.com/watch?v=T9mxtnoy9Qw&themeRefresh=1) (video) +- [Customizing event listener options](/docs/components/events/#event-options-decorator) +- [A complete guide on shadow DOM and event propagation](https://pm.dartus.fr/posts/2021/shadow-dom-and-event-propagation/) (external) + +### Rendering lists + +Lit-html can render JavaScript arrays and iterables. For most simple use cases, +you can use the `Array.map()` method to render arrays of items or the `map()` +directive to render any other iterables. This pattern is best used for short, +simple lists. + +{% playground-ide "articles/lit-cheat-sheet/render-lists", true %} + +**Related Documentation & Topics:** + +- [Lists](/docs/templates/lists/) +- [Working With Lists Tutorial](/tutorials/working-with-lists/) +- [Built-in directives – `map()`](/docs/templates/directives/#map) +- [Built-in directives – `range()`](/docs/templates/directives/#range) +- [Built-in directives – `join()`](/docs/templates/directives/#join) + +### Re-rendering lists efficiently + +For long lists that may change frequently, use the `repeat()` directive to efficiently re-render only the items that have changed. + +{% playground-ide "articles/lit-cheat-sheet/repeat", true %} + +- [Lists](/docs/templates/lists/) +- [Working With Lists Tutorial – The `repeat()` directive](/tutorials/working-with-lists/#6) +- [Built-in directives – `repeat()`](/docs/templates/directives/#repeat) + +### Virtualizing long lists + +For lists that are so long that it would be impractical to render all items at once, use the Lit Virtualizer to render only the items that are currently in view. + +{% playground-ide "articles/lit-cheat-sheet/virtualizer", true %} + +{% aside "labs" %} + +Lit Virtualizer is in labs + +meaning that its implementation might change until it has graduated and become stable. Additionally there are many more features to virtualizer, so it is recommended to look at the documentation. + +{% endaside %} + +**Related Documentation & Topics:** + +- [Lit Virtualizer Documentation](https://github.com/lit/lit/tree/main/packages/labs/virtualizer#readme) (external) +- [Lit Labs: Virtualizer](https://www.youtube.com/watch?v=ay8ImAgO9ik) (video) + +## Styles + +### Add Styles + +Add styles by defining the `static styles` property. Write CSS in the `css` tagged template literal. + +{% playground-ide "articles/lit-cheat-sheet/add-styles", true %} + +**Related Documentation & Topics:** + +- [Styles](/docs/components/styles/) + +### Styles are Scoped + +Styles *only* apply to the current element. That means you can feel free to use super generic selectors that you'd normally have to make up class names for. + +{% playground-ide "articles/lit-cheat-sheet/scope-styles", true %} + +**Related Documentation & Topics:** + +- [Styles](/docs/components/styles/) +- [Shadow DOM](/docs/components/shadow-dom/) + +### Conditionally Add Classes + +To conditionally apply styles it's generally best to use `classMap`. + +{% playground-ide "articles/lit-cheat-sheet/classes", true %} + +**Related Documentation & Topics:** + +- [Defining Scoped Styles in the template](/docs/components/styles/#styles-in-the-template) +- [`classMap`](/docs/templates/directives/#classmap) +- [`classMap` tsdoc](/docs/api/directives/#classMap) +- [Playground example](/playground/#sample=examples/directive-class-map) + + +### Sharing Lit styles with imports + +You can share Lit stylesheets with other components by exporting them from a module and importing them into another. + +{% playground-ide "articles/lit-cheat-sheet/share-styles-import", true %} + +- [Styling](/docs/components/styles/) +- [Sharing Styles](/docs/components/styles/#sharing-styles) + +### Inheriting Styles Through Shadow DOM With CSS Custom Properties + + +CSS Custom Properties can pierce multiple shadow roots allowing you to share values for specific properties. + +{% playground-ide "articles/lit-cheat-sheet/inheriting-custom-props", true %} + +**Related Documentation & Topics:** + +- [CSS Custom Properties](/docs/components/styles/#customprops) +- [Theming](/docs/components/styles/#theming) +- [How to style your Lit elements](https://www.youtube.com/watch?v=Xt7blcyuw5s) (Video) + +### Setting Arbitrary Styles With CSS Shadow Parts + +CSS Shadow Parts are exposed by components with the `part=""` attribute. + +Shadow Parts can pierce individual shadow roots allowing you to set arbitrary styles on a given node using the `::part()` pseudo-element. + +{% playground-ide "articles/lit-cheat-sheet/css-shadow-parts", true %} + +**Related Documentation & Topics:** + +- [How to style your Lit elements](https://www.youtube.com/watch?v=Xt7blcyuw5s) (video) +- [CSS Shadow Parts](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_shadow_parts) (external) +- [`::part`](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) (external) + +### Exporting a CSS Shadow Part + +CSS Shadow part names can only apply to the targeted element. You need to use `exportparts` to expose a shadow part in nested shadow roots. + +You can export multiple parts by separating them with a comma (`,`). + +You can also rename parts with a colon (`:`). + +{% playground-ide "articles/lit-cheat-sheet/export-part", true %} + +**Related Documentation & Topics:** + +- [`exportparts`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/exportparts) (external) +- [How to style your Lit elements](https://www.youtube.com/watch?v=Xt7blcyuw5s) (video) +- [CSS Shadow Parts](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_shadow_parts) (external) +- [`::part`](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) (external) + +## Shadow DOM + +### What does Shadow DOM do? + +- Scopes styles to the shadow root +- Scopes the DOM to the shadow root + - Can't be targeted by querySelector calls from outside the shadow root +- Enables slotting content with the `` element +- Exposes an API for CSS with CSS Custom Properties and CSS Shadow Parts + +**Related Documentation & Topics:** + +- [DOM Encapsulation](/docs/components/rendering/#dom-encapsulation) +- [Working with Shadow DOM](/docs/components/shadow-dom/) +- [How to style your Lit elements](https://www.youtube.com/watch?v=Xt7blcyuw5s) (video) + +### Turn off Shadow DOM + +You can turn off the Shadow DOM by overriding the `createRenderRoot()` method and setting the render root to the element itself. + +{% playground-ide "articles/lit-cheat-sheet/turn-off-shadow-dom", true %} + +{% aside "warn" %} + +By turning off shadow DOM you lose the benefits of encapsulation, DOM scoping, and `` elements. + +Since the Shadow root no longer exists, Lit will no longer handle the `static styles` property for you. You must must decide how to handle your styles. + +{% endaside %} + +**Related Documentation & Topics:** + +- [Implementing `createRenderRoot()`](/docs/components/shadow-dom/#implementing-createrenderroot) + +### Turning on `delegatesFocus` and other shadow root options + +You can set shadow root options passed to `Element.attachShadow()` by overriding the static `shadowRootOptions` member. + +{% playground-ide "articles/lit-cheat-sheet/shadow-root-options", true %} + +**Related Documentation & Topics:** + +- [Setting `shadowRootOptions`](/docs/components/shadow-dom/#setting-shadowrootoptions) +- [`Element.prototype.attachShadow():options`](https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow#options) (external) +- [`delegatesFocus`](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/delegatesFocus) (external) + +## Properties and State + +## Lifecycle + +### Lifecycle order + +There are two lifecycles in Lit, the native Web Component lifecycle and the +lifecycle that Lit adds on top of it to help handle property and state changes. + +There are more lifecycle events which can be +[found in the documentation](/docs/components/lifecycle/#reactive-update-cycle), +but the ones you would normally use are the following and this is their general +order: + +1. `constructor` – (Native custom element lifecycle) +2. `connectedCallback` – (Native) +3. `willUpdate` – (Lit lifecycle) +4. `update` – (Lit) +5. `render` – (Lit) +6. `firstUpdated` – (Lit) +7. `updated` – (Lit) +8. `disconnectedCallback` – (Native) + +{% aside "warn" %} + +The Lit lifecycle and the native custom element lifecycle are distinct and managed separately. + +While they generally follow a specific order, they may intermix because the +browser controls the native lifecycle, while Lit and JavaScript manage the Lit +lifecycle. + +For example, a component may be attached to the DOM and then removed before the +Lit lifecycle may run at all, or a component may be created with +`document.createElement` which would call the `constructor`, but if it's never +added to the DOM, the `connectedCallback` would never run and thus the Lit +lifecycle would never run. + +{% endaside %} + +**Related Documentation & Topics:** + +- [Lifecycle](/docs/components/lifecycle/) +- [Lifecycle diagram](/docs/components/lifecycle/#reactive-update-cycle) + +#### `constructor` + +- Runs when the element is created via: + - `document.createElement('my-element')` + - `element.innerHTML = ''` + - `new MyElement()` + - etc. +- A good place to set initial properties +- Do **NOT** require parameters in the constructor or modify DOM + +#### `connectedCallback` + +- *May* run on the server. This has not been finalized. +- Runs when the element is added to the DOM via: + - `element.appendChild(element)` + - `element.innerHTML = ''` + - etc. +- Can run multiple times, but a good spot to set up event listeners + +#### `willUpdate` + +- Runs on the server – do **NOT** access the DOM or browser APIs +- A good place to set up properties that depend on other properties + +#### `update` + +- A good place to update properties that depend on other properties that depend on DOM + +#### `render` + +- Runs on the server - do NOT access the DOM or browser APIs + +#### `firstUpdated` + +- Runs after the first render +- A good place to do some initializations that require the copmonent's rendered + DOM + +#### `updated` + +- A good place to do some updates that require the component's rendered DOM or + to update properties that depend on the rendered DOM +- Try to avoid setting reactive properties in this lifecycle as it may cause + unnecessary renders. Try to do them in `willUpdate` or `update` if possible. + +#### `disconnectedCallback` + +- Is called *AFTER* the element is removed from the DOM +- A good place to clean up event listeners + +### Waiting for an update + +All Lit elements have asynchronous lifecycles. You need to wait for the `updateComplete` promise to resolve before you can be sure that the element has finished updating its DOM. + +{% playground-ide "articles/lit-cheat-sheet/update-complete", true %} + +**Related Documentation & Topics:** + +- [Lifecycle](/docs/components/lifecycle/) +- [updateComplete()](/docs/components/lifecycle/#updatecomplete) +- [requestUpdate()](/docs/components/lifecycle/#requestUpdate) + +### Adding listeners to host element or globally + +A common pattern is to add event listeners to the host element or globally in the `connectedCallback` and remove them in the `disconnectedCallback`. + +{% playground-ide "articles/lit-cheat-sheet/host-global-listeners", true %} + +**Related Documentation & Topics:** + +- [Lifecycle](/docs/components/lifecycle/) +- [Events](/docs/components/events/) +- [Authoring components for Lit SSR](/docs/ssr/authoring/) +- [A complete guide on shadow DOM and event propagation](https://pm.dartus.fr/posts/2021/shadow-dom-and-event-propagation/) (external) + +## Data Flow and State Management + +### Pass data down + +The simplest way to pass data down is to use properties and attributes. + +For example, you can pass data down to child components using property bindings like this: + +`.name=${'Steven'}` + +For boolean properties, use a question mark instead of a period, like this: + +`?programmer=${true}`. + +You generally want to expose you component's external attribute and property API with @property() instead of @state()static properties = {propName: {state: false}}. + +{% playground-ide "articles/lit-cheat-sheet/pass-data-down", true %} + +**Related Documentation & Topics:** + +- [Expressions](/docs/templates/expressions/) +- [Expressions – Attribute Expressions](/docs/templates/expressions/#attribute-expressions) +- [Expressions – Property Expressions](/docs/templates/expressions/#property-expressions) +- [Event communication between web components](https://www.youtube.com/watch?v=T9mxtnoy9Qw&themeRefresh=1) (video) + +### Dispatch Events Up + +To send data up the tree to ancestors, you can dispatch custom events. Yo emit an event, use `Element.dispatchEvent()`. + +`dispatchEvent()` takes an event object as the first argument. Construct a custom event object like this: + +`new CustomEvent('event-name', {detail: data, bubbles: true, composed: true})` + +Provide data you wat to pass to ancestors in the `detail` property of the event, and ancestors can react to the event by adding an event listener to the component like this: + +`@event-name=${this.eventHandler}` + +If you want an event to bubble through shadow Roots, set `composed: true`. + +{% playground-ide "articles/lit-cheat-sheet/data-up", true %} + +**Related Documentation & Topics:** + +- [Event communication between web components](https://www.youtube.com/watch?v=T9mxtnoy9Qw&themeRefresh=1) (video) +- [A complete guide on shadow DOM and event propagation](https://pm.dartus.fr/posts/2021/shadow-dom-and-event-propagation/) (external) +- [Expressions](/docs/templates/expressions/) +- [Expressions – Event listener expressions](/docs/templates/expressions/#event-listener-expressions) +- [Events](/docs/components/events/) +- [Customizing event listener options](/docs/components/events/#event-options-decorator) diff --git a/packages/lit-dev-content/site/css/docs.css b/packages/lit-dev-content/site/css/docs.css index e72209812..dc94c35bc 100644 --- a/packages/lit-dev-content/site/css/docs.css +++ b/packages/lit-dev-content/site/css/docs.css @@ -137,11 +137,11 @@ litdev-example[filename] { } body[code-language-preference="ts"] litdev-example { - --litdev-example-editor-height: calc(var(--litdev-example-editor-lines-ts) * 22px + 22px); + --litdev-example-editor-height: calc(var(--litdev-example-editor-lines-ts) * 22.4px + 22px); } body[code-language-preference="js"] litdev-example { - --litdev-example-editor-height: calc(var(--litdev-example-editor-lines-js) * 22px + 22px); + --litdev-example-editor-height: calc(var(--litdev-example-editor-lines-js) * 22.4px + 22px); } litdev-example { diff --git a/packages/lit-dev-content/site/images/articles/lit_cheat_sheet.jpg b/packages/lit-dev-content/site/images/articles/lit_cheat_sheet.jpg new file mode 100644 index 0000000000000000000000000000000000000000..432687ec13cd1f33401027cba900a4e1f89a9497 GIT binary patch literal 12249 zcmc(F2{;s7+we$58>*+Y4P$9%3}c-!p(v7s%2E?!48}GXV??r~&?ePmEA)!&YpG#~ zWT{ADEM-W9Y$IjK{@+v2)BC>P|32UMUjO&~|L;=nIp;q2cJA$*GvUXM9$K?<%Sr?S zvBp4O*A#(R;*CHEI0`R^k@q%_BjC>pcYRAb0KCbS7jX-E>`M8tF&J-_{EyaQAMvxw5mr0|jb_8j26(fw1`vHn0Ro~Z> zV&;4FIN8^ktYIguwGXA~g98Gt6fY9W$JND+j`JZ%|DcNlm_Mu_jrxJ&8 z7#%|$pm|bI8fZm%G6tiBQqw?_R7t8>4OMlL97+kJq^y9!DqvLQ6%}zRN;r%P>W?33 zVCZRQk2BRh_y;@qM38p$@^Z&1C@`5!G!u)ac{(U4YG`OEV3ZV;l;iss#m$QjxQf4U!B9ptBciaI_3dxJ+d7MUb`O|%l{YeF7PO(Mp;(H4kJPD0KsgTu`?d+8) zSVg7Xs9lF>GzS+7>VTss&6Tp7ZhEvp#$Ee{j zn4hRd;JbDtFVg>xtcp{_;FMMV37KX`wLkk`qS}#h_B2md5^O8gmE=HCaCdX~!Oh4B zXW&NnBDs+%2D$`k5EV_O+TpNRMT(lLin2UeSw&S|SxHG%UR^_xB(FqKQ&F*1!BT8h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$E&`2W6!Hn zNzoFIL-ESvrSJF+gxGmt=6Q0G+p#!3cXe6k^jC3gKzy1YzX(cqy;NzmUZ~2}`jBE_ z^(5xjBhr^=V~yQA(ox<+t^2+~;Rw5IAsy*+U>(~z@CN&w-posd)0){Wn9M}q(_y6hFX#VM|I+g3f vbt^`7Kmrs~@8(g%JrjN?`0(Oo)uO0T--GiblDps|0%4$cR5xe8P4NE$(?2*| literal 0 HcmV?d00001 diff --git a/packages/lit-dev-content/site/images/articles/lit_cheat_sheet_2x.jpg b/packages/lit-dev-content/site/images/articles/lit_cheat_sheet_2x.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e8d88d89d8cb1a532a77b69f745744de23d4951a GIT binary patch literal 21484 zcmeIac{tT=_b9%}kSL-QnKKnKhHXyDl%e5aM`7D!w%O*H%w!0u$j~4>61zfWYM@OS z%9M=JM&@~*&ibh5dEf8(z3=(H*YBL`I{%!m>v`Ir&*#3^z3w%yb+5Zl5BiE-)H}Qd0GH!QvdO-FYmnZS0(t`KHUO`FQNCl=+NL>PhIioVK>L z)AA))U-Z?#g!6U4p{@8-Rd|%V6##&fwL6x_+sV<{O~G54ZwIad{6=1j^YQEqad%MW zJB2LBgV8hOIgKY+^Po>iis2+Aqk8|-LIPNTNg%h`Sw05#~c6WoZl7Ei{Lh0%KJ^WvSb#nT9w43`G zPr&H+-u~riw@W@Q*5Vhe-S8d+ob?$`Sn=pzh`G66u>J>W{)6c-{O`%`cGv#RT;$7t zA%L~F-M<-%eEBa!U2O60csE=8zaj14pZ}iZqHvmEjdjNpF5&Txe~FLbUr>0Atu1+k z5otLAl5|3X=Oj*E#_F1kwX~$vF&<$}Jl@99n&-4F0qSi;R(Kr1_?xN>NZnzW3Bm87J+EY|wh-T@l}f*sfZtm8jJMX<6$u(FiG;iTlG#H?^u zQeral(twquv;^R1i3NDFR#rG!J|09+5HNre7SS?gKFQxNF^IrAdi;7RCnW)Y#3hmc z|NegYzxn=;&wn`E0V$>Uco0!jIE{D26E1=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ZF6zW({^p$LyK#x0LdrxBMG3anp{_%1_x$OTZSaBK$rvy=btAG`TaXmDej Z`#@o{LzZ3L2v82CeMVp7sk+7W{{d(&h;IM@ literal 0 HcmV?d00001 diff --git a/packages/lit-dev-content/src/components/litdev-example.ts b/packages/lit-dev-content/src/components/litdev-example.ts index 705d58556..6dbc2d222 100644 --- a/packages/lit-dev-content/src/components/litdev-example.ts +++ b/packages/lit-dev-content/src/components/litdev-example.ts @@ -5,7 +5,7 @@ */ import {LitElement, html, css, nothing} from 'lit'; -import {property} from 'lit/decorators.js'; +import {property, state} from 'lit/decorators.js'; import {styleMap} from 'lit/directives/style-map.js'; import {ifDefined} from 'lit/directives/if-defined.js'; import { @@ -110,6 +110,23 @@ export class LitDevExample extends LitElement { @property() project?: string; + /** + * Whether to load the project on intersection with the viewport. + */ + @property({type: Boolean}) + lazy = false; + + /** + * Whether or not to load the project. Setting Lazy to true will re-initialize + * this value to `false`. We would want to do this so that we do not load the + * large TS worker file until the user has scrolled to the example. This is + * something we would want to do if we want to have the server cache the + * worker. Otherwise every example on the page would load the worker at the + * same time and none of them would be cached. + */ + @state() + private loadProject = true; + /** * Name of file in project to display. * If no file is provided, we show the tab-bar with all project files. @@ -143,6 +160,12 @@ export class LitDevExample extends LitElement { this.requestUpdate(); }; + willUpdate() { + if (!this.hasUpdated) { + this.loadProject = !this.lazy; + } + } + render() { if (!this.project) { return nothing; @@ -162,17 +185,23 @@ export class LitDevExample extends LitElement { mode === 'ts' ? this.filename : this.filename?.replace(/.ts$/, '.js'); return html` - - + ${this.loadProject + ? // We need to conditionally render this because playground-project + // will load its serviceworker on firstUpdated + html` + ` + : nothing}
${showTabBar ? html`` : nothing} @@ -184,15 +213,35 @@ export class LitDevExample extends LitElement { - + `; } + + firstUpdated() { + if (this.lazy) { + const io = new IntersectionObserver( + (entries) => { + if (entries[0].isIntersecting) { + this.loadProject = true; + io.disconnect(); + } + }, + { + rootMargin: '40px', + } + ); + + io.observe(this); + } + } } customElements.define('litdev-example', LitDevExample); diff --git a/packages/lit-dev-server/src/server.ts b/packages/lit-dev-server/src/server.ts index c3b71cf67..23da80b89 100644 --- a/packages/lit-dev-server/src/server.ts +++ b/packages/lit-dev-server/src/server.ts @@ -92,6 +92,16 @@ app.use( if (path.includes('/fonts/')) { res.setHeader('Cache-Control', 'max-age=31536000'); } + if (path.includes('/playground-typescript-worker.js')) { + // This is a huge file, so we want to cache the request for 2 minutes + // which should basically handle a page with multiple playgrounds. + // Then after those two minutes, it will use the same cached file for a + // day while it revalidates the cache in the background. + res.setHeader( + 'Cache-Control', + 'max-age=120, stale-while-revalidate=86400' + ); + } }, }) ); diff --git a/packages/lit-dev-tools-cjs/src/playground-plugin/plugin.ts b/packages/lit-dev-tools-cjs/src/playground-plugin/plugin.ts index e9fa8c5c9..5fd291e3d 100644 --- a/packages/lit-dev-tools-cjs/src/playground-plugin/plugin.ts +++ b/packages/lit-dev-tools-cjs/src/playground-plugin/plugin.ts @@ -163,31 +163,35 @@ export const playgroundPlugin = ( (code: string, lang: 'js' | 'ts' | 'html' | 'css') => render(code, lang) ); - eleventyConfig.addShortcode('playground-ide', async (project: string) => { - if (!project) { - throw new Error( - `Invalid playground-ide invocation.` + - `Usage {% playground-ide "path/to/project" %}` + eleventyConfig.addShortcode( + 'playground-ide', + async (project: string, lazy = false) => { + if (!project) { + throw new Error( + `Invalid playground-ide invocation.` + + `Usage {% playground-ide "path/to/project" %}` + ); + } + project = trimTrailingSlash(project); + const config = await readProjectConfig(project); + const firstFilename = Object.keys(config.files ?? {})[0]; + const numVisibleLines = await getNumVisibleLinesForProjectFile( + project, + firstFilename ); - } - project = trimTrailingSlash(project); - const config = await readProjectConfig(project); - const firstFilename = Object.keys(config.files ?? {})[0]; - const numVisibleLines = await getNumVisibleLinesForProjectFile( - project, - firstFilename - ); - const previewHeight = config.previewHeight ?? '120px'; - return ` + const previewHeight = config.previewHeight ?? '120px'; + return ` `.trim(); - }); + } + ); type LitProjectConfig = ProjectManifest & { previewHeight?: string;