3.1.3 • Published 26 days ago

@amboss/design-system v3.1.3

Weekly downloads
445
License
ISC
Repository
github
Last release
26 days ago

amboss-design-system

Latest version Dependencies React Version

📄 Browse the design system (Storyboard documentation)

Quick start

Development Ensure that you are using npm >= 7.0.0 before running npm install

To start the project run npm run start

To generate a new component run npm run component myComponentName

Building the package

To build the package run npm run build

Building storybook

To build storybook run npm run build-storybook

Publishing

  • Add minor, major or patch label to your PR to specify release type.
  • Add skip-release label to skip the release
  • If you want your commit to skip ci, add "skip ci" to your commit message.

Generating mobile tokens npm run tokens:ios npm run tokens:android

Codebase Overview

1. Tech stack 2. Linting 3. Folder structure 4. Build 5. Tokens, styles and theming 6. Assets 7. Media queries

Tech stack

  • Code: typescript
  • Styles: emotion.js
  • Framework: react
  • Bundler: webpack
  • Environment: storybook
  • Tokens: style-dictionary
  • Testing: jest + react testing library

Linting

As for linting and formatting, you can configure your editor to automatically lint and format your code on save. For this purpose, we're using Prettier and ESLint. If you need to do it manually, you can run:

npm run lint

This command is also run as a pre-push hook and in the pipeline.

Folder structure

|-- .storybook
    |-- components
        |-- ColorGrid.tsx
        |-- SizeGrid.tsx
    |-- main.js
    |-- preview.js
|-- assets
    |-- fonts
        |-- Lato.woff
|-- build (autogenerated)
|-- build-tokens (autogenerated)
    |-- android
        |-- design_system_color.xml
    |-- ios
        |-- DesignSystemColorTokens.swift
    |-- scss
        |-- _theming.scss
        |-- _variables.scss
    |-- assets
        |-- icons.json
        |-- icons16.json
    |-- _colors.json
    |-- _sizes.json
    |-- visualConfig.ts
|-- docs
    |-- Design-principles.mdx
|-- static
    |-- image-for-storybook.png
|-- tokens
    |-- global
      |-- themes
          |-- dark.json
          |-- light.json
      |-- assets.json
      |-- colors.json
    |-- web
      |-- component
        |-- dark.json
        |-- light.json
    |-- android
      |-- opacity.json
    |-- ios
      |-- opacity.json
|-- src
    |-- index.ts
    |-- components
        |-- Button
            |-- Button.tsx
            |-- Button.stories.tsx
            |-- Button.test.tsx
    |-- shared
        -- mediaQueries.ts
    |-- types
        |-- index.ts

Build

There are 3 stages of a build.

  1. Generate variables, theme values and assets from tokens
  2. Build all exported components with babel (preset-react, preset-typescript)
  3. Bundle all built components with webpack

Generate variables, theme values and assets from tokens

In order to structure our tokens we use style-dictionary. This tool is used for creation a content of ./build-tokens folder where we keep all the scss variables and mixins.

New variables and mixins gets generated automaticaly:

  • in watch mode while npm run start is running
  • after npm install
  • before build

You can generate tokens manually using npm run tokens:web and npm run tokens:watch

We use tokens to control the most atomic values in styles and themes.

How does it work?

We have a set of .json files that are located in ./tokens folder, and we have a style-dictionary as a tool for converting .json in to various formats.

For example:

We have a file - ./tokens/global/light|dark.json that gets converted into part of ./build-tokens/visualConfig.ts.

visualConfig.ts is used later as a source for emotion.js theme.

The configuration for style-dictionary is inside ./style-dictionary/{platformName}/{platformName}.sd.config.json. In this config we use some custom transforms, filters and formatters, all of them defined in corresponding files of platform folders.

custom/format/emotion-visual-config - a formatter that generates visualConfig.ts that contains all variables and themed values.

custom/filter/emotion-build-tokens - a filter for all token categories that should go to visutal config.

custom/format/json - a formatter for generation .json files per category. This formatter also add isUsed flag to according token.

custom/format/sub-theme-types - a formatter that generates type definitions for sub-themes.

custom/assets/svg - a transformer that adds a path name to dictionary of svg icons.

More about tokens, themes and styles.

Bundle all exported components

Before publishing the design system for NPM, we run npm run build. This runs the script at bundles everything that is exported from.tsand.tsx files within the source.

For this, we use tsup, which runs esbuild under the hood. We also use a lenient browserslist config to ensure compatibility with older browsers.

