@czi-sds/mcp 0.16.0 → 0.18.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/ProteinStructureViewer.md +1044 -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 +267 -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/ProteinStructureViewer.json +117 -0
- 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/data/tailwind.json +20 -14
- 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,256 @@
|
|
|
1
|
+
# ButtonDropdown
|
|
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/ButtonDropdown/index.tsx).
|
|
6
|
+
|
|
7
|
+
## Import
|
|
8
|
+
|
|
9
|
+
**React TypeScript**
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { ButtonDropdown } from "@czi-sds/components";
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Code examples
|
|
16
|
+
|
|
17
|
+
### **Default ButtonDropdown**
|
|
18
|
+
|
|
19
|
+
This example has the minimum props needed for the ButtonDropdown component.
|
|
20
|
+
|
|
21
|
+
**Example: DefaultButtonDropdown**
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { ButtonDropdown } from "@czi-sds/components";
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
return (
|
|
28
|
+
<div className="app">
|
|
29
|
+
<ButtonDropdown>Label</ButtonDropdown>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default App;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### ButtonDropdown styles
|
|
38
|
+
|
|
39
|
+
This example shows the three styles available through `sdsStyle`, from most to least emphasis.
|
|
40
|
+
|
|
41
|
+
**Example: ButtonDropdownStyles**
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { ButtonDropdown } from "@czi-sds/components";
|
|
45
|
+
|
|
46
|
+
function App() {
|
|
47
|
+
return (
|
|
48
|
+
<div className="app" style={{ display: "flex", gap: "16px" }}>
|
|
49
|
+
<ButtonDropdown sdsStyle="solid">Solid</ButtonDropdown>
|
|
50
|
+
<ButtonDropdown sdsStyle="outline">Outline</ButtonDropdown>
|
|
51
|
+
<ButtonDropdown sdsStyle="minimal">Minimal</ButtonDropdown>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default App;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### ButtonDropdown types
|
|
60
|
+
|
|
61
|
+
This example shows the two color schemes available through `sdsType`. Each one can be combined with any of the styles above. Unlike Button, there is no `"destructive"` type: a dropdown trigger opens a menu rather than carrying out an action.
|
|
62
|
+
|
|
63
|
+
**Example: ButtonDropdownTypes**
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { ButtonDropdown } from "@czi-sds/components";
|
|
67
|
+
|
|
68
|
+
function App() {
|
|
69
|
+
return (
|
|
70
|
+
<div className="app" style={{ display: "flex", gap: "16px" }}>
|
|
71
|
+
<ButtonDropdown sdsType="primary">Primary</ButtonDropdown>
|
|
72
|
+
<ButtonDropdown sdsType="secondary">Secondary</ButtonDropdown>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default App;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### ButtonDropdown sizes
|
|
81
|
+
|
|
82
|
+
This example shows the three sizes available through the `size` prop. The trailing chevron follows the size of the button it sits in.
|
|
83
|
+
|
|
84
|
+
**Example: ButtonDropdownSizes**
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { ButtonDropdown } from "@czi-sds/components";
|
|
88
|
+
|
|
89
|
+
function App() {
|
|
90
|
+
return (
|
|
91
|
+
<div
|
|
92
|
+
className="app"
|
|
93
|
+
style={{ alignItems: "center", display: "flex", gap: "16px" }}
|
|
94
|
+
>
|
|
95
|
+
<ButtonDropdown size="large">Large</ButtonDropdown>
|
|
96
|
+
<ButtonDropdown size="medium">Medium</ButtonDropdown>
|
|
97
|
+
<ButtonDropdown size="small">Small</ButtonDropdown>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default App;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### ButtonDropdown with a start icon
|
|
106
|
+
|
|
107
|
+
This example shows how to incorporate a starting icon within a ButtonDropdown component.
|
|
108
|
+
|
|
109
|
+
**Example: ButtonDropdownWithAStartIcon**
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { ButtonDropdown, Icon } from "@czi-sds/components";
|
|
113
|
+
|
|
114
|
+
function App() {
|
|
115
|
+
return (
|
|
116
|
+
<div className="app">
|
|
117
|
+
<ButtonDropdown
|
|
118
|
+
sdsType="secondary"
|
|
119
|
+
startIcon={<Icon sdsIcon="Bacteria" sdsSize="s" />}
|
|
120
|
+
>
|
|
121
|
+
Bacteria Types
|
|
122
|
+
</ButtonDropdown>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default App;
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### ButtonDropdown without a background on hover
|
|
131
|
+
|
|
132
|
+
This example shows `backgroundOnHover`, which only applies to the minimal style. Turning it off drops the button's padding along with its hover and pressed backgrounds, so it sits flush with the text around it.
|
|
133
|
+
|
|
134
|
+
**Example: ButtonDropdownBackgroundOnHover**
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
// backgroundOnHover only applies to the minimal style. Turning it off drops the
|
|
138
|
+
// button's padding along with the hover and pressed backgrounds, which is what
|
|
139
|
+
// lets it sit flush with the text around it.
|
|
140
|
+
|
|
141
|
+
import { ButtonDropdown } from "@czi-sds/components";
|
|
142
|
+
|
|
143
|
+
function App() {
|
|
144
|
+
return (
|
|
145
|
+
<div className="app" style={{ display: "flex", gap: "32px" }}>
|
|
146
|
+
<ButtonDropdown sdsStyle="minimal" sdsType="primary">
|
|
147
|
+
Hover for a background
|
|
148
|
+
</ButtonDropdown>
|
|
149
|
+
|
|
150
|
+
<ButtonDropdown
|
|
151
|
+
backgroundOnHover={false}
|
|
152
|
+
sdsStyle="minimal"
|
|
153
|
+
sdsType="primary"
|
|
154
|
+
>
|
|
155
|
+
Flush with the text
|
|
156
|
+
</ButtonDropdown>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default App;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### ButtonDropdown on a dark background
|
|
165
|
+
|
|
166
|
+
This example shows `backgroundAppearance="dark"`, which tells the button it sits on a dark surface so it can pick colors with enough contrast. The button paints no background of its own, so the panel is supplied alongside the prop.
|
|
167
|
+
|
|
168
|
+
**Example: ButtonDropdownOnADarkBackground**
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
// backgroundAppearance tells the button which surface it is on so it can pick
|
|
172
|
+
// colors with enough contrast. It paints no background of its own, so the dark
|
|
173
|
+
// panel below is the page's to supply.
|
|
174
|
+
|
|
175
|
+
import {
|
|
176
|
+
ButtonDropdown,
|
|
177
|
+
getCorners,
|
|
178
|
+
getSemanticColors,
|
|
179
|
+
getSpaces,
|
|
180
|
+
} from "@czi-sds/components";
|
|
181
|
+
import { useTheme } from "@mui/material/styles";
|
|
182
|
+
|
|
183
|
+
function App() {
|
|
184
|
+
const theme = useTheme();
|
|
185
|
+
const corners = getCorners({ theme });
|
|
186
|
+
const semanticColors = getSemanticColors({ theme });
|
|
187
|
+
const spaces = getSpaces({ theme });
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<div className="app">
|
|
191
|
+
<div
|
|
192
|
+
style={{
|
|
193
|
+
alignItems: "center",
|
|
194
|
+
backgroundColor: semanticColors?.base?.backgroundPrimaryDark,
|
|
195
|
+
borderRadius: corners?.m,
|
|
196
|
+
display: "flex",
|
|
197
|
+
gap: spaces?.xl,
|
|
198
|
+
padding: spaces?.xl,
|
|
199
|
+
}}
|
|
200
|
+
>
|
|
201
|
+
<ButtonDropdown backgroundAppearance="dark" sdsStyle="solid">
|
|
202
|
+
Solid
|
|
203
|
+
</ButtonDropdown>
|
|
204
|
+
|
|
205
|
+
<ButtonDropdown backgroundAppearance="dark" sdsStyle="outline">
|
|
206
|
+
Outline
|
|
207
|
+
</ButtonDropdown>
|
|
208
|
+
|
|
209
|
+
<ButtonDropdown backgroundAppearance="dark" sdsStyle="minimal">
|
|
210
|
+
Minimal
|
|
211
|
+
</ButtonDropdown>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export default App;
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## SDS vs MUI
|
|
221
|
+
|
|
222
|
+
The SDS ButtonDropdown component is the regular Button component with a ChevronDown icon added after the label text, via the MUI `endIcon` prop. The chevron is only added when the button has a label, and its size follows the `size` prop. A `startIcon` is optional; when used, it takes the Icon component, which references the specific icon to call as one of its props, like so:
|
|
223
|
+
|
|
224
|
+
**React TypeScript**
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
startIcon={<Icon sdsIcon="Download" sdsSize="s" />}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
whereas MUI expects the prop to receive an individual icon as its own component (for example `startIcon={<DeleteIcon />}`).
|
|
231
|
+
|
|
232
|
+
The chevron is applied after your props, so an `endIcon` passed to a ButtonDropdown is ignored: the trailing slot belongs to the component. Where a different trailing icon is what you are after, use Button and put it there yourself.
|
|
233
|
+
|
|
234
|
+
Because ButtonDropdown renders a Button, it accepts every Button prop except `sdsType`, which is narrowed to `"primary"` and `"secondary"`: a dropdown trigger is never a destructive action, and passing `"destructive"` logs a warning and renders nothing. The same MUI caveats as Button apply, so `variant`, `color`, and `disableElevation` are all best avoided.
|
|
235
|
+
|
|
236
|
+
## MUI Documentation
|
|
237
|
+
|
|
238
|
+
Documentation for the underlying MUI component can be found [here](https://mui.com/material-ui/react-button/).
|
|
239
|
+
|
|
240
|
+
## Props
|
|
241
|
+
|
|
242
|
+
Any custom SDS props and MUI props required for implementation are found on the table below. See the MUI documentation for additional optional props.
|
|
243
|
+
|
|
244
|
+
| Name | Type | Default | Description |
|
|
245
|
+
| ---------------------- | --------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
246
|
+
| `sdsStyle` | `"solid"` \| `"outline"` \| `"minimal"` | `"solid"` | Style of the button. Same values as Button. |
|
|
247
|
+
| `sdsType` | `"primary" \| "secondary"` | `"primary"` | Color scheme of the button. Unlike Button, `"destructive"` is not supported. |
|
|
248
|
+
| `size` | `"small"` \| `"medium"` \| `"large"` | `"large"` | Size of the button. Also sets the size of the trailing chevron. |
|
|
249
|
+
| `backgroundOnHover` | `boolean` | `true` | Only applies when `sdsStyle` is `"minimal"`. When `false`, the button drops its padding and renders no background on hover or press, so it sits flush with surrounding text. |
|
|
250
|
+
| `backgroundAppearance` | `"matchBackground" \| "dark"` | `"matchBackground"` | Tells the button which surface it sits on so it can pick colors with enough contrast. Set it to `"dark"` when the button is placed on a dark background in light mode. |
|
|
251
|
+
| `startIcon` | `ReactNode` | - | An optional icon placed before the label. Pass the SDS Icon component, for example `<Icon sdsIcon="Download" sdsSize="s" />`. |
|
|
252
|
+
| `children` | `ReactNode` | - | The button label. The trailing chevron is only rendered when a label is present. |
|
|
253
|
+
| `disabled` | `boolean` | `false` | Disables the button when set to `true`. |
|
|
254
|
+
| `onClick` | `(event: React.MouseEvent) => void` | - | Callback fired when the button is clicked. Typically used to open the associated menu. |
|
|
255
|
+
|
|
256
|
+
Everything else Button accepts passes through unchanged and behaves identically here, including its `href` and `target` props and MUI's own, such as `sx` and `className`. The one exception is `endIcon`, which the chevron overwrites, as noted above.
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# ButtonGroup
|
|
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/ButtonGroup).
|
|
6
|
+
|
|
7
|
+
## Import
|
|
8
|
+
|
|
9
|
+
**React TypeScript**
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { ButtonGroup } from "@czi-sds/components";
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Code examples
|
|
16
|
+
|
|
17
|
+
### **Default ButtonGroup**
|
|
18
|
+
|
|
19
|
+
This example has the minimum props needed for the ButtonGroup component. Buttons can mix icon-only, icon plus label, and label-only content.
|
|
20
|
+
|
|
21
|
+
**Example: DefaultButtonGroup**
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { Button, ButtonGroup, Icon } from "@czi-sds/components";
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
return (
|
|
28
|
+
<div className="app">
|
|
29
|
+
<ButtonGroup>
|
|
30
|
+
<Button aria-label="Download">
|
|
31
|
+
<Icon sdsIcon="Download" sdsSize="s" />
|
|
32
|
+
</Button>
|
|
33
|
+
<Button startIcon={<Icon sdsIcon="Copy" sdsSize="s" />}>Copy</Button>
|
|
34
|
+
<Button>Label</Button>
|
|
35
|
+
</ButtonGroup>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default App;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### ButtonGroup types
|
|
44
|
+
|
|
45
|
+
This example shows the two color schemes available through `sdsType`. The group paints the buttons in it, so an `sdsType` set on an individual button is overridden.
|
|
46
|
+
|
|
47
|
+
**Example: ButtonGroupTypes**
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { Button, ButtonGroup } from "@czi-sds/components";
|
|
51
|
+
|
|
52
|
+
function App() {
|
|
53
|
+
return (
|
|
54
|
+
<div className="app" style={{ display: "flex", gap: "32px" }}>
|
|
55
|
+
<ButtonGroup sdsType="primary">
|
|
56
|
+
<Button>Day</Button>
|
|
57
|
+
<Button>Week</Button>
|
|
58
|
+
<Button>Month</Button>
|
|
59
|
+
</ButtonGroup>
|
|
60
|
+
|
|
61
|
+
<ButtonGroup sdsType="secondary">
|
|
62
|
+
<Button>Day</Button>
|
|
63
|
+
<Button>Week</Button>
|
|
64
|
+
<Button>Month</Button>
|
|
65
|
+
</ButtonGroup>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default App;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### ButtonGroup sizes
|
|
74
|
+
|
|
75
|
+
This example shows the three sizes available through the `size` prop. The group injects it into every Button and ButtonToggle child, which is what keeps a mixed group at one height.
|
|
76
|
+
|
|
77
|
+
**Example: ButtonGroupSizes**
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
// The group injects its size into every button in it, so a size set on an
|
|
81
|
+
// individual button is overwritten and a mixed group stays at one height.
|
|
82
|
+
|
|
83
|
+
import { Button, ButtonGroup } from "@czi-sds/components";
|
|
84
|
+
|
|
85
|
+
function App() {
|
|
86
|
+
return (
|
|
87
|
+
<div
|
|
88
|
+
className="app"
|
|
89
|
+
style={{ alignItems: "center", display: "flex", gap: "32px" }}
|
|
90
|
+
>
|
|
91
|
+
<ButtonGroup size="large">
|
|
92
|
+
<Button>Day</Button>
|
|
93
|
+
<Button>Week</Button>
|
|
94
|
+
<Button>Month</Button>
|
|
95
|
+
</ButtonGroup>
|
|
96
|
+
|
|
97
|
+
<ButtonGroup size="medium">
|
|
98
|
+
<Button>Day</Button>
|
|
99
|
+
<Button>Week</Button>
|
|
100
|
+
<Button>Month</Button>
|
|
101
|
+
</ButtonGroup>
|
|
102
|
+
|
|
103
|
+
<ButtonGroup size="small">
|
|
104
|
+
<Button>Day</Button>
|
|
105
|
+
<Button>Week</Button>
|
|
106
|
+
<Button>Month</Button>
|
|
107
|
+
</ButtonGroup>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default App;
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Icon-only ButtonGroup
|
|
116
|
+
|
|
117
|
+
This example shows an icon-only group in both orientations. Vertical is only available because none of the buttons carry a label.
|
|
118
|
+
|
|
119
|
+
**Example: ButtonGroupIconOnly**
|
|
120
|
+
|
|
121
|
+
```tsx
|
|
122
|
+
// Vertical orientation is only honored when every button is icon-only
|
|
123
|
+
|
|
124
|
+
import { Button, ButtonGroup, Icon } from "@czi-sds/components";
|
|
125
|
+
|
|
126
|
+
function App() {
|
|
127
|
+
return (
|
|
128
|
+
<div className="app" style={{ display: "flex", gap: "32px" }}>
|
|
129
|
+
<ButtonGroup sdsType="secondary">
|
|
130
|
+
<Button aria-label="Search">
|
|
131
|
+
<Icon sdsIcon="Search" sdsSize="s" />
|
|
132
|
+
</Button>
|
|
133
|
+
<Button aria-label="Edit">
|
|
134
|
+
<Icon sdsIcon="Edit" sdsSize="s" />
|
|
135
|
+
</Button>
|
|
136
|
+
<Button aria-label="Delete">
|
|
137
|
+
<Icon sdsIcon="TrashCan" sdsSize="s" />
|
|
138
|
+
</Button>
|
|
139
|
+
</ButtonGroup>
|
|
140
|
+
|
|
141
|
+
<ButtonGroup sdsType="secondary" orientation="vertical">
|
|
142
|
+
<Button aria-label="Search">
|
|
143
|
+
<Icon sdsIcon="Search" sdsSize="s" />
|
|
144
|
+
</Button>
|
|
145
|
+
<Button aria-label="Edit">
|
|
146
|
+
<Icon sdsIcon="Edit" sdsSize="s" />
|
|
147
|
+
</Button>
|
|
148
|
+
<Button aria-label="Delete">
|
|
149
|
+
<Icon sdsIcon="TrashCan" sdsSize="s" />
|
|
150
|
+
</Button>
|
|
151
|
+
</ButtonGroup>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default App;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### ButtonGroup with ButtonToggles
|
|
160
|
+
|
|
161
|
+
This example shows a group of ButtonToggle components rather than Buttons, which turns it from a row of actions into a set of independent switches. Each toggle owns its own state through `sdsStage`.
|
|
162
|
+
|
|
163
|
+
**Example: ButtonGroupWithButtonToggles**
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
// A group takes ButtonToggle as readily as Button, which turns it from a row of
|
|
167
|
+
// actions into a set of switches. Each toggle owns its state through sdsStage.
|
|
168
|
+
|
|
169
|
+
import { useState } from "react";
|
|
170
|
+
import { ButtonGroup, ButtonToggle, Icon } from "@czi-sds/components";
|
|
171
|
+
|
|
172
|
+
const TOGGLES = [
|
|
173
|
+
{ icon: "Search", label: "Search" },
|
|
174
|
+
{ icon: "Copy", label: "Copy" },
|
|
175
|
+
{ icon: "Code", label: "Code" },
|
|
176
|
+
] as const;
|
|
177
|
+
|
|
178
|
+
function App() {
|
|
179
|
+
const [active, setActive] = useState<Record<string, boolean>>({
|
|
180
|
+
Search: true,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div className="app">
|
|
185
|
+
<ButtonGroup sdsType="secondary">
|
|
186
|
+
{TOGGLES.map(({ icon, label }) => (
|
|
187
|
+
<ButtonToggle
|
|
188
|
+
key={label}
|
|
189
|
+
aria-label={label}
|
|
190
|
+
sdsStage={active[label] ? "on" : "off"}
|
|
191
|
+
sdsStyle="outline"
|
|
192
|
+
startIcon={<Icon sdsIcon={icon} sdsSize="s" />}
|
|
193
|
+
onClick={() =>
|
|
194
|
+
setActive((previous) => ({
|
|
195
|
+
...previous,
|
|
196
|
+
[label]: !previous[label],
|
|
197
|
+
}))
|
|
198
|
+
}
|
|
199
|
+
/>
|
|
200
|
+
))}
|
|
201
|
+
</ButtonGroup>
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default App;
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Disabled ButtonGroup
|
|
210
|
+
|
|
211
|
+
This example shows one disabled button inside an otherwise active group, beside a group disabled as a whole. `disabled` on the group reaches every button in it.
|
|
212
|
+
|
|
213
|
+
**Example: ButtonGroupDisabled**
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
// A single button carries its own disabled prop; disabled on the group reaches
|
|
217
|
+
// every button in it.
|
|
218
|
+
|
|
219
|
+
import { Button, ButtonGroup } from "@czi-sds/components";
|
|
220
|
+
|
|
221
|
+
function App() {
|
|
222
|
+
return (
|
|
223
|
+
<div className="app" style={{ display: "flex", gap: "32px" }}>
|
|
224
|
+
<ButtonGroup sdsType="secondary">
|
|
225
|
+
<Button>Day</Button>
|
|
226
|
+
<Button disabled>Week</Button>
|
|
227
|
+
<Button>Month</Button>
|
|
228
|
+
</ButtonGroup>
|
|
229
|
+
|
|
230
|
+
<ButtonGroup disabled sdsType="secondary">
|
|
231
|
+
<Button>Day</Button>
|
|
232
|
+
<Button>Week</Button>
|
|
233
|
+
<Button>Month</Button>
|
|
234
|
+
</ButtonGroup>
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export default App;
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### ButtonGroup on a dark background
|
|
243
|
+
|
|
244
|
+
This example shows `backgroundAppearance="dark"`, which tells the group it sits on a dark surface so it can pick borders and text with enough contrast. The group paints no background of its own, so the panel is supplied alongside the prop.
|
|
245
|
+
|
|
246
|
+
**Example: ButtonGroupOnADarkBackground**
|
|
247
|
+
|
|
248
|
+
```tsx
|
|
249
|
+
// backgroundAppearance tells the group which surface it is on so it can pick
|
|
250
|
+
// borders and text with enough contrast. It paints no background of its own, so
|
|
251
|
+
// the dark panel below is the page's to supply.
|
|
252
|
+
|
|
253
|
+
import {
|
|
254
|
+
Button,
|
|
255
|
+
ButtonGroup,
|
|
256
|
+
getCorners,
|
|
257
|
+
getSemanticColors,
|
|
258
|
+
getSpaces,
|
|
259
|
+
} from "@czi-sds/components";
|
|
260
|
+
import { useTheme } from "@mui/material/styles";
|
|
261
|
+
|
|
262
|
+
function App() {
|
|
263
|
+
const theme = useTheme();
|
|
264
|
+
const corners = getCorners({ theme });
|
|
265
|
+
const semanticColors = getSemanticColors({ theme });
|
|
266
|
+
const spaces = getSpaces({ theme });
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<div className="app">
|
|
270
|
+
<div
|
|
271
|
+
style={{
|
|
272
|
+
backgroundColor: semanticColors?.base?.backgroundPrimaryDark,
|
|
273
|
+
borderRadius: corners?.m,
|
|
274
|
+
display: "flex",
|
|
275
|
+
gap: spaces?.xl,
|
|
276
|
+
padding: spaces?.xl,
|
|
277
|
+
}}
|
|
278
|
+
>
|
|
279
|
+
<ButtonGroup backgroundAppearance="dark" sdsType="primary">
|
|
280
|
+
<Button>Day</Button>
|
|
281
|
+
<Button>Week</Button>
|
|
282
|
+
<Button>Month</Button>
|
|
283
|
+
</ButtonGroup>
|
|
284
|
+
|
|
285
|
+
<ButtonGroup backgroundAppearance="dark" sdsType="secondary">
|
|
286
|
+
<Button>Day</Button>
|
|
287
|
+
<Button>Week</Button>
|
|
288
|
+
<Button>Month</Button>
|
|
289
|
+
</ButtonGroup>
|
|
290
|
+
</div>
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export default App;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## SDS vs MUI
|
|
299
|
+
|
|
300
|
+
ButtonGroup collects related Button or ButtonToggle components into a single segmented control, joining them with shared borders. It sets MUI's `variant` to `"outlined"` and injects its own `size` into every button in the group, which is why `variant` and `size` are removed from the MUI props it accepts.
|
|
301
|
+
|
|
302
|
+
Vertical orientation is only honored when every button in the group is icon-only. Requesting it for a group that contains labels logs a warning and falls back to horizontal.
|
|
303
|
+
|
|
304
|
+
## MUI Documentation
|
|
305
|
+
|
|
306
|
+
Documentation for the underlying MUI component can be found [here](https://mui.com/material-ui/react-button-group/).
|
|
307
|
+
|
|
308
|
+
## Props
|
|
309
|
+
|
|
310
|
+
Any custom SDS props and MUI props required for implementation are found on the table below. See the MUI documentation for additional optional props.
|
|
311
|
+
|
|
312
|
+
| Name | Type | Default | Description |
|
|
313
|
+
| ---------------------- | ------------------------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
314
|
+
| `sdsStyle` | `"outline"` | `"outline"` | Style of the button group. Outline is the only value. |
|
|
315
|
+
| `sdsType` | `"primary" \| "secondary"` | `"primary"` | Color scheme applied to every button in the group. |
|
|
316
|
+
| `size` | `"small"` \| `"medium"` \| `"large"` | `"large"` | Size of the group. It is injected into each Button and ButtonToggle child, so setting `size` on an individual button has no effect and a mixed group stays at one height. Anything else in the group keeps its own size. |
|
|
317
|
+
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Direction the buttons are stacked in. Vertical is only available when every button is icon-only. |
|
|
318
|
+
| `backgroundAppearance` | `"matchBackground" \| "dark"` | `"matchBackground"` | Tells the group which surface it sits on so it can pick colors with enough contrast. |
|
|
319
|
+
| `disabled` | `boolean` | `false` | MUI's prop, passed down through the group so every button in it is disabled at once. |
|
|
320
|
+
| `children` | `ReactNode` | - | The Button or ButtonToggle components to group. |
|