@czi-sds/data-viz 0.17.2 → 0.19.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 CHANGED
@@ -1,328 +1,44 @@
1
- # Purpose
1
+ # `@czi-sds/data-viz`
2
2
 
3
- The Science Design System (SDS) brings consistency and universal standards to CZI’s science products by offering a library of high quality, reusable components that deliver predictable, accessible and easy to learn experiences. Our goal is to democratize access to tools and technologies for scientists.
3
+ Data visualization components for the [Science Design System (SDS)](https://sds.czi.design/), primarily built on [Apache ECharts](https://echarts.apache.org/). Shares the same Material UI v9 peer dependencies as `@czi-sds/components`.
4
4
 
5
- ## Design System Documentation
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
- ![Science Design System Zeroheight Homepage Snapshot](https://user-images.githubusercontent.com/6309723/155802483-366008aa-7380-4a01-b356-ae0ab02f4f3b.png)
5
+ Full documentation (usage, scripts, contributing) lives in the [repository README](https://github.com/chanzuckerberg/sci-components#readme).
10
6
 
11
7
  ## Installation
12
8
 
13
- [NPM Package](https://www.npmjs.com/package/czi-sds/components)
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:
9
+ Peer dependencies:
20
10
 
21
11
  ```
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
38
-
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
12
+ @emotion/css
13
+ @emotion/react
14
+ @emotion/styled
15
+ @mui/icons-material
16
+ @mui/material
17
+ echarts
18
+ lodash
19
+ react
20
+ react-dom
41
21
  ```
42
22
 
43
- ## Yarn scripts
23
+ ```bash
24
+ # npm
25
+ npm i @czi-sds/data-viz @czi-sds/components @emotion/css @emotion/react @emotion/styled @mui/material @mui/icons-material echarts lodash react react-dom
44
26
 
45
- Common yarn scrips have been moved to the monorepo root. The -- syntax can be used to pass parameters to the underlying yarn scripts. For instance, to update the snapshots, use `lerna run test -- -u` instead of running all tests on both packages with `yarn test`.
46
-
47
- - `yarn start`: Starts storybook on the local machine
48
- - `yarn build-storybook`: Builds the storybook in the docs-build folder
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>;
27
+ # yarn
28
+ yarn add @czi-sds/data-viz @czi-sds/components @emotion/css @emotion/react @emotion/styled @mui/material @mui/icons-material echarts lodash react react-dom
72
29
  ```
73
30
 
74
- 2. Mixins - Grouped styles defined by the design system
75
-
76
- ```javascript
77
- import { styled } from '@emotion/styled';
78
- import { Typography } from "@mui/material";
79
- import { fontHeaderXL } from "@czi-sds/components";
80
-
81
- export const Title - styled(Typography)`
82
- ${fontHeaderXl}
83
-
84
- // which compiles to:
85
- font-size: 22px;
86
- font-weight: 600;
87
- letter-spacing: 0.3px;
88
- line-height: 30px;
89
- `;
90
- ```
91
-
92
- 3. Selectors - Helper functions that return theme variables baased on passed props
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
- 💡 CZGE example available [here](https://github.com/chanzuckerberg/czgenepi/blob/trunk/src/frontend/src/common/styles/theme.ts).
258
-
259
- 💡 Material UI docs for custom theming available [here](https://mui.com/material-ui/customization/theming/).
260
-
261
- ## Q&A
262
-
263
- 1. Why wrapping a component with `styled()` doesn't style the root element as expected?
264
-
265
- 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
266
-
267
- For example, if a `czif` component `Foo` has the following implementation, `styled(Foo)` won't style the wrapper `<div />` as expected:
268
-
269
- ```tsx
270
- function Foo() {
271
- return (
272
- <div>
273
- <ChildA />
274
- <ChildB />
275
- </div>
276
- );
277
- }
278
- ```
279
-
280
- The fix is:
281
-
282
- ```tsx
283
- function Foo({ className }) {
284
- return (
285
- <div className={className}>
286
- <ChildA />
287
- <ChildB />
288
- </div>
289
- );
290
- }
291
- ```
292
-
293
- 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
294
-
295
- For example, `ComplexFilter` exports `ComplexFilterInputDropdown` sub-component, so if you want to style it, you can do the following:
296
-
297
- ```tsx
298
- import {
299
- ComplexFilter,
300
- ComplexFilterInputDropdown,
301
- } from "@czi-sds/components";
302
- import styled from "@emotion/styled";
303
-
304
- const StyledComplexFilterInputDropdown = styled(ComplexFilterInputDropdown)`
305
- color: pink;
306
- `;
307
-
308
- function Foo() {
309
- return (
310
- <ComplexFilter
311
- InputDropdownComponent={StyledComplexFilterInputDropdown}
312
- />
313
- );
314
- }
315
- ```
316
-
317
- ## Project status
31
+ > **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"`.
318
32
 
319
- This project is under **active development**. Contributions and ideas are welcome! If you would like to contribute, check out the [contribution guidelines](docs/contribution.md) or open an issue.
320
- This project is governed under the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct.
33
+ ## Migrating to SDS 24.0.0
321
34
 
322
- ## Reporting Security Issues
35
+ The `@czi-sds/data-viz` release that ships with SDS `24.0.0` also requires Material UI v9. If you are upgrading from an older SDS / data-viz version, follow the step-by-step guide:
323
36
 
324
- Please note: If you believe you have found a security issue, please responsibly disclose by contacting us at security@chanzuckerberg.com. More information is in our [Security Readme](docs/SECURITY.md)
37
+ → [MIGRATION.md](https://github.com/chanzuckerberg/sci-components/blob/main/MIGRATION.md)
325
38
 
326
- ## 2022 Plans
39
+ ## Links
327
40
 
328
- [2022 Plans](https://docs.google.com/presentation/d/1pKAY6Wl3-EHInvOZuf0L3yEDFt2xVvMlO7ZWefQbgjA/edit?usp=sharing)
41
+ - [Design docs (Zeroheight)](https://sds.czi.design/)
42
+ - [Full repo docs](https://github.com/chanzuckerberg/sci-components#readme)
43
+ - [npm package](https://www.npmjs.com/package/@czi-sds/data-viz)
44
+ - [ECharts documentation](https://echarts.apache.org/en/index.html)