For styles, we use emotion.js.

What in the bundle?

  • JS code that is compiled from .tsx files (includes common components and emotion.js styled components)
  • SVG icons that are inlined

fonts that are base64-ed currently taken off the build

Tokens, styles and theming

Currently, we have 4 types of tokens:

  • Atomic values, like colors, sizes, shadows.
  • Font assets, that are basically base64 of font files. (not used in production)
  • Theme values, that are referencing atomic different atomic values
  • Svg icon assets, that are inlined to a .json file

As we use Emotion.js all tokenized values are accessible via theme provider.

Basically during the build phase we generate big objects of variables and themed values for each theme (currently light and dark).

We call this object ambossVisualConfiguration.

Particular themes from ambossVisualConfiguration has to be imported and passed to the theme provider at the consumer side.

Atomic values are straight forward and simply converted to variables.

After build all atomic values are passed to theme.variables by emotion.

Example:

const StyledContainer - styled.div(
  ({ theme }) => ({
    marginTop: theme.variables.size.spacing.s
  })
);

Theme tokens are little more complex. We generate separate VisualConfig for each theme, but together with that we generate type definition that describe any of the themes. This enables developers not care about current theme and how many themes are there.

After build all themes values are passed to theme.values by emotion.

Example:

const StyledContainer - styled.div(
  ({ theme }) => ({
    backgroundColor: theme.values.color.background.primary.default
  })
);

Sub-themes are following the same concept as themes. Developer can fully rely on theme.values object. As long as component in runtime is wrapped in SubThemeProvider and its tokens listed in "tokens/themes/sub-themes/...", all values will be set correctly and automatically.

Note that not all tokens are enabled in sub-themes. Make sure to add missing ones to "tokens/themes/sub-themes/...".

Components that have a "Sub-themed" badge are already in.

Assets

  • assets are defined in tokens/assets.json
  • with the help from style-dictionary we create a json file with tokens (/build-tokens/assets/)
  • those json files supposed to be imported in the ts module (see Icons.tsx)
  • in order to secure d.ts filed in the build we "manually" copy asset jsons on the postbuild phase (see package.json)

Media queries

There is an API for media-query related props: an array of 3 elements small, medium, large, for respective screen sizes.

For example <Box space=["xs", "xl", "xxl"] /> will set xs for small screens, xl for medium screens and xxl for large.

Basically, if you see a type of MQ<Whatever> you can provide an array of 3 Whatevers.

In order to add a media query support to your components:

import React from "react";

import styled from "@emotion/styled";
import { mq } from "../../shared/mediaQueries";

type TextAlignment = "left" | "center" | "right";

type BoxProps = {
  alignText: TextAlignment | MQ<TextAlignment>;
};

export const Box = styled.div<BoxProps>(({ alignText = "left" }) =>
  mq({
    textAlign: [alignText, { left: "left", right: "right", center: "center" }],
  })
);

Shadow-DOM

In order to use emotion-enabled DS components in the shadow-dom, you need to take some steps to 'link' the styles in the light-dom (these are added by emotion using CSSStyleSheet.insertRule() which is why appears empty in the DOM).

emotion-js/emotion#1366 https://emotion.sh/docs/cache-provider https://stackblitz.com/edit/emotion-shadow-dom-example?file=ShadowDomContainer.js https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule

import {
  ThemeProvider,
  light,
  Card,
  H1,
  CacheProvider,
  createCache,
} from "@amboss/design-system";
class SuchShadow extends HTMLElement {
  connectedCallback() {
    const root = document.createElement("div");
    this.attachShadow({ mode: "open" });
    this.emotionCache = createCache({ container: this.shadowRoot });
    render(
      <ThemeProvider theme={light}>
        <CacheProvider value={this.emotionCache}>
          <Card>
            <H1>I love you shadow unicorn!!!</H1>
          </Card>
        </CacheProvider>
      </ThemeProvider>,
      root
    );
  }
}

customElements.define("shadow-element", SuchShadow);
3.1.3

26 days ago

3.1.2

1 month ago

3.1.1

1 month ago

3.1.0

1 month ago

3.0.4

2 months ago

3.0.3

2 months ago

3.0.6

1 month ago

3.0.5

2 months ago

3.0.2

2 months ago

2.4.3

3 months ago

2.4.2

3 months ago

2.4.5

2 months ago

2.4.4

3 months ago

3.0.1

2 months ago

3.0.0

2 months ago

2.4.1

3 months ago

