Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
I will show you a series of useful techniques to start programming your design systems with Atomico, analyzing the recommended structure and its files.
We will analyze the above.
File that imports, exports and declares all the components of our design system, example:
the utilities of this are to centralize everything in components.js are:
Clarity of the definition of customElements in a single file for our entire design system
Export of all customElements to be extended or redefined.
File that centralizes the custom-properties of our design system, example:
From the example above I highlight the custom property declaration pattern
--background
will be a token that can be modified at the instance level and this inherits a global token from our system called --my-ds-input--background
, I want you to notice that the global name of our custom property has a pattern, example:
Where:
prefix: Prefix of our global design system
namespace: group independent of our design system
property: property associated with the system, such as color, size, or other value.
Why use the recommended pattern? To individualize the configuration at the group level and separate the property definition from it thanks to the use of double hyphens (--), internally everything is simplified since the tokens only capture the global configuration global to reflect it to a simpler variable accessible only from the component instance level.
It is the instance of the component either in HTML or JS, example:
From the previous code I highlight:
import of "../tokens"
and the destructuring of the module that declares the use of tokensColor
and tokensInput
.
button.styles: Atomico allows to associate multiple styles through the use of an array.
Button export.
First thanks for using Atomico 😉, in this guide you will find some useful tips when developing with Atomico, all with the aim that your webcomponents are sustainable and scalable over time.
component
: function that declares the webcomponent for Atomico.
VanillaElement
: class that will be extended by Atomico to create Component, Atomico will not break the life cycle of the component, allowing them to interact freely.
classes produced by the Atomico function c
, these can be extended between components, example:
Consider the following effects when using this inheritance model:
The render
will be rewritten.
The props
are inherited, Atomico will reuse the previously declared props.
Styles
are inherited. Atomico will merge the stylesheets.
The c
function creates an optimized standard custom element, which can be extended to modify its behavior, be:
Adding methods.
Creating or replacing style sheets.
Creando nuevas propiedades.
Suppose we have a MyButton
product of the function c
, we can extend this component to modify its appearance without the need to completely rewrite it, example:
The benefit of this inheritance is to simplify the modification of the appearance of a component created with Atomico, since it avoids its rewriting.
When creating design systems or component systems, we recommend that you maintain a centralized distribution structure in a single export package with multiple import paths, example:
Aesthetic coherence, the entire design system leverages itself and thanks to this we gain aesthetic coherence.
While a monorepo might seem like an ideal path, it actually increases the complexity of maintenance, whether it be component versioning and dependency maintenance.
We move faster and reduce implementation errors if you don't rely on individual versioning at the component level and leave this only defined at the design system level.
This has its pros and cons:
Pros:
It speeds up the creation of components, since it avoids the individual publication process and centralizes all this at the design system level.
Cons
you will not be able to update a component individually, since it is leveraged at the design system level.
you always prefer to keep each component isolated in a directory with names associative to the same component, example:
The following format is friendly when sharing a webcomponent to NPM using @atomico/exports
From the previous structure we highlight:
src/define
: import the components from src/elements
and declare them as customElements
src/elements
: groups and export components as CustomElements
since it improves the customElements definition experience, example:
Thanks to @atomico/exports this is really easy, example:
You can see a use case of this structure in @atomico/components
Improve the interaction with the forms and accessibility of your components.
It is normal that we use the technique of dispatching events from the component to communicate states and more, but when using forms this changes since the events inside the shadowDOM do not interact with the form outside of it, example:
To solve this we will have to nest an input tag in the lightDOM of our component, in order to reflect the logic of this to the form. Atomico facilitates this hybrid interaction between lightDOM and shadowDOM with the hook that allows executing a second render that works from the lightDOM, example:
With this you have gained full control over the existing input tag in the lightDOM, allowing you to apply styles using the ::slotted
selector, example:
We have created an input tag that allows you to interact directly with the form, this technique is applicable with all the tags that interact with the form, such as button, input, textarea and others.
Here are some tips you can take into account when creating webcomponents with Atomico
Write the functional component using the first lowercase character, since the functional declaration is not instantiable as a constructor in JSX.
This prevents confusion when identifying the constructor of the component instance.
preferably use useProp in the following cases:
By modifying the prop from inside the component.
By isolating the logic of the prop in a customHook.
In most cases downloading the prop from the first argument of the function is simpler and more declarative, example:
This does not rule out the use within the style tag, since it is sometimes the solution to the definition of conditional styles or variables to the logic and outside the scope of the custom properties.
why? The NPM-oriented packaging tool allows automatic export from the recommended structure,@atomico/exports
will generate a modern package.json to current standards, automatically generating all (main, types, exports and more) what is necessary for your package to be distributed correctly.