0.66.1 • Published 3 days ago

@instill-ai/design-system v0.66.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 days ago

About new design system

We are undergoing a series of revamps for our design-system, which included several aspects:

  1. Compound component first approach. Under the hood, we will use Radix-UI.
  2. We are abandoning one style one prop approach due to it being too verbose to use

Info

  • We use pnpm -r publish at the root folder to publish the packages

How to use the storybook at local

  • pnpm watch:css and let it run
  • pnpm sb

How to deploy storybook

  • Because design-system relies on design-tokens, when deploy to Vercel, we need to build the package first from the root with pnpm ci-build-storybook
  • The output will be put into /packages/design-system/storybook-static, we indicate this folder in the Vercel setting

Old design system

This is a react design system builds on top of TailwindCSS with several principles:

  • Two-level component design: base-level components and exported-level components
  • One style one prop approach: The base component will expose style as props as much as possible, one prop will only have one style string

How to use

  1. Install: yarn add @instill-ai/design-system
  2. Add this package into your main project tailwind.config.js and make sure you have all the necessary style
module.exports = {
  content: [
    "./src/pages/**/*.{js,ts,jsx,tsx}",
    "./src/components/**/*.{js,ts,jsx,tsx}",
    "./node_modules/@instill-ai/design-system/build/*.js",
  ],
};

How to contribute

Install typescript intelligence

  • We heavily rely on typescript at this moment, before you make any contribution please install typescript intelligence.

You should write component unit-test for every base-level component

  • We haven't embodied this approach

You should check the export structure.

  • We want to abstrct away the file structure, so every component should be exported to its outer folder.
    • If it is components, you should check whether it had already been exported to @instill-ai/design-system/components before you move on to the next step

Build before publish

  • You should use yarn build script to build the latest version of design-system and change the version of it, then you could publish the package. In the future, after the official 0.1.0 release we will adapt ci for this task.

Why we choose the utility class approach.

  • The utility class is easy to write, it can deliver an application at a relatively quick pace.
  • Just CSS, there has no further abstraction users need to learn.
  • Get rid of naming overhead: We don't want to re-invent thousands of class names just to select the right element.
  • Easy to use pseudo-class: peer, hover, group...etc are all very good functionality we could leverage out of the box.

The problems we try to solve

  • Oversize comes from being over-designed:
    • Traditionally, design systems want to find a one size for all components that leads to over-desige. This may result in a huge component with hundreds of if...else conditionally rendered style.
  • Over abstraction
    • Some design systems will try to abstract every layer of element. At the first glance, this can fertilize re-usability and encapsulate the styles, but it will bring up a lot of abstraction and cause unncessary overhead for consumers.
    • They don't want to make the style as props but comes up with other naming convention which causes another layer of abstraction like type={},
    • In this article, the author have a suitable example, In our perspective the first example is harder to read than the second one, it has too many layers of abstraction that is exactly what we want to avoid.
<Box padding={5} width="320px" border="sm">
  <Stack gap={2}>
    <Image borderRadius="md" src="https://bit.ly/2k1H1t6" />
    <Row gap={2}>
      <Badge color="#702459">Plus</Badge>
      <Spacer left={2}>
        <Text size="sm" weight="bold" color="#702459">
          VERIFIED &bull; CAPE TOWN
        </Text>
      </Spacer>
    </Row>
    <Text size="xl" weight="semibold">
      Modern, Chic Penthouse with Mountain, City & Sea Views
    </Text>
    <Text>$119/night</Text>
    <Row gap={1}>
      <Icon src={MdStar} color="#ED8936" />
      <Text size="sm">
        <Text size="sm" weight="bold">
          4.84
        </Text>
        (190)
      </Text>
    </Row>
  </Stack>
</Box>
<div className="w-32 rounded p-5">
  <div className="flex">
    <img className="w-full rounded" src="https://bit.ly/2k1H1t6" />
    <div className="mt-2 flex flex-row">
      <div className="bg-mono-400 rounded px-4 py-2">
        <div className="text-mono-100">Plus</div>
      </div>
      <div className="text-pale-100 text-sm font-bold">
        VERIFIED &bull; CAPE TOWN
      </div>
    </div>
    <span className="text-xl font-semibold">
      Modern, Chic Penthouse with Mountain, City & Sea Views
    </span>
    <span className="text-xl font-semibold">$119/night</span>
    <div className="flex flex-row items-center">
      <Icon src={MdStar} color="#ED8936" />
      <span className="text-sm">
        <span className="font-bold">4.84</span>
        (190)
      </span>
    </div>
  </div>
</div>
  • Flexibility ends up with slow iteration:
    • If you adopt a single, huge component route, the first thing you need to solve is the design corner case. To fulfill these needs you may add lots of conditions or sub-components here or there in the main component, slowly but steadily your component will be hard to iterate or upgrade.
    • It's hard to read through all the dependency between these props due to they may have other meanings besides CSS styles.

