@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,253 @@
|
|
|
1
|
+
# Text Area
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> Image: Illustration of Text Area 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
|
+
- You need to capture multiline plain text, such as comments or descriptions
|
|
15
|
+
- You want to ask users an open-ended question, such as "Do you have any feedback?"
|
|
16
|
+
- When information cannot be predicted with a set of predefined options
|
|
17
|
+
|
|
18
|
+
## When to use another component
|
|
19
|
+
- If you need to capture single line plain text, use Text
|
|
20
|
+
- If you need to secure data, information, or a profile, use `Text` with `type="password"`
|
|
21
|
+
- When it's easier for users to select from a list options, use `Select` or `Multiselect`
|
|
22
|
+
|
|
23
|
+
```mermaid
|
|
24
|
+
graph TD
|
|
25
|
+
accDescr: Decision tree that guides on when to use the TextArea component or something else
|
|
26
|
+
A(Need to secure data?) -- No --- B(Need to capture multiple lines?)
|
|
27
|
+
B -- No --- C(Text)
|
|
28
|
+
B -- Yes --- D(Text Area)
|
|
29
|
+
A -- Yes --- E("Text type='password'")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Check out
|
|
33
|
+
- [Control Group][1]
|
|
34
|
+
- [Multiselect][2]
|
|
35
|
+
- [Select][3]
|
|
36
|
+
- [Text][4]
|
|
37
|
+
|
|
38
|
+
## Behaviors
|
|
39
|
+
|
|
40
|
+
### Min and Max rows
|
|
41
|
+
Text area will grow and shrink vertically based on the defined minimum and maximum number of rows. The default minimum is set to 2 rows, maximum rows is 8. When the content exceeds the max number of rows, Text Area will add a scroll bar.
|
|
42
|
+
|
|
43
|
+
> Image: Three text areas demonstrating dynamic resizing: the first with 2 rows as the minimum, the second with 8 rows as the maximum, and the third showing a scrollbar when content exceeds 8 rows.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### Placeholders
|
|
49
|
+
Placeholder text presents a number of visual and cognitive issues; it is best to avoid using it.
|
|
50
|
+
Placeholder does not replace a label. [Splunk Style Guide placeholder guidelines][5]
|
|
51
|
+
|
|
52
|
+
> Image: Comparison of two text areas labeled
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Text Area width
|
|
56
|
+
Don't extend Text Area across the entire width of a screen. To maintain usability and readability, ensure a width that doesn't exceeded 80 characters.
|
|
57
|
+
|
|
58
|
+
> Image: Two text areas labeled
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### Clear Text area
|
|
62
|
+
The suggested way to support a clear content action is a button with clear label and an icon placed outside of Text Area. Avoid placing the clear action inside Text area.
|
|
63
|
+
|
|
64
|
+
> Image: Two Text Areas examples labeled
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Text Area resize
|
|
68
|
+
Add a [resize][6] handle to provide user the ability to make Text Area size fit there needs.
|
|
69
|
+
|
|
70
|
+
> Image: Text Area example with heart eyes emoji labeled
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Content guidelines
|
|
75
|
+
|
|
76
|
+
### Labels
|
|
77
|
+
Labels are required. Keep Text Area labels brief and use sentence-style capitalization.
|
|
78
|
+
|
|
79
|
+
> Image: Two Text Area examples with labels demonstrating best practices: the first example with heart eyes emoji is labeled
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
[1]: ./ControlGroup
|
|
83
|
+
[2]: ./Multiselect
|
|
84
|
+
[3]: ./Select
|
|
85
|
+
[4]: ./Text
|
|
86
|
+
[5]: https://docs.splunk.com/Documentation/StyleGuide/drafts/StyleGuide/UIGuidelines#Placeholder_text
|
|
87
|
+
[6]: ./Resize
|
|
88
|
+
|
|
89
|
+
## Examples
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Controlled
|
|
93
|
+
|
|
94
|
+
Text Area requires a value prop and an onChange callback to update the value prop for most use cases.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import React, { useState } from 'react';
|
|
98
|
+
|
|
99
|
+
import TextArea, { TextAreaChangeHandler } from '@splunk/react-ui/TextArea';
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
const Basic = () => {
|
|
103
|
+
const [text, setText] = useState('');
|
|
104
|
+
const handleChange: TextAreaChangeHandler = (e, { value }) => {
|
|
105
|
+
setText(value);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return <TextArea value={text} onChange={handleChange} />;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export default Basic;
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### Uncontrolled
|
|
117
|
+
|
|
118
|
+
Alternatively, Text Area can be uncontrolled and optionally provided a defaultValue. The onChange callback still fires. The value prop cannot be set or updated externally.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import React from 'react';
|
|
122
|
+
|
|
123
|
+
import TextArea from '@splunk/react-ui/TextArea';
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
function Uncontrolled() {
|
|
127
|
+
return <TextArea defaultValue="Hello" />;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default Uncontrolled;
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
### Inline
|
|
136
|
+
|
|
137
|
+
Passing inline will create an inline element and the input will be its default size.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import React, { useState } from 'react';
|
|
141
|
+
|
|
142
|
+
import TextArea, { TextAreaChangeHandler } from '@splunk/react-ui/TextArea';
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
const Inline = () => {
|
|
146
|
+
const [text, setText] = useState('Hello');
|
|
147
|
+
const handleChange: TextAreaChangeHandler = (e, { value }) => {
|
|
148
|
+
setText(value);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return <TextArea inline value={text} onChange={handleChange} />;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export default Inline;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
### Disabled
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import React from 'react';
|
|
163
|
+
|
|
164
|
+
import TextArea from '@splunk/react-ui/TextArea';
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
const Disabled = () => <TextArea style={{ width: '250px' }} disabled />;
|
|
168
|
+
|
|
169
|
+
export default Disabled;
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
### Error
|
|
175
|
+
|
|
176
|
+
Setting error will highlight the field.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import React, { useState } from 'react';
|
|
180
|
+
|
|
181
|
+
import TextArea, { TextAreaChangeHandler } from '@splunk/react-ui/TextArea';
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
const Error = () => {
|
|
185
|
+
const [text, setText] = useState('invalid');
|
|
186
|
+
const handleChange: TextAreaChangeHandler = (e, { value }) => {
|
|
187
|
+
setText(value);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return <TextArea style={{ width: '250px' }} error value={text} onChange={handleChange} />;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export default Error;
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
## API
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
### TextArea API
|
|
203
|
+
|
|
204
|
+
Note: TextArea places role and aria props onto the input. All other props are placed on the wrapper.
|
|
205
|
+
|
|
206
|
+
#### Props
|
|
207
|
+
|
|
208
|
+
| Name | Type | Required | Default | Description |
|
|
209
|
+
|------|------|------|------|------|
|
|
210
|
+
| append | boolean | no | false | Append removes rounded borders and the border from the right side. |
|
|
211
|
+
| autoCapitalize | string | no | | Control the browser's automatic capitalization functionality. Note: Doesn't apply to physical keyboard input. Examples: 'on', 'off', 'sentences', 'words, 'characters'. |
|
|
212
|
+
| autoComplete | string | no | | Control the browser's autofill functionality. See [the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute) for details. Examples: 'on', 'off', 'cc-name', 'shipping street-address'. |
|
|
213
|
+
| autoCorrect | string | no | | Set the input's autocorrect attribute. Only supported by Safari. See also `spellCheck`. |
|
|
214
|
+
| autoFocus | boolean | no | false | Specify that the input should request focus when mounted. |
|
|
215
|
+
| children | React.ReactNode | no | | |
|
|
216
|
+
| defaultValue | string | no | | Set this property instead of value to make value uncontrolled. |
|
|
217
|
+
| describedBy | string | no | | The id of the description. When placed in a ControlGroup, this is automatically set to the ControlGroup's help component. |
|
|
218
|
+
| disabled | boolean | no | false | Determines whether or not the input is editable. |
|
|
219
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts, and null when it unmounts. |
|
|
220
|
+
| endAdornment | React.ReactNode | no | | Adornment after the input. |
|
|
221
|
+
| error | boolean | no | false | Highlight the field as having an error. The border will turn red. |
|
|
222
|
+
| inline | boolean | no | false | When false, display as inline-block with the default width. |
|
|
223
|
+
| inputId | string | no | | An id for the input, which may be necessary for accessibility, such as for aria attributes. |
|
|
224
|
+
| inputRef | React.Ref<HTMLTextAreaElement> | no | | A React ref which is set to the input element when the component mounts and null when it unmounts. |
|
|
225
|
+
| labelledBy | string | no | | The id of the label. When placed in a ControlGroup, this is automatically set to the ControlGroup's label. |
|
|
226
|
+
| maxLength | number | no | | Set the input's maxlength attribute. |
|
|
227
|
+
| name | string | no | | The name is returned with onChange events, which can be used to identify the control when multiple controls share an onChange callback. |
|
|
228
|
+
| onBlur | TextAreaBlurHandler | no | | A callback for when the input loses focus. |
|
|
229
|
+
| onChange | TextAreaChangeHandler | no | | This is equivalent to onInput which is called on keydown, paste, and so on. If value is set, this callback is required. This must set the value prop to retain the change. |
|
|
230
|
+
| onFocus | TextAreaFocusHandler | no | | A callback for when the input takes focus. |
|
|
231
|
+
| onInputClick | React.MouseEventHandler<HTMLTextAreaElement> | no | | A callback for when the user clicks the textbox. This will only trigger when the textbox itself is clicked and will not trigger for other parts of the component, such as nodes added via "startAdornment" or "endAdornment" props. If you want to handle all click events, pass the "onClick" prop, which will be attached to `TextArea`'s root element. |
|
|
232
|
+
| onKeyDown | React.KeyboardEventHandler<HTMLTextAreaElement> | no | | A keydown callback can be used to prevent a certain input by utilizing the event argument. |
|
|
233
|
+
| onSelect | React.ReactEventHandler<HTMLTextAreaElement> | no | | A callback for when the text selection or cursor position changes. |
|
|
234
|
+
| prepend | boolean | no | false | Prepend removes rounded borders from the left side. |
|
|
235
|
+
| rowsMax | number | no | 8 | Maximum number of rows to display |
|
|
236
|
+
| rowsMin | number | no | 2 | Minimum number of rows to display |
|
|
237
|
+
| spellCheck | boolean | no | | Control the browser's spelling and grammar checking functionality. |
|
|
238
|
+
| startAdornment | React.ReactNode | no | | Adornment in front of the input. |
|
|
239
|
+
| tabIndex | number | no | 0 | |
|
|
240
|
+
| value | string | no | | The contents of the input. Setting this value makes the property controlled. A callback is required. |
|
|
241
|
+
|
|
242
|
+
#### Types
|
|
243
|
+
|
|
244
|
+
| Name | Type | Description |
|
|
245
|
+
|------|------|------|
|
|
246
|
+
| TextAreaBlurHandler | ( event: React.FocusEvent<HTMLTextAreaElement>, data: { name?: string; value: string; } ) => void | |
|
|
247
|
+
| TextAreaChangeHandler | ( event: React.ChangeEvent<HTMLTextAreaElement>, data: { name?: string; value: string; } ) => void | |
|
|
248
|
+
| TextAreaFocusHandler | ( event: React.FocusEvent<HTMLTextAreaElement>, data: { name?: string; value: string; } ) => void | |
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
package/docs-llm/Text.md
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# Text
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> Image: Illustration of a text input
|
|
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
|
+
- When single line plain text is needed.
|
|
15
|
+
- When information cannot be predicted with a set of predefined options.
|
|
16
|
+
- When you need to secure data, information, or a profile, use `type="password"`.
|
|
17
|
+
|
|
18
|
+
## When to use another component
|
|
19
|
+
- If you need to capture multiline plain text, such as a comment or description, use `Text Area`.
|
|
20
|
+
- If you need to resize the input or validate character count, use `Text Area` or the `Resize` utility.
|
|
21
|
+
|
|
22
|
+
```mermaid
|
|
23
|
+
graph TD
|
|
24
|
+
accDescr: Decision tree that guides on when to use the Text component or something else
|
|
25
|
+
A(Need to secure data?) -- No --- B(Need to capture multiple lines?)
|
|
26
|
+
B -- No --- C(Text)
|
|
27
|
+
B -- Yes --- D(Text Area)
|
|
28
|
+
A -- Yes --- E("type='password'")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Check out
|
|
32
|
+
- [Control Group][1]
|
|
33
|
+
- [Text Area][2]
|
|
34
|
+
- [Resize][3]
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Placeholders
|
|
39
|
+
Since placeholder text presents a number of visual and cognitive issues, it is best to avoid using it.
|
|
40
|
+
Placeholder does not replace a label. [Splunk Style Guide placeholder guidelines][4]
|
|
41
|
+
> Image: Examples of using placeholder text in the Text component. The first example with heart eyes emoji has a Text component labeled
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Text width
|
|
45
|
+
Adjust the width to accommodate the anticipated input length, ensuring it is sufficiently wide to support the longest expected values. Avoid extending `Text` across the entire width of large screens to maintain usability and readability.
|
|
46
|
+
> Image: Examples of Text component widths. The first example with heart eyes emoji has a Text component labeled
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Content guidelines
|
|
50
|
+
|
|
51
|
+
### Labels
|
|
52
|
+
Labels are required, keep Text labels brief and use sentence-style capitalization.
|
|
53
|
+
> Image: Example of keeping Text component labels brief. The first example with heart eyes emoji has a Text component labeled
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
[1]: ./ControlGroup
|
|
57
|
+
[2]: ./TextArea
|
|
58
|
+
[3]: ./Resize
|
|
59
|
+
[4]: https://docs.splunk.com/Documentation/StyleGuide/drafts/StyleGuide/UIGuidelines#Placeholder_text
|
|
60
|
+
|
|
61
|
+
## Examples
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Controlled
|
|
65
|
+
|
|
66
|
+
Text requires a value prop and an onChange callback to update the value prop for most use cases.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import React, { useState } from 'react';
|
|
70
|
+
|
|
71
|
+
import Text, { TextChangeHandler } from '@splunk/react-ui/Text';
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const Basic = () => {
|
|
75
|
+
const [value, setValue] = useState<string | undefined>('');
|
|
76
|
+
|
|
77
|
+
const handleChange: TextChangeHandler = (e, { value: newValue }) => {
|
|
78
|
+
setValue(newValue);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return <Text canClear value={value} onChange={handleChange} />;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default Basic;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
### Uncontrolled
|
|
90
|
+
|
|
91
|
+
Alternatively, Text can be uncontrolled and optionally provided a defaultValue. The onChange callback still fires. The value prop cannot be set or updated externally.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import React from 'react';
|
|
95
|
+
|
|
96
|
+
import Text from '@splunk/react-ui/Text';
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
function Uncontrolled() {
|
|
100
|
+
return <Text defaultValue="Hello" canClear />;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default Uncontrolled;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### Inline
|
|
109
|
+
|
|
110
|
+
Passing inline will create an inline element and the input will be its default size.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import React, { useState } from 'react';
|
|
114
|
+
|
|
115
|
+
import Text, { TextChangeHandler } from '@splunk/react-ui/Text';
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
const Inline = () => {
|
|
119
|
+
const [value, setValue] = useState<string | undefined>('');
|
|
120
|
+
|
|
121
|
+
const handleChange: TextChangeHandler = (e, { value: newValue }) => {
|
|
122
|
+
setValue(newValue);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return <Text inline value={value} onChange={handleChange} />;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default Inline;
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### Dimmed
|
|
134
|
+
|
|
135
|
+
If you absolutely need to disable a Text use a dimmed Text. When the disabled prop is set to "dimmed", the Text does not respond to events but can still receive focus to ensure users can navigate to the Text when using assistive technologies. This also sets aria-disabled to true.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import React from 'react';
|
|
139
|
+
|
|
140
|
+
import Text from '@splunk/react-ui/Text';
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
const Dimmed = () => <Text disabled="dimmed" defaultValue="This cannot be edited." inline />;
|
|
144
|
+
|
|
145
|
+
export default Dimmed;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
### Disabled
|
|
151
|
+
|
|
152
|
+
Disabled cannot accept an input or become focused.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import React from 'react';
|
|
156
|
+
|
|
157
|
+
import Text from '@splunk/react-ui/Text';
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
const Disabled = () => <Text disabled defaultValue="This cannot be edited." inline />;
|
|
161
|
+
|
|
162
|
+
export default Disabled;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
### Error
|
|
168
|
+
|
|
169
|
+
Setting error will highlight the field.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import React, { useState } from 'react';
|
|
173
|
+
|
|
174
|
+
import Text, { TextChangeHandler } from '@splunk/react-ui/Text';
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
const Error = () => {
|
|
178
|
+
const [value, setValue] = useState<string | undefined>('invalid');
|
|
179
|
+
|
|
180
|
+
const handleChange: TextChangeHandler = (e, { value: newValue }) => {
|
|
181
|
+
setValue(newValue);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return <Text error inline value={value} onChange={handleChange} />;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export default Error;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### Password
|
|
193
|
+
|
|
194
|
+
The Text control also supports a password input type and visibility toggle independently of each other.
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import React, { useState } from 'react';
|
|
198
|
+
|
|
199
|
+
import Text, { TextChangeHandler } from '@splunk/react-ui/Text';
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
const Password = () => {
|
|
203
|
+
const [value, setValue] = useState<string | undefined>('password123');
|
|
204
|
+
|
|
205
|
+
const handleChange: TextChangeHandler = (e, { value: newValue }) => {
|
|
206
|
+
setValue(newValue);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<>
|
|
211
|
+
<Text inline type="password" value={value} onChange={handleChange} />
|
|
212
|
+
|
|
213
|
+
<br />
|
|
214
|
+
<br />
|
|
215
|
+
|
|
216
|
+
<Text inline passwordVisibilityToggle defaultValue="password123" onChange={() => {}} />
|
|
217
|
+
</>
|
|
218
|
+
);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export default Password;
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### StyledButton
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import React from 'react';
|
|
230
|
+
|
|
231
|
+
import styled from 'styled-components';
|
|
232
|
+
|
|
233
|
+
import LinesThree from '@splunk/react-icons/LinesThree';
|
|
234
|
+
import Magnifier from '@splunk/react-icons/Magnifier';
|
|
235
|
+
import PaperFolded from '@splunk/react-icons/PaperFolded';
|
|
236
|
+
import Portrait from '@splunk/react-icons/Portrait';
|
|
237
|
+
import Button from '@splunk/react-ui/Button';
|
|
238
|
+
import Text from '@splunk/react-ui/Text';
|
|
239
|
+
|
|
240
|
+
const StyledButton = styled(Button)`
|
|
241
|
+
min-width: 24px;
|
|
242
|
+
min-height: 24px;
|
|
243
|
+
margin: 4px;
|
|
244
|
+
`;
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
const CustomizedIcon = () => (
|
|
248
|
+
<>
|
|
249
|
+
<Text defaultValue="" inline startAdornment={<div>$</div>} endAdornment={<div>.00</div>} />
|
|
250
|
+
<br />
|
|
251
|
+
<br />
|
|
252
|
+
<Text
|
|
253
|
+
defaultValue=""
|
|
254
|
+
startAdornment={
|
|
255
|
+
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
256
|
+
<Portrait variant="filled" />
|
|
257
|
+
</div>
|
|
258
|
+
}
|
|
259
|
+
inline
|
|
260
|
+
/>
|
|
261
|
+
<br />
|
|
262
|
+
<br />
|
|
263
|
+
<Text
|
|
264
|
+
defaultValue=""
|
|
265
|
+
endAdornment={
|
|
266
|
+
<>
|
|
267
|
+
<StyledButton appearance="secondary" icon={<Magnifier />} />
|
|
268
|
+
<span>|</span>
|
|
269
|
+
<StyledButton appearance="secondary" icon={<PaperFolded />} />
|
|
270
|
+
</>
|
|
271
|
+
}
|
|
272
|
+
inline
|
|
273
|
+
startAdornment={<StyledButton appearance="secondary" icon={<LinesThree />} />}
|
|
274
|
+
/>
|
|
275
|
+
</>
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
export default CustomizedIcon;
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
## API
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
### Text API
|
|
288
|
+
|
|
289
|
+
Note: Text places role and aria props onto the input. All other props are placed on the wrapper.
|
|
290
|
+
|
|
291
|
+
#### Props
|
|
292
|
+
|
|
293
|
+
| Name | Type | Required | Default | Description |
|
|
294
|
+
|------|------|------|------|------|
|
|
295
|
+
| append | boolean | no | false | Append removes rounded borders and the border from the right side. |
|
|
296
|
+
| autoCapitalize | string | no | | Control the browser's automatic capitalization functionality. Note: Doesn't apply to physical keyboard input. Examples: 'on', 'off', 'sentences', 'words, 'characters'. |
|
|
297
|
+
| autoComplete | string | no | | Control the browser's autofill functionality. See [the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute) for details. Examples: 'on', 'off', 'cc-name', 'shipping street-address'. |
|
|
298
|
+
| autoCorrect | string | no | | Set the input's autocorrect attribute. Only supported by Safari. See also `spellCheck`. |
|
|
299
|
+
| autoFocus | boolean | no | false | Specify that the input should request focus when mounted. |
|
|
300
|
+
| canClear | boolean | no | false | Include an "X" button to clear the value. If `passwordVisibilityToggle` is `true`, this prop is ignored. |
|
|
301
|
+
| children | React.ReactNode | no | | |
|
|
302
|
+
| defaultValue | string | no | | Set this property instead of value to make value uncontrolled. |
|
|
303
|
+
| describedBy | string | no | | The id of the description. When placed in a ControlGroup, this is automatically set to the ControlGroup's help component. |
|
|
304
|
+
| disabled | boolean \| 'dimmed' | no | false | Determines whether or not the input is editable. If set to `"dimmed"`, the menu item does not respond to events but can still receive focus, and `aria-disabled` is set to `true`. |
|
|
305
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts, and null when it unmounts. |
|
|
306
|
+
| endAdornment | React.ReactNode | no | | Adornment after the input. |
|
|
307
|
+
| error | boolean | no | false | Highlight the field as having an error. The border and text will turn red. |
|
|
308
|
+
| inline | boolean | no | false | When false, display as inline-block with the default width. |
|
|
309
|
+
| inputId | string | no | | An id for the input, which may be necessary for accessibility, such as for aria attributes. |
|
|
310
|
+
| inputRef | React.Ref<HTMLInputElement> | no | | A React ref which is set to the input element when the component mounts and null when it unmounts. |
|
|
311
|
+
| labelledBy | string | no | | The id of the label. When placed in a ControlGroup, this is automatically set to the ControlGroup's label. |
|
|
312
|
+
| maxLength | number | no | | Set the input's maxlength attribute. |
|
|
313
|
+
| name | string | no | | The name is returned with onChange events, which can be used to identify the control when multiple controls share an onChange callback. |
|
|
314
|
+
| onBlur | TextBlurHandler | no | | A callback for when the input loses focus. |
|
|
315
|
+
| onChange | TextChangeHandler | no | | This is equivalent to onInput which is called on keydown, paste, and so on. If value is set, this callback is required. This must set the value prop to retain the change. |
|
|
316
|
+
| onClick | React.MouseEventHandler<HTMLInputElement> | no | | A callback for when the user clicks the textbox. This will only trigger when the textbox itself is clicked and will not trigger for other parts of the component, such as the clear button or nodes added via "startAdornment" or "endAdornment" props. |
|
|
317
|
+
| onFocus | TextFocusHandler | no | | A callback for when the input takes focus. |
|
|
318
|
+
| onKeyDown | React.KeyboardEventHandler<HTMLInputElement> | no | | A keydown callback can be used to prevent a certain input by utilizing the event argument. |
|
|
319
|
+
| onSelect | React.ReactEventHandler<HTMLInputElement> | no | | A callback for when the text selection or cursor position changes. |
|
|
320
|
+
| passwordVisibilityToggle | boolean | no | false | Allow password visibility to be toggled with an icon button. If this is enabled, `type` prop will be ignored. |
|
|
321
|
+
| prepend | boolean | no | false | Prepend removes rounded borders from the left side. |
|
|
322
|
+
| spellCheck | boolean | no | | Control the browser's spelling and grammar checking functionality. |
|
|
323
|
+
| startAdornment | React.ReactNode | no | | Adornment in front of the input. |
|
|
324
|
+
| tabIndex | number | no | 0 | |
|
|
325
|
+
| type | string | no | 'text' | Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types). @default 'text' |
|
|
326
|
+
| value | string | no | | The contents of the input. Setting this value makes the property controlled. A callback is required. |
|
|
327
|
+
|
|
328
|
+
#### Types
|
|
329
|
+
|
|
330
|
+
| Name | Type | Description |
|
|
331
|
+
|------|------|------|
|
|
332
|
+
| TextBlurHandler | ( event: React.FocusEvent<HTMLInputElement>, data: { name?: string; value: string; } ) => void | |
|
|
333
|
+
| TextChangeHandler | ( event: React.ChangeEvent<HTMLInputElement> \| React.MouseEvent<HTMLSpanElement>, data: { name?: string; value: string; } ) => void | |
|
|
334
|
+
| TextFocusHandler | ( event: React.FocusEvent<HTMLInputElement>, data: { name?: string; value: string; } ) => void | |
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|