2.4.0

3 months ago

2.3.0

5 months ago

2.3.2

5 months ago

2.3.1

5 months ago

2.3.4

5 months ago

2.3.3

5 months ago

2.3.6

4 months ago

2.3.5

4 months ago

2.2.1

5 months ago

2.2.0

6 months ago

2.2.3

5 months ago

2.2.2

5 months ago

2.2.4

5 months ago

2.3.8

4 months ago

2.3.7

4 months ago

2.3.9

4 months ago

2.1.2

6 months ago

2.1.1

6 months ago

2.1.4

6 months ago

2.1.3

6 months ago

2.1.6

6 months ago

2.1.5

6 months ago

2.3.13

3 months ago

2.3.12

3 months ago

2.3.14

3 months ago

2.3.11

3 months ago

2.3.10

4 months ago

2.1.0

6 months ago

2.0.3

6 months ago

2.0.2

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.30.1

7 months ago

1.30.0

7 months ago

1.29.3

7 months ago

1.29.2

8 months ago

1.29.1

8 months ago

1.29.0

8 months ago

1.28.0

8 months ago

1.26.6

8 months ago

1.26.5

8 months ago

1.27.0

8 months ago

1.26.3

8 months ago

1.26.4

8 months ago

1.26.2

8 months ago

1.26.1

9 months ago

1.26.0

9 months ago

1.25.2

9 months ago

1.25.1

9 months ago

1.25.0

9 months ago

1.24.8

9 months ago

1.24.7

9 months ago

1.24.7-canary.1

9 months ago

1.24.7-canary.0

9 months ago

1.24.6

9 months ago

1.24.5

10 months ago

1.24.4

10 months ago

1.24.3

10 months ago

1.24.2

10 months ago

1.24.1

10 months ago

1.24.0

10 months ago

1.23.2

10 months ago

1.23.1

10 months ago

1.23.0

10 months ago

1.22.0

11 months ago

1.21.3

11 months ago

1.21.2

11 months ago

1.21.1--canary-1

11 months ago

1.21.1

11 months ago

1.21.0

11 months ago

1.20.4

12 months ago

1.20.3

12 months ago

1.20.2

12 months ago

1.18.0

12 months ago

1.19.0

12 months ago

1.19.1

12 months ago

1.20.1

12 months ago

1.20.0

12 months ago

1.17.2

1 year ago

1.17.1

1 year ago

1.17.6

1 year ago

1.17.5

1 year ago

1.17.4

1 year ago

1.17.3

1 year ago

1.17.7

12 months ago

1.16.6

1 year ago

1.17.0

1 year ago

1.16.1--canary4

1 year ago

1.16.1--canary3

1 year ago

1.16.1--canary2

1 year ago

1.12.1

1 year ago

1.12.0

1 year ago

1.16.1--canary

1 year ago

1.16.4--canary1

1 year ago

1.16.2--canary3

1 year ago

1.16.2--canary4

1 year ago

1.13.2

1 year ago

1.13.1

1 year ago

1.13.0

1 year ago

1.13.6

1 year ago

1.13.5

1 year ago

1.13.4

1 year ago

1.13.3

1 year ago

1.13.7

1 year ago

1.14.1

1 year ago

1.14.0

1 year ago

1.14.5

1 year ago

1.14.4

1 year ago

1.14.3

1 year ago

1.14.2

1 year ago

1.14.6

1 year ago

1.15.0

1 year ago

1.15.4

1 year ago

1.15.3

1 year ago

1.15.2

1 year ago

1.15.1

1 year ago

1.16.3

1 year ago

1.16.2

1 year ago

1.16.1

1 year ago

1.16.0

1 year ago

1.16.5

1 year ago

1.16.4

1 year ago

1.16.2-canary2

1 year ago

1.16.2-canary1

1 year ago

1.16.2-canary3

1 year ago

1.16.3--canary1

1 year ago

1.10.3

1 year ago

1.10.2

1 year ago

1.10.1

1 year ago

1.10.0

1 year ago

1.11.0

1 year ago

1.9.1

2 years ago

1.9.0

2 years ago

1.9.8

2 years ago

1.9.7

2 years ago

1.9.6

2 years ago

1.9.5

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.8.7

2 years ago

1.8.6

2 years ago

1.8.5

2 years ago

1.8.4

2 years ago

1.8.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.8.3

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.19

2 years ago

1.5.21

2 years ago

1.5.20

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.10

2 years ago

1.5.12

2 years ago

1.5.11

