@czi-sds/mcp 0.2.2 → 0.3.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/data/zeroheight-cache.json +5195 -0
- package/data/zeroheight-exports/Accordion.md +675 -0
- package/data/zeroheight-exports/Banner.md +576 -0
- package/data/zeroheight-exports/Borders.md +118 -0
- package/data/zeroheight-exports/Buttons.md +2260 -0
- package/data/zeroheight-exports/Callout.md +756 -0
- package/data/zeroheight-exports/Colors.md +633 -0
- package/data/zeroheight-exports/Content-Card.md +162 -0
- package/data/zeroheight-exports/Contributing-to-SDS.md +99 -0
- package/data/zeroheight-exports/Control-Inputs.md +2066 -0
- package/data/zeroheight-exports/Corners.md +112 -0
- package/data/zeroheight-exports/Cover-page.md +4 -0
- package/data/zeroheight-exports/Dialog.md +1133 -0
- package/data/zeroheight-exports/Downloads.md +121 -0
- package/data/zeroheight-exports/Drop-Shadows.md +80 -0
- package/data/zeroheight-exports/Dropdown-Input.md +1149 -0
- package/data/zeroheight-exports/Dropdown-Menu.md +3787 -0
- package/data/zeroheight-exports/Element-Status-Tracker.md +268 -0
- package/data/zeroheight-exports/Field-Inputs.md +965 -0
- package/data/zeroheight-exports/Filters.md +868 -0
- package/data/zeroheight-exports/Getting-Started.md +1296 -0
- package/data/zeroheight-exports/Hero.md +256 -0
- package/data/zeroheight-exports/Icons.md +432 -0
- package/data/zeroheight-exports/Intent.md +47 -0
- package/data/zeroheight-exports/Introduction-to-Bases.md +36 -0
- package/data/zeroheight-exports/Introduction-to-Cells.md +36 -0
- package/data/zeroheight-exports/Introduction-to-DNA.md +36 -0
- package/data/zeroheight-exports/Introduction-to-Genes.md +36 -0
- package/data/zeroheight-exports/Introduction.md +116 -0
- package/data/zeroheight-exports/Link.md +373 -0
- package/data/zeroheight-exports/Lists.md +617 -0
- package/data/zeroheight-exports/Loading-Indicator.md +38 -0
- package/data/zeroheight-exports/Navigation.md +853 -0
- package/data/zeroheight-exports/Notification.md +858 -0
- package/data/zeroheight-exports/Panel.md +862 -0
- package/data/zeroheight-exports/README.md +124 -0
- package/data/zeroheight-exports/Responsive-Design.md +275 -0
- package/data/zeroheight-exports/Search-Input.md +54 -0
- package/data/zeroheight-exports/Search.md +609 -0
- package/data/zeroheight-exports/Segmented-Control.md +561 -0
- package/data/zeroheight-exports/Spacing.md +298 -0
- package/data/zeroheight-exports/Table.md +4832 -0
- package/data/zeroheight-exports/Tabs.md +773 -0
- package/data/zeroheight-exports/Tags.md +1025 -0
- package/data/zeroheight-exports/Text-Link.md +185 -0
- package/data/zeroheight-exports/Theming.md +313 -0
- package/data/zeroheight-exports/Tooltips.md +1564 -0
- package/data/zeroheight-exports/Typography.md +769 -0
- package/dist/stdio.js +188 -0
- package/package.json +4 -3
|
@@ -0,0 +1,1149 @@
|
|
|
1
|
+
# Dropdown Input
|
|
2
|
+
|
|
3
|
+
The Dropdown Input is an element that triggers Dropdown Menus to open, enabling users to make selections and communicate choices in the UI.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
| | In Figma | | | Meets Accessibility | | | In napari hub + .org Codebases |
|
|
8
|
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
|
9
|
+
|
|
10
|
+
Dropdown Inputs are always accompanied by a Dropdown Menu which is triggered by the user clicking on the input.
|
|
11
|
+
|
|
12
|
+
The Dropdown Input is used on napari hub as part of plugin Filters, enabling users to find plugins relevant to their work more easily.
|
|
13
|
+
|
|
14
|
+
Click on each state below to enter inspect view and get details on its code attributes and any global styles it uses.
|
|
15
|
+
|
|
16
|
+
| **Default** | **Hover** | **Open** | **Disabled** |
|
|
17
|
+
| --- | --- | --- | --- |
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### Dropdown Input Spacing
|
|
22
|
+
|
|
23
|
+
These rules establish how much margin should exist between and around elements.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Code
|
|
30
|
+
|
|
31
|
+
## Dropdown Input Component
|
|
32
|
+
|
|
33
|
+
| Below you will find an interactive Storybook iframe for Dropdown Inputs. Tabs within each iframe provide a different set of tools: The Controls tab allows you to see and adjust all available props. The Actions tab shows you data displayed by event handler arguments. | | **Jump to component:** InputDropdown |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
>This component appears as it is in the default SDS codebase. Once imported into the napari hub or napari.org codebases, use a theme file to enable the napari visual appearance customization.
|
|
39
|
+
|
|
40
|
+
### InputDropdown
|
|
41
|
+
|
|
42
|
+
Storybook
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
Dropdown Inputs are elements that trigger Dropdown Menus to open, enabling users to make selections and communicate choices in the UI.
|
|
49
|
+
|
|
50
|
+
## Overview
|
|
51
|
+
|
|
52
|
+
## Dropdown Input Variants
|
|
53
|
+
|
|
54
|
+
| There are three Dropdown Input variants available for designers to use depending on the placement location within the UI. Dropdown Inputs are always accompanied by a Dropdown Menu which is triggered by the user clicking on the input. Follow the usage criteria accompanying each variant as a guide for selecting the correct Dropdown Input for any given use case. | | **Jump to variant:** Rounded Square Minimal |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
|
|
57
|
+
### Visual Preview
|
|
58
|
+
|
|
59
|
+
Use the links below to jump to information on a specific Dropdown Input variant:
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Rounded Dropdown Input
|
|
64
|
+
|
|
65
|
+
| | In Figma | | | Meets Accessibility | | | In CZ ID Codebase |
|
|
66
|
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
|
67
|
+
|
|
68
|
+
### Single-select Rounded Dropdown Input
|
|
69
|
+
|
|
70
|
+
Use when the user is only able to select one option from a group of choices within the triggered Dropdown Menu.
|
|
71
|
+
|
|
72
|
+
Used within CZ ID for filtering within Tables and datasets.
|
|
73
|
+
|
|
74
|
+
Using the `details` prop, optional text can be added to the Input to communicate additional information such as providing a sub-label or listing the user's selection.
|
|
75
|
+
|
|
76
|
+
Click on each state below to enter inspect view and get details on its code attributes and any global styles it uses.
|
|
77
|
+
|
|
78
|
+
| **Default** | **Hover** | **Default** | **Open** | **Disabled** |
|
|
79
|
+
| --- | --- | --- | --- | --- |
|
|
80
|
+
|
|
81
|
+
| **Default + Details** | **Hover** | **Default** | **Open** | **Disabled** |
|
|
82
|
+
| --- | --- | --- | --- | --- |
|
|
83
|
+
|
|
84
|
+
### Multi-select Rounded Dropdown Input
|
|
85
|
+
|
|
86
|
+
Use when the user is able to select more than one option from a group of choices within the triggered Dropdown Menu.
|
|
87
|
+
|
|
88
|
+
Used within CZ ID for filtering within Tables and datasets.
|
|
89
|
+
|
|
90
|
+
Using the `details` prop, an optional counter can be added to the Input to communicate how many selections the user has chosen within the triggered Dropdown Menu.
|
|
91
|
+
|
|
92
|
+
Click on each state below to enter inspect view and get details on its code attributes and any global styles it uses.
|
|
93
|
+
|
|
94
|
+
| **Default** | **Hover** | **Default** | **Open** | **Disabled** |
|
|
95
|
+
| --- | --- | --- | --- | --- |
|
|
96
|
+
|
|
97
|
+
| **Default + Details** | **Hover** | **Default** | **Open** | **Disabled** |
|
|
98
|
+
| --- | --- | --- | --- | --- |
|
|
99
|
+
|
|
100
|
+
### Rounded Dropdown Input Intent States
|
|
101
|
+
|
|
102
|
+
The `intent` prop is used to communicate the state of the user's response from the accompanying Dropdown Menu.
|
|
103
|
+
|
|
104
|
+
Use `intent: default` to communicate when a user has entered an accepted or complete response.
|
|
105
|
+
|
|
106
|
+
Use `intent: error` to communicate when a user has entered an incorrect or incomplete response.
|
|
107
|
+
|
|
108
|
+
Use `intent: warning` to communicate when a user needs to be alerted that their response needs attention.
|
|
109
|
+
|
|
110
|
+
Each intent is demonstrated below using the Single-select Dropdown Input for reference; all variants follow the same pattern:
|
|
111
|
+
|
|
112
|
+
| **Default** | **Error** | **Warning** |
|
|
113
|
+
| --- | --- | --- |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### Rounded Dropdown Input Spacing
|
|
118
|
+
|
|
119
|
+
These rules establish how much margin should exist between and around elements.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Square Dropdown Input
|
|
124
|
+
|
|
125
|
+
| | In Figma | | | Meets Accessibility | | | In CZ ID Codebase |
|
|
126
|
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
|
127
|
+
|
|
128
|
+
### Single-select Square Dropdown Input
|
|
129
|
+
|
|
130
|
+
Use when the user is only able to select one option from a group of choices within the triggered Dropdown Menu.
|
|
131
|
+
|
|
132
|
+
Used within CZ ID on forms and Dialogs that contain menu options for users.
|
|
133
|
+
|
|
134
|
+
Using the `details` prop, optional text can be added to the Input to communicate additional information such as providing a sub-label or listing the user's selection.
|
|
135
|
+
|
|
136
|
+
Note: `singleSelect` is the only `sdsType` prop value available for Square Dropdown Input.
|
|
137
|
+
|
|
138
|
+
Click on each state below to enter inspect view and get details on its code attributes and any global styles it uses.
|
|
139
|
+
|
|
140
|
+
| **Default** | **Hover** | **Default** | **Open** | **Disabled** |
|
|
141
|
+
| --- | --- | --- | --- | --- |
|
|
142
|
+
|
|
143
|
+
| **Default + Details** | **Hover** | **Default** | **Open** | **Disabled** |
|
|
144
|
+
| --- | --- | --- | --- | --- |
|
|
145
|
+
|
|
146
|
+
### Square Dropdown Input Intent States
|
|
147
|
+
|
|
148
|
+
The `intent` prop is used to communicate the state of the user's response from the accompanying Dropdown Menu.
|
|
149
|
+
|
|
150
|
+
Use `intent: default` to communicate when a user has entered an accepted or complete response.
|
|
151
|
+
|
|
152
|
+
Use `intent: error` to communicate when a user has entered an incorrect or incomplete response.
|
|
153
|
+
|
|
154
|
+
Use `intent: warning` to communicate when a user needs to be alerted that their response needs attention.
|
|
155
|
+
|
|
156
|
+
Each intent is demonstrated below using the Single-select Dropdown Input for reference; all variants follow the same pattern:
|
|
157
|
+
|
|
158
|
+
| **Default** | **Error** | **Warning** |
|
|
159
|
+
| --- | --- | --- |
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
### Square Dropdown Input Spacing
|
|
164
|
+
|
|
165
|
+
These rules establish how much margin should exist between and around elements.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Minimal Dropdown Input
|
|
170
|
+
|
|
171
|
+
| | In Figma | | | Meets Accessibility | | | In CZ ID Codebase |
|
|
172
|
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
|
173
|
+
|
|
174
|
+
Use when the user is only able to select one option from a group of choices within the triggered Dropdown Menu.
|
|
175
|
+
|
|
176
|
+
The Minimal Dropdown Input is typically reserved for use in Filters (documentation coming soon).
|
|
177
|
+
|
|
178
|
+
Note: `singleSelect` is the only `sdsType` prop value available for Minimal Dropdown Input.
|
|
179
|
+
|
|
180
|
+
Click on each state below to enter inspect view and get details on its code attributes and any global styles it uses.
|
|
181
|
+
|
|
182
|
+
| **Default** | **Hover** | **Default** | **Open** | **Disabled** |
|
|
183
|
+
| --- | --- | --- | --- | --- |
|
|
184
|
+
|
|
185
|
+
### Minimal Dropdown Input Intent States
|
|
186
|
+
|
|
187
|
+
The `intent` prop is used to communicate the state of the user's response from the accompanying Dropdown Menu.
|
|
188
|
+
|
|
189
|
+
Use `intent: default` to communicate when a user has entered an accepted or complete response.
|
|
190
|
+
|
|
191
|
+
| **Default** | | |
|
|
192
|
+
| --- | --- | --- |
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### Minimal Dropdown Input Spacing
|
|
197
|
+
|
|
198
|
+
These rules establish how much margin should exist between and around elements.
|
|
199
|
+
|
|
200
|
+
## Code
|
|
201
|
+
|
|
202
|
+
## Dropdown Input Component
|
|
203
|
+
|
|
204
|
+
| Below you will find an interactive Storybook iframe for Dropdown Inputs. Tabs within each iframe provide a different set of tools: The Controls tab allows you to see and adjust all available props. The Actions tab shows you data displayed by event handler arguments. | | **Jump to component:** InputDropdown |
|
|
205
|
+
| --- | --- | --- |
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### InputDropdown
|
|
210
|
+
|
|
211
|
+
Storybook
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
Dropdown Inputs are elements that trigger Dropdown Menus to open, enabling users to make selections and communicate choices in the UI.
|
|
216
|
+
|
|
217
|
+
## Guidelines
|
|
218
|
+
|
|
219
|
+
## Dropdown Input Component
|
|
220
|
+
|
|
221
|
+
| | In Figma | | | Meets Accessibility | | | In Code |
|
|
222
|
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
|
223
|
+
|
|
224
|
+
### Dropdown Input Types
|
|
225
|
+
|
|
226
|
+
There are two Dropdown Input types designers can use depending on whether their design calls for the input field's label to be inside the input itself (Label variant) or if an external label will be used with an accompanying Dropdown Input (Value variant).
|
|
227
|
+
|
|
228
|
+
On click, Dropdown Inputs always trigger a Dropdown Menu to open.
|
|
229
|
+
|
|
230
|
+
>**Note:** The external field label shown as part of the Value variant visual below is for demonstration purposes only and is not built into the component itself; a separate label must be added to achieve this in product.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
### Live Instance
|
|
235
|
+
|
|
236
|
+
Interact with the live instance below and adjust the available props to better conceptualize how it will appear in product:
|
|
237
|
+
|
|
238
|
+
Default
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
### Dropdown Input – Label
|
|
243
|
+
|
|
244
|
+
The Label variant functions as both the field label **and** the input field itself from which users make their selections. Before a selection is made, only the field label is displayed inside the input; after the user makes a selection, the selected value appears alongside the label inside the input field.
|
|
245
|
+
|
|
246
|
+
In instances where users can select more than one value, a counter showing the number of selections made is shown beside the label (this feature is limited to the rounded and square variants only). In cases where the designer does not want the value to appear in the input field after a selection is made (such as when using in combination with Filter Tags), this feature can be disabled.
|
|
247
|
+
|
|
248
|
+
Optionally, Intent Messages can be displayed to further communicate why a Negative or Notice intent was triggered.
|
|
249
|
+
|
|
250
|
+
#### Rounded
|
|
251
|
+
|
|
252
|
+
| Default | Hover | Open | Disabled |
|
|
253
|
+
| :---: | :---: | :---: | :---: |
|
|
254
|
+
|
|
255
|
+
*Intent Variations*
|
|
256
|
+
|
|
257
|
+
Use Negative to communicate when a user has entered an incorrect or incomplete response and Notice when a user's response needs attention. Optionally, Intent Messages can be displayed to further communicate why a Negative or Notice intent was triggered. For more information see Intents.
|
|
258
|
+
|
|
259
|
+
| Negative | Negative + Intent Message | Notice | Notice + Intent Message |
|
|
260
|
+
| :---: | --- | :---: | --- |
|
|
261
|
+
|
|
262
|
+
#### Square
|
|
263
|
+
|
|
264
|
+
| Default | Hover | Open | Disabled |
|
|
265
|
+
| :---: | :---: | :---: | :---: |
|
|
266
|
+
|
|
267
|
+
*Intent Variations*
|
|
268
|
+
|
|
269
|
+
Use Negative to communicate when a user has entered an incorrect or incomplete response and Notice when a user's response needs attention. Optionally, Intent Messages can be displayed to further communicate why a Negative or Notice intent was triggered. For more information see Intents.
|
|
270
|
+
|
|
271
|
+
| Negative | Negative + Intent Message | Notice | Notice + Intent Message |
|
|
272
|
+
| :---: | --- | :---: | --- |
|
|
273
|
+
|
|
274
|
+
#### Minimal
|
|
275
|
+
|
|
276
|
+
| Default | Hover | Open | Disabled |
|
|
277
|
+
| :---: | :---: | :---: | :---: |
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
### Dropdown Input – Value
|
|
282
|
+
|
|
283
|
+
Use the Value variant when designs call for the input label to be a separate (external) HTML element from the input itself. Before a selection is made, the input should display a prompt instructing users to make a selection; after the user makes a selection, the selected value replaces the prompt in the input field.
|
|
284
|
+
|
|
285
|
+
Additionally, detail text can be included with each value to communicate additional information to the user such as providing a sub-label or clarifying information.
|
|
286
|
+
|
|
287
|
+
Optionally, Intent Messages can be displayed to further communicate why a Negative or Notice intent was triggered.
|
|
288
|
+
|
|
289
|
+
#### **Rounded**
|
|
290
|
+
|
|
291
|
+
| Default | Hover | Open | Disabled |
|
|
292
|
+
| :---: | :---: | :---: | :---: |
|
|
293
|
+
|
|
294
|
+
*Intent Variations*
|
|
295
|
+
|
|
296
|
+
Use Negative to communicate when a user has entered an incorrect or incomplete response and Notice when a user's response needs attention. Optionally, Intent Messages can be displayed to further communicate why a Negative or Notice intent was triggered. For more information see Intents.
|
|
297
|
+
|
|
298
|
+
| Negative | Negative + Intent Message | Notice | Notice + Intent Message |
|
|
299
|
+
| :---: | --- | :---: | --- |
|
|
300
|
+
|
|
301
|
+
#### **Square**
|
|
302
|
+
|
|
303
|
+
| Default | Hover | Open | Disabled |
|
|
304
|
+
| :---: | :---: | :---: | :---: |
|
|
305
|
+
|
|
306
|
+
*Intent Variations*
|
|
307
|
+
|
|
308
|
+
Use Negative to communicate when a user has entered an incorrect or incomplete response and Notice when a user's response needs attention. Optionally, Intent Messages can be displayed to further communicate why a Negative or Notice intent was triggered. For more information see Intents.
|
|
309
|
+
|
|
310
|
+
| Negative | Negative + Intent Message | Notice | Notice + Intent Message |
|
|
311
|
+
| :---: | --- | :---: | --- |
|
|
312
|
+
|
|
313
|
+
#### **Minimal**
|
|
314
|
+
|
|
315
|
+
| Default | Hover | Open | Disabled |
|
|
316
|
+
| :---: | :---: | :---: | :---: |
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
### Dropdown Input Spacing
|
|
321
|
+
|
|
322
|
+
These rules establish how much margin should exist between and around elements.
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
## Code
|
|
327
|
+
|
|
328
|
+
>**Note:** The code examples below must install dependencies before displaying and may take extra time to load
|
|
329
|
+
|
|
330
|
+
## InputDropdown
|
|
331
|
+
|
|
332
|
+
### SDS Source Code
|
|
333
|
+
|
|
334
|
+
The component's source code in the SDS codebase can be found here.
|
|
335
|
+
|
|
336
|
+
### SDS vs MUI
|
|
337
|
+
|
|
338
|
+
The SDS's `InputDropdown` component utilizes MUI's `Button` component as its foundation but introduces some SDS-specific enhancements. Below, the key distinctions between the SDS's `InputDropdown` and MUI's `Button` are outlined:
|
|
339
|
+
|
|
340
|
+
* **Variation**: MUI's `Button` offers a `variant` prop to define different visual styles for buttons. SDS's `InputDropdown`, however, uses the `sdsStyle` prop instead, providing the ability to select between three variants: `square`, `rounded`, or `minimal`.
|
|
341
|
+
* **Color**: In MUI's `Button`, the button's color can be modified using the `color` prop. SDS's `InputDropdown` deviates from this and introduces the `intent` prop. This prop provides the ability to choose between `default`, `warning`, and `error` colors, depending on the state of the `InputDropdown`.
|
|
342
|
+
* **Size**: While MUI's `Button` provides a `size` prop for adjusting the button's size, SDS's `InputDropdown` does not offer this capability. The size of the `InputDropdown` component remains fixed and cannot be altered through props.
|
|
343
|
+
* **Icon**: Unlike MUI's `Button`, which supports custom icons, SDS's `InputDropdown` does not accept external icon components. Instead, SDS's `InputDropdown` incorporates a built-in Chevron icon, which is an integral part of the component and cannot be replaced.
|
|
344
|
+
|
|
345
|
+
### MUI Documentation
|
|
346
|
+
|
|
347
|
+
Documentation for the underlying MUI component can be found here.
|
|
348
|
+
|
|
349
|
+
### Props
|
|
350
|
+
|
|
351
|
+
Any custom SDS props and MUI props required for implementation are found on the table below. See the MUI documentation for additional optional props.
|
|
352
|
+
|
|
353
|
+
| Name | Type | Default | Description |
|
|
354
|
+
| --- | --- | --- | --- |
|
|
355
|
+
| `counter` | `ReactNode` | `-` | If multiple set to `true`, this number shows the number of selected menu items. |
|
|
356
|
+
| `details` | `ReactNode` | `-` | A text showing details for the selected menu item. |
|
|
357
|
+
| `disabled` | `bool` | `false` | If `true`, the component is disabled. |
|
|
358
|
+
| `intent` | `"default"` `| "negative"` `| "notice"` `| "positive"` | `default` | The color of the component. |
|
|
359
|
+
| `label` | `ReactNode` | `-` | The label of the Input Button. |
|
|
360
|
+
| `multiple` | `bool` | `false` | Allows users to select multiple menu items.`multiple=true` cannot be used with the `minimum` variant. |
|
|
361
|
+
| `onClick` | `func` | `(event: React.MouseEvent<HTMLElement>) => void` | Sets what happens when a user clicks on the component. |
|
|
362
|
+
| `sdsStyle` | `"minimal"` `| "square"` `| "rounded"` | `square` | The visual appearance of the component. |
|
|
363
|
+
| `sdsType` | `"label"` `| "value"` | `label` | The `label` variant includes the label within the input field and showcases the selected menu item as additional details or sets the counter when in multi-select mode. The `value` variant replaces the label with the selected value directly within the input field. The detailed information is then displayed in a separate section dedicated to displaying additional details. However, it's important to note that the value variant cannot be used in conjunction with multi-select mode. |
|
|
364
|
+
| `shouldPutAColonAfterLabel` | `bool` | `true` | If `true`, a colon (:) will be added after the label or value. |
|
|
365
|
+
| `shouldTruncateMinimalDetails` | `bool` | `false` | If `true`, the details section of the minimal variant displays a truncated one-liner with an ellipsis (...), if `false` the details section expands to multiple lines for a comprehensive display. |
|
|
366
|
+
| `value` | `ReactNode` | `-` | The value that will be displayed in the component for the `value` variant. |
|
|
367
|
+
|
|
368
|
+
There are more props that can be used with the `InputDropdown` component, via those available to MUI's `Button` component.
|
|
369
|
+
|
|
370
|
+
### Code Examples
|
|
371
|
+
|
|
372
|
+
#### Default InputDropdown
|
|
373
|
+
|
|
374
|
+
This example has the minimum props needed for the `InputDropdown` component.
|
|
375
|
+
|
|
376
|
+
**/styles.css**
|
|
377
|
+
|
|
378
|
+
```css
|
|
379
|
+
body {
|
|
380
|
+
font-size: 13px;
|
|
381
|
+
font-weight: 400;
|
|
382
|
+
letter-spacing: 0.08px;
|
|
383
|
+
line-height: 20px;
|
|
384
|
+
text-transform: none;
|
|
385
|
+
font-family: "Inter", sans-serif;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
h1 {
|
|
389
|
+
font-size: 1.5rem;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.app {
|
|
393
|
+
padding: 20px;
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
**tsconfig.json**
|
|
398
|
+
|
|
399
|
+
```json
|
|
400
|
+
{
|
|
401
|
+
"include": [
|
|
402
|
+
"./**/*"
|
|
403
|
+
],
|
|
404
|
+
"compilerOptions": {
|
|
405
|
+
"strict": true,
|
|
406
|
+
"esModuleInterop": true,
|
|
407
|
+
"lib": [ "dom", "es2015" ],
|
|
408
|
+
"jsx": "react-jsx"
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
**/App.tsx**
|
|
414
|
+
|
|
415
|
+
```tsx
|
|
416
|
+
// Most minimal InputDropdown (just has the basic requirements)
|
|
417
|
+
|
|
418
|
+
import React, { SyntheticEvent, useState, useRef, useEffect } from "react";
|
|
419
|
+
import { InputDropdown } from "@czi-sds/components";
|
|
420
|
+
import "./styles.css";
|
|
421
|
+
|
|
422
|
+
function App() {
|
|
423
|
+
return (
|
|
424
|
+
<div className="app">
|
|
425
|
+
<InputDropdown label="Label"/>
|
|
426
|
+
</div>
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export default App;
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
**/index.tsx**
|
|
434
|
+
|
|
435
|
+
```tsx
|
|
436
|
+
import React from "react";
|
|
437
|
+
import { createRoot } from "react-dom/client";
|
|
438
|
+
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
|
|
439
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
|
|
440
|
+
import { Theme } from "@czi-sds/components";
|
|
441
|
+
import CssBaseline from "@mui/material/CssBaseline";
|
|
442
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
443
|
+
|
|
444
|
+
import App from "./App";
|
|
445
|
+
|
|
446
|
+
const container = document.getElementById("root");
|
|
447
|
+
const root = createRoot(container!);
|
|
448
|
+
|
|
449
|
+
const RootApp = () => {
|
|
450
|
+
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
|
451
|
+
const theme = prefersDarkMode ? Theme("dark") : Theme("light");
|
|
452
|
+
|
|
453
|
+
return (
|
|
454
|
+
<StyledEngineProvider injectFirst>
|
|
455
|
+
<ThemeProvider theme={theme}>
|
|
456
|
+
<EmotionThemeProvider theme={theme}>
|
|
457
|
+
<CssBaseline />
|
|
458
|
+
<App />
|
|
459
|
+
</EmotionThemeProvider>
|
|
460
|
+
</ThemeProvider>
|
|
461
|
+
</StyledEngineProvider>
|
|
462
|
+
);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
root.render(
|
|
466
|
+
<React.StrictMode>
|
|
467
|
+
<RootApp />
|
|
468
|
+
</React.StrictMode>
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
**/public/index.html**
|
|
474
|
+
|
|
475
|
+
```html
|
|
476
|
+
<!DOCTYPE html>
|
|
477
|
+
<html lang="en">
|
|
478
|
+
<head>
|
|
479
|
+
<meta charset="UTF-8" />
|
|
480
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
481
|
+
<title>Dropdown Inputs</title>
|
|
482
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
483
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
484
|
+
<link
|
|
485
|
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
|
|
486
|
+
rel="stylesheet"
|
|
487
|
+
/>
|
|
488
|
+
<link
|
|
489
|
+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&display=swap"
|
|
490
|
+
rel="stylesheet"
|
|
491
|
+
/>
|
|
492
|
+
</head>
|
|
493
|
+
<body>
|
|
494
|
+
<div id="root"></div>
|
|
495
|
+
</body>
|
|
496
|
+
</html>
|
|
497
|
+
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
**/package.json**
|
|
501
|
+
|
|
502
|
+
```json
|
|
503
|
+
{"dependencies":{"react":"^18.0.0","react-dom":"^18.0.0","react-scripts":"^4.0.0"},"devDependencies":{"@types/react":"^18.0.0","@types/react-dom":"^18.0.0","typescript":"^4.0.0"},"main":"/index.tsx"}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
>**MUI Tip:** To ensure the InputDropdown button expands to fit the width of its container, users can utilize the `fullWidth` prop provided by MUI. When set to `true`, the `fullWidth` prop enables the InputDropdown button to occupy the entire available width within its parent container.
|
|
509
|
+
|
|
510
|
+
#### InputDropdown combined with a multi-select Dropdown
|
|
511
|
+
|
|
512
|
+
Below is an example demonstrating the combined utilization of the `InputDropdown` component and a multi-select `Dropdown` component. The `Dropdown` allows multiple selections, while the `InputDropdown` features a `square` variant.
|
|
513
|
+
|
|
514
|
+
**/styles.css**
|
|
515
|
+
|
|
516
|
+
```css
|
|
517
|
+
body {
|
|
518
|
+
font-size: 13px;
|
|
519
|
+
font-weight: 400;
|
|
520
|
+
letter-spacing: 0.08px;
|
|
521
|
+
line-height: 20px;
|
|
522
|
+
text-transform: none;
|
|
523
|
+
font-family: "Inter", sans-serif;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
h1 {
|
|
527
|
+
font-size: 1.5rem;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.app {
|
|
531
|
+
padding: 20px;
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**tsconfig.json**
|
|
536
|
+
|
|
537
|
+
```json
|
|
538
|
+
{
|
|
539
|
+
"include": [
|
|
540
|
+
"./**/*"
|
|
541
|
+
],
|
|
542
|
+
"compilerOptions": {
|
|
543
|
+
"strict": true,
|
|
544
|
+
"esModuleInterop": true,
|
|
545
|
+
"lib": [ "dom", "es2015" ],
|
|
546
|
+
"jsx": "react-jsx"
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
**/App.tsx**
|
|
552
|
+
|
|
553
|
+
```tsx
|
|
554
|
+
import React, { SyntheticEvent, useState, useRef, useEffect } from "react";
|
|
555
|
+
import { InputDropdown, DropdownMenu, noop } from "@czi-sds/components";
|
|
556
|
+
import "./styles.css";
|
|
557
|
+
|
|
558
|
+
const options = [
|
|
559
|
+
{
|
|
560
|
+
details: "Details",
|
|
561
|
+
name: "Menu Item 1",
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
details: "A very long Details for the second Menu Item",
|
|
565
|
+
name: "Menu Item 2",
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: "Menu Item 3",
|
|
569
|
+
},
|
|
570
|
+
];
|
|
571
|
+
|
|
572
|
+
function App() {
|
|
573
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
|
574
|
+
const [open, setOpen] = useState(false);
|
|
575
|
+
const [details, setDetials] = useState<string>();
|
|
576
|
+
const [counter, setCounter] = useState<string>();
|
|
577
|
+
const [inputDropdownValue, setInputDropdownValue] = useState<string>();
|
|
578
|
+
const [value, setValue] = useState<
|
|
579
|
+
DefaultDropdownMenuOption | DefaultDropdownMenuOption[] | null
|
|
580
|
+
>([]);
|
|
581
|
+
const [pendingValue, setPendingValue] = useState<
|
|
582
|
+
DefaultDropdownMenuOption | DefaultDropdownMenuOption[] | null
|
|
583
|
+
>([]);
|
|
584
|
+
|
|
585
|
+
return (
|
|
586
|
+
<div className="app">
|
|
587
|
+
<InputDropdown
|
|
588
|
+
label="Label"
|
|
589
|
+
onClick={handleClick}
|
|
590
|
+
sdsStyle="square"
|
|
591
|
+
multiple
|
|
592
|
+
value={inputDropdownValue}
|
|
593
|
+
counter={counter}
|
|
594
|
+
/>
|
|
595
|
+
<DropdownMenu
|
|
596
|
+
open={open}
|
|
597
|
+
anchorEl={anchorEl}
|
|
598
|
+
onClose={noop}
|
|
599
|
+
onChange={handleChange}
|
|
600
|
+
search={false}
|
|
601
|
+
multiple
|
|
602
|
+
disableCloseOnSelect
|
|
603
|
+
options={options}
|
|
604
|
+
value={pendingValue}
|
|
605
|
+
onClickAway={handleClickAway}
|
|
606
|
+
/>
|
|
607
|
+
</div>
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
function handleClick(event: React.MouseEvent<HTMLElement>) {
|
|
611
|
+
if (open) {
|
|
612
|
+
setOpen(false);
|
|
613
|
+
|
|
614
|
+
if (anchorEl) {
|
|
615
|
+
anchorEl.focus();
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
setAnchorEl(null);
|
|
619
|
+
} else {
|
|
620
|
+
setAnchorEl(event.currentTarget);
|
|
621
|
+
setOpen(true);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
function handleChange(
|
|
626
|
+
_: React.SyntheticEvent<Element, Event>,
|
|
627
|
+
newValue: DefaultDropdownMenuOption | DefaultDropdownMenuOption[] | null
|
|
628
|
+
){
|
|
629
|
+
setPendingValue(newValue);
|
|
630
|
+
setCounter((newValue as DefaultDropdownMenuOption[])?.length.toString());
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
function handleClickAway(){
|
|
634
|
+
if (open) {
|
|
635
|
+
setOpen(false);
|
|
636
|
+
}
|
|
637
|
+
setValue(pendingValue);
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export default App;
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
**/index.tsx**
|
|
645
|
+
|
|
646
|
+
```tsx
|
|
647
|
+
import React from "react";
|
|
648
|
+
import { createRoot } from "react-dom/client";
|
|
649
|
+
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
|
|
650
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
|
|
651
|
+
import { Theme } from "@czi-sds/components";
|
|
652
|
+
import CssBaseline from "@mui/material/CssBaseline";
|
|
653
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
654
|
+
|
|
655
|
+
import App from "./App";
|
|
656
|
+
|
|
657
|
+
const container = document.getElementById("root");
|
|
658
|
+
const root = createRoot(container!);
|
|
659
|
+
|
|
660
|
+
const RootApp = () => {
|
|
661
|
+
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
|
662
|
+
const theme = prefersDarkMode ? Theme("dark") : Theme("light");
|
|
663
|
+
|
|
664
|
+
return (
|
|
665
|
+
<StyledEngineProvider injectFirst>
|
|
666
|
+
<ThemeProvider theme={theme}>
|
|
667
|
+
<EmotionThemeProvider theme={theme}>
|
|
668
|
+
<CssBaseline />
|
|
669
|
+
<App />
|
|
670
|
+
</EmotionThemeProvider>
|
|
671
|
+
</ThemeProvider>
|
|
672
|
+
</StyledEngineProvider>
|
|
673
|
+
);
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
root.render(
|
|
677
|
+
<React.StrictMode>
|
|
678
|
+
<RootApp />
|
|
679
|
+
</React.StrictMode>
|
|
680
|
+
);
|
|
681
|
+
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
**/public/index.html**
|
|
685
|
+
|
|
686
|
+
```html
|
|
687
|
+
<!DOCTYPE html>
|
|
688
|
+
<html lang="en">
|
|
689
|
+
<head>
|
|
690
|
+
<meta charset="UTF-8" />
|
|
691
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
692
|
+
<title>Dropdown Inputs</title>
|
|
693
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
694
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
695
|
+
<link
|
|
696
|
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
|
|
697
|
+
rel="stylesheet"
|
|
698
|
+
/>
|
|
699
|
+
<link
|
|
700
|
+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&display=swap"
|
|
701
|
+
rel="stylesheet"
|
|
702
|
+
/>
|
|
703
|
+
</head>
|
|
704
|
+
<body>
|
|
705
|
+
<div id="root"></div>
|
|
706
|
+
</body>
|
|
707
|
+
</html>
|
|
708
|
+
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
**/package.json**
|
|
712
|
+
|
|
713
|
+
```json
|
|
714
|
+
{"dependencies":{"react":"^18.0.0","react-dom":"^18.0.0","react-scripts":"^4.0.0"},"devDependencies":{"@types/react":"^18.0.0","@types/react-dom":"^18.0.0","typescript":"^4.0.0"},"main":"/index.tsx"}
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
---
|
|
718
|
+
|
|
719
|
+
#### Rounded InputDropdown combined with a single select Dropdown
|
|
720
|
+
|
|
721
|
+
Below is an example demonstrating the combined utilization of the default `label` variant `InputDropdown` component and a single-select `Dropdown` component.
|
|
722
|
+
|
|
723
|
+
**/styles.css**
|
|
724
|
+
|
|
725
|
+
```css
|
|
726
|
+
body {
|
|
727
|
+
font-size: 13px;
|
|
728
|
+
font-weight: 400;
|
|
729
|
+
letter-spacing: 0.08px;
|
|
730
|
+
line-height: 20px;
|
|
731
|
+
text-transform: none;
|
|
732
|
+
font-family: "Inter", sans-serif;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
h1 {
|
|
736
|
+
font-size: 1.5rem;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
.app {
|
|
740
|
+
padding: 20px;
|
|
741
|
+
}
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
**tsconfig.json**
|
|
745
|
+
|
|
746
|
+
```json
|
|
747
|
+
{
|
|
748
|
+
"include": [
|
|
749
|
+
"./**/*"
|
|
750
|
+
],
|
|
751
|
+
"compilerOptions": {
|
|
752
|
+
"strict": true,
|
|
753
|
+
"esModuleInterop": true,
|
|
754
|
+
"lib": [ "dom", "es2015" ],
|
|
755
|
+
"jsx": "react-jsx"
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
**/App.tsx**
|
|
761
|
+
|
|
762
|
+
```tsx
|
|
763
|
+
import React, { SyntheticEvent, useState, useRef, useEffect } from "react";
|
|
764
|
+
import { InputDropdown, DropdownMenu, noop } from "@czi-sds/components";
|
|
765
|
+
import "./styles.css";
|
|
766
|
+
|
|
767
|
+
const options = [
|
|
768
|
+
{
|
|
769
|
+
details: "Details",
|
|
770
|
+
name: "Menu Item 1",
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
details: "A very long Details for the second Menu Item",
|
|
774
|
+
name: "Menu Item 2",
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
name: "Menu Item 3",
|
|
778
|
+
},
|
|
779
|
+
];
|
|
780
|
+
|
|
781
|
+
function App() {
|
|
782
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
|
783
|
+
const [open, setOpen] = useState(false);
|
|
784
|
+
const [details, setDetials] = useState<string>();
|
|
785
|
+
const [inputDropdownValue, setInputDropdownValue] = useState<string>();
|
|
786
|
+
const [value, setValue] = useState<
|
|
787
|
+
DefaultDropdownMenuOption | DefaultDropdownMenuOption[] | null
|
|
788
|
+
>(null);
|
|
789
|
+
|
|
790
|
+
return (
|
|
791
|
+
<div className="app">
|
|
792
|
+
<InputDropdown
|
|
793
|
+
label="Label"
|
|
794
|
+
onClick={handleClick}
|
|
795
|
+
sdsStyle="rounded"
|
|
796
|
+
multiple={false}
|
|
797
|
+
value={inputDropdownValue}
|
|
798
|
+
/>
|
|
799
|
+
<DropdownMenu
|
|
800
|
+
open={open}
|
|
801
|
+
anchorEl={anchorEl}
|
|
802
|
+
onClose={noop}
|
|
803
|
+
onChange={handleChange}
|
|
804
|
+
search={false}
|
|
805
|
+
multiple={false}
|
|
806
|
+
disableCloseOnSelect
|
|
807
|
+
options={options}
|
|
808
|
+
value={value}
|
|
809
|
+
onClickAway={handleClickAway}
|
|
810
|
+
/>
|
|
811
|
+
</div>
|
|
812
|
+
);
|
|
813
|
+
|
|
814
|
+
function handleClick(event: React.MouseEvent<HTMLElement>) {
|
|
815
|
+
if (open) {
|
|
816
|
+
setOpen(false);
|
|
817
|
+
|
|
818
|
+
if (anchorEl) {
|
|
819
|
+
anchorEl.focus();
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
setAnchorEl(null);
|
|
823
|
+
} else {
|
|
824
|
+
setAnchorEl(event.currentTarget);
|
|
825
|
+
setOpen(true);
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
function handleChange(
|
|
830
|
+
_: React.SyntheticEvent<Element, Event>,
|
|
831
|
+
newValue: DefaultDropdownMenuOption | DefaultDropdownMenuOption[] | null
|
|
832
|
+
){
|
|
833
|
+
setOpen(false);
|
|
834
|
+
setValue(newValue);
|
|
835
|
+
|
|
836
|
+
if (newValue) {
|
|
837
|
+
setInputDropdownValue(newValue.name);
|
|
838
|
+
|
|
839
|
+
if (newValue?.details) setDetials(newValue?.details);
|
|
840
|
+
else setDetials(undefined);
|
|
841
|
+
} else {
|
|
842
|
+
setDetials(undefined);
|
|
843
|
+
setInputDropdownValue(undefined);
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
function handleClickAway(){
|
|
848
|
+
if (open) {
|
|
849
|
+
setOpen(false);
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
export default App;
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
**/index.tsx**
|
|
858
|
+
|
|
859
|
+
```tsx
|
|
860
|
+
import React from "react";
|
|
861
|
+
import { createRoot } from "react-dom/client";
|
|
862
|
+
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
|
|
863
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
|
|
864
|
+
import { Theme } from "@czi-sds/components";
|
|
865
|
+
import CssBaseline from "@mui/material/CssBaseline";
|
|
866
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
867
|
+
|
|
868
|
+
import App from "./App";
|
|
869
|
+
|
|
870
|
+
const container = document.getElementById("root");
|
|
871
|
+
const root = createRoot(container!);
|
|
872
|
+
|
|
873
|
+
const RootApp = () => {
|
|
874
|
+
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
|
875
|
+
const theme = prefersDarkMode ? Theme("dark") : Theme("light");
|
|
876
|
+
|
|
877
|
+
return (
|
|
878
|
+
<StyledEngineProvider injectFirst>
|
|
879
|
+
<ThemeProvider theme={theme}>
|
|
880
|
+
<EmotionThemeProvider theme={theme}>
|
|
881
|
+
<CssBaseline />
|
|
882
|
+
<App />
|
|
883
|
+
</EmotionThemeProvider>
|
|
884
|
+
</ThemeProvider>
|
|
885
|
+
</StyledEngineProvider>
|
|
886
|
+
);
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
root.render(
|
|
890
|
+
<React.StrictMode>
|
|
891
|
+
<RootApp />
|
|
892
|
+
</React.StrictMode>
|
|
893
|
+
);
|
|
894
|
+
|
|
895
|
+
```
|
|
896
|
+
|
|
897
|
+
**/public/index.html**
|
|
898
|
+
|
|
899
|
+
```html
|
|
900
|
+
<!DOCTYPE html>
|
|
901
|
+
<html lang="en">
|
|
902
|
+
<head>
|
|
903
|
+
<meta charset="UTF-8" />
|
|
904
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
905
|
+
<title>Dropdown Inputs</title>
|
|
906
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
907
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
908
|
+
<link
|
|
909
|
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
|
|
910
|
+
rel="stylesheet"
|
|
911
|
+
/>
|
|
912
|
+
<link
|
|
913
|
+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&display=swap"
|
|
914
|
+
rel="stylesheet"
|
|
915
|
+
/>
|
|
916
|
+
</head>
|
|
917
|
+
<body>
|
|
918
|
+
<div id="root"></div>
|
|
919
|
+
</body>
|
|
920
|
+
</html>
|
|
921
|
+
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
**/package.json**
|
|
925
|
+
|
|
926
|
+
```json
|
|
927
|
+
{"dependencies":{"react":"^18.0.0","react-dom":"^18.0.0","react-scripts":"^4.0.0"},"devDependencies":{"@types/react":"^18.0.0","@types/react-dom":"^18.0.0","typescript":"^4.0.0"},"main":"/index.tsx"}
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
---
|
|
931
|
+
|
|
932
|
+
#### Minimal InputDropdown combined with a single-select Dropdown
|
|
933
|
+
|
|
934
|
+
An example of the combined use of the value variation `InputDropdown` component and a single-select `Dropdown` component is shown below.
|
|
935
|
+
|
|
936
|
+
>**Warning:** The `value` variant can not be used in conjunction with the multi-select Dropdowns. If you set `sdsType="value"` and `multiple="true"`, the component will default to showing a label and a counter instead.
|
|
937
|
+
|
|
938
|
+
**/styles.css**
|
|
939
|
+
|
|
940
|
+
```css
|
|
941
|
+
body {
|
|
942
|
+
font-size: 13px;
|
|
943
|
+
font-weight: 400;
|
|
944
|
+
letter-spacing: 0.08px;
|
|
945
|
+
line-height: 20px;
|
|
946
|
+
text-transform: none;
|
|
947
|
+
font-family: "Inter", sans-serif;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
h1 {
|
|
951
|
+
font-size: 1.5rem;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
.app {
|
|
955
|
+
padding: 20px;
|
|
956
|
+
}
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
**tsconfig.json**
|
|
960
|
+
|
|
961
|
+
```json
|
|
962
|
+
{
|
|
963
|
+
"include": [
|
|
964
|
+
"./**/*"
|
|
965
|
+
],
|
|
966
|
+
"compilerOptions": {
|
|
967
|
+
"strict": true,
|
|
968
|
+
"esModuleInterop": true,
|
|
969
|
+
"lib": [ "dom", "es2015" ],
|
|
970
|
+
"jsx": "react-jsx"
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
**/App.tsx**
|
|
976
|
+
|
|
977
|
+
```tsx
|
|
978
|
+
import React, { SyntheticEvent, useState, useRef, useEffect } from "react";
|
|
979
|
+
import { InputDropdown, DropdownMenu, noop } from "@czi-sds/components";
|
|
980
|
+
import "./styles.css";
|
|
981
|
+
|
|
982
|
+
const options = [
|
|
983
|
+
{
|
|
984
|
+
details: "Details",
|
|
985
|
+
name: "Menu Item 1",
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
details: "A very long Details for the second Menu Item",
|
|
989
|
+
name: "Menu Item 2",
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
name: "Menu Item 3",
|
|
993
|
+
},
|
|
994
|
+
];
|
|
995
|
+
|
|
996
|
+
function App() {
|
|
997
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
|
998
|
+
const [open, setOpen] = useState(false);
|
|
999
|
+
const [details, setDetials] = useState<string>();
|
|
1000
|
+
const [inputDropdownValue, setInputDropdownValue] = useState<string>();
|
|
1001
|
+
const [value, setValue] = useState<
|
|
1002
|
+
DefaultDropdownMenuOption | DefaultDropdownMenuOption[] | null
|
|
1003
|
+
>(null);
|
|
1004
|
+
|
|
1005
|
+
return (
|
|
1006
|
+
<div className="app">
|
|
1007
|
+
<InputDropdown
|
|
1008
|
+
label="Label"
|
|
1009
|
+
onClick={handleClick}
|
|
1010
|
+
sdsType="value"
|
|
1011
|
+
sdsStyle="minimal"
|
|
1012
|
+
multiple={false}
|
|
1013
|
+
details={details}
|
|
1014
|
+
value={inputDropdownValue}
|
|
1015
|
+
style={{ maxWidth: 250 }}
|
|
1016
|
+
/>
|
|
1017
|
+
<DropdownMenu
|
|
1018
|
+
open={open}
|
|
1019
|
+
anchorEl={anchorEl}
|
|
1020
|
+
onClose={noop}
|
|
1021
|
+
onChange={handleChange}
|
|
1022
|
+
search={false}
|
|
1023
|
+
multiple={false}
|
|
1024
|
+
disableCloseOnSelect
|
|
1025
|
+
options={options}
|
|
1026
|
+
value={value}
|
|
1027
|
+
onClickAway={handleClickAway}
|
|
1028
|
+
/>
|
|
1029
|
+
</div>
|
|
1030
|
+
);
|
|
1031
|
+
|
|
1032
|
+
function handleClick(event: React.MouseEvent<HTMLElement>) {
|
|
1033
|
+
if (open) {
|
|
1034
|
+
setOpen(false);
|
|
1035
|
+
|
|
1036
|
+
if (anchorEl) {
|
|
1037
|
+
anchorEl.focus();
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
setAnchorEl(null);
|
|
1041
|
+
} else {
|
|
1042
|
+
setAnchorEl(event.currentTarget);
|
|
1043
|
+
setOpen(true);
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
function handleChange(
|
|
1048
|
+
_: React.SyntheticEvent<Element, Event>,
|
|
1049
|
+
newValue: DefaultDropdownMenuOption | DefaultDropdownMenuOption[] | null
|
|
1050
|
+
){
|
|
1051
|
+
setOpen(false);
|
|
1052
|
+
setValue(newValue);
|
|
1053
|
+
|
|
1054
|
+
if (newValue) {
|
|
1055
|
+
setInputDropdownValue(newValue.name);
|
|
1056
|
+
|
|
1057
|
+
if (newValue?.details) setDetials(newValue?.details);
|
|
1058
|
+
else setDetials(undefined);
|
|
1059
|
+
} else {
|
|
1060
|
+
setDetials(undefined);
|
|
1061
|
+
setInputDropdownValue(undefined);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
function handleClickAway(){
|
|
1066
|
+
if (open) {
|
|
1067
|
+
setOpen(false);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
export default App;
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
**/index.tsx**
|
|
1076
|
+
|
|
1077
|
+
```tsx
|
|
1078
|
+
import React from "react";
|
|
1079
|
+
import { createRoot } from "react-dom/client";
|
|
1080
|
+
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
|
|
1081
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
|
|
1082
|
+
import { Theme } from "@czi-sds/components";
|
|
1083
|
+
import CssBaseline from "@mui/material/CssBaseline";
|
|
1084
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
1085
|
+
|
|
1086
|
+
import App from "./App";
|
|
1087
|
+
|
|
1088
|
+
const container = document.getElementById("root");
|
|
1089
|
+
const root = createRoot(container!);
|
|
1090
|
+
|
|
1091
|
+
const RootApp = () => {
|
|
1092
|
+
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
|
1093
|
+
const theme = prefersDarkMode ? Theme("dark") : Theme("light");
|
|
1094
|
+
|
|
1095
|
+
return (
|
|
1096
|
+
<StyledEngineProvider injectFirst>
|
|
1097
|
+
<ThemeProvider theme={theme}>
|
|
1098
|
+
<EmotionThemeProvider theme={theme}>
|
|
1099
|
+
<CssBaseline />
|
|
1100
|
+
<App />
|
|
1101
|
+
</EmotionThemeProvider>
|
|
1102
|
+
</ThemeProvider>
|
|
1103
|
+
</StyledEngineProvider>
|
|
1104
|
+
);
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
root.render(
|
|
1108
|
+
<React.StrictMode>
|
|
1109
|
+
<RootApp />
|
|
1110
|
+
</React.StrictMode>
|
|
1111
|
+
);
|
|
1112
|
+
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1115
|
+
**/public/index.html**
|
|
1116
|
+
|
|
1117
|
+
```html
|
|
1118
|
+
<!DOCTYPE html>
|
|
1119
|
+
<html lang="en">
|
|
1120
|
+
<head>
|
|
1121
|
+
<meta charset="UTF-8" />
|
|
1122
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
1123
|
+
<title>Dropdown Inputs</title>
|
|
1124
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
1125
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
1126
|
+
<link
|
|
1127
|
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
|
|
1128
|
+
rel="stylesheet"
|
|
1129
|
+
/>
|
|
1130
|
+
<link
|
|
1131
|
+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&display=swap"
|
|
1132
|
+
rel="stylesheet"
|
|
1133
|
+
/>
|
|
1134
|
+
</head>
|
|
1135
|
+
<body>
|
|
1136
|
+
<div id="root"></div>
|
|
1137
|
+
</body>
|
|
1138
|
+
</html>
|
|
1139
|
+
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
**/package.json**
|
|
1143
|
+
|
|
1144
|
+
```json
|
|
1145
|
+
{"dependencies":{"react":"^18.0.0","react-dom":"^18.0.0","react-scripts":"^4.0.0"},"devDependencies":{"@types/react":"^18.0.0","@types/react-dom":"^18.0.0","typescript":"^4.0.0"},"main":"/index.tsx"}
|
|
1146
|
+
```
|
|
1147
|
+
|
|
1148
|
+
---
|
|
1149
|
+
|