The principles

We try to solve these problems with two principles

  • Two-level component design:
    • Base-level components: The foundation of every type of component.
      • You can find them in the storybook with path: /Base
      • Base level components won't be exported to be used by exterior consumers.
      • Base components will define all the props and functions the component needs.
    • Exported-level components: Inherits all the props from a base component but may have a pre-defined style, meant to be used by the consumer.
      • You can find them in the storybook with path: /Ui
      • Exported-level components will be consumed with the limited props like onChangeInput, borderStyle, fontFamiliy, or other functional props.
      • We will limit as little style input as possible, to control the visual style of the component.
  • One style one prop
    • Every base component will expose as many styles as possible, it seldomly has pre-defined styles.
    • Every exposed style props can only have one style string, we don't accept something like styleName="font-base text-black", we will separate it as fontSize="font-base" and textColor="text-black".
// We won't do this

const square = ({ styleName, children }) => {
  return <div className={styleName}>{children}</div>;
};

// We will do this
// cn is a aggregator, it will compose two string like "hi" "yo" to "hi yo"

const square = ({ width, height, color, children }) => {
  return <div className={cn(width, height, color)}>{children}</div>;
};

How we solve above problems with the three principles

  • Oversize comes from being over-designed:
    • The base-level component will have limited condition rendering thanks to Tailwind CSS, it only needs to expose as many as style props as possible for further customization.
  • Over abstraction
    • Because we don't need to encapsulate style within layer of components just to manage bunch of css files, we can avoid over abstraction.
  • Flexibility ends up with slow iteration:
    • With the two-level component design, we make base-level components act as a single source of truth, every group of the component should only inherit the base-level component
    • The design system team doesn't need to use a single component to face all the needs, they can create the new exported-level components to achieve different corner cases. They can iterate at a relatively fast speed.

Drawbacks & Known issues

  • Dynamic styles
    • Tailwind CSS fell short at calculated style, for example, if we have a width: 80px square and we want to put a dot at around 1/3 - 10px of its width, at the first glance you may think this is easy, we can just use Just-In-Time feature. But due to Tailwind CSS's prune nature, this won't work, at compile time Tailwind CSS can't recognize the dynamic style like that.
const square = ({ width }) => {
  return (
    <div className={`w-[${width}px] relative`}>
      <div className={`dot absolute left-[${width / 3 - 10}px]`} />
    </div>
  );
};
  • Hard to integrate with 3rd party tooling
    • This is the known issue if the design system wants to adapt to another component library such as react-select. They have to come up with a method to exchange styles across different CSS frameworks because we are using utility classes, these may cause much more issues than the traditional CSS approach.

Rules

  • Don't use short-cut features of javascript, use a library like clsx or classnames
  • Include import React from "react" in every file use react(To avoid jsx-runtime specific function not compatible issue)
  • Everytime you create a new base-level component, you need to create a exported-level component inherit that base-level component to act as manual.
  • Use arbitrary number as many as possible when it comes to size related className like fontSize or lineHeight, due to we may use getTailwindClassNumber() to extract number from className, currently it not support with something like text-sm

FQA

  • I need to input so many style props in a component, why not just gave me a component and a type prop

About storybook

  • Use {...args} to set props.

Code quality

  • Every base-level component should have a test suite
  • Every base-level and exported-level component should have a story

Lesson learned

  • Don't rely on pseudo-class like disabled: or read-only:. you should pass disabled and read-only style without these pseudo-class, use simple style and apply it on container instead of input itself.
    • Caveat: TextArea may have the resizing issue
    • Placeholders have to use placeholder: pseudo-class because there don't have another simple method to programmatically address placeholder style
  • Don't use some ambiguous story like playground and default, they almost have identical style props, but Default is a fixed style.
    • Only have playground story, make default style available and users can modify as their wishes
    • Caveat: playground is using Template.bind() to construct story, its console.log is different from regular console.log
  • You may want to remove the whole args props in storybook to make the type check cleaner, but in this way user can't directly change the props' value on storybook UI

About the design of the base and exported level

  • We will always digest as many props at base level as possible, take SingleSelectBase as example, when use InputDescription component, we didn't use BasicInputDescription but InputDescriptionBase to make SingleSelectBase as flexible as possible, but here comes another problem, we need to store the same config for BasicInputDescription at BasicInputDescription and BasicSingleSelece. To solve this problem, we will export a set of BasicInputDescriptionConfig to let other component use the config and reduce the maintance overhead.

About the passThrough props

Normally we don't accept passThrough props like below. The only exception will be input related field like textarea (BasicTextArea).

In the future, we will make it has explicit type.

type FooProps = {
  id: string
}

