@redsift/icons 6.0.0-alpha.9 → 6.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/CONTRIBUTING.md +382 -0
  2. package/package.json +4 -4
@@ -0,0 +1,382 @@
1
+ # Contribute
2
+
3
+ ## Develop
4
+
5
+ Make sure you have the following requirements installed: [node](https://nodejs.org/) (v16+) and [yarn](https://yarnpkg.com/en/) (v1.22.0+)
6
+
7
+ Clone the repo (or fork it first if you're not part of Red Sift organization).
8
+ ```
9
+ git clone git@github.com:redsift/design-system.git
10
+ cd design-system
11
+ yarn install
12
+ ```
13
+
14
+ You can then run the storybook and browse to [http://localhost:9000](http://localhost:9000) with:
15
+ ```bash
16
+ yarn start:storybook
17
+ ```
18
+
19
+ #### Architecture
20
+
21
+ The Design System is following a monorepo architecture, providing multiple packages based on different use cases.
22
+
23
+ - `@redsift/icons`
24
+
25
+ This package provides icons based on [Material Design Icon](https://materialdesignicons.com/) library.
26
+
27
+ - `@redsift/design-system`
28
+
29
+ This package is the main package of Red Sift's Design System. It provides the majority of the components, including layout, formatting, navigation, form and interactive components.
30
+
31
+ - `@redsift/table`
32
+
33
+ This package provides datagrid components and features based on [MUI DataGrid](https://mui.com/x/react-data-grid/). Due to the use of advanced features, a [premium license](https://mui.com/x/introduction/licensing/#premium-plan) from MUI is required.
34
+
35
+ - `@redsift/charts`
36
+
37
+ This package provides charts components. Charts are based on [d3.js](https://d3js.org/) and are mainly static. For filterable charts, see `@redsift/dashboard`.
38
+
39
+ - `@redsift/dashboard`
40
+
41
+ This package provides dashboard-related components. Charts are based on [dc.js](https://dc-js.github.io/dc.js/) and [crossfilter](https://crossfilter.github.io/crossfilter/) and datagrids are based on `@redsift/table`. It contains every filterable elements to use inside a dashboard. For static charts, see `@redsift/charts`.
42
+
43
+ - _Deprecated_ `@redsift/design-system-legacy`
44
+
45
+ This package contains all components prior to the 6.0.0 version. These components are deprecated and contributing to this package is discouraged since it will be removed in the future.
46
+
47
+ Please make sure to work inside the correct package when making contribution.
48
+
49
+ #### Shared code
50
+
51
+ If you need something inside more than one package, do not duplicate the code. Place it inside one package, export it from this package and import it inside the others.
52
+
53
+ For instance, `@redsift/dashboard` and `@redsift/charts` both have a `PieChart` component that both share the `PieChartVariant` type interface. `PieChartVariant` has been implemented inside `@redsift/charts` and is imported inside `@redsift/dashboard`.
54
+
55
+ For more convenience, add an export of this shared code in every package using it. In this example, `@redsift/dashboard` also exports `PieChartVariant`. This will make it easier for the user later.
56
+
57
+ ```ts
58
+ // Even if PieChartVariant is implemented inside the charts package, the following code is not practical
59
+ import { PieChartVariant } from '@redsift/charts';
60
+ import { PieChart } from '@redsift/dashbord';
61
+
62
+ // Reexporting it from the dashboard package makes it really easier
63
+ import { PieChart, PieChartVariant } from '@redsift/dashbord';
64
+ ```
65
+
66
+ To define which package should contain the shared code, select the one that would not create any circular dependencies.
67
+
68
+ #### Dependencies
69
+
70
+ We try to use as few dependencies as possible.
71
+
72
+ For instance, we don't want to use `lodash` or `underscore` in the Design System. See why [you don't need them](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore) and how to work without them.
73
+
74
+ We also don't want to use `momentjs`. See why [you don't need it](https://github.com/you-dont-need/You-Dont-Need-Momentjs) and what alternatives are there.
75
+
76
+ When dependencies are required, we try not to import them entirely to optimise the tree-shaking of the Design System.
77
+
78
+ ```ts
79
+ // don't
80
+ import * as d3 from 'd3';
81
+
82
+ // do
83
+ import { sum, scaleOrdinal } from 'd3';
84
+ ```
85
+
86
+ #### Scaffolding
87
+
88
+ Each component should be in its own folder. If a subcomponent can be used as a standalone component, it should be in its own folder too. For instance, `CheckboxGroup` uses `Checkbox` but `Checkbox` can be used alone. In this case, `CheckboxGroup` and `Checkbox` both have their own folder. For `PieChart` and `PieChartSlice`, a `PieChartSlice` can not be used alone. It only exists inside a `PieChart` component. Therefore, both components are inside the same folder.
89
+
90
+ The name of the folder shoud be in kebab-case, the names of the component files are in PascalCase and the names of others files are in kebab-case. The scaffolding should be the same for every component. For instance, for the `Badge` component, it looks like this:
91
+
92
+ ```
93
+ badge/
94
+ __snapshots__/
95
+ Badge.stories.tsx
96
+ Badge.test.tsx
97
+ Badge.tsx
98
+ index.ts
99
+ styles.ts
100
+ types.ts
101
+ ```
102
+
103
+ See the Typescript section to see what to put inside the `types.ts` file.
104
+
105
+ See the Styling section to see what to put inside the `styles.ts` file.
106
+
107
+ The component should stricly follow the following structure:
108
+
109
+ ```ts
110
+ import React, { forwardRef, RefObject, useRef } from 'react';
111
+ import classNames from 'classnames';
112
+ import { Comp } from '~/types';
113
+ import { StyledBadge } from './styles';
114
+ import { BadgeProps } from './types';
115
+
116
+ const COMPONENT_NAME = 'RedSiftBadge';
117
+ const CLASSNAME = 'redsift-badge';
118
+ const DEFAULT_PROPS: Partial<BadgeProps> = {
119
+ // default values
120
+ };
121
+
122
+ /**
123
+ * The Badge component.
124
+ */
125
+ export const Badge: Comp<BadgeProps, HTMLDivElement> = forwardRef((props, ref) => {
126
+ const {
127
+ // props
128
+ ...forwardedProps
129
+ } = props;
130
+
131
+ return (
132
+ <StyledBadge
133
+ {...forwardedProps}
134
+ // transient props
135
+ className={classNames(Badge.className, `${Badge.className}-${variant}`, className)}
136
+ ref={badgeRef as RefObject<HTMLDivElement>}
137
+ >
138
+ // content of the component if needed
139
+ </StyledBadge>
140
+ );
141
+ });
142
+ Badge.className = CLASSNAME;
143
+ Badge.defaultProps = DEFAULT_PROPS;
144
+ Badge.displayName = COMPONENT_NAME;
145
+ ```
146
+
147
+ The main things to keep in mind here are:
148
+ - to use the custom `Comp` type,
149
+ - to forward ref and props,
150
+ - to concatenate classNames,
151
+ - to define default values and
152
+ - to use types from `types.ts` and styles from `styles.ts`.
153
+
154
+ #### API
155
+
156
+ The API of the components should be consistent with other components.
157
+
158
+ For instance, `isSelected` is the dedicated name for a prop indicating whether a component is selected or not. You should not use `selected` for instance. You could even be tempted to use `checked` or `isChecked` for a Checkbox component, but even if it can feel more suitable for this particular component, it creates inconsistencies among all components.
159
+
160
+ Try to think Design System when creating the API of your component. We want to provide visual options and variants for our components, but the possibilities should be limited.
161
+
162
+ ```ts
163
+ // don't
164
+ innerRadius?: number;
165
+ outerRadius?: number;
166
+ height?: number;
167
+ width?: number;
168
+
169
+ // do
170
+ size?: ButtonSize;
171
+ ```
172
+
173
+ To know how to define your API, to name and document your props, take a look at the existing components.
174
+
175
+ ### Tests
176
+ We use [jest](https://jestjs.io/) for unit tests and [react-testing-library](https://testing-library.com/docs/react-testing-library/intro) for rendering and writing assertions. We also use [Storyshots](https://storybook.js.org/addons/@storybook/addon-storyshots) to automatically take a code snapshot of every story.
177
+
178
+ Please make sure you include tests with your pull requests. Our CI will run the tests on each PR. A minimum of 90% code coverage is required for statements, branches, functions and lines of every package. However, in practice, we try to reach a 100% code coverage.
179
+
180
+ We split the tests into 2 groups.
181
+
182
+ *Visual tests*
183
+ - A Storybook story should be written for each visual state that a component can be in (based on props).
184
+
185
+ *Unit tests*
186
+ - (Props) Anything that should be changed by a prop should be tested via react-testing-library.
187
+ - (Events) Anything that should trigger an event should be tested via react-testing-library.
188
+
189
+ You can run the tests with:
190
+
191
+ ```bash
192
+ yarn test
193
+ ```
194
+
195
+ Or for a specific package with:
196
+
197
+ ```bash
198
+ yarn test:design-system
199
+ yarn test:charts
200
+ yarn test:dashboard
201
+ ```
202
+
203
+ Do not forget to update the snapshots with the `-u` option when you modify or create stories. However, you should **always** check the generated snapshots to see if they are correct. Do **not** blindly update the snapshots.
204
+
205
+ ### Linting
206
+
207
+ The code is linted with [eslint](https://eslint.org/). You can run the linter with:
208
+ ```bash
209
+ yarn lint
210
+ ```
211
+
212
+ Or for a specific package with:
213
+
214
+ ```bash
215
+ yarn lint:charts
216
+ yarn lint:dashboard
217
+ yarn lint:design-system
218
+ yarn lint:table
219
+ ```
220
+
221
+ ### TypeScript
222
+
223
+ The code is written in [TypeScript](https://www.typescriptlang.org/). The type checker will usually run in your editor, but also runs when you run:
224
+ ```bash
225
+ yarn check-types
226
+ ```
227
+
228
+ Or for a specific package with:
229
+
230
+ ```bash
231
+ yarn check-types:charts
232
+ yarn check-types:dashboard
233
+ yarn check-types:design-system
234
+ yarn check-types:table
235
+ ```
236
+
237
+ Types and interfaces are implemented inside `types.ts` files. Every shared type and interface should be placed inside a `types.ts` file at the root of the `src` folder of a component.
238
+
239
+ The `types.ts` file of a component should at minima export an interface for the component itself, named using the name of the component followed by `Props` (i.e. `BadgeProps`) and extending the HTML element it is based on (i.e. `React.ComponentProps<'div'>`). It should also export an interface for the main styled components it uses, using the same name prefixed by `Styled` (i.e. `StyledBadgeProps`). The props of the main interface **must** be documented with [jsdoc](https://jsdoc.app/) comments because this will be automatically parsed to fill the prop table inside the documentation website.
240
+
241
+ ```ts
242
+ /**
243
+ * Component props.
244
+ */
245
+ export interface BadgeProps extends ComponentProps<'div'> {
246
+ /** Badge variant. */
247
+ variant?: BadgeVariant;
248
+ }
249
+ ```
250
+
251
+ The styled component interface should be based on the main interface but omit every prop you don't want to forward to the rendered component. Every non native prop you need to use inside the styled component should be use as [transient props](https://styled-components.com/docs/api#transient-props) and therefore prefixed by a `$` character.
252
+
253
+ ```ts
254
+ export type StyledBadgeProps = Omit<BadgeProps, 'variant'> & {
255
+ $variant: BadgeProps['variant'];
256
+ };
257
+ ```
258
+
259
+ This file is also use to implement and export any other props you may need for your component like variant interface, color interface, etc.
260
+
261
+ ```ts
262
+ /**
263
+ * Component variant.
264
+ */
265
+ export const BadgeVariant = {
266
+ dot: 'dot',
267
+ standard: 'standard',
268
+ } as const;
269
+ export type BadgeVariant = ValueOf<typeof BadgeVariant>;
270
+ ```
271
+
272
+ The variants, colors and all other enum-based interfaces should be implemented exactly as above to make the property compatible with both the enum values and their string equivalent values. In this example, `BadgeVariant.standard` and `"standard"` are both valid values for the `variant` prop.
273
+
274
+ ### Styling
275
+
276
+ We use [styled-components](https://styled-components.com/) and [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) for styling. CSS variables are centralized through a [style dictionary](https://amzn.github.io/style-dictionary/#/).
277
+
278
+ The `styles.ts` of a component should contain all the styled-component codes. At least one main variable should be implemented and named using the name of the component prefixed by `Styled` (i.e. `StyledBadge`).
279
+
280
+ ```ts
281
+ /**
282
+ * Component style.
283
+ */
284
+ export const StyledBadge = styled.div<StyledBadgeProps>`
285
+ ${({ $color }) => $color ? css`
286
+ color: var(--redsift-color-${$color}-contrast);
287
+ background-color: var(--redsift-color-${$color}-main);
288
+ ` : ''}
289
+ `
290
+ ```
291
+
292
+ Make sure you are using the same HTML element for the styled component (i.e. `styled.div`) and the type interface (i.e. `ComponentProps<'div'>`). Type your variable with the interface you created in the `types.ts` file.
293
+
294
+ Make sure to use only [transient props](https://styled-components.com/docs/api#transient-props) and to use the styled-component's `css` helper when conditionnaly creating a new CSS block.
295
+
296
+ ### Accessibility
297
+
298
+ We are trying to make the Design System as accessible as possible by following the [Web Accessibility Initiative guidelines](https://www.w3.org/WAI/ARIA/apg/).
299
+
300
+ Before implementing a component, try to see if there is a [pattern](https://www.w3.org/WAI/ARIA/apg/patterns/) - or a composition of multiple patterns - that is suitable for this component and follow the guidelines.
301
+
302
+ However, before using any ARIA, [read this disclaimer carefully](https://www.w3.org/WAI/ARIA/apg/practices/read-me-first/).
303
+
304
+ ### Storybook
305
+ We use [Storybook](https://storybooks.js.org) for local development. Run the following command to start it:
306
+
307
+ ```bash
308
+ yarn start:storybook
309
+ ```
310
+
311
+ Then, open [http://localhost:9000](http://localhost:9000) in your browser to play around with the components and test your changes.
312
+
313
+ You can use knobs and other storybook addons to create your stories. However, it is necessary to create stories covering all the options and variants of your component to generate snapshots.
314
+
315
+ Storybook is shared among every packages of the Design System. Follow the naming of the components that already exists in the same package to make sure it will appear in the correct section.
316
+
317
+ ### Documentation
318
+
319
+ We use a [Next.js](https://nextjs.org/) app with [MDX](https://mdxjs.com/) support as a documentation and demonstration site for the Design System. This app can be run as following:
320
+
321
+ ```bash
322
+ yarn dev:website
323
+ ```
324
+
325
+ Then, open [http://localhost:3000](http://localhost:3000) in your browser.
326
+
327
+ To add documentation for a component, a MDX file should be created in the `packages/website/pages/` folder and more precisely inside the subfolder corresponding to the section the page belongs to (i.e. `packages/website/pages/forms/checkbox.mdx` for the `Checkbox` component inside the `Forms` section).
328
+
329
+ To appear in the website's Side Panel, the page should be listed in `packages/website/components/CustomAppSidePanel/CustomAppSidePanel.tsx`) under the corresponding section.
330
+
331
+ A component page should be structured as following:
332
+ - **Introduction**
333
+ - **Installation**: explains which package to install and how
334
+ - **Usage**: explains how to import the component
335
+ - **Example**: explains the simplest example of usage for the component
336
+ - **Content** (optional): explains what the component can contain, if it can (for instance, a CheckboxGroup can contain Checkboxes)
337
+ - **Labeling** (optional): explains how to label the component, with accessibility and internationalization concerns; should only be used when the label is the only accessibility concern for this component, if there is more, use the Accessbility section below instead
338
+ - **Value** (optional): explains the values and states a component can have; only used for form components
339
+ - **Data** (optional): explains how the data should be formatted to display the component; only used for charts, table and dashboard components
340
+ - **Events** (optional): explains the different events attached to the component, controlled and uncontrolled version, validation system, etc...
341
+ - **Accessibility** (optional): dedicated accessibility section when it goes beyond the labeling, for instance to give navigation advice, etc
342
+ - **Visual options**: displays all the visual options and variants of the component
343
+ - **Props**: displays a table of component props
344
+
345
+ To display a prop table, use the `PropsTable` component as following:
346
+
347
+ ```ts
348
+ <PropsTable component="Button" />
349
+ ```
350
+
351
+ To display a demo, first create a demo (a simple `tsx` file) in the demo folder (`packages/website/demo/`) inside a subfolder with the name of the component (i.e. `packages/website/demo/button/coloring` for a coloring demo of the `Button` component). Then use the `DemoBlock` as following:
352
+
353
+ ```ts
354
+ <DemoBlock path="button/coloring" />
355
+ ```
356
+
357
+ To display simple code, use the `CodeBlock` as following:
358
+
359
+ ```ts
360
+ <CodeBlock codeString={`
361
+ yarn add @redsift/design-system
362
+ `} language="sh" />
363
+ ```
364
+
365
+ ## Build
366
+
367
+ The Design System is built using [Rollup](https://rollupjs.org/guide/en/) inside the `dist` folder of each package by running the following command:
368
+
369
+ ```bash
370
+ yarn build
371
+ ```
372
+
373
+ Or for a specific package with:
374
+
375
+ ```bash
376
+ yarn build:charts
377
+ yarn build:dashboard
378
+ yarn build:design-system
379
+ yarn build:icons
380
+ yarn build:legacy
381
+ yarn build:table
382
+ ```
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/redsift/design-system/issues"
7
7
  },
8
- "description": "Red Sift icons.",
8
+ "description": "Icon library as part of Red Sift's Design System. This package is based on mdi/js library.",
9
9
  "homepage": "https://github.com/redsift/design-system",
10
10
  "license": "MIT",
11
11
  "name": "@redsift/icons",
@@ -19,7 +19,7 @@
19
19
  "url": "git+https://github.com/redsift/design-system"
20
20
  },
21
21
  "sideEffects": false,
22
- "version": "6.0.0-alpha.9",
22
+ "version": "6.1.0-alpha.0",
23
23
  "scripts": {
24
24
  "build": "rollup -c",
25
25
  "prepublishOnly": "yarn build"
@@ -45,8 +45,8 @@
45
45
  "rollup-plugin-cleaner": "^1.0.0",
46
46
  "rollup-plugin-copy": "^3.4.0",
47
47
  "rollup-plugin-execute": "^1.1.0",
48
- "rollup-plugin-tsconfig-paths": "^1.1.8",
48
+ "rollup-plugin-ts-paths-resolve": "^1.7.1",
49
49
  "rollup-plugin-typescript-paths": "^1.3.1"
50
50
  },
51
- "gitHead": "a7fb1748bcef2c39c02ddc88158e3bf2b7c4d323"
51
+ "gitHead": "cbf71715865796ec3f73f017709f6635be4a8091"
52
52
  }