@redsift/icons 6.3.0 → 7.0.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.
- package/CONTRIBUTING.md +71 -40
- package/package.json +2 -2
package/CONTRIBUTING.md
CHANGED
|
@@ -5,18 +5,28 @@
|
|
|
5
5
|
Make sure you have the following requirements installed: [node](https://nodejs.org/) (v16+) and [yarn](https://yarnpkg.com/en/) (v1.22.0+)
|
|
6
6
|
|
|
7
7
|
Clone the repo (or fork it first if you're not part of Red Sift organization).
|
|
8
|
+
|
|
8
9
|
```
|
|
9
10
|
git clone git@github.com:redsift/design-system.git
|
|
10
11
|
cd design-system
|
|
11
12
|
yarn install
|
|
12
13
|
```
|
|
13
14
|
|
|
15
|
+
Set up your environment variable file by copying the template file:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
cp .env.template .env
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then edit the `.env` file with the correct values. NEVER commit the `.env` file directly or any secrets and credentials it might contain.
|
|
22
|
+
|
|
14
23
|
You can then run the storybook and browse to [http://localhost:9000](http://localhost:9000) with:
|
|
24
|
+
|
|
15
25
|
```bash
|
|
16
26
|
yarn start:storybook
|
|
17
27
|
```
|
|
18
28
|
|
|
19
|
-
|
|
29
|
+
### Architecture
|
|
20
30
|
|
|
21
31
|
The Design System is following a monorepo architecture, providing multiple packages based on different use cases.
|
|
22
32
|
|
|
@@ -46,7 +56,7 @@ The Design System is following a monorepo architecture, providing multiple packa
|
|
|
46
56
|
|
|
47
57
|
Please make sure to work inside the correct package when making contribution.
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
### Shared code
|
|
50
60
|
|
|
51
61
|
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
62
|
|
|
@@ -65,7 +75,7 @@ import { PieChart, PieChartVariant } from '@redsift/dashbord';
|
|
|
65
75
|
|
|
66
76
|
To define which package should contain the shared code, select the one that would not create any circular dependencies.
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
### Dependencies
|
|
69
79
|
|
|
70
80
|
We try to use as few dependencies as possible.
|
|
71
81
|
|
|
@@ -83,7 +93,7 @@ import * as d3 from 'd3';
|
|
|
83
93
|
import { sum, scaleOrdinal } from 'd3';
|
|
84
94
|
```
|
|
85
95
|
|
|
86
|
-
|
|
96
|
+
### Scaffolding
|
|
87
97
|
|
|
88
98
|
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
99
|
|
|
@@ -122,36 +132,43 @@ const DEFAULT_PROPS: Partial<BadgeProps> = {
|
|
|
122
132
|
/**
|
|
123
133
|
* The Badge component.
|
|
124
134
|
*/
|
|
125
|
-
export const Badge: Comp<BadgeProps, HTMLDivElement> = forwardRef(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
135
|
+
export const Badge: Comp<BadgeProps, HTMLDivElement> = forwardRef(
|
|
136
|
+
(props, ref) => {
|
|
137
|
+
const {
|
|
138
|
+
// props
|
|
139
|
+
...forwardedProps
|
|
140
|
+
} = props;
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<StyledBadge
|
|
144
|
+
{...forwardedProps}
|
|
145
|
+
// transient props
|
|
146
|
+
className={classNames(
|
|
147
|
+
Badge.className,
|
|
148
|
+
`${Badge.className}-${variant}`,
|
|
149
|
+
className
|
|
150
|
+
)}
|
|
151
|
+
ref={ref as RefObject<HTMLDivElement>}
|
|
152
|
+
>
|
|
153
|
+
// content of the component if needed
|
|
154
|
+
</StyledBadge>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
142
158
|
Badge.className = CLASSNAME;
|
|
143
159
|
Badge.defaultProps = DEFAULT_PROPS;
|
|
144
160
|
Badge.displayName = COMPONENT_NAME;
|
|
145
161
|
```
|
|
146
162
|
|
|
147
163
|
The main things to keep in mind here are:
|
|
164
|
+
|
|
148
165
|
- to use the custom `Comp` type,
|
|
149
166
|
- to forward ref and props,
|
|
150
167
|
- to concatenate classNames,
|
|
151
168
|
- to define default values and
|
|
152
169
|
- to use types from `types.ts` and styles from `styles.ts`.
|
|
153
170
|
|
|
154
|
-
|
|
171
|
+
### API
|
|
155
172
|
|
|
156
173
|
The API of the components should be consistent with other components.
|
|
157
174
|
|
|
@@ -167,22 +184,25 @@ height?: number;
|
|
|
167
184
|
width?: number;
|
|
168
185
|
|
|
169
186
|
// do
|
|
170
|
-
size?:
|
|
187
|
+
size?: PieChartSize;
|
|
171
188
|
```
|
|
172
189
|
|
|
173
190
|
To know how to define your API, to name and document your props, take a look at the existing components.
|
|
174
191
|
|
|
175
|
-
|
|
192
|
+
## Tests
|
|
193
|
+
|
|
176
194
|
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
195
|
|
|
178
196
|
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
197
|
|
|
180
198
|
We split the tests into 2 groups.
|
|
181
199
|
|
|
182
|
-
|
|
200
|
+
_Visual tests_
|
|
201
|
+
|
|
183
202
|
- A Storybook story should be written for each visual state that a component can be in (based on props).
|
|
184
203
|
|
|
185
|
-
|
|
204
|
+
_Unit tests_
|
|
205
|
+
|
|
186
206
|
- (Props) Anything that should be changed by a prop should be tested via react-testing-library.
|
|
187
207
|
- (Events) Anything that should trigger an event should be tested via react-testing-library.
|
|
188
208
|
|
|
@@ -195,16 +215,18 @@ yarn test
|
|
|
195
215
|
Or for a specific package with:
|
|
196
216
|
|
|
197
217
|
```bash
|
|
198
|
-
yarn test:design-system
|
|
199
218
|
yarn test:charts
|
|
219
|
+
yarn test:design-system
|
|
200
220
|
yarn test:dashboard
|
|
221
|
+
yarn test:table
|
|
201
222
|
```
|
|
202
223
|
|
|
203
224
|
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
225
|
|
|
205
|
-
|
|
226
|
+
## Linting
|
|
206
227
|
|
|
207
228
|
The code is linted with [eslint](https://eslint.org/). You can run the linter with:
|
|
229
|
+
|
|
208
230
|
```bash
|
|
209
231
|
yarn lint
|
|
210
232
|
```
|
|
@@ -218,9 +240,10 @@ yarn lint:design-system
|
|
|
218
240
|
yarn lint:table
|
|
219
241
|
```
|
|
220
242
|
|
|
221
|
-
|
|
243
|
+
## TypeScript
|
|
222
244
|
|
|
223
245
|
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:
|
|
246
|
+
|
|
224
247
|
```bash
|
|
225
248
|
yarn check-types
|
|
226
249
|
```
|
|
@@ -271,7 +294,7 @@ export type BadgeVariant = ValueOf<typeof BadgeVariant>;
|
|
|
271
294
|
|
|
272
295
|
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
296
|
|
|
274
|
-
|
|
297
|
+
## Styling
|
|
275
298
|
|
|
276
299
|
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
300
|
|
|
@@ -282,18 +305,21 @@ The `styles.ts` of a component should contain all the styled-component codes. At
|
|
|
282
305
|
* Component style.
|
|
283
306
|
*/
|
|
284
307
|
export const StyledBadge = styled.div<StyledBadgeProps>`
|
|
285
|
-
${({ $color }) =>
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
308
|
+
${({ $color }) =>
|
|
309
|
+
$color
|
|
310
|
+
? css`
|
|
311
|
+
color: var(--redsift-color-neutral-white);
|
|
312
|
+
background-color: var(--redsift-color-${$color}-primary);
|
|
313
|
+
`
|
|
314
|
+
: ''}
|
|
315
|
+
`;
|
|
290
316
|
```
|
|
291
317
|
|
|
292
318
|
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
319
|
|
|
294
320
|
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
321
|
|
|
296
|
-
|
|
322
|
+
## Accessibility
|
|
297
323
|
|
|
298
324
|
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
325
|
|
|
@@ -301,7 +327,8 @@ Before implementing a component, try to see if there is a [pattern](https://www.
|
|
|
301
327
|
|
|
302
328
|
However, before using any ARIA, [read this disclaimer carefully](https://www.w3.org/WAI/ARIA/apg/practices/read-me-first/).
|
|
303
329
|
|
|
304
|
-
|
|
330
|
+
## Storybook
|
|
331
|
+
|
|
305
332
|
We use [Storybook](https://storybooks.js.org) for local development. Run the following command to start it:
|
|
306
333
|
|
|
307
334
|
```bash
|
|
@@ -314,7 +341,7 @@ You can use knobs and other storybook addons to create your stories. However, it
|
|
|
314
341
|
|
|
315
342
|
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
343
|
|
|
317
|
-
|
|
344
|
+
## Documentation
|
|
318
345
|
|
|
319
346
|
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
347
|
|
|
@@ -329,6 +356,7 @@ To add documentation for a component, a MDX file should be created in the `packa
|
|
|
329
356
|
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
357
|
|
|
331
358
|
A component page should be structured as following:
|
|
359
|
+
|
|
332
360
|
- **Introduction**
|
|
333
361
|
- **Installation**: explains which package to install and how
|
|
334
362
|
- **Usage**: explains how to import the component
|
|
@@ -357,9 +385,12 @@ To display a demo, first create a demo (a simple `tsx` file) in the demo folder
|
|
|
357
385
|
To display simple code, use the `CodeBlock` as following:
|
|
358
386
|
|
|
359
387
|
```ts
|
|
360
|
-
<CodeBlock
|
|
388
|
+
<CodeBlock
|
|
389
|
+
codeString={`
|
|
361
390
|
yarn add @redsift/design-system
|
|
362
|
-
`}
|
|
391
|
+
`}
|
|
392
|
+
language="sh"
|
|
393
|
+
/>
|
|
363
394
|
```
|
|
364
395
|
|
|
365
396
|
## Build
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "git+https://github.com/redsift/design-system"
|
|
20
20
|
},
|
|
21
21
|
"sideEffects": false,
|
|
22
|
-
"version": "
|
|
22
|
+
"version": "7.0.0-alpha.0",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "rollup -c",
|
|
25
25
|
"prepublishOnly": "yarn build"
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"rollup-plugin-ts-paths-resolve": "^1.7.1",
|
|
49
49
|
"rollup-plugin-typescript-paths": "^1.3.1"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "49c0e4c8f8dad94eed4101fb388c62c95c7f4d69"
|
|
52
52
|
}
|