aristid-ds v5.0.0
ARiSTiD Design System Readme.
Getting Started
Prerequisites
- npm
npm install npm@latest -g
- yarn
npm install yarn -g
Installation
- Create a folder for this repo
mkdir DESIGN-SYSTEM
- Clone the repo
git clone https://gitlab.aristid.com/dev/design-system.git
- Install requiered packages
yarn install
- Start the application
yarn storybook
- Once the installation is complete, you can access to the application at http://localhost:6006.
Usage in a project
- How To Import
yarn add aristid-ds
npm install aristid-ds
- How to use KitApp
The KitApp is an essential context for the proper functioning of the design system components. This context is mainly used to supply the various components with style and translation overloads.
By default KitApp provides Aristid Theme but you can override to customize every component with theme tokens.
import {KitApp} from "aristid-ds";
<KitApp>
<App />
</KitApp>
If you don't use KitApp, you'll get missing styles / translation and errors when using components.
- Usage
All components are exported directly from 'aristid-ds' package.
import {KitButton, Kitcheckbox} from "aristid-ds";
Theme You can override default theme by passing a theme configuration to the props
theme
ofKitApp
. All tokens are available in the documentation of each components in the sectionDesign Tokens
. Your theme configuration can be ease by using the Theme Editor available in the storybook. You canedit
andexport
a ready to use configuration.Internationalization You can override default translation by passing translation configuration to the props
locale
of theKitApp
. Major part of tokens are override by antd cf Antd translation documentation and the other part is design system tokens. You can fin them in the sectionTranslation Tokens
of each components.
Development
Code structure
- 📁 .storybook (💡 Configuration files of Storybook)
- 📁 src (💡 Design system code folder)
- 📁 fonts (💡 Provided font)
- 📁 hooks (💡 Custom Hooks)
- 📁 Kit (💡 Components code)
- 📁 App
- 📁 DataDisplay
- 📁 DataEntry
- 📁 Feedback
- 📁 General
- 📁 Layout
- index.tsx
- 📁 theme (💡 Theming code)
- 📁 aristid (💡 Default theme use by
KitApp
) - 📁 types (💡 Themes types declaration)
- 📁 utils (💡 All themes utils)
- 📁 theme-builder (💡 Use to build active theme)
- 📁 tokens-mapper (💡 Use to map our custom tokens with Antd tokens)
- theme-context.tsx
- 📁 aristid (💡 Default theme use by
- 📁 translation (💡 Translation code)
- 📁 en-US (💡
en-US
custom tokens) - 📁 fr-FR (💡
fr-FR
custom tokens) - 📁 types (💡 Translation types declaration)
- 📁 utils (💡 All translation utils)
- locale-context.tsx
- 📁 en-US (💡
- 📁 utils (💡 All components utils)
- 📁 functions (💡 Function use in several components)
- index.tsx
- vite-env.d.ts
- 📁 stories (💡 Storybook documentation) - 📁 01-Design - themeEditor.mdx (💡 Live theme editor page) - 📁 02-Design System (💡 Components folder) - 📁 01-General - 📁 02-Layout - 📁 03-Navigation - 📁 04-DataEntry - 📁 05-DataDisplay - 📁 06-Feedback - 📁 assets - 📁 Root - 📁 template - index.tsx (💡 Export all EditorTemplate for themeEditor.mdx) - tokens.tsx (💡 Theme tokens generate by tokens-generator.js) - types.d.ts
Creating a component
Component code
- Create a new folder for the code of your component
mkdir DESIGN-SYSTEM/src/Kit/DataDisplay/Tooltip
- In this folder create three files
cd Tooltip
touch index.tsx
touch types.d.ts
touch styles.module.scss
- Example of
Tooltip/index.tsx
import React, {FunctionComponent} from 'react';
import {Tooltip as AntdTooltip} from 'antd';
import {IKitTooltip} from './types';
import styles from './styles.module.scss';
export const KitTooltip: FunctionComponent<IKitTooltip> = tooltipProps => {
const {appId} = useKitTheme();
return <AntdTooltip {...tooltipProps} className={`${appId} ${styles['kit-tooltip']} ${tooltipProps.className ?? ''}`}/>;
};
KitTooltip.displayName = 'KitTooltip';
- Ecample of
Tooltip/styles.module.scss
@import '../../../css/mixins.scss';
:local(.kit-tooltip) {
...
}
- Example of
Tooltip/types.d.ts
import {TooltipProps} from 'antd';
import {HTMLAttributes} from 'react';
type AntdTooltipTypesToOmit = 'color' | 'overlayClassName' | 'overlayStyle' | 'overlayInnerStyle';
export interface IKitTooltip extends Omit<TooltipProps, AntdTooltipTypesToOmit>, HTMLAttributes<HTMLDivElement> {}
- Export your component in
/Kit/05-DataDisplay/index.tsx
import {KitTooltip} from './Tooltip';
...
export {KitTooltip};
Component theming
Every components style of the design system can be override by tokens.
Create a token file type The
theme
folder is structure as same as the Kit folder.mkdir DESIGN-SYSTEM/src/theme/type/components/DataDisplay/tooltip
Create a token file The token file is the definition of all tokens with their value. It exports a function that create the theme for the cmponent. You define this file in the
aristid
that is the default theme of the design system.mkdir DESIGN-SYSTEM/src/theme/aristid/components/DataDisplay/tooltip
Global theme type After that, go to file
src/theme/type/index.tsx
to add your component type. This files contains all components that can be override.Global theme You can now add your component in the
src/theme/aristid/index.tsx
and you add your component and the function that creates tokens defined in point 2.Component Antd mapper As we use both
antd
anddesign system
tokens, we normalize all token to follow a same model. If your component uses antd tokens, you have to add a mapper in thesrc/theme/utils/tokens-mapper
folder. This folder as the same folder structure as the rest of the application.// utils/tokens-mapper/DataDisplay/Tag import {IKitTagTheme} from '@theme/types/components/DataDisplay/Tag'; export const mapTagKitTokenToAntdToken = (kitTagTheme: IKitTagTheme) => { const {colors, border} = kitTagTheme; return { defaultBg: colors.default.background.default, defaultColor: colors.default.typography.default, borderRadiusSM: border.radius }; };
Global theme mapper After that, you have to add your component mapper to the global mapper in the file
src/theme/utils/tokens-mapper/index.tsx
.Theme consumption You can use the theme in your styled component by calling the hook
useKitTheme
. You can get the component theme by callingtheme.components.Tooltip
.const {theme} = useKitTheme(); const tooltipTheme = theme.components.Tooltip; return <KitTooltip $theme={tooltipTheme} />;
Component documentation
- Copy - Paste the template folder (stories/template)
This folder contains all required files to create component documentation.
examples
: contains all the code of examples, index.tsx export all examples in the convenient format.data.tsx
: contains the API data (Args, Template, ...)Component.mdx
: file that contains the component documentation (usage / examples / api / tokens)Component.stories.tsx
: file use by storybook as a story to test and display.
Implement examples Create all examples needed in the documentation.
// basic.tsx import React from 'react'; const App = () => { return ( <KitTooltip title"this is an example"> <div>Template Example</div> </KitTooltip> ); }; export default App;
Export examples You have to export all of your examples in the index.tsx of the examples folder. It permits to export all files in the convenient format to be read by the custom canvas component.
import Basic from './basic'; import BasicSource from './basic?raw'; export const Sources = { Basic: BasicSource }; export default { Basic };
Modify Component.mdx
- Rename Component in the file name by your component name (ex : Tooltip.mdx).
- Rename Component in the file by your component name.
- Complete all examples you want to display in documentation.
// Tooltip.mdx import { Meta, Story, Canvas } from "@storybook/addon-docs"; import { Controls } from "@storybook/addon-docs"; import { argTypes, Template } from "./data"; import Examples, { Sources } from './examples'; import CustomCanvas from '../../../../.storybook/components/CustomCanvas.jsx'; import DesignTokens from '../../.storybook/components/DesignTokens'; import fields from '../tokens'; import * as Tooltip from './Tooltip.stories'; <Meta of={Tooltip} /> # Tooltip Brief component description. ## Examples ##### Basic Example description <CustomCanvas content={Examples.Basic} source={Sources.Basic} id="tooltip-basic"/> ## Api <Canvas of={Tooltip.Api} /> <Controls of={Tooltip.Api} /> ## Design Tokens <DesignTokens path="components.Tooltip" tokens={fields?.components?.Tooltip} />
Modify Component.stories.tsx
- Rename Component in the file name by your component name (ex : Tooltip.stories.tsx).
- Rename the meta object title attribute by the pass of the component (ex : title: 'Design System/DataDisplay/Tooltip'). The path specify where the component will be placed in the storybook.
- Replace KitComponent by your component (ex KitTooltip).
// Tooltip.stories.tsx import type {Meta, StoryObj} from '@storybook/react'; import {KitTooltip} from '@components/DataDisplay'; import {argTypes, Template} from './data'; const meta: Meta<typeof KitTooltip> = { component: KitTooltip, title: 'Design System/DataDisplay/Tooltip', argTypes: argTypes }; export default meta; type Story = StoryObj<typeof KitTooltip>; export const Api: Story = { render: Template };
Import Component Theme Editor Template In the
data.tsx
file, you defined aEditorTemplate
. It permits to modify in live all tokens and get a preview of the component. You have to import this Editor in thestories/index.tsx
and add it inside the object that contains all theme editor that already exist.import {EditorTemplate as Tooltip} from './02-Design System/05-DataDisplay/Tooltip/data'; export default { ... DataDisplay: { ... Tooltip ... } ... }
Design tokens generation When everything is setup, you have to run the tokens-generator script to generate all design tokens in the documentation.
node tokens-generator.js
After the script run, section
Design Tokens
documentation is up to date with all design tokens.
Nightly build
A nightly version of the package is published on daily basis on branch develop (assuming new commits have been pushed on develop branch). To use it just install the more recent next version :
yarn add aristid-ds@next
Note: Though it is useful to test upcoming feature, this version should NEVER be used in production
Important
Every import of antd library should pass by antd
or ant/es
. lib
import will lead to issues in the build process.
Contributing
Any contributions you make are greatly appreciated. If you have a suggestion that would make this better, please create a pull request. You can also simply open an issue with the appropriate tag to report a bug or inconsistencies in documentation.
Commit
Commit message must respect the following pattern :
git commit -m "type[(component)] : message"
The type is telling us what change or iteration is being made. We have the following types:
Type | Description | Example |
---|---|---|
test | indicates any type of creation or alteration of test codes | Creation of unit tests |
feat | indicates the development of a new feature for the project. | Adding a service, functionality, endpoint, etc |
refactor | used when there is a code refactoring that does not have any impact on the system logic/rules | Code changes after a code review |
style | used when there are code formatting and style changes that do not change the system in any way | Change the style-guide, change the lint convention, fix indentations, remove white spaces, remove comments, etc… |
fix | used when correcting errors that are generating bugs in the system | Apply a handling for a function that is not behaving as expected and returning an error |
chore | indicates changes to the project that do not affect the system or test files. These are developmental changes | Change rules for eslint, add prettier, add more file extensions to .gitignore |
docs | used when there are changes in the project documentation | add information in the API documentation, change the README, etc |
build | used to indicate changes that affect the project build process or external dependencies | add/remove npm dependencies, etc… |
perf | indicates a change that improved system performance | change ForEach to While, etc… |
ci | used for changes in CI configuration files | Circle, Travis, BrowserStack, etc… |
revert | indicates the reversal of a previous commit |
Example :
git commit -m "style(Tooltip) : Change color on hover"
📚 Based on this article.
Gitflow
We use Gitflow as Git branching model for this project. We have two branches to record our project history :
- main (💡 Stores the official release history)
- develop (💡 Serves as an integration branch for features)
📚 Based on this article.
Feature
Creating a feature branch
git flow feature start addTooltipComponent
Continue your work and use Git like you normally would.
Finishing a feature branch
git flow feature finish addTooltipComponent
Release
Creating a release
git flow release start 0.1.0
⚠️ - Don't forget to update the version number in package.json
Finishing a release
git flow release finish '0.1.0'
Hotfix
Creating a release
git flow hotfix start fixTooltip
Finishing a release
git flow hotfix finish fixTooltip
5 days ago
10 days ago
10 days ago
10 days ago
12 days ago
26 days ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
6 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago