Skip to content

Commit 6da7195

Browse files
Create web-component-in-mdx.mdx (#411)
1 parent b67389c commit 6da7195

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Using web components in MDX
3+
astroRange: ^4.0.0
4+
---
5+
6+
If you have a web component defined in a separate JavaScript file, you can include it in your MDX file by importing the script and adding a `<script>` tag with `type="module"`.
7+
The script will be executed on the client side.
8+
9+
```js title="src/web-component.js"
10+
class MyEl extends HTMLElement { ... }
11+
customElements.define('my-el', MyEl);
12+
```
13+
14+
Then in your `.mdx` file you can import it
15+
16+
```mdx title="src/Page.mdx"
17+
import webComponent from "./web-component.js?url";
18+
19+
<script src={webComponent} type="module"></script>
20+
21+
<my-el />
22+
```

0 commit comments

Comments
 (0)