Design systems
I will show you a series of useful techniques to start programming your design systems with Atomico, analyzing the recommended structure and its files.
1
src/
2
# Import, export and declare all our components
3
components.js
4
# Group all the tokens in our system
5
tokens.js
6
# Structure example for our component
7
/button
8
button.{js,jsx,ts,tsx}
9
button.md
10
button.test.js
Copied!
We will analyze the above.

src/components.js

File that imports, exports and declares all the components of our design system, example:
1
import { Button } from "./button/button";
2
export { Button } from "./button/button";
3
4
customElements.define("my-button", Button);
Copied!
the utilities of this are to centralize everything in components.js are:
  1. 1.
    Clarity of the definition of customElements in a single file for our entire design system
  2. 2.
    Export of all customElements to be extended or redefined.

src/tokens.js

File that centralizes the custom-properties of our design system, example:
1
import { css } from "atomico";
2
3
export const tokensInput = css`
4
:host {
5
--background: var(--my-ds-input--background, #fff);
6
--border-width: var(--my-ds-input--border-width, 1px);
7
--border-color: var(--my-ds-input--border-color, black);
8
--radius: var(--my-ds-input--radius, 0.5rem);
9
--min-height: var(--my-ds-input--min-height, 40px);
10
}
11
`;
12
13
export const tokenColors = css`
14
:host {
15
--primary: var(--my-ds--primary);
16
--secondary: var(--my-ds--secondary);
17
--success: var(--my-ds--warning);
18
--warning: var(--my-ds--warning);
19
--danger: var(--my-ds--warning);
20
--info: var(--my-ds--warning);
21
}
22
`;
Copied!
From the example above I highlight the custom property declaration pattern
1
:host {
2
--background: var(--my-ds-input--background, #fff);
3
}
Copied!
--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:
1
---my-ds-input--background
2
---<prefix>-<namespace>--<property>
Copied!
Where:
  1. 1.
    prefix: Prefix of our global design system
  2. 2.
    namespace: group independent of our design system
  3. 3.
    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.

Instance level

It is the instance of the component either in HTML or JS, example:
HTML
JS
1
<my-component style="--background: red;"></my-component>;
Copied!
1
const component = document.createElement("my-component");
2
3
component.style = "--background: red";
Copied!

src/button.js

JS
JSX
1
import { c, html, css } from "atomico";
2
import { tokensColor, tokensInput } from "../tokens";
3
4
function button(props) {
5
6
return html`<host shadowDom>
7
<button ...${props} class="input-box">
8
<slot name="icon"></slot>
9
<slot></slot>
10
</button>
11
</host>`;
12
}
13
14
button.props = {
15
name: String,
16
value: String,
17
disabled: Boolean,
18
};
19
20
button.styles = [
21
tokensColor,
22
tokensInput,
23
css`
24
.input-box {
25
display: flex;
26
gap: 1rem;
27
}
28
`,
29
];
Copied!
1
import { c, css } from "atomico";
2
import { tokensColor, tokensInput } from "../tokens";
3
4
function button(props) {
5
return (
6
<host shadowDom>
7
<button {...props} class="input-box input-box--use-border">
8
<slot name="icon"></slot>
9
<slot></slot>
10
</button>
11
</host>
12
);
13
}
14
15
button.props = {
16
name: String,
17
value: String,
18
disabled: Boolean,
19
};
20
21
button.styles = [
22
tokensColor,
23
tokensInput,
24
css`
25
.input-box {
26
display: flex;
27
gap: 1rem;
28
}
29
`,
30
];
31
32
export const Button = c(button);
33
Copied!
From the previous code I highlight:
  1. 1.
    import of "../tokens" and the destructuring of the module that declares the use of tokensColor and tokensInput.
  2. 2.
    button.styles: Atomico allows to associate multiple styles through the use of an array.
  3. 3.
    Button export.
Last modified 1mo ago