Skip to content

Commit d41a1f7

Browse files
committed
feat: add doc for web components in MDX
Related to withastro/roadmap#1260
1 parent d8df7a0 commit d41a1f7

File tree

1 file changed

+18
-0
lines changed
  • src/content/docs/en/guides/integrations-guide

1 file changed

+18
-0
lines changed

src/content/docs/en/guides/integrations-guide/mdx.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,24 @@ const { Content } = await render(entry);
247247
<Content components={{ h1: CustomHeading }} />
248248
```
249249

250+
### Using web components in MDX
251+
252+
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"`.
253+
The script will be executed on the client side.
254+
255+
```js title="src/web-component.js"
256+
class MyEl extends HTMLElement { ... }
257+
customElements.define('my-el', MyEl);
258+
```
259+
260+
```mdx title="src/Page.mdx"
261+
import webComponent from "./web-component.js?url";
262+
263+
<script src={webComponent} type="module"></script>
264+
265+
<my-el />
266+
```
267+
250268
## Configuration
251269

252270
Once the MDX integration is installed, no configuration is necessary to use `.mdx` files in your Astro project.

0 commit comments

Comments
 (0)