Skip to content

Commit e3b555f

Browse files
authored
[examples] Update React examples (#1122)
1 parent 562f1e4 commit e3b555f

38 files changed

+292
-279
lines changed

package-lock.json

+42-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lit-dev-content/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@
172172
"@lit-labs/ssr": "^3.1.2",
173173
"@lit-labs/ssr-client": "^1.1.1",
174174
"@rollup/plugin-node-resolve": "^15.0.1",
175+
"@types/react": "^18.2.6",
176+
"@types/react-dom": "^18.2.4",
175177
"clean-css": "^5.1.0",
176178
"codemirror": "^5.58.2",
177179
"eleventy-plugin-nesting-toc": "^1.3.0",
@@ -203,7 +205,6 @@
203205
"@material/mwc-formfield": "^0.27.0",
204206
"@material/mwc-snackbar": "^0.27.0",
205207
"@material/mwc-textfield": "^0.27.0",
206-
"@types/react": "^18.0.17",
207208
"@webcomponents/template-shadowroot": "^0.2.1",
208209
"algoliasearch": "^4.14.2",
209210
"lit": "^2.7.4",

packages/lit-dev-content/samples/examples/motion-carousel/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "/samples/base.json",
33
"title": "Carousel Transitions",
44
"description": "Animated carousel.",
5-
"section": "Motion",
5+
"section": "@lit-labs/motion",
66
"files": {
77
"motion-carousel.ts": {},
88
"styles.ts": {},

packages/lit-dev-content/samples/examples/motion-grid/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "/samples/base.json",
33
"title": "Grid Layout Transitions",
44
"description": "Animate css grid layouts.",
5-
"section": "Motion",
5+
"section": "@lit-labs/motion",
66
"files": {
77
"motion-grid.ts": {},
88
"styles.ts": {},

packages/lit-dev-content/samples/examples/motion-hero/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "/samples/base.json",
33
"title": "List/Detail Hero Transition",
44
"description": "Hero animation.",
5-
"section": "Motion",
5+
"section": "@lit-labs/motion",
66
"files": {
77
"motion-hero.ts": {},
88
"styles.ts": {},

packages/lit-dev-content/samples/examples/motion-in-out/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "/samples/base.json",
33
"title": "Lit Logo Animation",
44
"description": "Animate elements when they go in and out of the page.",
5-
"section": "Motion",
5+
"section": "@lit-labs/motion",
66
"files": {
77
"motion-lit.ts": {},
88
"styles.ts": {},

packages/lit-dev-content/samples/examples/motion-list/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "/samples/base.json",
33
"title": "List Item Animation",
44
"description": "Animate list items.",
5-
"section": "Motion",
5+
"section": "@lit-labs/motion",
66
"files": {
77
"motion-list.ts": {},
88
"styles.ts": {},

packages/lit-dev-content/samples/examples/motion-simple/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "/samples/base.json",
33
"title": "Sliding Circle",
44
"description": "Simple `animate()` directive example.",
5-
"section": "Motion",
5+
"section": "@lit-labs/motion",
66
"files": {
77
"motion-slide.ts": {},
88
"index.html": {},

packages/lit-dev-content/samples/examples/motion-todos/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "/samples/base.json",
33
"title": "Todos List Transitions",
44
"description": "Animated list of todos.",
5-
"section": "Motion",
5+
"section": "@lit-labs/motion",
66
"files": {
77
"motion-todos.ts": {},
88
"styles.ts": {},
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import {React, ReactDOM} from './react.js';
1+
import React from 'https://esm.sh/react@18';
2+
import {createRoot} from 'https://esm.sh/react-dom@18/client';
23
import {createComponent} from '@lit-labs/react';
34
import {DemoGreeting as DemoGreetingWC} from './demo-greeting.js';
45

6+
// Creates a React component from a Lit component
57
const DemoGreeting = createComponent({
68
react: React,
79
tagName: 'demo-greeting',
8-
elementClass: DemoGreetingWC
10+
elementClass: DemoGreetingWC,
911
});
1012

11-
const node = document.querySelector('#app');
12-
const root = ReactDOM.createRoot(node!);
13+
const root = createRoot(document.getElementById('app')!);
1314

14-
root.render(<DemoGreeting name={'React'}></DemoGreeting>);
15+
root.render(<DemoGreeting name="React" />);
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
import { html, LitElement } from 'lit';
2-
import { customElement, property } from 'lit/decorators.js';
1+
import {html, css, LitElement} from 'lit';
2+
import {customElement, property} from 'lit/decorators.js';
33

4+
// A plain Lit component which can be used in any framework
45
@customElement('demo-greeting')
56
export class DemoGreeting extends LitElement {
7+
static styles = css`
8+
p {
9+
display: inline-block;
10+
border: solid 1px gray;
11+
background: white;
12+
padding: 0 1em;
13+
}
14+
`;
15+
616
@property() name = 'Somebody';
717

818
render() {
9-
return html`
10-
<p>Hello, ${this.name}!</p>
11-
<p>Checkout our <a href="https://lit.dev/docs/frameworks/react/" target="_blank" rel="noopener noreferrer">React framework docs</a>!</p>
12-
`;
19+
return html`<p>Hello, ${this.name}!</p>`;
20+
}
21+
}
22+
23+
declare global {
24+
interface HTMLElementTagNameMap {
25+
'demo-greeting': DemoGreeting;
1326
}
1427
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<!doctype html>
22
<head>
3-
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
4-
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
53
<script type="module" src="./app.js"></script>
64
</head>
75
<body>
86
<div id="app"></div>
7+
<p>Checkout our <a href="https://lit.dev/docs/frameworks/react/" target="_blank" rel="noopener noreferrer">React framework docs</a>!</p>
98
</body>

packages/lit-dev-content/samples/examples/react-basics/project.json

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
"order": 0,
44
"title": "Basics",
55
"description": "Render web components in React apps.",
6-
"section": "React",
6+
"section": "@lit-labs/react",
77
"files": {
8-
"app.tsx": {"contentType": "text/typescript-jsx"},
8+
"app.tsx": {
9+
"contentType": "text/typescript-jsx"
10+
},
911
"demo-greeting.ts": {},
10-
"react.ts": {},
11-
"index.html": {}
12+
"react.d.ts": {
13+
"content": "declare module 'https://esm.sh/react@18' {\n export default React;\n}\n\ndeclare module 'https://esm.sh/react-dom@18/client' {\n export * from 'react-dom/client';\n}",
14+
"hidden": true
15+
},
16+
"index.html": {},
17+
"package.json": {
18+
"content": "{\n \"dependencies\": {\n \"lit\": \"^2\",\n \"@types/react\": \"^18\",\n \"@types/react-dom\": \"^18\",\n \"@types/react-dom/client\": \"^18\"\n }\n}",
19+
"hidden": true
20+
}
1221
}
1322
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'https://esm.sh/react@18' {
2+
export default React;
3+
}
4+
5+
declare module 'https://esm.sh/react-dom@18/client' {
6+
export * from 'react-dom/client';
7+
}

packages/lit-dev-content/samples/examples/react-basics/react.ts

-3
This file was deleted.

packages/lit-dev-content/samples/examples/react-custom-event/app.tsx

-38
This file was deleted.

packages/lit-dev-content/samples/examples/react-custom-event/index.html

-9
This file was deleted.

packages/lit-dev-content/samples/examples/react-custom-event/project.json

-13
This file was deleted.

0 commit comments

Comments
 (0)