2.1.39 • Published 9 days ago

demio-ui v2.1.39

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
9 days ago

Demio React UI Components Library

As a small team, we need to build and maintain our UI library quickly and with a high level of quality. These are the tools and processes we use to achieve this.

Table of Contents

  1. Project Roadmap
  2. Getting Started
  3. Tools
  4. VS Code setup
  5. Project Structure
  6. Component Development
  7. Styling
  8. Storybook
  9. Testing
  10. Publishing

Project Roadmap

  • add www.chromatic.com integration to include designer in the UI components reviewing process
  • add CSS variables to variables.css from Figma
    • add color palette --demio-ui-color-{color-name}-{color-shade}
    • add font sizes --demio-ui-text-{size-name}
    • add font families --demio-ui-font-{font-name}
    • add elevations (shadows) --demio-ui-shadow-{elevation-name}
  • create a new components ( one MR for one component implementation)

    • <Icon /> - SVG icon component
      • all SVG styles (including color and size) should be managed by CSS
  • review Rollup configuration for CSS modules to add readable class names for components(possible switch to Webpack)

  • compare NewButton component with the design and replace Button with props updating at UD and Room apps
  • all existing components should be aligned with the current design( + update styles using CSS variables)
  • review and improve test coverage

Getting Started

To get started with the Demio React UI Components Library, follow these steps:

  1. Clone the repository: git clone git@gitlab.com:banzai_io/demio/demio-ui.git
  2. Install dependencies: npm install
  3. Run Storybook: npm run storybook and open http://localhost:6006 in your browser if it doesn't open automatically.

Tools

  • TypeScript - strongly typed programming language that builds on JavaScript
  • Rollup - module bundler like Webpack. While webpack and Rollup can achieve similar outcomes based on their configurations, webpack is commonly utilized for bundling applications, whereas Rollup is especially well-suited for bundling libraries.
  • Storybook - UI library development environment and component showcase
  • Maybe chromatic - visual regression testing for Storybook
  • Prettier - Code for matter
  • ESLint - Code linter
  • Jest and React Testing Library - unit testing
  • Rudix-UI
    • we can import only the components we need - this is important for bundle size
    • as it is unstyled, we don't need to overwrite styles like in Ant Design or Material UI
    • it has a high level of accessibility and customizability
  • CSS Modules - CSS modules allow us to write CSS in a modular way. Each component has its own CSS file, and class names are scoped to the component. This prevents CSS collisions and makes it easy to find and update styles.

Project Structure

The project follows a modular structure to make organizing and maintaining components easy. Key directories include:

  • src/components: Contains individual UI components.
  • src/icons: SVG icons.
  • src/index.css: Global styles.
  • src/variables.css Global CSS variables.
  • src/stories: global Storybook stories.
  • .storybook: Storybook configuration files.

VS Code setup

  • install Component Creator extension to create new component from template (.vscode/cch-template/React FC (ts, css, story, test)/{{pascalCase}}) with one command
  • install ESLint extension to lint your code
  • install Prettier extension to format your code

Component Development

All changes of Demio-UI should be done through MR!

When creating new components, follow these steps:

  1. Create a new component by Component Creator plugin with the name of your component in PascalCase.
  2. Check if this component already exists in the Radix UI library. If it does, use it instead of creating a new one.
  3. If you decide to add a new npm package, share the results of your research with the dev team.
  4. Add your component to src/{ComponentName}/{ComponentName}.stories.tsx file.
  5. Write tests for your component in src/{ComponentName}/{ComponentName}.test.tsx file.
  6. After development is finished - export your component from src/index.ts file.

Code recommendations:

  • one component -> one file with all related files (CSS, tests etc.)
  • try to make components as simple as possible(try make it stateless if it possible)
  • group hooks by type (state, ref, effect, etc.)
  • if you write a comment - try to make it short and clear, don't add obvious comments in code like // render component or //hooks
  • component should accept cssClass as a prop and apply it to the root element
  • use consistent naming across the whole library's components (i.e., className, width, isOpen, etc.).
  • try to keep backward compatibility while it doesn't cause unnecessary complications (all the corner cases have to be discussed)
  • every important node of the component has to have a unique class name formatted as "demio-ui-${component-name}-${element}" (for example, "demio-ui-modal-close-button", "demio-ui-modal-title", "demio-ui-modal-content", etc.). This is important for testing and styling purposes.
  • Avoid inline styling. If the component accepts the inline style - it should be applied to a component.
  • Props naming. Use consistent naming across the whole lib's components (i.e., className, width, isOpen, etc.).

Styling

  1. Every CSS variable should start with the --demio-ui- prefix. For example, --demio-ui-color-primary.
  2. The CSS variable name should be in the kebab-case.
  3. Global CSS variables should be defined in the src/variables.css file. These variables include the color palette, font sizes, font families, border radius, and more. Use them in your components.
  4. Component-specific styles should be defined in the src/components/{ComponentName}/{ComponentName}.module.css file. Use global css variables in your component styles to set up local variables. For example:
--demio-ui-button-color: var(--demio-ui-color-primary);

.button {
  color: var(--demio-ui-button-color);
}
  1. Use CSS variables to manage component variants without property duplication. For example:
