@splunk/react-ui 5.7.1 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/Accordion.js +6 -6
  2. package/Box.js +83 -34
  3. package/CHANGELOG.md +29 -0
  4. package/CollapsiblePanel.js +11 -11
  5. package/ComboBox.js +31 -27
  6. package/ControlGroup.js +92 -91
  7. package/DefinitionList.js +9 -9
  8. package/Drawer.d.ts +2 -0
  9. package/Drawer.js +679 -0
  10. package/DualListbox.js +1 -1
  11. package/JSONTree.js +73 -72
  12. package/Link.js +2 -2
  13. package/MIGRATION.md +10 -0
  14. package/Menu.js +338 -240
  15. package/Modal.js +127 -109
  16. package/Multiselect.js +437 -351
  17. package/Paginator.js +14 -12
  18. package/Popover.js +4 -1
  19. package/README.md +11 -0
  20. package/RadioBar.js +1 -1
  21. package/Search.js +103 -88
  22. package/Select.js +42 -40
  23. package/SelectBase.js +374 -328
  24. package/SidePanel.js +346 -167
  25. package/SlidingPanels.js +11 -11
  26. package/StepBar.js +7 -7
  27. package/Switch.js +5 -5
  28. package/Text.js +24 -24
  29. package/TextArea.js +7 -7
  30. package/TransitionOpen.js +188 -169
  31. package/docs-llm/Accordion.md +267 -0
  32. package/docs-llm/Anchor Menu.md +115 -0
  33. package/docs-llm/Anchor.md +54 -0
  34. package/docs-llm/AnimationToggle.md +254 -0
  35. package/docs-llm/Avatar.md +298 -0
  36. package/docs-llm/Badge.md +212 -0
  37. package/docs-llm/Breadcrumbs.md +306 -0
  38. package/docs-llm/Button Group.md +53 -0
  39. package/docs-llm/Button.md +361 -0
  40. package/docs-llm/Card Layout.md +286 -0
  41. package/docs-llm/Card.md +619 -0
  42. package/docs-llm/Checkbox.md +218 -0
  43. package/docs-llm/Chip.md +291 -0
  44. package/docs-llm/Clickable.md +160 -0
  45. package/docs-llm/Code.md +292 -0
  46. package/docs-llm/Collapsible Panel.md +744 -0
  47. package/docs-llm/Color.md +253 -0
  48. package/docs-llm/Column Layout.md +391 -0
  49. package/docs-llm/Combo Box.md +540 -0
  50. package/docs-llm/Control Group.md +594 -0
  51. package/docs-llm/Date.md +270 -0
  52. package/docs-llm/Definition List.md +278 -0
  53. package/docs-llm/Divider.md +216 -0
  54. package/docs-llm/Drawer.md +414 -0
  55. package/docs-llm/Dropdown.md +472 -0
  56. package/docs-llm/Dual Listbox.md +325 -0
  57. package/docs-llm/File.md +653 -0
  58. package/docs-llm/Form Rows.md +374 -0
  59. package/docs-llm/Heading.md +179 -0
  60. package/docs-llm/Image.md +109 -0
  61. package/docs-llm/JSON Tree.md +260 -0
  62. package/docs-llm/Layer.md +74 -0
  63. package/docs-llm/Layout.md +50 -0
  64. package/docs-llm/Link.md +318 -0
  65. package/docs-llm/List.md +189 -0
  66. package/docs-llm/Markdown.md +179 -0
  67. package/docs-llm/Menu.md +735 -0
  68. package/docs-llm/Message Bar.md +236 -0
  69. package/docs-llm/Message.md +248 -0
  70. package/docs-llm/Modal.md +443 -0
  71. package/docs-llm/Monogram.md +159 -0
  72. package/docs-llm/Multiselect.md +937 -0
  73. package/docs-llm/Number.md +298 -0
  74. package/docs-llm/Paginator.md +395 -0
  75. package/docs-llm/Paragraph.md +148 -0
  76. package/docs-llm/Phone Number.md +254 -0
  77. package/docs-llm/Popover.md +166 -0
  78. package/docs-llm/Progress.md +141 -0
  79. package/docs-llm/Radio Bar.md +303 -0
  80. package/docs-llm/Radio List.md +350 -0
  81. package/docs-llm/Resize.md +362 -0
  82. package/docs-llm/Screen Reader Content.md +73 -0
  83. package/docs-llm/Scroll Container Context.md +155 -0
  84. package/docs-llm/Scroll.md +152 -0
  85. package/docs-llm/Search.md +381 -0
  86. package/docs-llm/Select.md +985 -0
  87. package/docs-llm/Side Panel.md +777 -0
  88. package/docs-llm/Slider.md +339 -0
  89. package/docs-llm/Sliding Panels.md +340 -0
  90. package/docs-llm/Split Button.md +295 -0
  91. package/docs-llm/Static Content.md +90 -0
  92. package/docs-llm/Step Bar.md +292 -0
  93. package/docs-llm/Switch.md +268 -0
  94. package/docs-llm/Tab Bar.md +439 -0
  95. package/docs-llm/Tab Layout.md +398 -0
  96. package/docs-llm/Table.md +2642 -0
  97. package/docs-llm/Text Area.md +253 -0
  98. package/docs-llm/Text.md +339 -0
  99. package/docs-llm/Tooltip.md +325 -0
  100. package/docs-llm/Transition Open.md +406 -0
  101. package/docs-llm/Tree.md +586 -0
  102. package/docs-llm/Typography.md +125 -0
  103. package/docs-llm/Wait Spinner.md +121 -0
  104. package/docs-llm/llms.txt +97 -0
  105. package/package.json +6 -5
  106. package/types/src/Box/Box.d.ts +2 -10
  107. package/types/src/Drawer/Body.d.ts +17 -0
  108. package/types/src/Drawer/Drawer.d.ts +114 -0
  109. package/types/src/Drawer/DrawerContext.d.ts +11 -0
  110. package/types/src/Drawer/Footer.d.ts +25 -0
  111. package/types/src/Drawer/Header.d.ts +41 -0
  112. package/types/src/Drawer/docs/examples/Basic.d.ts +6 -0
  113. package/types/src/Drawer/docs/examples/ContainerPosition.d.ts +7 -0
  114. package/types/src/Drawer/docs/examples/InitialFocus.d.ts +9 -0
  115. package/types/src/Drawer/docs/examples/InlinePosition.d.ts +7 -0
  116. package/types/src/Drawer/docs/examples/PagePosition.d.ts +7 -0
  117. package/types/src/Drawer/index.d.ts +2 -0
  118. package/types/src/JSONTree/JSONTree.d.ts +12 -5
  119. package/types/src/JSONTree/renderTreeItems.d.ts +2 -1
  120. package/types/src/Menu/Item.d.ts +2 -1
  121. package/types/src/Menu/docs/examples/SelectableCheckbox.d.ts +7 -0
  122. package/types/src/Modal/Modal.d.ts +1 -2
  123. package/types/src/Select/Option.d.ts +6 -3
  124. package/types/src/Select/Select.d.ts +8 -5
  125. package/types/src/Select/docs/examples/Dimmed.d.ts +7 -0
  126. package/types/src/SelectBase/OptionBase.d.ts +6 -3
  127. package/types/src/SelectBase/SelectBase.d.ts +8 -3
  128. package/types/src/SidePanel/SidePanel.d.ts +43 -2
  129. package/types/src/SidePanel/docs/examples/DockLayout.d.ts +17 -0
  130. package/types/src/SidePanel/docs/examples/InitialFocus.d.ts +9 -0
  131. package/types/src/TransitionOpen/TransitionOpen.d.ts +29 -4
  132. package/types/src/useKeyPress/index.d.ts +9 -2
  133. package/types/src/useOnClickOutside/index.d.ts +2 -0
  134. package/types/src/useOnClickOutside/useOnClickOutside.d.ts +4 -0
  135. package/useKeyPress.js +23 -18
  136. package/useOnClickOutside.d.ts +2 -0
  137. package/useOnClickOutside.js +79 -0
  138. package/types/src/RadioList/docs/examples/Row.d.ts +0 -6
