Makes it easy to manage tokens as CSS custom properties for design system development
@atomico/postcss-tokens
works through yaml or json files that declare tokens to be later imported from CSS files using the @tokens atRule. Through @tokens you can define if the resource to be generated should be global in scope (:root) or at the webcomponent level (:host)
Tokens are declared using YAML to JSON files, token declarations can be:
simple: object declaring only token property and value
variations by attributes: object that declares the tokens according to the assignment of an attribute at the webcomponent level
This type of declaration allows assigning tokens according to the attribute of a webcomponent
Thanks to this type of declaration you will be able to manage the variations directly from the token file.
This atRule allows importing yaml or json files to be used as custom properties, example:
Importing the tokens.yaml file
Output
Importing the tokens.yaml file
Output
Defines the type of root that will use the tokens, by default ":host"
, example:
Consider the following behaviors:
root puede ser cualquier tipo de selector
if root is equal to ":root"
, the build rules will work at the :root/lightDOM
level.
if root is equal to ":host"
, the generation rules will work at the :host/shadowDOM
level.
It will only take the tokens assigned in the filter to create the custom properties, example:
From the previous example @atomic/postcss-tokens
will only take the tokens from the color property.
It behaves similarly to filter, but with the big difference that filter preserves the scope structure vs use that shortens it, example:
Define el prefijo para las custom properties
Define que las customProperties que trabaje a nivel de shadowDom poseeran un valor por defecto si no se declara el tokens en :root, ejemplo:
With @atomico/vite you can use @atomico/postcss-tokens in your cssLiterals with the following configuration:
Enable the use of postcss for cssLiterals in the vite.config.js
file
2. Add @atomico/postcss-tokensto your postcss config, example:
3. ready to use