Yes, but Atomico doesn't only depend on ESM, it also depends on the following api's that you will have to cover with Polyfill or some bundle tool.
ESM modules: documentation - caniuse
CustomElements: documentation - caniuse
ShadowRoot: documentation - caniuse
Map: documentation - caniuse
Symbol and Symbol.for: documentation - caniuse
append and prepend: documentation - caniuse
Declarative Shadow DOM: Only for using SSR with webcomponents that use shadowDOM. documentation
Let's understand that today Atomico covers 94% of existing browsers without the need for polyfills or packers, the 6% not covered are usually browsers like ie11 or others.
If you depend on the uncovered segment of browsers you can use the following tools to support the apis necessary for Atomico to work.
polyfill-fastly.io to associate Map, Symbol, append and prepend.
https://github.com/Rich-Harris/shimport to associate esm.
https://github.com/ungap/custom-elements to associate customElements apis.
By creating a UI solution that coexists in the web ecosystem such as HTML, libraries and frameworks, since the shadowDOM allows you to:
Protect your UI from libraries like React, Vue and others
Associate styles natively, efficiently and safely
Reference lightDOM content in the shadowDOM
Webcomponents with Shadow DOM are ideal for creating cross UI solutions as they coexist without conflict with the entire web ecosystem.
To protect our component at the DOM manipulation level and take advantage of some of the benefits of the shadowDOM such as:
Slot management
CSS appearance of web component.
The shadowDOM is ideal for creating components that interact with libraries like React, Vue or others. The ShadowDOM protects the DOM it contains from manipulations generated by other libraries.
Slots allow us to reflect existing nodes in the lightDOM into the shadowDOM, example:
This is really useful, since we can group slots according to their name in a specific place of the webcomponent.
We invite you to learn more about slots through the following guide:
The shadowDOM allows you to do something fantastic, protect your CSS from global styles, this has 2 great advantages:
The appearance of our component will not be affected by global CSS declarations.
Customization protected by CSS custom Properties
We invite you to learn more about handling styles in atomic through the following guide:
Atomico makes it easy to declare events at the type level using the Host type.
In the previous code, we have declared the onMyCustomEvent
event at the type level. According to the template logic, this event will be dispatched every time the button is clicked, and the detail attached to this event will be of type CustomDetail
.
It is not recommended to use the props API to create an event, as this callback associated as props will have the following limitations:
Its name cannot have the on
prefix since, if it does, Atomico will recognize it as a property expecting to listen to the event.
It can only have one listener, limiting others from observing the event.
Using the useEvent hook to dispatch component-level events or any custom hook.
Using the Prop.event API to dispatch events when the observed prop changes.
Always prefer the two previously mentioned methods, as they allow you to:
Define if the event bubbles.
Define if the event is cancelable.
Define if the bubbling event can penetrate the shadow DOM.
Define a custom constructor for the event.
Having multiple listeners for the event
Cuando se busca comunicar parametros o leer el retorno de este, ejemplo: