@czi-sds/mcp 0.16.0 → 0.17.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 +2 -1
- package/data/component-docs/Accordion.md +291 -0
- package/data/component-docs/Autocomplete.md +525 -0
- package/data/component-docs/Banner.md +231 -0
- package/data/component-docs/Button.md +224 -0
- package/data/component-docs/ButtonDropdown.md +256 -0
- package/data/component-docs/ButtonGroup.md +320 -0
- package/data/component-docs/ButtonToggle.md +397 -0
- package/data/component-docs/Callout.md +268 -0
- package/data/component-docs/CellBasic.md +122 -0
- package/data/component-docs/CellComponent.md +63 -0
- package/data/component-docs/CellHeader.md +128 -0
- package/data/component-docs/ComplexFilter.md +294 -0
- package/data/component-docs/ContentCard.md +406 -0
- package/data/component-docs/Dialog.md +651 -0
- package/data/component-docs/Dropdown.md +155 -0
- package/data/component-docs/DropdownMenu.md +949 -0
- package/data/component-docs/HeatmapChart.md +782 -0
- package/data/component-docs/Hero.md +363 -0
- package/data/component-docs/Icon.md +283 -0
- package/data/component-docs/InputCheckbox.md +205 -0
- package/data/component-docs/InputDropdown.md +482 -0
- package/data/component-docs/InputRadio.md +173 -0
- package/data/component-docs/InputSearch.md +81 -0
- package/data/component-docs/InputSlider.md +189 -0
- package/data/component-docs/InputText.md +110 -0
- package/data/component-docs/InputToggle.md +141 -0
- package/data/component-docs/IntentMessage.md +293 -0
- package/data/component-docs/Legend.md +442 -0
- package/data/component-docs/Link.md +23 -0
- package/data/component-docs/List.md +300 -0
- package/data/component-docs/LoadingIndicator.md +198 -0
- package/data/component-docs/Menu.md +298 -0
- package/data/component-docs/MenuItem.md +100 -0
- package/data/component-docs/NavigationFooter.md +165 -0
- package/data/component-docs/NavigationHeader.md +500 -0
- package/data/component-docs/NavigationJumpTo.md +414 -0
- package/data/component-docs/Notification.md +288 -0
- package/data/component-docs/Pagination.md +67 -0
- package/data/component-docs/Panel.md +636 -0
- package/data/component-docs/Popover.md +448 -0
- package/data/component-docs/PreComposedTable.md +2947 -0
- package/data/component-docs/SegmentedControl.md +396 -0
- package/data/component-docs/StackedBarChart.md +475 -0
- package/data/component-docs/Table.md +2000 -0
- package/data/component-docs/TableHeader.md +53 -0
- package/data/component-docs/TableRow.md +74 -0
- package/data/component-docs/Tabs.md +455 -0
- package/data/component-docs/Tag.md +647 -0
- package/data/component-docs/TagFilter.md +131 -0
- package/data/component-docs/Tooltip.md +561 -0
- package/data/component-docs/TooltipCondensed.md +203 -0
- package/data/component-docs/TooltipTable.md +145 -0
- package/data/component-docs/index.json +262 -0
- package/data/component-list.json +2 -5
- package/data/component-props/Accordion.json +31 -11
- package/data/component-props/Alert.json +3 -3
- package/data/component-props/Autocomplete.json +150 -15
- package/data/component-props/Banner.json +31 -17
- package/data/component-props/Button.json +45 -20
- package/data/component-props/ButtonDropdown.json +36 -17
- package/data/component-props/ButtonDropdownLegacy.json +11 -11
- package/data/component-props/ButtonGroup.json +32 -11
- package/data/component-props/ButtonIcon.json +10 -10
- package/data/component-props/ButtonLegacy.json +19 -19
- package/data/component-props/ButtonToggle.json +32 -19
- package/data/component-props/ButtonToggleLegacy.json +11 -11
- package/data/component-props/Callout.json +58 -17
- package/data/component-props/CellBasic.json +94 -41
- package/data/component-props/CellComponent.json +23 -7
- package/data/component-props/CellHeader.json +62 -19
- package/data/component-props/ComplexFilter.json +52 -21
- package/data/component-props/ContentCard.json +70 -47
- package/data/component-props/Dialog.json +47 -14
- package/data/component-props/Dropdown.json +68 -31
- package/data/component-props/DropdownMenu.json +128 -23
- package/data/component-props/HeatmapChart.json +88 -12
- package/data/component-props/Hero.json +80 -39
- package/data/component-props/Icon.json +20 -9
- package/data/component-props/InputCheckbox.json +36 -14
- package/data/component-props/InputDropdown.json +75 -27
- package/data/component-props/InputRadio.json +31 -13
- package/data/component-props/InputSearch.json +41 -18
- package/data/component-props/InputSlider.json +46 -19
- package/data/component-props/InputText.json +26 -19
- package/data/component-props/InputToggle.json +26 -9
- package/data/component-props/IntentMessage.json +38 -9
- package/data/component-props/Link.json +13 -7
- package/data/component-props/LoadingIndicator.json +11 -3
- package/data/component-props/MenuItem.json +38 -19
- package/data/component-props/MenuSelect.json +8 -8
- package/data/component-props/NavigationFooter.json +49 -19
- package/data/component-props/NavigationHeader.json +150 -37
- package/data/component-props/NavigationJumpTo.json +33 -7
- package/data/component-props/Notification.json +39 -21
- package/data/component-props/Pagination.json +39 -11
- package/data/component-props/Panel.json +62 -9
- package/data/component-props/Popover.json +80 -7
- package/data/component-props/PreComposedTable.json +99 -27
- package/data/component-props/SegmentedControl.json +42 -3
- package/data/component-props/StackedBarChart.json +116 -42
- package/data/component-props/TableRow.json +38 -19
- package/data/component-props/Tabs.json +66 -9
- package/data/component-props/Tag.json +34 -17
- package/data/component-props/TagFilter.json +10 -3
- package/data/component-props/Tooltip.json +49 -18
- package/data/component-props/TooltipCondensed.json +18 -9
- package/data/component-props/TooltipTable.json +17 -7
- package/data/resources/{zeroheight-rules.md → documentation-rules.md} +43 -30
- package/data/resources/figma-rules.md +2 -2
- package/dist/stdio.js +112 -208
- package/package.json +9 -5
- package/data/component-props/ButtonDropdownV2.json +0 -34
- package/data/component-props/ButtonNew.json +0 -47
- package/data/component-props/ButtonToggleV2.json +0 -44
- package/data/component-props/ButtonV2.json +0 -43
- package/data/zeroheight-cache.json +0 -10259
- package/data/zeroheight-exports/Accordion.md +0 -774
- package/data/zeroheight-exports/Banner.md +0 -691
- package/data/zeroheight-exports/Borders.md +0 -117
- package/data/zeroheight-exports/Buttons.md +0 -1854
- package/data/zeroheight-exports/Callout.md +0 -931
- package/data/zeroheight-exports/Colors.md +0 -1755
- package/data/zeroheight-exports/Content-Card.md +0 -309
- package/data/zeroheight-exports/Contributing-to-SDS.md +0 -98
- package/data/zeroheight-exports/Control-Inputs.md +0 -2818
- package/data/zeroheight-exports/Corners.md +0 -104
- package/data/zeroheight-exports/Cover-page.md +0 -3
- package/data/zeroheight-exports/Dialog.md +0 -1367
- package/data/zeroheight-exports/Downloads.md +0 -236
- package/data/zeroheight-exports/Drop-Shadows.md +0 -79
- package/data/zeroheight-exports/Dropdown-Input.md +0 -1776
- package/data/zeroheight-exports/Dropdown-Menus.md +0 -913
- package/data/zeroheight-exports/Element-Status-Tracker.md +0 -267
- package/data/zeroheight-exports/Field-Inputs.md +0 -1405
- package/data/zeroheight-exports/Filters.md +0 -1111
- package/data/zeroheight-exports/Getting-Started.md +0 -1157
- package/data/zeroheight-exports/Hero.md +0 -414
- package/data/zeroheight-exports/Icons.md +0 -2067
- package/data/zeroheight-exports/Intent.md +0 -86
- package/data/zeroheight-exports/Introduction-to-Bases.md +0 -35
- package/data/zeroheight-exports/Introduction-to-Cells.md +0 -35
- package/data/zeroheight-exports/Introduction-to-DNA.md +0 -35
- package/data/zeroheight-exports/Introduction-to-Genes.md +0 -35
- package/data/zeroheight-exports/Introduction.md +0 -115
- package/data/zeroheight-exports/Link.md +0 -432
- package/data/zeroheight-exports/Lists.md +0 -986
- package/data/zeroheight-exports/Loading-Indicator.md +0 -41
- package/data/zeroheight-exports/Navigation.md +0 -1190
- package/data/zeroheight-exports/Notification.md +0 -1038
- package/data/zeroheight-exports/Panel.md +0 -1030
- package/data/zeroheight-exports/README.md +0 -122
- package/data/zeroheight-exports/Responsive-Design.md +0 -330
- package/data/zeroheight-exports/Search-Input.md +0 -91
- package/data/zeroheight-exports/Search.md +0 -822
- package/data/zeroheight-exports/Segmented-Control.md +0 -609
- package/data/zeroheight-exports/Spacing.md +0 -297
- package/data/zeroheight-exports/Table.md +0 -5345
- package/data/zeroheight-exports/Tabs.md +0 -1324
- package/data/zeroheight-exports/Tags.md +0 -1545
- package/data/zeroheight-exports/Text-Link.md +0 -268
- package/data/zeroheight-exports/Theming.md +0 -362
- package/data/zeroheight-exports/Tooltips.md +0 -2015
- package/data/zeroheight-exports/Typography.md +0 -800
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
# ButtonToggle
|
|
2
|
+
|
|
3
|
+
## Source Code
|
|
4
|
+
|
|
5
|
+
The component's source code in the SDS codebase can be found [here](https://github.com/chanzuckerberg/sci-components/tree/main/packages/components/src/core/ButtonToggle).
|
|
6
|
+
|
|
7
|
+
## Import
|
|
8
|
+
|
|
9
|
+
**React TypeScript**
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { ButtonToggle } from "@czi-sds/components";
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Code examples
|
|
16
|
+
|
|
17
|
+
### **Default ButtonToggle**
|
|
18
|
+
|
|
19
|
+
This example has the minimum props needed for the ButtonToggle component. Because `sdsStage` is controlled, the on and off stages are driven from state.
|
|
20
|
+
|
|
21
|
+
**Example: DefaultButtonToggle**
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import * as React from "react";
|
|
25
|
+
import { ButtonToggle, Icon } from "@czi-sds/components";
|
|
26
|
+
|
|
27
|
+
function App() {
|
|
28
|
+
const [toggle, setToggle] = React.useState(false);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div className="app">
|
|
32
|
+
<ButtonToggle
|
|
33
|
+
sdsStyle="outline"
|
|
34
|
+
sdsType="primary"
|
|
35
|
+
sdsStage={toggle ? "on" : "off"}
|
|
36
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
37
|
+
onClick={() => setToggle((prev) => !prev)}
|
|
38
|
+
>
|
|
39
|
+
Label
|
|
40
|
+
</ButtonToggle>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default App;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### ButtonToggle styles
|
|
49
|
+
|
|
50
|
+
This example shows the two styles a toggle is designed around, `"outline"` and `"minimal"`, in both stages. `sdsStyle` also accepts Button's `"solid"`, which has no toggle treatment of its own, so set one of these two explicitly rather than taking the inherited default.
|
|
51
|
+
|
|
52
|
+
**Example: ButtonToggleStyles**
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
// Toggles are designed around the outline and minimal styles. sdsStyle also
|
|
56
|
+
// accepts Button's "solid", which has no toggle treatment of its own, so set one
|
|
57
|
+
// of these two explicitly rather than taking the inherited default.
|
|
58
|
+
//
|
|
59
|
+
// sdsType is set explicitly for the same reason: the on stage resolves its colors
|
|
60
|
+
// before Button applies its own default, so leaving it out draws the neutral
|
|
61
|
+
// treatment over a button that is otherwise primary.
|
|
62
|
+
//
|
|
63
|
+
// The stages below are fixed rather than driven from state, so both can be seen
|
|
64
|
+
// without clicking.
|
|
65
|
+
|
|
66
|
+
import { ButtonToggle, Icon } from "@czi-sds/components";
|
|
67
|
+
|
|
68
|
+
function App() {
|
|
69
|
+
return (
|
|
70
|
+
<div className="app" style={{ display: "flex", gap: "16px" }}>
|
|
71
|
+
<ButtonToggle
|
|
72
|
+
sdsStage="off"
|
|
73
|
+
sdsStyle="outline"
|
|
74
|
+
sdsType="primary"
|
|
75
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
76
|
+
>
|
|
77
|
+
Outline off
|
|
78
|
+
</ButtonToggle>
|
|
79
|
+
|
|
80
|
+
<ButtonToggle
|
|
81
|
+
sdsStage="on"
|
|
82
|
+
sdsStyle="outline"
|
|
83
|
+
sdsType="primary"
|
|
84
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
85
|
+
>
|
|
86
|
+
Outline on
|
|
87
|
+
</ButtonToggle>
|
|
88
|
+
|
|
89
|
+
<ButtonToggle
|
|
90
|
+
sdsStage="off"
|
|
91
|
+
sdsStyle="minimal"
|
|
92
|
+
sdsType="primary"
|
|
93
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
94
|
+
>
|
|
95
|
+
Minimal off
|
|
96
|
+
</ButtonToggle>
|
|
97
|
+
|
|
98
|
+
<ButtonToggle
|
|
99
|
+
sdsStage="on"
|
|
100
|
+
sdsStyle="minimal"
|
|
101
|
+
sdsType="primary"
|
|
102
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
103
|
+
>
|
|
104
|
+
Minimal on
|
|
105
|
+
</ButtonToggle>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default App;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### ButtonToggle types
|
|
114
|
+
|
|
115
|
+
This example shows the two color schemes available through `sdsType`, which is what decides how the on stage reads: primary fills with the accent color, secondary stays neutral.
|
|
116
|
+
|
|
117
|
+
**Example: ButtonToggleTypes**
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
// The type decides what the on stage looks like: primary fills with the accent
|
|
121
|
+
// color, secondary stays neutral. Both stages are shown for each.
|
|
122
|
+
|
|
123
|
+
import { ButtonToggle, Icon } from "@czi-sds/components";
|
|
124
|
+
|
|
125
|
+
function App() {
|
|
126
|
+
return (
|
|
127
|
+
<div className="app" style={{ display: "flex", gap: "16px" }}>
|
|
128
|
+
<ButtonToggle
|
|
129
|
+
sdsStage="off"
|
|
130
|
+
sdsStyle="outline"
|
|
131
|
+
sdsType="primary"
|
|
132
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
133
|
+
>
|
|
134
|
+
Primary off
|
|
135
|
+
</ButtonToggle>
|
|
136
|
+
|
|
137
|
+
<ButtonToggle
|
|
138
|
+
sdsStage="on"
|
|
139
|
+
sdsStyle="outline"
|
|
140
|
+
sdsType="primary"
|
|
141
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
142
|
+
>
|
|
143
|
+
Primary on
|
|
144
|
+
</ButtonToggle>
|
|
145
|
+
|
|
146
|
+
<ButtonToggle
|
|
147
|
+
sdsStage="off"
|
|
148
|
+
sdsStyle="outline"
|
|
149
|
+
sdsType="secondary"
|
|
150
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
151
|
+
>
|
|
152
|
+
Secondary off
|
|
153
|
+
</ButtonToggle>
|
|
154
|
+
|
|
155
|
+
<ButtonToggle
|
|
156
|
+
sdsStage="on"
|
|
157
|
+
sdsStyle="outline"
|
|
158
|
+
sdsType="secondary"
|
|
159
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
160
|
+
>
|
|
161
|
+
Secondary on
|
|
162
|
+
</ButtonToggle>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export default App;
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### ButtonToggle sizes
|
|
171
|
+
|
|
172
|
+
This example shows the three sizes available through the `size` prop.
|
|
173
|
+
|
|
174
|
+
**Example: ButtonToggleSizes**
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
import { ButtonToggle, Icon } from "@czi-sds/components";
|
|
178
|
+
|
|
179
|
+
function App() {
|
|
180
|
+
return (
|
|
181
|
+
<div
|
|
182
|
+
className="app"
|
|
183
|
+
style={{ alignItems: "center", display: "flex", gap: "16px" }}
|
|
184
|
+
>
|
|
185
|
+
<ButtonToggle
|
|
186
|
+
size="large"
|
|
187
|
+
sdsStyle="outline"
|
|
188
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
189
|
+
>
|
|
190
|
+
Large
|
|
191
|
+
</ButtonToggle>
|
|
192
|
+
|
|
193
|
+
<ButtonToggle
|
|
194
|
+
size="medium"
|
|
195
|
+
sdsStyle="outline"
|
|
196
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
197
|
+
>
|
|
198
|
+
Medium
|
|
199
|
+
</ButtonToggle>
|
|
200
|
+
|
|
201
|
+
<ButtonToggle
|
|
202
|
+
size="small"
|
|
203
|
+
sdsStyle="outline"
|
|
204
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
205
|
+
>
|
|
206
|
+
Small
|
|
207
|
+
</ButtonToggle>
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export default App;
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Icon-only ButtonToggle
|
|
216
|
+
|
|
217
|
+
This example shows the form a toggle usually takes. Leaving `children` out is what makes it square, and since there is then no text for a screen reader to announce, each one needs an `aria-label`.
|
|
218
|
+
|
|
219
|
+
**Example: ButtonToggleIconOnly**
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
// Leaving children out is what makes a toggle square, and it is the form a
|
|
223
|
+
// toggle usually takes. There is then no text for a screen reader to announce,
|
|
224
|
+
// so each one needs an aria-label of its own.
|
|
225
|
+
|
|
226
|
+
import { useState } from "react";
|
|
227
|
+
import { ButtonToggle, Icon } from "@czi-sds/components";
|
|
228
|
+
|
|
229
|
+
function App() {
|
|
230
|
+
const [labels, setLabels] = useState(true);
|
|
231
|
+
const [filters, setFilters] = useState(false);
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<div className="app" style={{ display: "flex", gap: "16px" }}>
|
|
235
|
+
<ButtonToggle
|
|
236
|
+
aria-label="Show labels"
|
|
237
|
+
sdsStage={labels ? "on" : "off"}
|
|
238
|
+
sdsStyle="outline"
|
|
239
|
+
sdsType="primary"
|
|
240
|
+
startIcon={<Icon sdsIcon="EyeOpen" sdsSize="s" />}
|
|
241
|
+
onClick={() => setLabels((previous) => !previous)}
|
|
242
|
+
/>
|
|
243
|
+
|
|
244
|
+
<ButtonToggle
|
|
245
|
+
aria-label="Show filters"
|
|
246
|
+
sdsStage={filters ? "on" : "off"}
|
|
247
|
+
sdsStyle="outline"
|
|
248
|
+
sdsType="primary"
|
|
249
|
+
startIcon={<Icon sdsIcon="Filter" sdsSize="s" />}
|
|
250
|
+
onClick={() => setFilters((previous) => !previous)}
|
|
251
|
+
/>
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export default App;
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### ButtonToggle on a dark background
|
|
260
|
+
|
|
261
|
+
This example shows `backgroundAppearance="dark"`, which tells the toggle it sits on a dark surface so it can pick colors with enough contrast in both stages. The toggle paints no background of its own, so the panel is supplied alongside the prop.
|
|
262
|
+
|
|
263
|
+
**Example: ButtonToggleOnADarkBackground**
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
// backgroundAppearance tells the toggle which surface it is on so it can pick
|
|
267
|
+
// colors with enough contrast, in both stages. It paints no background of its
|
|
268
|
+
// own, so the dark panel below is the page's to supply.
|
|
269
|
+
|
|
270
|
+
import {
|
|
271
|
+
ButtonToggle,
|
|
272
|
+
Icon,
|
|
273
|
+
getCorners,
|
|
274
|
+
getSemanticColors,
|
|
275
|
+
getSpaces,
|
|
276
|
+
} from "@czi-sds/components";
|
|
277
|
+
import { useTheme } from "@mui/material/styles";
|
|
278
|
+
|
|
279
|
+
function App() {
|
|
280
|
+
const theme = useTheme();
|
|
281
|
+
const corners = getCorners({ theme });
|
|
282
|
+
const semanticColors = getSemanticColors({ theme });
|
|
283
|
+
const spaces = getSpaces({ theme });
|
|
284
|
+
|
|
285
|
+
return (
|
|
286
|
+
<div className="app">
|
|
287
|
+
<div
|
|
288
|
+
style={{
|
|
289
|
+
alignItems: "center",
|
|
290
|
+
backgroundColor: semanticColors?.base?.backgroundPrimaryDark,
|
|
291
|
+
borderRadius: corners?.m,
|
|
292
|
+
display: "flex",
|
|
293
|
+
gap: spaces?.l,
|
|
294
|
+
padding: spaces?.xl,
|
|
295
|
+
}}
|
|
296
|
+
>
|
|
297
|
+
<ButtonToggle
|
|
298
|
+
backgroundAppearance="dark"
|
|
299
|
+
sdsStage="off"
|
|
300
|
+
sdsStyle="outline"
|
|
301
|
+
sdsType="primary"
|
|
302
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
303
|
+
>
|
|
304
|
+
Off
|
|
305
|
+
</ButtonToggle>
|
|
306
|
+
|
|
307
|
+
<ButtonToggle
|
|
308
|
+
backgroundAppearance="dark"
|
|
309
|
+
sdsStage="on"
|
|
310
|
+
sdsStyle="outline"
|
|
311
|
+
sdsType="primary"
|
|
312
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
313
|
+
>
|
|
314
|
+
On
|
|
315
|
+
</ButtonToggle>
|
|
316
|
+
|
|
317
|
+
<ButtonToggle
|
|
318
|
+
backgroundAppearance="dark"
|
|
319
|
+
sdsStage="on"
|
|
320
|
+
sdsStyle="minimal"
|
|
321
|
+
sdsType="primary"
|
|
322
|
+
startIcon={<Icon sdsIcon="LinesHorizontal3" sdsSize="s" />}
|
|
323
|
+
>
|
|
324
|
+
Minimal on
|
|
325
|
+
</ButtonToggle>
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export default App;
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Toggles in a ButtonGroup
|
|
335
|
+
|
|
336
|
+
This example shows icon-only toggles collected into a ButtonGroup, each tracking its own stage.
|
|
337
|
+
|
|
338
|
+
**Example: ButtonToggleGroup**
|
|
339
|
+
|
|
340
|
+
```tsx
|
|
341
|
+
import * as React from "react";
|
|
342
|
+
import { ButtonGroup, ButtonToggle, Icon } from "@czi-sds/components";
|
|
343
|
+
|
|
344
|
+
const TOGGLES = [
|
|
345
|
+
{ icon: "Search", label: "Search" },
|
|
346
|
+
{ icon: "Copy", label: "Copy" },
|
|
347
|
+
{ icon: "Code", label: "Code" },
|
|
348
|
+
] as const;
|
|
349
|
+
|
|
350
|
+
function App() {
|
|
351
|
+
const [active, setActive] = React.useState<Record<string, boolean>>({});
|
|
352
|
+
|
|
353
|
+
return (
|
|
354
|
+
<div className="app">
|
|
355
|
+
<ButtonGroup sdsType="secondary">
|
|
356
|
+
{TOGGLES.map(({ icon, label }) => (
|
|
357
|
+
<ButtonToggle
|
|
358
|
+
key={label}
|
|
359
|
+
aria-label={label}
|
|
360
|
+
sdsStyle="outline"
|
|
361
|
+
sdsType="secondary"
|
|
362
|
+
sdsStage={active[label] ? "on" : "off"}
|
|
363
|
+
startIcon={<Icon sdsIcon={icon} sdsSize="s" />}
|
|
364
|
+
onClick={() =>
|
|
365
|
+
setActive((prev) => ({ ...prev, [label]: !prev[label] }))
|
|
366
|
+
}
|
|
367
|
+
/>
|
|
368
|
+
))}
|
|
369
|
+
</ButtonGroup>
|
|
370
|
+
</div>
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export default App;
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
## MUI Documentation
|
|
378
|
+
|
|
379
|
+
Documentation for the underlying MUI component can be found [here](https://mui.com/material-ui/react-button/).
|
|
380
|
+
|
|
381
|
+
## Props
|
|
382
|
+
|
|
383
|
+
Any custom SDS props and MUI props required for implementation are found on the table below. See the MUI documentation for additional optional props.
|
|
384
|
+
|
|
385
|
+
| Name | Type | Default | Description |
|
|
386
|
+
| ---------------------- | --------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
387
|
+
| `startIcon` | `ReactElement` | - | **Required.** The icon displayed within the component. Pass the SDS Icon component, for example `<Icon sdsIcon="Search" sdsSize="s" />`. |
|
|
388
|
+
| `sdsStage` | `"on"` \| `"off"` | `"off"` | Controls the toggle stage. The component is fully controlled, so keep this value in state and update it from `onClick`. |
|
|
389
|
+
| `sdsStyle` | `"solid"` \| `"outline"` \| `"minimal"` | `"solid"` | Style of the button. ButtonToggle inherits Button's default of `"solid"`, but toggles are designed around `"outline"` and `"minimal"`, so set one of those explicitly. |
|
|
390
|
+
| `sdsType` | `"primary" \| "secondary"` | `"primary"` | Color scheme of the button. Primary uses the accent color in the on stage, secondary stays neutral. Set it explicitly: the on stage resolves its colors before Button applies this default, so an omitted value draws the neutral treatment over a button that is otherwise primary. Button's `"destructive"` is inherited by the type but has no on-stage treatment, so it should not be used here. |
|
|
391
|
+
| `size` | `"small"` \| `"medium"` \| `"large"` | `"large"` | Size of the button. |
|
|
392
|
+
| `disabled` | `boolean` | `false` | Disables the toggle button when set to `true`. |
|
|
393
|
+
| `backgroundAppearance` | `"matchBackground"` \| `"dark"` | `"matchBackground"` | Button's prop, telling the toggle which surface it sits on so it can pick colors with enough contrast. |
|
|
394
|
+
| `children` | `ReactNode` | - | Text beside the icon. A toggle is normally icon-only, and leaving this out is what makes it square. |
|
|
395
|
+
| `onClick` | `(event: React.MouseEvent) => void` | - | Callback fired when the button is clicked. |
|
|
396
|
+
|
|
397
|
+
ButtonToggle always renders with `backgroundOnHover` enabled and ignores `endIcon`, which is reserved for the toggle's own styling.
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Callout
|
|
2
|
+
|
|
3
|
+
## Source Code
|
|
4
|
+
|
|
5
|
+
The component's source code in the SDS codebase can be found [here](https://github.com/chanzuckerberg/sci-components/blob/main/packages/components/src/core/Callout/index.tsx).
|
|
6
|
+
|
|
7
|
+
## Import
|
|
8
|
+
|
|
9
|
+
**React TypeScript**
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { Callout, CalloutTitle } from "@czi-sds/components";
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Code examples
|
|
16
|
+
|
|
17
|
+
### Default Callout
|
|
18
|
+
|
|
19
|
+
This example has the minimum props needed for the Callout component. Only `intent` is required, but a Callout with no `title` or `body` renders as an empty box, so both are given here.
|
|
20
|
+
|
|
21
|
+
**Example: DefaultCallout**
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
// Most minimal Callout (just has the basic requirements)
|
|
25
|
+
|
|
26
|
+
import { Callout } from "@czi-sds/components";
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
return (
|
|
30
|
+
<div className="app">
|
|
31
|
+
<Callout
|
|
32
|
+
intent="info"
|
|
33
|
+
title="Callout box"
|
|
34
|
+
body="The Callout component is a versatile UI element designed to draw attention to important information or messages within your interface."
|
|
35
|
+
/>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default App;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Callout intents
|
|
44
|
+
|
|
45
|
+
This example shows the five intents, each with the icon the Callout picks by default.
|
|
46
|
+
|
|
47
|
+
**Example: CalloutIntents**
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
// Every intent, each with the icon the Callout picks by default
|
|
51
|
+
|
|
52
|
+
import { Callout } from "@czi-sds/components";
|
|
53
|
+
|
|
54
|
+
function App() {
|
|
55
|
+
return (
|
|
56
|
+
<div className="app">
|
|
57
|
+
<Callout
|
|
58
|
+
intent="info"
|
|
59
|
+
title="Info"
|
|
60
|
+
body="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
|
61
|
+
/>
|
|
62
|
+
<Callout
|
|
63
|
+
intent="accent"
|
|
64
|
+
title="Accent"
|
|
65
|
+
body="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
|
66
|
+
/>
|
|
67
|
+
<Callout
|
|
68
|
+
intent="positive"
|
|
69
|
+
title="Positive"
|
|
70
|
+
body="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
|
71
|
+
/>
|
|
72
|
+
<Callout
|
|
73
|
+
intent="notice"
|
|
74
|
+
title="Notice"
|
|
75
|
+
body="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
|
76
|
+
/>
|
|
77
|
+
<Callout
|
|
78
|
+
intent="negative"
|
|
79
|
+
title="Negative"
|
|
80
|
+
body="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
|
81
|
+
/>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default App;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Expandable Callout
|
|
90
|
+
|
|
91
|
+
The Expandable Callout component provides an interactive and space-efficient way to present information. By default, it displays a brief summary, however, users can expand it to reveal more detailed content, similar to an accordion. This feature is particularly useful for sharing additional context or insights while keeping the initial interface clutter-free. The extra content is passed as `children`, and `sdsStage` sets whether the Callout starts open or closed.
|
|
92
|
+
|
|
93
|
+
**Example: ExpandableCallout**
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
// Expandable Callout: children are the extra content revealed by the chevron
|
|
97
|
+
|
|
98
|
+
import { Callout } from "@czi-sds/components";
|
|
99
|
+
|
|
100
|
+
function App() {
|
|
101
|
+
return (
|
|
102
|
+
<div className="app">
|
|
103
|
+
<Callout
|
|
104
|
+
intent="notice"
|
|
105
|
+
sdsStyle="expandable"
|
|
106
|
+
sdsStage="closed"
|
|
107
|
+
title="Attention Required"
|
|
108
|
+
body="The Callout serves as a visual alert to draw immediate attention to information that requires action or consideration."
|
|
109
|
+
>
|
|
110
|
+
Use the expandable style strategically, and only when there really is
|
|
111
|
+
extra content to reveal. The chevron is rendered either way, so an
|
|
112
|
+
expandable Callout with no children toggles to an empty section.
|
|
113
|
+
</Callout>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default App;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Dismissible Callout
|
|
122
|
+
|
|
123
|
+
The dismissible Callout variant provides users with the ability to dismiss it at their convenience. It includes a close button located in the top right corner, offering a familiar interaction pattern for users to remove the Callout from view. The Callout hides itself when that button is clicked, so `onClose` is for keeping your own state in sync; setting `dismissed` back to `false` is what brings the Callout back.
|
|
124
|
+
|
|
125
|
+
**Example: DismissibleCallout**
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
// Closable Callout
|
|
129
|
+
|
|
130
|
+
import { useState } from "react";
|
|
131
|
+
import { Button, Callout } from "@czi-sds/components";
|
|
132
|
+
|
|
133
|
+
function App() {
|
|
134
|
+
const [dismissed, setDismissed] = useState(false);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<div className="app">
|
|
138
|
+
<Callout
|
|
139
|
+
intent="negative"
|
|
140
|
+
sdsStyle="dismissible"
|
|
141
|
+
dismissed={dismissed}
|
|
142
|
+
onClose={() => setDismissed(true)}
|
|
143
|
+
title="An Error Occurred"
|
|
144
|
+
body="The Error Callout is a crucial component for communicating critical errors or issues to users."
|
|
145
|
+
/>
|
|
146
|
+
{dismissed && (
|
|
147
|
+
<Button onClick={() => setDismissed(false)} sdsType="primary">
|
|
148
|
+
Reset Callout
|
|
149
|
+
</Button>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default App;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Callout with a custom icon
|
|
159
|
+
|
|
160
|
+
This example replaces the icon that the `intent` would otherwise choose. The `icon` prop takes either an SDS icon name or an element.
|
|
161
|
+
|
|
162
|
+
**Example: CalloutWithACustomIcon**
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
// Replacing the intent's default icon with any SDS icon
|
|
166
|
+
|
|
167
|
+
import { Callout } from "@czi-sds/components";
|
|
168
|
+
|
|
169
|
+
function App() {
|
|
170
|
+
return (
|
|
171
|
+
<div className="app">
|
|
172
|
+
<Callout
|
|
173
|
+
intent="accent"
|
|
174
|
+
icon="Bacteria"
|
|
175
|
+
title="Custom icon"
|
|
176
|
+
body="Pass an icon name to swap the icon the intent would otherwise pick."
|
|
177
|
+
/>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export default App;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Callout with auto dismiss
|
|
186
|
+
|
|
187
|
+
This example dismisses itself after four seconds. Pass `true` instead of a number to use the default delay of `8000` milliseconds.
|
|
188
|
+
|
|
189
|
+
**Example: CalloutWithAutoDismiss**
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
// The Callout dismisses itself once the timeout elapses. Remounting it with a
|
|
193
|
+
// new key restarts the countdown.
|
|
194
|
+
|
|
195
|
+
import { useState } from "react";
|
|
196
|
+
import { Button, Callout } from "@czi-sds/components";
|
|
197
|
+
|
|
198
|
+
function App() {
|
|
199
|
+
const [runId, setRunId] = useState(0);
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<div className="app">
|
|
203
|
+
<Callout
|
|
204
|
+
key={runId}
|
|
205
|
+
intent="positive"
|
|
206
|
+
autoDismiss={4000}
|
|
207
|
+
title="Saved"
|
|
208
|
+
body="This Callout disappears on its own after four seconds."
|
|
209
|
+
/>
|
|
210
|
+
<Button onClick={() => setRunId((prev) => prev + 1)} sdsType="primary">
|
|
211
|
+
Show again
|
|
212
|
+
</Button>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export default App;
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## SDS vs MUI
|
|
221
|
+
|
|
222
|
+
The SDS Callout component is built upon the MUI Alert component (as is the SDS Notification component), but there are some important differences:
|
|
223
|
+
|
|
224
|
+
- **Color:** SDS's Callout component has its own `intent` prop designed for setting both the color and default icon, and takes the values of `"accent"`, `"info"`, `"negative"`, `"notice"`, or `"positive"`. MUI's Alert instead uses the `severity` prop for this purpose (`severity` can also be used for SDS's Notification, and will take the same values as `intent`; this is not recommended)
|
|
225
|
+
|
|
226
|
+
- **Title and body:** Rather than composing an AlertTitle and text as children the way MUI's Alert does, SDS's Callout takes its content through the `title` and `body` props and renders the stylized CalloutTitle for you. Children are reserved for the extra content of an expandable Callout, and are ignored by the other styles.
|
|
227
|
+
|
|
228
|
+
- **Expanding and closing:** Both behaviors come from the `sdsStyle` prop rather than from separate props. Setting it to `"expandable"` adds a chevron in the top right that toggles the children in and out of view, and setting it to `"dismissible"` adds a close button that hides the Callout and fires `onClose`. An expandable Callout should only be used when there really is extra content to reveal, since the chevron is rendered either way. SDS uses MUI's Alert `action` prop under the hood, in case there is a need to further override the behavior.
|
|
229
|
+
|
|
230
|
+
- **Transitions:** SDS's Callout uses the Grow transition component by default
|
|
231
|
+
|
|
232
|
+
- **Icons:** Like with MUI's Alert, SDS's Callout also shows an icon to the left of the title text. It is chosen automatically from the `intent` (see the first bullet) and can be overridden with the `icon` prop, which takes either the name of an SDS icon or a custom SVG element:
|
|
233
|
+
|
|
234
|
+
**React TypeScript**
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
icon="Book"
|
|
238
|
+
icon={<Icon sdsSize="s" sdsIcon="Book" />}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Additionally, setting `icon={false}` has no effect, and `iconMapping` does not work to change icons associated to `intent` or `severity`.
|
|
242
|
+
|
|
243
|
+
- **Variants:** The `variant` prop is not available for SDS's Callout component.
|
|
244
|
+
|
|
245
|
+
## MUI Documentation
|
|
246
|
+
|
|
247
|
+
Documentation for the underlying MUI Alert component can be found [here](https://mui.com/material-ui/react-alert/).
|
|
248
|
+
|
|
249
|
+
## Props
|
|
250
|
+
|
|
251
|
+
Any custom SDS props and MUI props required for implementation are found on the table below. See the MUI documentation for additional optional props.
|
|
252
|
+
|
|
253
|
+
| Name | Type | Default | Description |
|
|
254
|
+
| -------------- | -------------------------------------------------------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
255
|
+
| `intent` | `"accent"` \| `"info"` \| `"negative"` \| `"notice"` \| `"positive"` | - | **Required.** Sets both the color of the component and the icon it defaults to. |
|
|
256
|
+
| `sdsStyle` | `"persistent"` \| `"expandable"` \| `"dismissible"` | `"persistent"` | Defines the style of the Callout: - `"persistent"`: Cannot be closed. - `"expandable"`: Includes a chevron icon that toggles the children in and out of view. - `"dismissible"`: Includes an “x” icon for manual dismissal. |
|
|
257
|
+
| `title` | `string` | - | The Callout title. |
|
|
258
|
+
| `body` | `ReactNode` | - | The Callout body, shown beneath the title. |
|
|
259
|
+
| `children` | `ReactNode` | - | Extra content revealed when an expandable Callout is open. The other styles ignore `children`, so use `body` for the main message. |
|
|
260
|
+
| `extraContent` | `ReactNode` | - | The same slot as `children`, for callers that would rather pass it as a prop. Both render when both are given, `children` first. |
|
|
261
|
+
| `hideTitle` | `boolean` | `false` | If set to `true`, hides the Callout title. |
|
|
262
|
+
| `hideBody` | `boolean` | `false` | If set to `true`, hides the Callout body and centers the icon against the remaining content. |
|
|
263
|
+
| `icon` | `SDSIcon \| React.ReactElement<CustomSVGProps>` | - | Icon displayed to the left of the Callout title, given either as an SDS icon name or as an element. Defaults to the icon for the current `intent`: `"CheckCircle"` for `"positive"`, `"InfoCircle"` for `"info"`, and `"ExclamationMarkCircle"` for `"accent"`, `"notice"`, and `"negative"`. |
|
|
264
|
+
| `sdsIconProps` | `Partial<IconProps>` | - | Props forwarded to the Icon component when `icon` is given as a name. |
|
|
265
|
+
| `sdsStage` | `"open" \| "closed"` | `"open"` | The stage an expandable Callout starts in. It is only the initial value; the chevron takes over from there. |
|
|
266
|
+
| `dismissed` | `boolean` | - | Hides the Callout when set to `true`. Changing it back to `false` brings the Callout back, which is how a dismissed Callout is restored. |
|
|
267
|
+
| `autoDismiss` | `boolean \| number` | - | Dismisses the Callout on a timer. A number sets the delay in milliseconds, and `true` uses `8000`. Leave it unset to keep the Callout visible until it is dismissed another way. |
|
|
268
|
+
| `onClose` | `(event: React.SyntheticEvent) => void` | - | Callback fired when the Callout is closed. The Callout hides itself regardless, so use this to sync your own state rather than to perform the hiding. |
|