Learn how to build and publish design systems effectively. Discover best practices for creating reusable components and enhancing UI consistency.
This blogpost is a part of the "Building Design System and Micro Frontends" series. For more content, read the first post. The source code for all parts of this series can be found in this GitHub repository.
React
Proven, stable, excellent component composition system, focus on back-compatibility. Read the "Design Principles" post on reacts blog; this post outlines react development guiding principles.
Tailwind
Gives us a simple way to define seed for the design system. Sizes/Distances scale, colour palettes, shadows, responsive breakpoints, transitions and animations etc., all can be defined succinctly. It also gives us ultimate style isolation and a big productivity boost.
Storybook
Helps us develop components in isolation. Helps in component testing and, when exported, delivers portable documentation.
Webpack
Proven, stable, vivid plugin ecosystem; a lot of materials.
Setting up a Design System Project
Create directory design-system and run the following commands from it:
npm init -y will setup package.json file.
Run npm run storybook to build and run storybook. It should bind to port 6006. Open http://localhost:6006. You should see some example stories.
The npx sb init command takes care of setting up the storybook. It will create a stories directory with examples in the project root directory. You can remove its content. We will create a simple story later from scratch.
Settin up Tailwind
npm i -D tailwindcss@2.2.4 postcss@8.3.5
npx tailwindcss init
npx tailwindcss init will create ./tailwind.config.js file with the default configuration.
Open ./tailwind.config.js Add mode property and set purge patterns (lines 2,3).
Run npm run storybook. Open http://localhost:6006. You should see something like this:
Building Design System Package
It is time to create production build of our design system. It should contain only necessary code. We will exclude react from the build. The assumption here is that whoever is consuming design system will be responsible for including react.
In a real project design system should be packaged and published to a npm repository so the other project can use npm to get it. However, for this walkthrough, we will build it and keep it in a directory on the disk. Other projects that we build in the next post will consume it from the disk.
Create an entry point for our library; Create ./src/index.js and add the following content:
import './styles.css'
import Button from "./components/Button";
export
Every component in our design system must be imported and re-exported in this file.
Bleiben Sie mit dem TIMETOACT GROUP Newsletter auf dem Laufenden!
Wir verwenden Cookies
Um Inhalte und Anzeigen zu personalisieren, Funktionen für soziale Medien anbieten zu können und die Zugriffe auf unsere Website zu analysieren. Außerdem geben wir Informationen zu Ihrer Verwendung unserer Website an unsere Partner für soziale Medien, Werbung und Analyse weiter. Unsere Partner führen diese Informationen möglicherweise mit weiteren Daten zusammen, die Sie ihnen bereitgestellt haben oder die sie im Rahmen Ihrer Nutzung der Dienste gesammelt haben. Dies schließt gegebenenfalls die Verarbeitung Ihrer Daten in den USA ein.
Weitere Informationen zu Cookies erhalten Sie in unserem Datenschutzhinweis