@splunk/react-ui 5.7.0 → 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.
- package/Accordion.js +6 -6
- package/Box.js +83 -34
- package/CHANGELOG.md +34 -0
- package/CollapsiblePanel.js +11 -11
- package/ComboBox.js +31 -27
- package/ControlGroup.js +92 -91
- package/DefinitionList.js +9 -9
- package/Drawer.d.ts +2 -0
- package/Drawer.js +679 -0
- package/DualListbox.js +1 -1
- package/JSONTree.js +73 -72
- package/Link.js +2 -2
- package/MIGRATION.md +10 -0
- package/Menu.js +338 -240
- package/Modal.js +127 -109
- package/Multiselect.js +437 -351
- package/Paginator.js +14 -12
- package/Popover.js +4 -1
- package/README.md +11 -0
- package/RadioBar.js +1 -1
- package/Search.js +103 -88
- package/Select.js +42 -40
- package/SelectBase.js +374 -328
- package/SidePanel.js +346 -167
- package/SlidingPanels.js +11 -11
- package/StepBar.js +7 -7
- package/Switch.js +5 -5
- package/Text.js +24 -24
- package/TextArea.js +7 -7
- package/TransitionOpen.js +204 -185
- package/docs-llm/Accordion.md +267 -0
- package/docs-llm/Anchor Menu.md +115 -0
- package/docs-llm/Anchor.md +54 -0
- package/docs-llm/AnimationToggle.md +254 -0
- package/docs-llm/Avatar.md +298 -0
- package/docs-llm/Badge.md +212 -0
- package/docs-llm/Breadcrumbs.md +306 -0
- package/docs-llm/Button Group.md +53 -0
- package/docs-llm/Button.md +361 -0
- package/docs-llm/Card Layout.md +286 -0
- package/docs-llm/Card.md +619 -0
- package/docs-llm/Checkbox.md +218 -0
- package/docs-llm/Chip.md +291 -0
- package/docs-llm/Clickable.md +160 -0
- package/docs-llm/Code.md +292 -0
- package/docs-llm/Collapsible Panel.md +744 -0
- package/docs-llm/Color.md +253 -0
- package/docs-llm/Column Layout.md +391 -0
- package/docs-llm/Combo Box.md +540 -0
- package/docs-llm/Control Group.md +594 -0
- package/docs-llm/Date.md +270 -0
- package/docs-llm/Definition List.md +278 -0
- package/docs-llm/Divider.md +216 -0
- package/docs-llm/Drawer.md +414 -0
- package/docs-llm/Dropdown.md +472 -0
- package/docs-llm/Dual Listbox.md +325 -0
- package/docs-llm/File.md +653 -0
- package/docs-llm/Form Rows.md +374 -0
- package/docs-llm/Heading.md +179 -0
- package/docs-llm/Image.md +109 -0
- package/docs-llm/JSON Tree.md +260 -0
- package/docs-llm/Layer.md +74 -0
- package/docs-llm/Layout.md +50 -0
- package/docs-llm/Link.md +318 -0
- package/docs-llm/List.md +189 -0
- package/docs-llm/Markdown.md +179 -0
- package/docs-llm/Menu.md +735 -0
- package/docs-llm/Message Bar.md +236 -0
- package/docs-llm/Message.md +248 -0
- package/docs-llm/Modal.md +443 -0
- package/docs-llm/Monogram.md +159 -0
- package/docs-llm/Multiselect.md +937 -0
- package/docs-llm/Number.md +298 -0
- package/docs-llm/Paginator.md +395 -0
- package/docs-llm/Paragraph.md +148 -0
- package/docs-llm/Phone Number.md +254 -0
- package/docs-llm/Popover.md +166 -0
- package/docs-llm/Progress.md +141 -0
- package/docs-llm/Radio Bar.md +303 -0
- package/docs-llm/Radio List.md +350 -0
- package/docs-llm/Resize.md +362 -0
- package/docs-llm/Screen Reader Content.md +73 -0
- package/docs-llm/Scroll Container Context.md +155 -0
- package/docs-llm/Scroll.md +152 -0
- package/docs-llm/Search.md +381 -0
- package/docs-llm/Select.md +985 -0
- package/docs-llm/Side Panel.md +777 -0
- package/docs-llm/Slider.md +339 -0
- package/docs-llm/Sliding Panels.md +340 -0
- package/docs-llm/Split Button.md +295 -0
- package/docs-llm/Static Content.md +90 -0
- package/docs-llm/Step Bar.md +292 -0
- package/docs-llm/Switch.md +268 -0
- package/docs-llm/Tab Bar.md +439 -0
- package/docs-llm/Tab Layout.md +398 -0
- package/docs-llm/Table.md +2642 -0
- package/docs-llm/Text Area.md +253 -0
- package/docs-llm/Text.md +339 -0
- package/docs-llm/Tooltip.md +325 -0
- package/docs-llm/Transition Open.md +406 -0
- package/docs-llm/Tree.md +586 -0
- package/docs-llm/Typography.md +125 -0
- package/docs-llm/Wait Spinner.md +121 -0
- package/docs-llm/llms.txt +97 -0
- package/package.json +6 -5
- package/types/src/Box/Box.d.ts +2 -10
- package/types/src/Drawer/Body.d.ts +17 -0
- package/types/src/Drawer/Drawer.d.ts +114 -0
- package/types/src/Drawer/DrawerContext.d.ts +11 -0
- package/types/src/Drawer/Footer.d.ts +25 -0
- package/types/src/Drawer/Header.d.ts +41 -0
- package/types/src/Drawer/docs/examples/Basic.d.ts +6 -0
- package/types/src/Drawer/docs/examples/ContainerPosition.d.ts +7 -0
- package/types/src/Drawer/docs/examples/InitialFocus.d.ts +9 -0
- package/types/src/Drawer/docs/examples/InlinePosition.d.ts +7 -0
- package/types/src/Drawer/docs/examples/PagePosition.d.ts +7 -0
- package/types/src/Drawer/index.d.ts +2 -0
- package/types/src/JSONTree/JSONTree.d.ts +12 -5
- package/types/src/JSONTree/renderTreeItems.d.ts +2 -1
- package/types/src/Menu/Item.d.ts +2 -1
- package/types/src/Menu/docs/examples/SelectableCheckbox.d.ts +7 -0
- package/types/src/Modal/Modal.d.ts +1 -2
- package/types/src/Select/Option.d.ts +6 -3
- package/types/src/Select/Select.d.ts +8 -5
- package/types/src/Select/docs/examples/Dimmed.d.ts +7 -0
- package/types/src/SelectBase/OptionBase.d.ts +6 -3
- package/types/src/SelectBase/SelectBase.d.ts +8 -3
- package/types/src/SidePanel/SidePanel.d.ts +43 -2
- package/types/src/SidePanel/docs/examples/DockLayout.d.ts +17 -0
- package/types/src/SidePanel/docs/examples/InitialFocus.d.ts +9 -0
- package/types/src/TransitionOpen/TransitionOpen.d.ts +29 -4
- package/types/src/useKeyPress/index.d.ts +9 -2
- package/types/src/useOnClickOutside/index.d.ts +2 -0
- package/types/src/useOnClickOutside/useOnClickOutside.d.ts +4 -0
- package/useKeyPress.js +23 -18
- package/useOnClickOutside.d.ts +2 -0
- package/useOnClickOutside.js +79 -0
- package/types/src/RadioList/docs/examples/Row.d.ts +0 -6
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
# Control Group
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> Image: Illustration of a group of data entry components in a Control Group.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## When to use this component
|
|
10
|
+
Control Group provides a robust experience for data entry and forms to:
|
|
11
|
+
- Group data entry components.
|
|
12
|
+
- Add labels and help or error messages to data entry components.
|
|
13
|
+
- Control the layout and/or visually combine multiple inputs on a single line.
|
|
14
|
+
|
|
15
|
+
## When to use another component
|
|
16
|
+
<Message appearance="fill" type="warning">
|
|
17
|
+
If you choose not to use Control Group, it is your responsibility to ensure the experience is accessible to all users. Affordances such as correct labeling, help text, and errors need to be considered.
|
|
18
|
+
</Message>
|
|
19
|
+
|
|
20
|
+
```mermaid
|
|
21
|
+
graph TD
|
|
22
|
+
accDescr: Decision tree that guides on when to use the ControlGroup component or something else
|
|
23
|
+
A(Are there multiple data entry components in a group or form?) -- No --- B(Data entry component with manually added label)
|
|
24
|
+
A -- Yes --- C(Does your data entry component need additional text, such as help or error text?)
|
|
25
|
+
C -- No --- D(Data entry component with manually added label)
|
|
26
|
+
C -- Yes --- E(Control Group)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Behaviors
|
|
30
|
+
|
|
31
|
+
### Fill layout
|
|
32
|
+
Control Group's default layout can be used to put one or multiple inputs on a single line. Multiple components on a single line will be kept separate. Removing the fill layout will allow controls to control their own size and wrap onto multiple lines. This should usually be used for Date, Number and Switch controls.
|
|
33
|
+
> Image: Example of a Control Group with four inputs on two lines. On the first line, Alert name, there is a Select and Text input with the help text
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Fill and join layout
|
|
37
|
+
Control Group can control the visual style of multiple inputs on a single line, making the input look joined as one. This is best used when the controls are directly related, for example a value input and its unit.
|
|
38
|
+
> Image: Example of a Control Group with four inputs on two lines. The inputs on the same lines are styled to visually be connected. On the first line, Alert name, there is a Select and Text input with the help text
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Avoid placeholder text and tooltips
|
|
44
|
+
|
|
45
|
+
#### Placeholder text
|
|
46
|
+
Placeholder text presents a number of visual and cognitive issues. It is best to avoid using it and use help text instead. Placeholder does not replace a label. [Read about issues placeholders can cause.] [1]
|
|
47
|
+
> Image: Example of a Control Group with three Text inputs: ID number, First name and Last name, and a Location Select input. In the first example with heart eyes emoji, the inputs are left blank, and help text is added for the ID number. In the second example with grimacing emoji, the labels are repeated as placeholder texts for each input.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
#### Tooltips
|
|
51
|
+
To ensure information accessibility and convenience, it's recommended to minimize reliance on tooltips. Tooltips necessitate extra user actions, conceal crucial details, and may obstruct surrounding inputs or content. Instead, using visible help text directly is recommended for clearer and more immediate guidance.
|
|
52
|
+
> Image: Examples of using tooltips with a Text component. The first example with heart eyes emoji has a Text component labeled
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Help and error text
|
|
56
|
+
Help and error text can describe multiple inputs within a Control Group. Both help and error text can visible at the same time and should complement one another.
|
|
57
|
+
|
|
58
|
+
> Image: Example of a Control Group with four inputs on two lines. On the first line, Alert name, there is a Select and Text input with the help text
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
#### Help text
|
|
62
|
+
Put information that's essential to completing the task in help text so it's always visible.
|
|
63
|
+
Don’t add help text if it doesn’t provide helpful information for the user.
|
|
64
|
+
> Image: Examples of using help text that is helpful and essential to completing a task. The first example with heart eyes emoji has a text input labeled
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
#### Error text with solution
|
|
68
|
+
Validation and error messages help users to understand and resolve problems. The error message should inform users what the problem is and how to fix it.
|
|
69
|
+
|
|
70
|
+
Note: Use [Message][2] to communicate server-side validation errors. Some errors, like those caused by temporary system issues, might only surface after submission.
|
|
71
|
+
> Image: Examples of a Control Group with a Select input and error message. In the first example with heart eyes emoji, the error message says
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
### Required vs optional fields
|
|
75
|
+
Use one of these styles when all fields in a form are required, or when the form includes both required and optional fields—don't mix styles.
|
|
76
|
+
|
|
77
|
+
#### All fields are required
|
|
78
|
+
When a form only contains required inputs, inform users that all fields are required once at the beginning of the form.
|
|
79
|
+
> Image: Example of a Control Group with three Text inputs: ID number, First name and Last name, and a Location Select input. A description at the top says,
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
#### Required and optional fields
|
|
83
|
+
When a form contains both required and optional fields, use the `required` prop for each required control group.
|
|
84
|
+
> Image: Example of a Control Group with three Text inputs: ID number, First name and Last name, and a Location Select input. The ID number input is marked as optional. A description at the top says,
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
#### Optional fields
|
|
88
|
+
If the majority of fields are required, consider marking the optional fields instead. Ensure the word '(optional)' is included as part of the label, placed after the input label text and wrapped in parentheses.
|
|
89
|
+
|
|
90
|
+
> Image: Example of a Control Group with three Text inputs: ID number, First name and Last name, and a Location Select input. Description at the top says,
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Field set
|
|
94
|
+
It is best to group related inputed in an HTML `<fieldset>` tag, which encloses related elements and provides a title for the children Control Group(s). Additionally, you can use a description to provide further context to help guide users.
|
|
95
|
+
> Image: Example of a Control Group with three Text inputs: ID number, First name and Last name, and a Location Select input. The Control Group has the title, Employee details, and the description, Use a description on field set to provide information that guides users.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## Content guidelines
|
|
99
|
+
|
|
100
|
+
### Labels
|
|
101
|
+
Labels are required, keep Control Group labels brief and use sentence-style capitalization.
|
|
102
|
+
> Image: Example of keeping Text component labels brief. The first example with heart eyes emoji has a Text component labeled
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
[1]: https://www.nngroup.com/articles/form-design-placeholders/
|
|
106
|
+
[2]: ./Message
|
|
107
|
+
|
|
108
|
+
## Examples
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### Default Appearance
|
|
112
|
+
|
|
113
|
+
By default, the label appears above and the control fills the available width.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import React from 'react';
|
|
117
|
+
|
|
118
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
119
|
+
import Text from '@splunk/react-ui/Text';
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
function Basic() {
|
|
123
|
+
return (
|
|
124
|
+
<div>
|
|
125
|
+
<ControlGroup
|
|
126
|
+
label="Field label"
|
|
127
|
+
tooltip="Tooltip helps explain the label."
|
|
128
|
+
help="This is the help text."
|
|
129
|
+
>
|
|
130
|
+
<Text canClear />
|
|
131
|
+
</ControlGroup>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export default Basic;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
### Labels to the left
|
|
142
|
+
|
|
143
|
+
Alternately, labels can be placed to the left of the control.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import React from 'react';
|
|
147
|
+
|
|
148
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
149
|
+
import Text from '@splunk/react-ui/Text';
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function LabelLeft() {
|
|
153
|
+
return (
|
|
154
|
+
<div>
|
|
155
|
+
<ControlGroup label="Label left" labelPosition="left">
|
|
156
|
+
<Text />
|
|
157
|
+
</ControlGroup>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default LabelLeft;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
### Help Text with a Link.
|
|
168
|
+
|
|
169
|
+
Help text may contain links or other content.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import React from 'react';
|
|
173
|
+
|
|
174
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
175
|
+
import Link from '@splunk/react-ui/Link';
|
|
176
|
+
import Text from '@splunk/react-ui/Text';
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
function HelpWithLinks() {
|
|
180
|
+
const help = (
|
|
181
|
+
<span>
|
|
182
|
+
Help text with a <Link to="http://duckduckgo.com">link</Link>
|
|
183
|
+
</span>
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div>
|
|
188
|
+
<ControlGroup label="Username" help={help}>
|
|
189
|
+
<Text />
|
|
190
|
+
</ControlGroup>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export default HelpWithLinks;
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
### Required
|
|
201
|
+
|
|
202
|
+
The required property will set the required attribute on each child component and add an asterisk before the label.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import React from 'react';
|
|
206
|
+
|
|
207
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
208
|
+
import Text from '@splunk/react-ui/Text';
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
function Required() {
|
|
212
|
+
return (
|
|
213
|
+
<div>
|
|
214
|
+
<ControlGroup required label="Field label">
|
|
215
|
+
<Text canClear />
|
|
216
|
+
</ControlGroup>
|
|
217
|
+
</div>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export default Required;
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### Error
|
|
227
|
+
|
|
228
|
+
Most form controls have their own error property. It is recommended to supply an error message so the user understands what the problem is and how to fix it.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import React from 'react';
|
|
232
|
+
|
|
233
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
234
|
+
import Text from '@splunk/react-ui/Text';
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
function Error() {
|
|
238
|
+
return (
|
|
239
|
+
<div>
|
|
240
|
+
<ControlGroup label="Alert name" error="Alert name cannot contain commas: ,">
|
|
241
|
+
<Text canClear defaultValue="Server, Crash" error />
|
|
242
|
+
</ControlGroup>
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export default Error;
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
### Help and error text
|
|
253
|
+
|
|
254
|
+
Help and error text can appear at the same time.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import React from 'react';
|
|
258
|
+
|
|
259
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
260
|
+
import Text from '@splunk/react-ui/Text';
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
function HelpWithErrorText() {
|
|
264
|
+
return (
|
|
265
|
+
<div>
|
|
266
|
+
<ControlGroup
|
|
267
|
+
label="Field label"
|
|
268
|
+
labelPosition="top"
|
|
269
|
+
help="Some help text."
|
|
270
|
+
error="Error text."
|
|
271
|
+
>
|
|
272
|
+
<Text error canClear />
|
|
273
|
+
</ControlGroup>
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export default HelpWithErrorText;
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
### Fill Layout (Default)
|
|
284
|
+
|
|
285
|
+
Fill layout will put space between the controls.
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import React from 'react';
|
|
289
|
+
|
|
290
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
291
|
+
import RadioBar from '@splunk/react-ui/RadioBar';
|
|
292
|
+
import Select from '@splunk/react-ui/Select';
|
|
293
|
+
import Text from '@splunk/react-ui/Text';
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
function LayoutFill() {
|
|
297
|
+
return (
|
|
298
|
+
<div>
|
|
299
|
+
<ControlGroup label="Two controls">
|
|
300
|
+
<Text />
|
|
301
|
+
<Select defaultValue="1">
|
|
302
|
+
<Select.Option label="Up" value="1" />
|
|
303
|
+
<Select.Option label="Down" value="2" />
|
|
304
|
+
</Select>
|
|
305
|
+
</ControlGroup>
|
|
306
|
+
<ControlGroup label="Two controls">
|
|
307
|
+
<Select defaultValue="1">
|
|
308
|
+
<Select.Option label="Up" value="1" />
|
|
309
|
+
<Select.Option label="Down" value="2" />
|
|
310
|
+
</Select>
|
|
311
|
+
<Text />
|
|
312
|
+
</ControlGroup>
|
|
313
|
+
|
|
314
|
+
<ControlGroup label="One control">
|
|
315
|
+
<Select defaultValue="1">
|
|
316
|
+
<Select.Option label="Up" value="1" />
|
|
317
|
+
<Select.Option label="Down" value="2" />
|
|
318
|
+
</Select>
|
|
319
|
+
</ControlGroup>
|
|
320
|
+
|
|
321
|
+
<ControlGroup label="RadioBar control">
|
|
322
|
+
<RadioBar defaultValue={3} style={{ width: '460px' }}>
|
|
323
|
+
<RadioBar.Option value={1} label="one" />
|
|
324
|
+
<RadioBar.Option value={2} label="two" />
|
|
325
|
+
<RadioBar.Option value={3} label="three three three" />
|
|
326
|
+
<RadioBar.Option value={4} label="four" />
|
|
327
|
+
</RadioBar>
|
|
328
|
+
</ControlGroup>
|
|
329
|
+
</div>
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export default LayoutFill;
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
### Fill and Join Layout
|
|
339
|
+
|
|
340
|
+
The controls will fill the space and will be joined together.
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
import React from 'react';
|
|
344
|
+
|
|
345
|
+
import Button from '@splunk/react-ui/Button';
|
|
346
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
347
|
+
import Number from '@splunk/react-ui/Number';
|
|
348
|
+
import Select from '@splunk/react-ui/Select';
|
|
349
|
+
import Text from '@splunk/react-ui/Text';
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
function LayoutFillJoin() {
|
|
353
|
+
return (
|
|
354
|
+
<div>
|
|
355
|
+
<ControlGroup label="Two controls" controlsLayout="fillJoin">
|
|
356
|
+
<Text />
|
|
357
|
+
<Select defaultValue="1">
|
|
358
|
+
<Select.Option label="Up" value="1" />
|
|
359
|
+
<Select.Option label="Down" value="2" />
|
|
360
|
+
</Select>
|
|
361
|
+
</ControlGroup>
|
|
362
|
+
<ControlGroup label="Two controls" controlsLayout="fillJoin">
|
|
363
|
+
<Select defaultValue="1" style={{ minWidth: '80px' }}>
|
|
364
|
+
<Select.Option label="Up" value="1" />
|
|
365
|
+
<Select.Option label="Down" value="2" />
|
|
366
|
+
</Select>
|
|
367
|
+
<Text />
|
|
368
|
+
</ControlGroup>
|
|
369
|
+
|
|
370
|
+
<ControlGroup label="One control" controlsLayout="fillJoin">
|
|
371
|
+
<Select defaultValue="13" prefixLabel="Direction">
|
|
372
|
+
<Select.Option label="Up" value="1" />
|
|
373
|
+
<Select.Option label="Down" value="2" />
|
|
374
|
+
<Select.Divider />
|
|
375
|
+
<Select.Option label="Down" value="3" />
|
|
376
|
+
<Select.Option label="Left" value="4" />
|
|
377
|
+
<Select.Divider />
|
|
378
|
+
<Select.Option
|
|
379
|
+
label="Behind"
|
|
380
|
+
value="11"
|
|
381
|
+
disabled
|
|
382
|
+
description="back"
|
|
383
|
+
descriptionPosition="right"
|
|
384
|
+
/>
|
|
385
|
+
<Select.Option label="Over" value="12" description="Ya know what over means?" />
|
|
386
|
+
<Select.Option label={new Array(10).join('Truncate ')} value="13" truncate />
|
|
387
|
+
<Select.Option label={new Array(8).join('Wrap ')} value="14" disabled />
|
|
388
|
+
</Select>
|
|
389
|
+
</ControlGroup>
|
|
390
|
+
|
|
391
|
+
<ControlGroup label="Multiple controls" controlsLayout="fillJoin">
|
|
392
|
+
<Number defaultValue={10} />
|
|
393
|
+
<Select defaultValue="1" style={{ minWidth: '80px' }}>
|
|
394
|
+
<Select.Option label="Up" value="1" />
|
|
395
|
+
<Select.Option label="Down" value="2" />
|
|
396
|
+
<Select.Option label="Right" value="3" />
|
|
397
|
+
<Select.Option label="Left" value="4" />
|
|
398
|
+
</Select>
|
|
399
|
+
<Button label="Cancel" />
|
|
400
|
+
<Button label="Submit" />
|
|
401
|
+
</ControlGroup>
|
|
402
|
+
</div>
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export default LayoutFillJoin;
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
### No Layout
|
|
412
|
+
|
|
413
|
+
Removing the layout will allow controls to control their own size and wrap onto multiple lines. This should usually be used for Date, Number and Switch controls. Setting the control to inline, adjusting spacing, and/or setting a width may be necessary.
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
import React from 'react';
|
|
417
|
+
|
|
418
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
419
|
+
import Date from '@splunk/react-ui/Date';
|
|
420
|
+
import Number from '@splunk/react-ui/Number';
|
|
421
|
+
import RadioBar from '@splunk/react-ui/RadioBar';
|
|
422
|
+
import Switch from '@splunk/react-ui/Switch';
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
function LayoutNone() {
|
|
426
|
+
return (
|
|
427
|
+
<div>
|
|
428
|
+
<ControlGroup label="RadioBar no layout" controlsLayout="none">
|
|
429
|
+
<RadioBar defaultValue={3} inline style={{ width: '460px' }}>
|
|
430
|
+
<RadioBar.Option value={1} label="one" />
|
|
431
|
+
<RadioBar.Option value={2} label="two" />
|
|
432
|
+
<RadioBar.Option value={3} label="threethreethree" />
|
|
433
|
+
<RadioBar.Option value={4} label="four" />
|
|
434
|
+
</RadioBar>
|
|
435
|
+
</ControlGroup>
|
|
436
|
+
<ControlGroup label="Date no layout" controlsLayout="none">
|
|
437
|
+
<Date defaultValue="2017-04-05" />
|
|
438
|
+
</ControlGroup>
|
|
439
|
+
<ControlGroup label="Number no layout" controlsLayout="none">
|
|
440
|
+
<Number defaultValue={400} inline style={{ width: 90 }} />
|
|
441
|
+
</ControlGroup>
|
|
442
|
+
<ControlGroup label="Switch no layout" controlsLayout="none">
|
|
443
|
+
<Switch value="Breakfast">Breakfast</Switch>
|
|
444
|
+
<Switch value="Lunch">Lunch</Switch>
|
|
445
|
+
<Switch value="Supper">Supper</Switch>
|
|
446
|
+
</ControlGroup>
|
|
447
|
+
</div>
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export default LayoutNone;
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
### Customized Label Target
|
|
457
|
+
|
|
458
|
+
Change the focus/activation target that should be linked to the label.
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
import React, { Component } from 'react';
|
|
462
|
+
|
|
463
|
+
import Checkbox, { CheckboxChangeHandler } from '@splunk/react-ui/Checkbox';
|
|
464
|
+
import ControlGroup from '@splunk/react-ui/ControlGroup';
|
|
465
|
+
import Select from '@splunk/react-ui/Select';
|
|
466
|
+
import Text from '@splunk/react-ui/Text';
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
class CustomizedLabelTarget extends Component<object, { values: string[] }> {
|
|
470
|
+
constructor(props: object) {
|
|
471
|
+
super(props);
|
|
472
|
+
|
|
473
|
+
this.state = {
|
|
474
|
+
values: [],
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
handleClick: CheckboxChangeHandler = (e, { value }) => {
|
|
479
|
+
const prevValues = this.state.values;
|
|
480
|
+
if (value != null) {
|
|
481
|
+
if (prevValues.includes(value)) {
|
|
482
|
+
this.setState({
|
|
483
|
+
values: prevValues.filter((prevValue) => prevValue !== value),
|
|
484
|
+
});
|
|
485
|
+
} else {
|
|
486
|
+
this.setState({
|
|
487
|
+
values: prevValues.concat(value),
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
render() {
|
|
494
|
+
const selectedValues = this.state.values;
|
|
495
|
+
const CheckboxSwitches = ['1', '2', '3', '4', '5'].map((value) => (
|
|
496
|
+
<Checkbox
|
|
497
|
+
key={value}
|
|
498
|
+
value={value}
|
|
499
|
+
checked={selectedValues.includes(value)}
|
|
500
|
+
onChange={this.handleClick}
|
|
501
|
+
id={`customized-switch-${value}`}
|
|
502
|
+
>
|
|
503
|
+
{value}
|
|
504
|
+
</Checkbox>
|
|
505
|
+
));
|
|
506
|
+
|
|
507
|
+
return (
|
|
508
|
+
<div>
|
|
509
|
+
<ControlGroup
|
|
510
|
+
label="Two controls"
|
|
511
|
+
labelFor="customized-select-before"
|
|
512
|
+
help="Clicking the label will focus/activate the Select rather than the default first Text."
|
|
513
|
+
>
|
|
514
|
+
<Select defaultValue="1" inputId="customized-select-before">
|
|
515
|
+
<Select.Option label="Up" value="1" />
|
|
516
|
+
<Select.Option label="Down" value="2" />
|
|
517
|
+
</Select>
|
|
518
|
+
<Text />
|
|
519
|
+
</ControlGroup>
|
|
520
|
+
|
|
521
|
+
<ControlGroup
|
|
522
|
+
label="Two controls"
|
|
523
|
+
labelFor="customized-select-after"
|
|
524
|
+
help="Clicking the label will focus/activate the Select rather than the default first Text."
|
|
525
|
+
>
|
|
526
|
+
<Text />
|
|
527
|
+
<Select defaultValue="1" inputId="customized-select-after">
|
|
528
|
+
<Select.Option label="Up" value="1" />
|
|
529
|
+
<Select.Option label="Down" value="2" />
|
|
530
|
+
</Select>
|
|
531
|
+
</ControlGroup>
|
|
532
|
+
|
|
533
|
+
<ControlGroup
|
|
534
|
+
label="Multiple controls"
|
|
535
|
+
labelFor="customized-switch-4"
|
|
536
|
+
help="Clicking the label will focus/activate the fourth Switch rather than the default first child."
|
|
537
|
+
>
|
|
538
|
+
{CheckboxSwitches}
|
|
539
|
+
</ControlGroup>
|
|
540
|
+
</div>
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export default CustomizedLabelTarget;
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
## API
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
### ControlGroup API
|
|
555
|
+
|
|
556
|
+
`ControlGroup` places a label and optional help text around one or more controls. The `ControlGroup`
|
|
557
|
+
will automatically add aria attributes to associate the controls with the labels and help text to
|
|
558
|
+
address accessibility requirements.
|
|
559
|
+
|
|
560
|
+
`ControlGroup` provides layouts to assist in aligning and laying out controls, but the defaults are
|
|
561
|
+
not helpful in all cases, nor will the layout options address all cases. Consider setting
|
|
562
|
+
`controlsLayout` to none and manually positioning the controls as required.
|
|
563
|
+
|
|
564
|
+
`ControlGroup` uses the HTML `label` tag. The rules for determining which child component is linked
|
|
565
|
+
to the label's `for` attribute are:
|
|
566
|
+
1. If one or more `children` are `Text` components, the first one is used.
|
|
567
|
+
2. If there aren't any `Text` components, the first child is used.
|
|
568
|
+
|
|
569
|
+
If the linked child supports an `inputId` prop and it's set, its value is used for the label's `for`
|
|
570
|
+
attribute. If `inputId` is supported but not set a generated id is used instead. If `inputId` isn't
|
|
571
|
+
supported `id` is used. The `labelFor` prop may be used to override the `for` attribute.
|
|
572
|
+
|
|
573
|
+
#### Props
|
|
574
|
+
|
|
575
|
+
| Name | Type | Required | Default | Description |
|
|
576
|
+
|------|------|------|------|------|
|
|
577
|
+
| children | React.ReactNode | no | | |
|
|
578
|
+
| controlsLayout | 'fill' \| 'fillJoin' \| 'none' \| 'stack' | no | 'fill' | A layout defines how controls are aligned and displayed. |
|
|
579
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
580
|
+
| error | boolean \| string | no | false | Highlight the control group as having an error and optionally provide error text. If error text is provided, displays it below the control. In addition to passing this prop, set the error prop on child components. |
|
|
581
|
+
| help | React.ReactNode | no | | |
|
|
582
|
+
| hideLabel | boolean | no | | Hide the `label` visually but still render it for screen readers. Only enable this prop if the purpose of the control is clear enough from the context. Enabling this prop will hide `tooltip`. |
|
|
583
|
+
| label | string | yes | | |
|
|
584
|
+
| labelFor | string | no | | Override the `for` attribute of the `label`. See the component description for details. |
|
|
585
|
+
| labelPosition | 'left' \| 'top' | no | 'top' | |
|
|
586
|
+
| labelWidth | number \| string | no | 120 | When labelPosition is left, the width of the label in pixels or a value with a unit. |
|
|
587
|
+
| required | boolean | no | false | Sets the control required and adds an asterisk before the `label`. |
|
|
588
|
+
| tooltip | React.ReactNode | no | | Displays a tooltip beside the `label`. |
|
|
589
|
+
| tooltipDefaultPlacement | 'above' \| 'below' \| 'left' \| 'right' | no | | If a `tooltip` is provided, sets its default placement. |
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|