arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

File structure

Design systems

hashtag
Distribution and consumption

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:

import { Button, Input } from "
import { Button } from "my-ds/button";

hashtag
What are the benefits of this type of distribution?

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:

  1. It speeds up the creation of components, since it avoids the individual publication process and centralizes all this at the design system level.

Cons

  1. you will not be able to update a component individually, since it is leveraged at the design system level.

hashtag
Recommended file structure for webcomponents

you always prefer to keep each component isolated in a directory with names associative to the same component, example:

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.

Monorepo

The following format is friendly when sharing a webcomponent to NPM using @atomico/exports

From the previous structure we highlight:

  1. src/define: import the components from src/elements and declare them as customElements

my-ds
"
;
import { Input } from "my-ds/input";
@atomico/exports
β”œβ”€β”€ my-button
β”‚   β”œβ”€β”€ my-button.{js,jsx,ts,tsx}
β”‚   β”œβ”€β”€ my-button.test.{js,jsx,ts,tsx}
β”‚   β”œβ”€β”€ my-button.stories.js
β”‚   └── my-button.md
└── my-input
    β”œβ”€β”€ my-input.{js,jsx,ts,tsx}
    β”œβ”€β”€ my-input.test.{js,jsx,ts,tsx}
    β”œβ”€β”€ my-input.stories.js
    └── my-input.md
src/elements: groups and export components as CustomElements

hashtag
Why separate the export of the element from the declaration?

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

β”œβ”€β”€ src
β”‚   β”œβ”€β”€ define.{js,ts,jsx,tsx}
β”‚   β”œβ”€β”€ elements.{js,ts,jsx,tsx}
β”‚   β”œβ”€β”€ define.test.{js,ts,jsx,tsx}
β”‚   └── slots
β”‚       β”œβ”€β”€ my-sub-element-1.{js,jsx,ts,tsx}
β”‚       └── my-sub-element-2.{js,jsx,ts,tsx}
β”œβ”€β”€ README.md
β”œβ”€β”€ index.html
β”œβ”€β”€ .npmignore
β”œβ”€β”€ package.json
└── tsconfig.json
    
import "my-component"; // internalmente define el customTag
import { MyElement } from "my-component/elements"; // no define el customTag
exports src/{define,elements}.{ts,tsx} --exports --types

Atomico style guide

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.

components/src/components/table at master Β· atomicojs/componentsGitHubchevron-right
Logo