--demio-ui-button-color: var(--demio-ui-button-color-primary);

.button {
  color: var(--demio-ui-button-color);
}

.button--secondary {
  --demio-ui-button-color: var(--demio-ui-button-color-secondary);
}

The same variables can be used to override component styles in your application. For example:

.parent .demio-ui-button {
  --demio-ui-button-color: blue;
}

For an example of component styles, look at the src/components/NewButton/Button.css file.

Storybook

Storybook is a UI library development environment and component showcase. It allows us to develop components in isolation, document them with examples, and test them in different states and configurations.

  1. Try to cover the main component variants in Storybook stories.
  2. Add all argTypes and args to your component stories.

We have automated deployment of Storybook to CDN on every push to the main branch.

Testing

We use Jest and React Testing Library for unit testing. We aim to have 100% test coverage for all components. Tests are run automatically on every commit or push. Testing commands:

  • npm run test - run all tests
  • npm run test:watch - run all tests in watch mode

Publishing

When publishing a new version of the library, follow these steps: Try to follow Semantic Versioning rules and Conventional Commits.

  • update the CHANGELOG.md file with the description of the changes
  • npm version <major|minor|patch> - bump the version
  • npm publish - publish to NPM (only from main branch)
  • push changes to the git
  • share CHANGELOG.md changes with the team in Slack dev channel

Git hooks

We use pre-commit and pre-push git hooks to run tests and linting before committing and pushing code. This ensures we don't commit code that doesn't pass tests or linting. Hooks are managed by husky and lint-staged.

2.1.39

9 days ago

2.1.37

13 days ago

2.1.36

17 days ago

2.1.35

25 days ago

2.1.34

1 month ago

2.1.32

1 month ago

2.1.33

1 month ago

2.1.31

1 month ago

2.1.28

1 month ago

2.1.29

1 month ago

2.1.30

1 month ago

2.1.27

1 month ago

2.1.26

2 months ago

2.1.25

2 months ago

2.1.23

2 months ago

2.1.21

2 months ago

2.1.22

2 months ago

2.1.20

2 months ago

2.1.19

3 months ago

2.1.18

3 months ago

2.1.16

3 months ago

2.1.17

3 months ago

2.1.15

3 months ago

2.1.14

3 months ago

2.1.12

3 months ago

2.1.13

3 months ago

2.1.10

3 months ago

2.1.11

3 months ago

2.1.9

3 months ago

2.1.2

3 months ago

2.1.4

3 months ago

2.1.3

3 months ago

2.1.6

3 months ago

2.1.5

3 months ago

2.1.8

3 months ago

2.1.7

3 months ago

2.1.1

3 months ago

2.0.11

3 months ago

2.0.10

4 months ago

2.0.9

4 months ago

2.0.7

4 months ago

2.0.8

4 months ago

2.0.5

4 months ago

2.0.6

4 months ago

2.0.2

4 months ago

2.0.4

4 months ago

2.0.0

4 months ago

1.0.95

4 months ago

1.0.96

4 months ago

1.0.94

5 months ago

1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.62

7 months ago

1.0.61

7 months ago

1.0.60

7 months ago

1.0.66

7 months ago

1.0.22

9 months ago

1.0.65

7 months ago

1.0.21

9 months ago

1.0.64

7 months ago

1.0.63

7 months ago

1.0.26

8 months ago

1.0.69

7 months ago

1.0.25

9 months ago

1.0.68

7 months ago

1.0.24

9 months ago

1.0.67

7 months ago

1.0.23

9 months ago

1.0.29

8 months ago

1.0.28

8 months ago

1.0.27

8 months ago

1.0.73

7 months ago

1.0.72

7 months ago

1.0.71

7 months ago

1.0.70

7 months ago

1.0.77

7 months ago

1.0.33

8 months ago

1.0.76

7 months ago

1.0.75

7 months ago

1.0.31

8 months ago

1.0.74

7 months ago

1.0.30

8 months ago

1.0.37

8 months ago

1.0.36

8 months ago

1.0.79

7 months ago

1.0.35

8 months ago

1.0.78

7 months ago

1.0.34

8 months ago

1.0.39

8 months ago

1.0.38

8 months ago

1.0.80

7 months ago

1.0.84

7 months ago

1.0.40

8 months ago

1.0.83

7 months ago

1.0.82

7 months ago

1.0.81

7 months ago

1.0.88

7 months ago

1.0.44

8 months ago

1.0.87

7 months ago

1.0.43

8 months ago

1.0.86

7 months ago

1.0.42

8 months ago

1.0.85

7 months ago

1.0.41

8 months ago

1.0.48

8 months ago

1.0.47

8 months ago

1.0.46

8 months ago

1.0.45

8 months ago

1.0.49

8 months ago

1.0.91

6 months ago

1.0.90

7 months ago

1.0.51

8 months ago

1.0.50

8 months ago

1.0.93

6 months ago

1.0.92

6 months ago

1.0.55

8 months ago

1.0.54

8 months ago

1.0.53

8 months ago

1.0.52

8 months ago

1.0.59

7 months ago

1.0.15

10 months ago

1.0.58

7 months ago

1.0.14

10 months ago

1.0.57

7 months ago

1.0.13

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.0

11 months ago