const Foo = (props: FooProps) => {
  const {id, ...passThrough} = props

  <input {...passThrough} id={id} />
}

Todo

  • Solve accessibility issues
  • Think about memorize component
  • InputLabel cursor
  • If we bundle the design-system as package, we may re-bundle it again with duplicate style css, need to investigate this.
  • Adapt instill color into Select component
  • Enable strict type checking
  • Force every component to use Nullable prop, instead of undefined
  • Decide whether to use controlled components or not
  • Solve upload field cursor not correctly display
  • Extract onChangeInput type from BasicInputFieldAttributes to individual component
0.66.1

3 days ago

0.66.0

9 days ago

0.65.1

1 month ago

0.65.0

2 months ago

0.65.1-rc.2

2 months ago

0.65.1-rc.3

2 months ago

0.65.1-rc.0

2 months ago

0.65.1-rc.1

2 months ago

0.65.1-rc.4

2 months ago

0.65.1-rc.5

2 months ago

0.65.0-rc.1

2 months ago

0.65.0-rc.0

2 months ago

0.64.0

3 months ago

0.63.1-rc.1

3 months ago

0.63.1-rc.0

3 months ago

0.63.0-rc.0

3 months ago

0.63.0

3 months ago

0.62.0

3 months ago

0.61.1

4 months ago

0.61.0

4 months ago

0.61.1-rc.0

4 months ago

0.59.1-rc.0

4 months ago

0.60.0

4 months ago

0.59.0

5 months ago

0.59.0-rc.6

5 months ago

0.59.0-rc.5

5 months ago

0.59.0-rc.4

5 months ago

0.59.0-rc.3

5 months ago

0.59.0-rc.2

5 months ago

0.59.0-rc.1

5 months ago

0.59.0-rc.0

5 months ago

0.43.0

8 months ago

0.55.6

7 months ago

0.55.7

7 months ago

0.55.4

7 months ago

0.55.5

7 months ago

0.55.2

7 months ago

0.58.0-rc.0

5 months ago

0.55.3

7 months ago

0.55.0

7 months ago

0.55.1

7 months ago

0.55.8

7 months ago

0.55.9

6 months ago

0.32.0

10 months ago

0.29.0

10 months ago

0.33.0-rc.2

10 months ago

0.44.0

8 months ago

0.33.0-rc.1

10 months ago

0.44.1

8 months ago

0.33.0-rc.0

10 months ago

0.39.0-rc.0

9 months ago

0.39.0-rc.1

9 months ago

0.33.1

10 months ago

0.56.0

6 months ago

0.33.0

10 months ago

0.33.2-rc.1

10 months ago

0.33.2-rc.0

10 months ago

0.41.0-rc.0

9 months ago

0.45.0

8 months ago

0.41.0

9 months ago

0.33.2-rc.2

10 months ago

0.38.1

9 months ago

0.38.0

9 months ago

0.56.0-rc.0

6 months ago

0.53.2

7 months ago

0.53.3

7 months ago

0.29.1-rc.1

10 months ago

0.29.1-rc.0

10 months ago

0.53.0

7 months ago

0.53.1

7 months ago

0.30.1

10 months ago

0.30.0

10 months ago

0.27.0

10 months ago

0.42.0

8 months ago

0.28.0-rc.1

10 months ago

0.39.0

9 months ago

0.23.1-rc.1

10 months ago

0.23.1-rc.0

10 months ago

0.23.1-rc.3

10 months ago

0.23.1-rc.2

10 months ago

0.54.0

7 months ago

0.31.0

10 months ago

0.28.0

10 months ago

0.36.4

9 months ago

0.36.3

9 months ago

0.36.2

9 months ago

0.36.1

9 months ago

0.36.0

9 months ago

0.36.6

9 months ago

0.36.5

9 months ago

0.51.0

8 months ago

0.48.0

8 months ago

0.25.0

10 months ago

0.32.0-rc.0

10 months ago

0.55.9-rc.0

6 months ago

0.40.2

9 months ago

0.40.0

9 months ago

0.40.1

9 months ago

0.37.2

9 months ago

0.37.1

9 months ago

0.37.0

9 months ago

0.52.0

8 months ago

0.49.1

8 months ago

0.49.0

8 months ago

0.26.0

10 months ago

0.34.0-rc.0

10 months ago

0.57.0

6 months ago

0.34.0

9 months ago

0.28.1-rc.0

10 months ago

0.28.1-rc.2

10 months ago

0.28.1-rc.1

10 months ago

0.46.0

8 months ago

0.46.1

8 months ago

0.35.1

9 months ago

0.58.0

5 months ago

0.35.0

9 months ago

0.57.0-rc.1

5 months ago

0.50.0

8 months ago

0.58.1-rc.0

5 months ago

0.47.3

8 months ago

0.47.4

8 months ago

0.47.1

8 months ago

