Skip to content

Commit c07aeac

Browse files
authored
docs: update cdn examples. (#82)
1 parent a779a93 commit c07aeac

File tree

4 files changed

+142
-40
lines changed

4 files changed

+142
-40
lines changed

docs/examples.md

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,67 @@
11
# Examples
22

3-
### Import Map
3+
### CDN + ESM
44

5-
Using `tts-react` with ESM from a CDN and [import maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap):
5+
Using `tts-react` with ESM from a CDN:
6+
7+
```html
8+
<!doctype html>
9+
<html lang="en">
10+
<head>
11+
<meta charset="UTF-8" />
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
13+
<title>ESM + CDN</title>
14+
</head>
15+
<body>
16+
<script type="module">
17+
import { createElement } from 'https://esm.sh/react@rc/?dev'
18+
import { createRoot } from 'https://esm.sh/react-dom@rc/client?dev'
19+
import { TextToSpeech } from 'https://esm.sh/tts-react@next?deps=react@rc&dev'
20+
21+
createRoot(document.body).render(
22+
createElement(TextToSpeech, { markTextAsSpoken: true }, 'Hello from tts-react.')
23+
)
24+
</script>
25+
</body>
26+
</html>
27+
```
28+
29+
#### `htm`
30+
31+
Use [`htm`](https://github.com/developit/htm) for JSX-like syntax:
32+
33+
```html
34+
<!doctype html>
35+
<html lang="en">
36+
<head>
37+
<meta charset="UTF-8" />
38+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
39+
<title>ESM + CDN + htm</title>
40+
</head>
41+
<body>
42+
<script type="module">
43+
import { createElement } from 'https://esm.sh/react@rc/?dev'
44+
import { createRoot } from 'https://esm.sh/react-dom@rc/client?dev'
45+
import { TextToSpeech } from 'https://esm.sh/tts-react@next?deps=react@rc&dev'
46+
import htm from 'https://esm.sh/htm'
47+
48+
const html = htm.bind(createElement)
49+
50+
createRoot(document.body).render(
51+
html`
52+
<${TextToSpeech} markTextAsSpoken>
53+
<p>Hello from tts-react.</p>
54+
</${TextToSpeech}>
55+
`
56+
)
57+
</script>
58+
</body>
59+
</html>
60+
```
61+
62+
#### Import Map
63+
64+
You can also use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) if you prefer bare specifiers in your import statements:
665

766
```html
867
<!doctype html>
@@ -13,23 +72,30 @@ Using `tts-react` with ESM from a CDN and [import maps](https://developer.mozill
1372
<script type="importmap">
1473
{
1574
"imports": {
16-
"react": "https://esm.sh/react@rc",
17-
"react-dom/": "https://esm.sh/react-dom@rc/",
18-
"react/jsx-runtime": "https://esm.sh/react@rc/jsx-runtime",
19-
"tts-react": "https://esm.sh/tts-react@next"
75+
"react": "https://esm.sh/react@rc/?dev",
76+
"react-dom/client": "https://esm.sh/react-dom@rc/client?dev",
77+
"tts-react": "https://esm.sh/tts-react@next?deps=react@rc&dev",
78+
"htm": "https://esm.sh/htm"
2079
}
2180
}
2281
</script>
23-
<title>ESM / CDN / Import Map</title>
82+
<title>ESM + CDN + Import Map + htm</title>
2483
</head>
2584
<body>
2685
<script type="module">
2786
import { createElement } from 'react'
2887
import { createRoot } from 'react-dom/client'
2988
import { TextToSpeech } from 'tts-react'
89+
import htm from 'htm'
90+
91+
const html = htm.bind(createElement)
3092
3193
createRoot(document.body).render(
32-
createElement(TextToSpeech, { markTextAsSpoken: true }, 'Hello from tts-react.')
94+
html`
95+
<${TextToSpeech} markTextAsSpoken>
96+
<p>Hello from tts-react.</p>
97+
</${TextToSpeech}>
98+
`
3399
)
34100
</script>
35101
</body>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)