Simplest example of vanilla webcomponent with no dependencies #23021
Unanswered
IORoot
asked this question in
Documentation
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It took me way too long to figure out how to get simple custom vanilla javascript webcomponents working in storybook.
The documentation has no examples and I couldn't find much documentation, so here's how to do it. (more for me to have a record to remember how to do it)
./stories/my-component.js// Define your web component class MyWebComponent extends HTMLElement { connectedCallback() { this.innerHTML = '<p>This is my web component</p>'; } } // Register your web component customElements.define('my-web-component', MyWebComponent);./stories/my-component.stories.jsThat's it. Storybook should now render your vanilla webcomponent. Sorry if this is super-basic, but I really struggled figuring this out since there were no examples I could find.
Beta Was this translation helpful? Give feedback.
All reactions