0.47.2

8 months ago

0.24.1

10 months ago

0.47.0

8 months ago

0.24.0

10 months ago

0.20.0

11 months ago

0.21.0

11 months ago

0.22.1

10 months ago

0.22.0

10 months ago

0.23.0

10 months ago

0.17.0

11 months ago

0.17.1

11 months ago

0.18.1

11 months ago

0.10.6

12 months ago

0.18.0

11 months ago

0.15.0

11 months ago

0.18.1-rc.0

11 months ago

0.16.0

11 months ago

0.13.0

11 months ago

0.14.0

11 months ago

0.19.0

11 months ago

0.11.0

11 months ago

0.12.0

11 months ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.4

1 year ago

0.7.3

1 year ago

0.7.0

1 year ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.4

1 year ago

0.10.5

1 year ago

0.10.0

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.7.7

1 year ago

0.6.0

1 year ago

0.3.0

1 year ago

0.3.1

1 year ago

0.4.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.9.0

1 year ago

0.9.2

1 year ago

0.9.1

1 year ago

0.2.0

1 year ago

0.0.145-rc.0

1 year ago

0.0.145-rc.3

1 year ago

0.0.145-rc.2

1 year ago

0.0.144-rc.3

1 year ago

0.0.144-rc.1

1 year ago

0.0.144-rc.2

1 year ago

0.0.144-rc.0

1 year ago

0.0.145-next1

1 year ago

0.0.141-rc.1

1 year ago

0.0.141-rc.0

1 year ago

0.0.139-rc.0

1 year ago

0.0.139-rc.1

1 year ago

0.0.139

1 year ago

0.0.138

1 year ago

0.0.147-rc.0

1 year ago

0.0.147

1 year ago

0.0.142

1 year ago

0.0.141

1 year ago

0.0.140

1 year ago

0.0.146

1 year ago

0.0.145

1 year ago

0.0.144

1 year ago

0.0.143

1 year ago

0.0.129-alpha.8

1 year ago

0.0.129

1 year ago

0.0.129-alpha.9

1 year ago

0.0.137

1 year ago

0.0.136

1 year ago

0.0.131

1 year ago

0.0.130

1 year ago

0.0.135

1 year ago

0.0.134

1 year ago

0.0.133

1 year ago

0.0.132

1 year ago

0.0.129-alpha.3

2 years ago

0.0.128

2 years ago

0.0.129-alpha.4

2 years ago

0.0.127

2 years ago

0.0.129-alpha.1

2 years ago

0.0.126

2 years ago

0.0.129-alpha.2

2 years ago

0.0.125

2 years ago

0.0.129-alpha.7

1 year ago

0.0.129-alpha.5

2 years ago

0.0.129-alpha.6

1 year ago

0.0.124

2 years ago

0.0.123

2 years ago

0.0.122

2 years ago

0.0.121

2 years ago

0.0.117

2 years ago

0.0.116

2 years ago

0.0.115

2 years ago

0.0.114

2 years ago

0.0.119

2 years ago

0.0.118

2 years ago

0.0.120

2 years ago

0.0.84

2 years ago

0.0.85

2 years ago

0.0.86

2 years ago

0.0.87

2 years ago

0.0.88

2 years ago

0.0.89

2 years ago

0.0.80

2 years ago

0.0.81

2 years ago

0.0.82

2 years ago

0.0.83

2 years ago

0.0.73

2 years ago

0.0.74

2 years ago

0.0.75

2 years ago

0.0.76

2 years ago

0.0.77

2 years ago

0.0.78

2 years ago

0.0.79

2 years ago

0.0.70

2 years ago

0.0.71

2 years ago

0.0.72

2 years ago

0.0.63

2 years ago

0.0.64

2 years ago

0.0.65

2 years ago

0.0.66

2 years ago

0.0.67

2 years ago

0.0.68

2 years ago

0.0.69

2 years ago

0.0.106

2 years ago

0.0.105

2 years ago

0.0.104

2 years ago

0.0.103

2 years ago

0.0.109

2 years ago

0.0.108

2 years ago

0.0.107

2 years ago

0.0.102

2 years ago

0.0.101

2 years ago

0.0.100

2 years ago

0.0.113

2 years ago

0.0.112

2 years ago

0.0.111

2 years ago

0.0.110

2 years ago

0.0.95

2 years ago

0.0.96

2 years ago

0.0.97

2 years ago

0.0.98

2 years ago

0.0.99

2 years ago

0.0.90

2 years ago

0.0.91

2 years ago

0.0.92

2 years ago

0.0.93

2 years ago

0.0.94

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.46

2 years ago

0.0.47

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.29

2 years ago

0.0.62

2 years ago

0.0.60

2 years ago

0.0.61

2 years ago

0.0.59

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.58

2 years ago

0.0.50

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago