@czi-sds/components 23.7.0 → 23.8.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/README.md +25 -338
- package/dist/index.cjs.d.ts +2009 -1787
- package/dist/index.cjs.js +18613 -15449
- package/dist/index.esm.d.ts +2009 -1787
- package/dist/index.esm.js +18268 -15213
- package/dist/variables.css +0 -1
- package/package.json +10 -11
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,355 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@czi-sds/components`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React component library for the [Science Design System (SDS)](https://sds.czi.design/). Built on **Material UI v9**.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`@czi-sds/components` implements the Science Design System as documented in [Zeroheight](https://sds.czi.design/). As a result, it's very useful to get familiar with the available **theme variables**, such as `colors`, `spaces`, `typography`, etc., so you can leverage the theme properly in your application.
|
|
8
|
-
|
|
9
|
-

|
|
5
|
+
Full documentation (usage, theming, scripts, contributing) lives in the [repository README](https://github.com/chanzuckerberg/sci-components#readme).
|
|
10
6
|
|
|
11
7
|
## Installation
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
**Currently SDS uses Material UI v5**
|
|
16
|
-
|
|
17
|
-
NOTE: Since most of the czi-sds components are built on top of Material UI's equivalent, it's also super useful to use their [API documentation](https://mui.com/) to learn about what you can do with the components. Many czi-sds components are style wrappers that pass props through to the MUI component without modifying them.
|
|
18
|
-
|
|
19
|
-
`@czi-sds/components` installs without direct dependencies to prevent version errors. Please ensure the following peer dependencies are also installed:
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
"@emotion/css"
|
|
23
|
-
"@emotion/react"
|
|
24
|
-
"@emotion/styled"
|
|
25
|
-
"@mui/base"
|
|
26
|
-
"@mui/icons-material"
|
|
27
|
-
"@mui/lab"
|
|
28
|
-
"@mui/material"
|
|
29
|
-
"react"
|
|
30
|
-
"react-dom"
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
To install @czi-sds/components and the dependencies:
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
// with npm
|
|
37
|
-
npm i @czi-sds/components @emotion/css @emotion/react @emotion/styled @mui/base @mui/material @mui/icons-material @mui/lab react react-dom
|
|
9
|
+
Peer dependencies:
|
|
38
10
|
|
|
39
|
-
// with yarn
|
|
40
|
-
yarn add @czi-sds/components @emotion/css @emotion/react @emotion/styled @mui/base @mui/material @mui/icons-material @mui/lab react react-dom
|
|
41
11
|
```
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
-
|
|
49
|
-
- `yarn test-storybook`: Tests current running instance of storybook
|
|
50
|
-
- `yarn storybook:axe`: Builds the storybook and runs accessibility tests
|
|
51
|
-
- `yarn storybook:axeOnly`: Runs accessibility tests on the latest build of the storybook inside the docs-build folder
|
|
52
|
-
- `yarn test`: Runs `jest` tests
|
|
53
|
-
- `yarn namespace-check`: Runs typescript type checking on namespace files to ensure that there are no duplicated exports
|
|
54
|
-
- `yarn lint`: Runs linter
|
|
55
|
-
- `yarn build`: Build the packages
|
|
56
|
-
- `yarn ci`: Executes `yarn install --frozen-lockfile` in both packages
|
|
57
|
-
|
|
58
|
-
- _To execute any script in the inner package, one can simply use the command `lerna run script --scope=<package>`. For instance, to run the linter only on the sci-components package, use the command `lerna run lint --scope=@czi-sds/components`._
|
|
59
|
-
|
|
60
|
-
## Usage
|
|
61
|
-
|
|
62
|
-
`@czi-sds/components` comes with five main exports that help you build your app:
|
|
63
|
-
|
|
64
|
-
1. Components - Accessible and reusable components
|
|
65
|
-
|
|
66
|
-
```javascript
|
|
67
|
-
import React from "react";
|
|
68
|
-
import { Button } from "@czi-sds/components";
|
|
69
|
-
<Button onClick={actions.onClick} sdsStyle="rounded" sdsType="primary">
|
|
70
|
-
{text}
|
|
71
|
-
</Button>;
|
|
12
|
+
@emotion/css
|
|
13
|
+
@emotion/react
|
|
14
|
+
@emotion/styled
|
|
15
|
+
@mui/icons-material
|
|
16
|
+
@mui/material
|
|
17
|
+
react
|
|
18
|
+
react-dom
|
|
72
19
|
```
|
|
73
20
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
import { styled } from '@emotion/styled';
|
|
78
|
-
import { Typography } from "@mui/material";
|
|
79
|
-
import { fontHeaderXL } from "@czi-sds/components";
|
|
21
|
+
```bash
|
|
22
|
+
# npm
|
|
23
|
+
npm i @czi-sds/components @emotion/css @emotion/react @emotion/styled @mui/material @mui/icons-material react react-dom
|
|
80
24
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// which compiles to:
|
|
85
|
-
font-size: 22px;
|
|
86
|
-
font-weight: 600;
|
|
87
|
-
letter-spacing: 0.3px;
|
|
88
|
-
line-height: 30px;
|
|
89
|
-
`;
|
|
25
|
+
# yarn
|
|
26
|
+
yarn add @czi-sds/components @emotion/css @emotion/react @emotion/styled @mui/material @mui/icons-material react react-dom
|
|
90
27
|
```
|
|
91
28
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
```ts
|
|
95
|
-
import { css, SerializedStyles } from "@emotion/react";
|
|
96
|
-
import styled from "@emotion/styled";
|
|
97
|
-
import { getColors, getCorners } from "@czi-sds/components";
|
|
98
|
-
|
|
99
|
-
export const Tag = styled("div")`
|
|
100
|
-
// This is a callback function that returns more CSS rules, but the only way
|
|
101
|
-
// to access the custom theme object
|
|
102
|
-
${(props) => {
|
|
103
|
-
// getColors() is a selector that picks out colors from the theme object
|
|
104
|
-
const colors = getColors(props);
|
|
105
|
-
// getSpaces() is a selector that picks out spaces from the theme object
|
|
106
|
-
const spaces = getSpaces(props);
|
|
107
|
-
|
|
108
|
-
return `
|
|
109
|
-
background-color: ${colors?.gray[500]};
|
|
110
|
-
padding-bottom: ${spaces?.m}px;
|
|
111
|
-
margin-bottom: ${spaces?.xxl}px;
|
|
112
|
-
`;
|
|
113
|
-
}}
|
|
114
|
-
`;
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
4. CSS & SCSS Variables - Variables for the `defaultTheme` to use if your app doesn't support `@emotion/styled`
|
|
118
|
-
|
|
119
|
-
```scss
|
|
120
|
-
// with SCSS variables
|
|
121
|
-
@import "~@czi-sds/components/dist/variables";
|
|
122
|
-
|
|
123
|
-
.button-primary {
|
|
124
|
-
background-color: $sds-color-primary-400;
|
|
125
|
-
padding: $sds-spaces-xxs;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// with CSS variables
|
|
129
|
-
.button-primary {
|
|
130
|
-
background-color: var(--sds-color-primary-400);
|
|
131
|
-
padding: var(--sds-spaces-xxs);
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
5. Tailwind - Tailwind compliant configuration for the `defaultTheme` to use if your app uses Tailwind
|
|
136
|
-
|
|
137
|
-
First you need to import the SDS config into your application's Tailwind config:
|
|
138
|
-
|
|
139
|
-
```js
|
|
140
|
-
// tailwind.config.js
|
|
141
|
-
|
|
142
|
-
const sds = require("@czi-sds/components/dist/tailwind.json");
|
|
143
|
-
|
|
144
|
-
module.exports = {
|
|
145
|
-
mode: "jit",
|
|
146
|
-
content: ["./src/**/*.{tsx,scss}"],
|
|
147
|
-
theme: {
|
|
148
|
-
extend: sds,
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
If you have existing styles that you'd like to maintain, you can pick and choose
|
|
154
|
-
different parts of the SDS config:
|
|
155
|
-
|
|
156
|
-
```js
|
|
157
|
-
// tailwind.config.js
|
|
158
|
-
|
|
159
|
-
const sds = require("@czi-sds/components/dist/tailwind.json");
|
|
160
|
-
|
|
161
|
-
module.exports = {
|
|
162
|
-
mode: "jit",
|
|
163
|
-
content: ["./src/**/*.{tsx,scss}"],
|
|
164
|
-
theme: {
|
|
165
|
-
extend: {
|
|
166
|
-
...sds,
|
|
167
|
-
|
|
168
|
-
width: {
|
|
169
|
-
...sds.width,
|
|
170
|
-
"app-modal-width": "500px",
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
height: {
|
|
174
|
-
...sds.width,
|
|
175
|
-
"app-modal-height": "200px",
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
After that, you should be able to use SDS Tailwind classes in your app:
|
|
183
|
-
|
|
184
|
-
```tsx
|
|
185
|
-
export function Hello() {
|
|
186
|
-
return (
|
|
187
|
-
<p className="m-sds-xl px-sds-xs py-sds-s text-sds-error-400">
|
|
188
|
-
Hello, World!
|
|
189
|
-
</p>
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Default Theme
|
|
195
|
-
|
|
196
|
-
To use the default theme in your React application, complete the following:
|
|
197
|
-
|
|
198
|
-
1. Add the following HTML to your `index.html` at the `<head>` section:
|
|
199
|
-
|
|
200
|
-
```html
|
|
201
|
-
// installs the sds font from google fonts
|
|
202
|
-
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
203
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
204
|
-
<link
|
|
205
|
-
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
|
|
206
|
-
rel="stylesheet"
|
|
207
|
-
/>
|
|
208
|
-
<link
|
|
209
|
-
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&display=swap"
|
|
210
|
-
rel="stylesheet"
|
|
211
|
-
/>
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
2. Import the default theme object and use it in Material UI's `<ThemeProvier />`:
|
|
215
|
-
|
|
216
|
-
```javascript
|
|
217
|
-
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
|
|
218
|
-
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
|
|
219
|
-
import { defaultTheme } from "@czi-sds/components";
|
|
220
|
-
|
|
221
|
-
<StyledEngineProvider injectFirst>
|
|
222
|
-
<ThemeProvider theme={defaultTheme}>
|
|
223
|
-
<EmotionThemeProvider theme={defaultTheme}>
|
|
224
|
-
<YourApp />
|
|
225
|
-
</EmotionThemeProvider>
|
|
226
|
-
</ThemeProvider>
|
|
227
|
-
</StyledEngineProvider>;
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
If you want to override the default theme, please use `defaultAppTheme`, override the options, and then call `createTheme` to generate
|
|
231
|
-
the full theme object like below. This is needed because `createTheme` generates
|
|
232
|
-
extra theme variables based on the themeOptions provided, so if you override `defaultTheme` directly, some auxillary theme variables will be based on `defaultAppTheme` instead of your own custom options
|
|
233
|
-
|
|
234
|
-
```tsx
|
|
235
|
-
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
|
|
236
|
-
import { defaultAppTheme, makeThemeOptions } from "@czi-sds/components";
|
|
237
|
-
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
|
|
238
|
-
import createTheme from "@mui/material/styles/createTheme";
|
|
239
|
-
|
|
240
|
-
const customTheme = {
|
|
241
|
-
...
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const appTheme = makeThemeOptions({ ...defaultAppTheme, ...customTheme })
|
|
245
|
-
|
|
246
|
-
const theme = createTheme(appTheme)
|
|
247
|
-
|
|
248
|
-
<StyledEngineProvider injectFirst>
|
|
249
|
-
<ThemeProvider theme={theme}>
|
|
250
|
-
<EmotionThemeProvider theme={theme}>
|
|
251
|
-
<YourApp />
|
|
252
|
-
</EmotionThemeProvider>
|
|
253
|
-
</ThemeProvider>
|
|
254
|
-
</StyledEngineProvider>
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
To apply custom colors that align with your branding while maintaining the SDS design configurations, use the `makeSdsSemanticAppTheme`. Provide it with a Colors object that follows the SDS model.
|
|
258
|
-
|
|
259
|
-
```tsx
|
|
260
|
-
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
|
|
261
|
-
import { makeSdsSemanticAppTheme, makeThemeOptions, type Colors } from "@czi-sds/components";
|
|
262
|
-
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
|
|
263
|
-
import createTheme from "@mui/material/styles/createTheme";
|
|
264
|
-
|
|
265
|
-
const CustomColors: Colors = {
|
|
266
|
-
...
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const customColorAppTheme = makeSdsSemanticAppTheme(CustomColors);
|
|
270
|
-
|
|
271
|
-
const appTheme = makeThemeOptions(customColorAppTheme)
|
|
272
|
-
|
|
273
|
-
const theme = createTheme(appTheme)
|
|
274
|
-
|
|
275
|
-
<StyledEngineProvider injectFirst>
|
|
276
|
-
<ThemeProvider theme={theme}>
|
|
277
|
-
<EmotionThemeProvider theme={theme}>
|
|
278
|
-
<YourApp />
|
|
279
|
-
</EmotionThemeProvider>
|
|
280
|
-
</ThemeProvider>
|
|
281
|
-
</StyledEngineProvider>
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
💡 CZGE example available [here](https://github.com/chanzuckerberg/czgenepi/blob/trunk/src/frontend/src/common/styles/theme.ts).
|
|
285
|
-
|
|
286
|
-
💡 Material UI docs for custom theming available [here](https://mui.com/material-ui/customization/theming/).
|
|
287
|
-
|
|
288
|
-
## Q&A
|
|
289
|
-
|
|
290
|
-
1. Why wrapping a component with `styled()` doesn't style the root element as expected?
|
|
291
|
-
|
|
292
|
-
This is likely because the component is **NOT** forwarding the css class name that `styled()` generates to the intended root element. So we likely need to update the `czif` component to make it work
|
|
293
|
-
|
|
294
|
-
For example, if a `czif` component `Foo` has the following implementation, `styled(Foo)` won't style the wrapper `<div />` as expected:
|
|
295
|
-
|
|
296
|
-
```tsx
|
|
297
|
-
function Foo() {
|
|
298
|
-
return (
|
|
299
|
-
<div>
|
|
300
|
-
<ChildA />
|
|
301
|
-
<ChildB />
|
|
302
|
-
</div>
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
The fix is:
|
|
308
|
-
|
|
309
|
-
```tsx
|
|
310
|
-
function Foo({ className }) {
|
|
311
|
-
return (
|
|
312
|
-
<div className={className}>
|
|
313
|
-
<ChildA />
|
|
314
|
-
<ChildB />
|
|
315
|
-
</div>
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
1. To style a sub-component of a `@czi-sds/components` component, typically we export the sub-component for the call site to import and style via `styled`, and then you will be able to pass back the styled sub-component to the `@czi-sds/components` component through prop
|
|
321
|
-
|
|
322
|
-
For example, `ComplexFilter` exports `ComplexFilterInputDropdown` sub-component, so if you want to style it, you can do the following:
|
|
323
|
-
|
|
324
|
-
```tsx
|
|
325
|
-
import {
|
|
326
|
-
ComplexFilter,
|
|
327
|
-
ComplexFilterInputDropdown,
|
|
328
|
-
} from "@czi-sds/components";
|
|
329
|
-
import styled from "@emotion/styled";
|
|
330
|
-
|
|
331
|
-
const StyledComplexFilterInputDropdown = styled(ComplexFilterInputDropdown)`
|
|
332
|
-
color: pink;
|
|
333
|
-
`;
|
|
334
|
-
|
|
335
|
-
function Foo() {
|
|
336
|
-
return (
|
|
337
|
-
<ComplexFilter
|
|
338
|
-
InputDropdownComponent={StyledComplexFilterInputDropdown}
|
|
339
|
-
/>
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
## Project status
|
|
29
|
+
> **React 18 note:** Material UI ships `react-is@19`. If your app uses React 18, pin `react-is` to match (Yarn `resolutions` / npm `overrides`), e.g. `"react-is": "^18.3.1"`.
|
|
345
30
|
|
|
346
|
-
|
|
347
|
-
This project is governed under the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct.
|
|
31
|
+
## Migrating to SDS 24.0.0
|
|
348
32
|
|
|
349
|
-
|
|
33
|
+
SDS `24.0.0` is a **breaking release** that moves the Material UI peer dependency from v5 to v9. Follow the step-by-step guide:
|
|
350
34
|
|
|
351
|
-
|
|
35
|
+
→ [MIGRATION.md](https://github.com/chanzuckerberg/sci-components/blob/main/MIGRATION.md)
|
|
352
36
|
|
|
353
|
-
##
|
|
37
|
+
## Links
|
|
354
38
|
|
|
355
|
-
[
|
|
39
|
+
- [Design docs (Zeroheight)](https://sds.czi.design/)
|
|
40
|
+
- [Full repo docs](https://github.com/chanzuckerberg/sci-components#readme)
|
|
41
|
+
- [npm package](https://www.npmjs.com/package/@czi-sds/components)
|
|
42
|
+
- [Material UI API docs](https://mui.com/)
|