@@ -0,0 +1,268 @@
1
+ # Switch
2
+
3
+ ## Overview
4
+
5
+
6
+ > Image: Illustration of a switch component.
7
+
8
+
9
+ <Message appearance="fill" type="info">
10
+ <div>All data entry components should be wrapped in a <Link to="ControlGroup">Control Group</Link> to provide a label, error states, and help or error text, ensuring an accessible experience for all users.</div>
11
+ </Message>
12
+
13
+ ## When to use this component
14
+ ### Toggle
15
+ - There's a binary choice for enabling a setting, like on/off, true/false, enable/disable, or activate/deactivate.
16
+ - Toggles can be grouped when the items can be independently controlled.
17
+
18
+ ### Checkbox
19
+ <Message appearance="fill" type="warning">
20
+ <div>Prefer the <Link to="Checkbox">Checkbox</Link> component over the checkbox appearance of Switch.</div>
21
+ </Message>
22
+
23
+ ## When to use another component
24
+ - If multiple related options can be selected from a list, use Checkbox
25
+ - If there are more than two choices or two choices that don't map to a boolean relationship (such as on/off) use Radio List or Radio Bar
26
+ - If there are multiple options, space conservation is important, and only one option can be selected at a time use a Select or Combobox
27
+ - If making a selection from a long list of items, consider using Multiselect instead.
28
+ - If only one option in a set can be selected, use Radio List or Radio Bar instead.
29
+
30
+ ```mermaid
31
+ graph TD
32
+ accDescr: Decision tree that guides on when to use the Switch component or something else
33
+ A(Can the user select more than 1 option?) -- Yes --- B(Are there fewer than 5 options and you don't need to conserve space?)
34
+ B -- Yes --- C(Switch - Checkbox group)
35
+ B -- No --- D(Multiselect)
36
+ A -- No --- E("Do the options have a boolean (Ex. on/off) relationship?")
37
+ E -- Yes --- F(Switch - Toggle)
38
+ E -- No --- G(Are there fewer than 5 options and you don't need to conserve space?)
39
+ G -- Yes --- H(Radio List or Radio Bar)
40
+ G -- No --- I(Select or ComboBox)
41
+ ```
42
+
43
+ ### Check out
44
+ - [Radio List][1]
45
+ - [Radio Bar][2]
46
+ - [Combo Box][3]
47
+ - [Select][4]
48
+ - [Multiselect][5]
49
+
50
+ ## Usage
51
+
52
+ ### Grouping settings
53
+ Checkboxes visually group similar items effectively and take up less space than switches.
54
+
55
+ > Image: Examples of a group of two Switches,
56
+
57
+
58
+ ### In forms
59
+ Toggles work best if changing the state is immediately effective and there's no need for an additional action to apply or save a change. Consider Checkboxes or Radio Lists within a form containing other elements that need to be saved or submitted.
60
+
61
+ > Image: Example of Notification settings with a group of two Switches,
62
+
63
+
64
+ ### Toggle groups
65
+ When grouped, toggles control binary options, not opposing states. A binary option represents a single selection that is either on or off.
66
+
67
+ > Image: Examples of a group of two Toggles grouped with a title. In the first example with heart eyes emoji, the Toggles are labeled,
68
+
69
+
70
+ ## Content
71
+
72
+ ### Be concise
73
+ Use sentence-style capitalization and keep labels concise.
74
+
75
+ > Image: Examples of switch label length: The first example with the heart eyes emoji has a concise label,
76
+
77
+
78
+ [1]: ./Radiolist
79
+ [2]: ./Radiobar
80
+ [3]: ./ComboBox
81
+ [4]: ./Select
82
+ [5]: ./Multiselect
83
+ [6]: ./Dropdown
84
+ [7]: ./Checkbox
85
+
86
+ ## Examples
87
+
88
+
89
+ ### Basic
90
+
91
+ ```typescript
92
+ import React, { useState } from 'react';
93
+
94
+ import Switch from '@splunk/react-ui/Switch';
95
+
96
+
97
+ const Basic = () => {
98
+ const [enableBluetooth, setEnableBluetooth] = useState(true);
99
+ const [enableWifi, setEnableWifi] = useState(false);
100
+
101
+ return (
102
+ <>
103
+ <Switch
104
+ appearance="toggle"
105
+ selected={enableBluetooth}
106
+ onClick={() => setEnableBluetooth(!enableBluetooth)}
107
+ >
108
+ Enable bluetooth
109
+ </Switch>
110
+ <Switch
111
+ appearance="toggle"
112
+ selected={enableWifi}
113
+ onClick={() => setEnableWifi(!enableWifi)}
114
+ >
115
+ Enable wifi
116
+ </Switch>
117
+ </>
118
+ );
119
+ };
120
+
121
+ export default Basic;
122
+ ```
123
+
124
+
125
+
126
+ ### Disabled
127
+
128
+ ```typescript
129
+ import React from 'react';
130
+
131
+ import Switch from '@splunk/react-ui/Switch';
132
+
133
+
134
+ const Disabled = () => {
135
+ return (
136
+ <>
137
+ <Switch appearance="toggle" disabled selected>
138
+ Enable bluetooth
139
+ </Switch>
140
+ <Switch appearance="toggle" disabled>
141
+ Enable wifi
142
+ </Switch>
143
+ </>
144
+ );
145
+ };
146
+
147
+ export default Disabled;
148
+ ```
149
+
150
+
151
+
152
+
153
+ ## API
154
+
155
+
156
+ ### Switch API
157
+
158
+ `Switch` is a basic form control with an on/off state.
159
+
160
+ #### Props
161
+
162
+ | Name | Type | Required | Default | Description |
163
+ |------|------|------|------|------|
164
+ | appearance | 'checkbox' \| 'toggle' | no | 'checkbox' | **DEPRECATED**: Value 'checkbox'. Consider using the `Checkbox` component instead. Determines if the component renders as a checkbox or toggle. The 'checkbox' value is deprecated and will be removed in a future major version. |
165
+ | children | React.ReactNode | no | | |
166
+ | describedBy | string | no | | The id of the description. When placed in a ControlGroup, this is automatically set to the ControlGroup's help component. |
167
+ | disabled | boolean | no | | |
168
+ | elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts, and null when it unmounts. |
169
+ | error | boolean | no | | Highlight the field as having an error only when appearance is 'checkbox'. |
170
+ | id | string | no | | If `Switch` is not provided children as the label, an id can be provided for the control. Set a label's for attribute to this id to link the two elements. |
171
+ | inline | boolean | no | | Make the control an inline block with variable width. |
172
+ | labelledBy | string | no | | If `Switch` is not provided children as the label, an id can be provided to another element. |
173
+ | onClick | SwitchClickHandler \| SwitchCheckboxWithSomeClickHandler | no | | |
174
+ | selected | boolean \| 'some' | no | | 'some' is only valid when appearance is 'checkbox'. The current value of `selected` is passed to the onClick handler. |
175
+ | selectedLabel | string | no | | **DEPRECATED**: This prop is deprecated and will be removed in the next major version. The customized content presented to screen readers when selected. |
176
+ | someSelectedLabel | string | no | | **DEPRECATED**: This prop is deprecated and will be removed in the next major version. The customized content presented to screen readers when selected="some". |
177
+ | toggleRef | React.Ref<HTMLAnchorElement \| HTMLButtonElement \| HTMLSpanElement> | no | | A React ref which is set to the toggle when the component mounts and null when it unmounts. |
178
+ | unselectedLabel | string | no | | **DEPRECATED**: This prop is deprecated and will be removed in the next major version. The customized content presented to screen readers when unselected. |
179
+ | value | any | no | | The `value` is used as an identifier and is passed to the `onClick` handler. This is useful when managing a group of switches with a single `onClick` handler. |
180
+
181
+ #### Types
182
+
183
+ | Name | Type | Description |
184
+ |------|------|------|
185
+ | SwitchCheckboxWithSomeClickHandler | ( event: React.MouseEvent<HTMLButtonElement>, data: { selected: boolean \| 'some'; value?: any; // eslint-disable-line @typescript-eslint/no-explicit-any } ) => void | |
186
+ | SwitchClickHandler | ( event: React.MouseEvent<HTMLButtonElement>, data: { selected: boolean; value?: any; // eslint-disable-line @typescript-eslint/no-explicit-any } ) => void | |
187
+
188
+
189
+
190
+
191
+
192
+ ## Accessibility
193
+
194
+ ## Switch / Checkbox
195
+ ## Visual Design
196
+
197
+ - Color contrast ratio **MUST** be:
198
+ - &gt=4.5:1 for Label text to page-background (all states) [SC 1.4.3][1]
199
+ - &gt=3:1 for [SC 1.4.11][2]:
200
+ - For toggle, circle to toggle-background-color
201
+ - For checkbox, checkmark to checkbox-background (selected)
202
+ - Border to page-background (active)
203
+ - Focus State: if the focus ring has a radius of [SC 1.4.11][2]:
204
+ - &lt 3px: &gt=4.5.1 between button &lt&gt focus &lt&gt background
205
+ - &gt 3px: &gt=3.1 between button &lt&gt focus &lt&gt background
206
+
207
+ ## States
208
+
209
+ - Color contrast rules do not apply to disabled checkbox
210
+
211
+ ## Interaction Model
212
+
213
+ - Toggle:
214
+ - Focus management
215
+ - **MUST** have keyboard navigation [SC 2.1][3]:
216
+ - <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> to focus on checkbox from element before or after in meaningful sequence
217
+ - <kbd>Space</kbd> and <kbd>Enter</kbd> to change state to on or off
218
+
219
+ - Checkbox:
220
+ - Checkbox **SHOULD** have `tabindex="0"` to make checkboxes focusable by keyboard
221
+ - **MUST** have keyboard navigation [SC 2.1][3]:
222
+ - <kbd>Tab</kbd> and <kbd>Shift+Tab</kbd> to focus on checkbox from element before or after in
223
+ a meaningful sequence
224
+ - <kbd>Space</kbd> to change status to...
225
+
226
+ - Simple State: `selected`, `unselected`
227
+ - Tri-state: `selected`, `unselected`, `mixed-state`
228
+
229
+ ## Implementation
230
+
231
+ - Toggle:
232
+ - Screen reader **MUST** announce when toggle is focused [SC 4.1.2][4]:
233
+ - Name of toggle(label)
234
+ - `"Switch"` or `"Toggle"` (role's name is dependent on browser)
235
+ - `"On"` or `"Off"` (value)
236
+
237
+ - Checkbox:
238
+ - Screen reader **MUST** announce when checkbox is focused [SC 4.1.2][4]:
239
+ - Label (name)
240
+ - `"checkbox"` (role)
241
+ - `"unchecked"` or `"checked"`, `"mixed"` (value)
242
+ - **MUST** include ARIA labels: [SC 4.1.2][4]:
243
+ - When checked, `aria-checked=true`
244
+ - When not checked, `aria-checked=false`
245
+ - when partially checked, `aria-checked=mixed`
246
+ - If checkboxes are in a **group** the following **MUST** apply for screen reader:
247
+ - Upon first focus into the group, announce how many checkboxes are in that list
248
+ - Name of group
249
+ - When developing a parent-child checkbox component, the following **MUST** apply:
250
+ - Focused checkbox:
251
+ - <kbd>Space</kbd>: cycle the checked state of the checkbox between checked, unchecked and mixed
252
+ - <kbd>Tab</kbd>: move focus to the next interactive element after checkbox
253
+ - <kbd>Shift+Tab</kbd>: move focus to the previous interactive element
254
+ - Parent checkbox:
255
+ - Unchecked makes all controlled checkboxes unchecked
256
+ - Checked makes all controlled checkboxes checked
257
+ - Mixed makes all the controlled checkboxes return to the last state the user selected for the particular checkbox or default state
258
+ - Child checkbox:
259
+ - Checked: all children checkboxes will check parent checkbox
260
+ - Unchecked: all children checkboxes will uncheck parent checkbox
261
+ - Checking some will partially check (mixed) the parent checkbox
262
+
263
+ [1]: https://www.w3.org/TR/WCAG21/#contrast-minimum
264
+ [2]: https://www.w3.org/TR/WCAG21/#non-text-contrast
265
+ [3]: https://www.w3.org/TR/WCAG21/#keyboard-accessible
266
+ [4]: https://www.w3.org/TR/WCAG21/#name-role-value
267
+
268
+