2 years ago

1.5.14

2 years ago

1.5.13

2 years ago

1.5.16

2 years ago

1.5.15

2 years ago

1.5.18

2 years ago

1.5.17

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.11

2 years ago

1.4.10

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.7

2 years ago

1.4.12-canary.0

2 years ago

1.4.12-canary.2

2 years ago

1.4.12-canary.1

2 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.12

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.9

3 years ago

1.2.0

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.11

3 years ago

1.0.12

3 years ago

1.0.0-canary-3

3 years ago

1.0.0-canary-4

3 years ago

1.0.0-canary-1

3 years ago

1.0.0-canary-2

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.10

3 years ago

0.26.9

3 years ago

0.26.8

3 years ago

0.26.7

3 years ago

0.26.6

3 years ago

0.27.2

3 years ago

0.27.1

3 years ago

0.27.0

3 years ago

0.26.10

3 years ago

0.26.3

3 years ago

0.26.5

3 years ago

0.26.4

3 years ago

0.26.2

3 years ago

0.26.1

3 years ago

0.25.18

3 years ago

0.25.19

3 years ago

0.25.15

3 years ago

0.25.16

3 years ago

0.25.17

3 years ago

0.26.0

3 years ago

0.25.14

3 years ago

0.25.11

3 years ago

0.25.12

3 years ago

0.25.13

3 years ago

0.25.10

3 years ago

0.25.9

3 years ago

0.25.8

3 years ago

0.25.7

3 years ago

0.25.6

3 years ago

0.25.5

3 years ago

0.25.4

3 years ago

0.25.3

3 years ago

0.25.2

3 years ago

0.25.1

3 years ago

0.25.0

3 years ago

0.24.4

3 years ago

0.24.3

3 years ago

0.24.2

3 years ago

0.23.5

3 years ago

0.24.1

3 years ago

0.24.0

3 years ago

0.23.4

3 years ago

0.23.3

3 years ago

0.23.2

3 years ago

0.23.1

3 years ago

0.23.0

3 years ago

0.22.5

3 years ago

0.22.4

3 years ago

0.22.3

3 years ago

0.21.9

3 years ago

0.22.2

3 years ago

0.22.1

3 years ago

0.22.0

3 years ago

0.21.8

3 years ago

0.21.7

3 years ago

0.21.6

3 years ago

0.21.5

3 years ago

0.21.4

3 years ago

0.21.3

3 years ago

0.21.2

3 years ago

0.21.1

3 years ago

0.20.1

3 years ago

0.20.0

3 years ago

0.21.0

3 years ago

0.20.4

3 years ago

0.20.3

3 years ago

0.20.2

3 years ago

0.19.0

3 years ago

0.19.1

3 years ago

0.18.4

3 years ago

0.18.5

3 years ago

0.18.2

3 years ago

0.18.3

3 years ago

0.18.1

3 years ago

0.18.1-canary.0

3 years ago

0.17.5-canary.0

3 years ago

0.17.5

3 years ago

0.18.0

3 years ago

0.17.4

3 years ago

0.17.3

3 years ago

0.17.2

3 years ago

0.17.1

3 years ago

0.17.0

3 years ago

0.16.0

3 years ago

0.15.4

3 years ago

0.15.1

3 years ago

0.15.2

3 years ago

0.15.3

3 years ago

0.15.0

3 years ago

0.14.2

3 years ago

0.13.1

4 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.11.0

4 years ago

0.11.1

4 years ago

0.13.0

4 years ago

0.11.2

4 years ago

0.12.10

4 years ago

0.12.7

4 years ago

0.12.8

4 years ago

0.12.9

4 years ago

0.12.0

4 years ago

0.12.1

4 years ago

0.12.2

4 years ago

0.12.3

4 years ago

0.12.4

4 years ago

0.12.5

4 years ago

0.12.6

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.7.0

4 years ago

0.8.0

4 years ago

0.6.0

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.23

4 years ago

0.1.21

4 years ago

0.1.22

4 years ago

0.1.20

4 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.15

4 years ago

0.1.16

4 years ago

0.1.14

4 years ago

0.1.14-canary

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.5-1

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5-0

4 years ago

0.1.3-1

4 years ago

0.1.3-0

4 years ago

0.1.2

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2-canary-5

4 years ago

0.0.2-canary-4

4 years ago

0.0.2-canary-3

4 years ago

0.0.2-canary-2

4 years ago

0.0.2-canary

4 years ago

0.0.1

4 years ago