@splunk/react-ui 5.7.1 → 5.9.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/Anchor.js +2 -1
- package/Box.js +83 -34
- package/CHANGELOG.md +51 -0
- package/Calendar.js +134 -134
- package/Clickable.js +131 -94
- package/CollapsiblePanel.js +175 -137
- package/ComboBox.js +32 -27
- package/ControlGroup.js +92 -91
- package/DefinitionList.js +9 -9
- package/Drawer.d.ts +2 -0
- package/Drawer.js +679 -0
- package/Dropdown.js +27 -18
- package/DualListbox.js +1 -1
- package/File.js +35 -35
- package/JSONTree.js +73 -72
- package/Link.js +2 -2
- package/MIGRATION.md +10 -0
- package/Menu.js +403 -261
- package/Modal.js +263 -252
- package/Monogram.js +2 -2
- package/Multiselect.js +551 -385
- package/Number.js +2 -1
- package/Paginator.js +14 -12
- package/Popover.js +4 -1
- package/README.md +11 -0
- package/RadioBar.js +1 -1
- package/Search.js +111 -95
- package/Select.js +42 -40
- package/SelectBase.js +819 -715
- package/SidePanel.js +346 -167
- package/SlidingPanels.js +11 -11
- package/StepBar.js +7 -7
- package/Switch.js +5 -5
- package/Table.js +116 -119
- package/Text.js +48 -48
- package/TextArea.js +7 -7
- package/TransitionOpen.js +188 -169
- 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 +292 -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 +939 -0
- package/docs-llm/Notifications.md +46 -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 +591 -0
- package/docs-llm/Typography.md +125 -0
- package/docs-llm/Wait Spinner.md +121 -0
- package/docs-llm/llms.txt +101 -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/Multiselect/Compact.d.ts +8 -3
- package/types/src/Multiselect/Multiselect.d.ts +8 -3
- package/types/src/Multiselect/Normal.d.ts +8 -3
- package/types/src/Multiselect/Option.d.ts +6 -3
- package/types/src/Multiselect/docs/examples/Disabled.d.ts +1 -0
- 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,267 @@
|
|
|
1
|
+
# Accordion
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
> Image: Illustration of a group of accordion components with the second accordion expanded to show its content.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## When to use this component
|
|
11
|
+
|
|
12
|
+
<Message appearance="fill" type="warning">
|
|
13
|
+
<Message.Title>
|
|
14
|
+
<strong>Use Collapsible Panel</strong>
|
|
15
|
+
<p>Collapsible Panel supports expanding a single or multiple panels.
|
|
16
|
+
It is suggested to use <Link to="./CollapsiblePanel">Collapsible Panel</Link> as Accordion is deprecated and will be removed in a future major version.</p>
|
|
17
|
+
</Message.Title>
|
|
18
|
+
</Message>
|
|
19
|
+
|
|
20
|
+
- When you have a large amount of non-essential content to show, and want to allow people to have control over the content visibility
|
|
21
|
+
- When you want to progressively disclose information or provide step-by-step guidance
|
|
22
|
+
- When you want to group related content and optimize space and information density
|
|
23
|
+
- When you are showing content on a small screen to reduce scrolling
|
|
24
|
+
|
|
25
|
+
## When to use another component
|
|
26
|
+
- If you need to expand a single or multiple panels at a time, use `Collapsible Panel`.
|
|
27
|
+
- If there are only one or two sections, it is better to display the content without requiring user interaction.
|
|
28
|
+
- If the content is critical and should always be visible, use a `list` or display the content without requiring user interaction.
|
|
29
|
+
- For information that needs to be viewed, grouped, or compared across categories use a `Table`.
|
|
30
|
+
- For large amounts of categorical content or for content that is not well-suited for organizing into sections, consider displaying this information using `Tab Bar`.
|
|
31
|
+
|
|
32
|
+
```mermaid
|
|
33
|
+
graph TD
|
|
34
|
+
accDescr: Decision tree that guides on when to use the Accordion component or something else
|
|
35
|
+
A(Is it critical content that should always be visible?) -- Yes --- B(List)
|
|
36
|
+
A -- No --- C(Is there a lot of content?)
|
|
37
|
+
C -- Yes --- D(Tab)
|
|
38
|
+
C -- No --- E(Accordion - suggested to use Collapsible Panel)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Check out
|
|
42
|
+
- [Collapsible Panel][1]
|
|
43
|
+
- [List][2]
|
|
44
|
+
- [Table][3]
|
|
45
|
+
- [Tab bar][4]
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Limit content
|
|
50
|
+
Avoid filling accordions with lots of content. Instead, use small, digestible chunks for the user.
|
|
51
|
+
|
|
52
|
+
> Image: Heart eye example with digestible amount of content next to a grimacing face example of an accordion with to much content
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Order panels logically
|
|
56
|
+
When your accordion panels need to be read in a specific order, order panels logically.
|
|
57
|
+
|
|
58
|
+
> Image: Heart eye example with accordions label in sequential order 1 - 4 next to a grimacing face example where the accordions are out of order 2, 1, 4, 3
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Content guidelines
|
|
62
|
+
|
|
63
|
+
### Panel title:
|
|
64
|
+
- Write a concise title that describes the associated body content so the user can decide whether to read the body content.
|
|
65
|
+
- Use sentence-style capitalization and capitalize the first word and proper nouns only.
|
|
66
|
+
- Don’t use punctuation such as periods, commas, or exclamation marks.
|
|
67
|
+
|
|
68
|
+
### Panel body:
|
|
69
|
+
- If you have a lot of content, split body content into paragraphs to create smaller chunks that are easier to read.
|
|
70
|
+
- Write in complete sentences with end punctuation.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
[1]: ./CollapsiblePanel
|
|
74
|
+
[2]: ./List
|
|
75
|
+
[3]: ./Table
|
|
76
|
+
[4]: ./TabBar
|
|
77
|
+
|
|
78
|
+
## Examples
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Controlled
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import React, { useState } from 'react';
|
|
85
|
+
|
|
86
|
+
import Accordion, { AccordionChangeHandler } from '@splunk/react-ui/Accordion';
|
|
87
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
function Controlled() {
|
|
91
|
+
const [openPanelId, setOpenPanelId] = useState<string | number | undefined>(2);
|
|
92
|
+
|
|
93
|
+
const handleChange: AccordionChangeHandler = (e, { panelId: panelValue }) => {
|
|
94
|
+
setOpenPanelId(panelValue);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Accordion openPanelId={openPanelId} onChange={handleChange}>
|
|
99
|
+
<Accordion.Panel panelId={1} title="Panel 1">
|
|
100
|
+
<P>
|
|
101
|
+
This is the content of Panel 1. Here is some more information. Additional
|
|
102
|
+
details can be placed here.
|
|
103
|
+
</P>
|
|
104
|
+
</Accordion.Panel>
|
|
105
|
+
<Accordion.Panel panelId={2} title="Panel 2">
|
|
106
|
+
<P>This is the content of Panel 2.</P>
|
|
107
|
+
</Accordion.Panel>
|
|
108
|
+
<Accordion.Panel panelId={3} title="Panel 3">
|
|
109
|
+
<P>This is the content of Panel 3. More information for Panel 3.</P>
|
|
110
|
+
</Accordion.Panel>
|
|
111
|
+
</Accordion>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default Controlled;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### Uncontrolled
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import React from 'react';
|
|
124
|
+
|
|
125
|
+
import Accordion from '@splunk/react-ui/Accordion';
|
|
126
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
function Uncontrolled() {
|
|
130
|
+
return (
|
|
131
|
+
<Accordion defaultOpenPanelId={2}>
|
|
132
|
+
<Accordion.Panel panelId={1} title="Panel 1">
|
|
133
|
+
<P>
|
|
134
|
+
This is the content of Panel 1. Here is some more information. Additional
|
|
135
|
+
details can be placed here.
|
|
136
|
+
</P>
|
|
137
|
+
</Accordion.Panel>
|
|
138
|
+
<Accordion.Panel panelId={2} title="Panel 2">
|
|
139
|
+
<P>This is the content of Panel 2.</P>
|
|
140
|
+
</Accordion.Panel>
|
|
141
|
+
<Accordion.Panel panelId={3} title="Panel 3">
|
|
142
|
+
<P>This is the content of Panel 3. More information for Panel 3.</P>
|
|
143
|
+
</Accordion.Panel>
|
|
144
|
+
</Accordion>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default Uncontrolled;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### Inset
|
|
154
|
+
|
|
155
|
+
inset adds padding to the Accordion Panel. This can be set on the Accordion, or individual Panels. Individual Panels can override inset from their parent Accordion.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import React, { useState } from 'react';
|
|
159
|
+
|
|
160
|
+
import Accordion, { AccordionChangeHandler } from '@splunk/react-ui/Accordion';
|
|
161
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
const Inset = () => {
|
|
165
|
+
const [openPanelId, setOpenPanelId] = useState<string | number | undefined>(1);
|
|
166
|
+
|
|
167
|
+
const handleChange: AccordionChangeHandler = (e, data) => {
|
|
168
|
+
setOpenPanelId(data.panelId);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<Accordion openPanelId={openPanelId} onChange={handleChange}>
|
|
173
|
+
<Accordion.Panel panelId={1} title="Inset true (default)" inset>
|
|
174
|
+
<P>This panel has inset enabled. Content is padded.</P>
|
|
175
|
+
</Accordion.Panel>
|
|
176
|
+
<Accordion.Panel panelId={2} title="Inset false" inset={false}>
|
|
177
|
+
<P>This panel has inset disabled. Content is flush with the edges.</P>
|
|
178
|
+
</Accordion.Panel>
|
|
179
|
+
</Accordion>
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export default Inset;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
## API
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### Accordion API
|
|
193
|
+
|
|
194
|
+
@deprecated
|
|
195
|
+
Accordion has been deprecated and will be removed in a future major version. Use Collapsible Panel's SingleOpenPanelGroup API instead.
|
|
196
|
+
|
|
197
|
+
#### Props
|
|
198
|
+
|
|
199
|
+
| Name | Type | Required | Default | Description |
|
|
200
|
+
|------|------|------|------|------|
|
|
201
|
+
| children | React.ReactNode | no | | Must be `Accordion.Panel`. |
|
|
202
|
+
| defaultOpenPanelId | string \| number | no | | Sets the panel to expand on the initial render. Use only when using `Accordion` as an uncontrolled component. Must match the `panelId` of one of the `Accordion.Panel` children. |
|
|
203
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
204
|
+
| inset | boolean | no | true | Inset Accordions have padding for content to the panels |
|
|
205
|
+
| onChange | AccordionChangeHandler | no | | Invoked on a change of the open panel. Callback is passed data, such as the `panelId` of the `Accordion.Panel` that originated the expand request. `panelId` is `undefined` when the open panel is collapsed. |
|
|
206
|
+
| openPanelId | string \| number | no | | Indicates the `panelId` of the currently expanded `Accordion.Panel`. Use only when using `Accordion` as a controlled component. |
|
|
207
|
+
|
|
208
|
+
#### Types
|
|
209
|
+
|
|
210
|
+
| Name | Type | Description |
|
|
211
|
+
|------|------|------|
|
|
212
|
+
| AccordionChangeHandler | ( event: React.MouseEvent<HTMLButtonElement>, data: { event: React.MouseEvent<HTMLButtonElement>; panelId?: string \| number; reason: 'toggleClick'; } ) => void | |
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
### Accordion.Panel API
|
|
217
|
+
|
|
218
|
+
`Accordion.Panel` operates as a container component for content in an `Accordion`.
|
|
219
|
+
|
|
220
|
+
#### Props
|
|
221
|
+
|
|
222
|
+
| Name | Type | Required | Default | Description |
|
|
223
|
+
|------|------|------|------|------|
|
|
224
|
+
| description | string | no | | Displays right-aligned text in the title bar of the panel. |
|
|
225
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
226
|
+
| inset | boolean | no | | When `true` renders the Panel with padding. When `false` render the Panel without padding. |
|
|
227
|
+
| panelId | string \| number | no | | Identifies the unique `id` for a panel. `Accordion` uses 'panelID' to track the expanded panel. |
|
|
228
|
+
| title | React.ReactNode | yes | | Displays the the name of the panel in its title bar. |
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
## Accessibility
|
|
235
|
+
|
|
236
|
+
## Visual Design
|
|
237
|
+
- Color contrast ratio **MUST** be:
|
|
238
|
+
- >= 4.5:1 for normal text: 14 pt (typically 18.66px) and bold or larger [SC 1.4.3][1]
|
|
239
|
+
- >= 3:1 for large text: 18 pt (typically 24px) or larger [SC 1.4.3][1]
|
|
240
|
+
- >= 3:1 for arrow icon against accordion header background [SC 1.4.11][2]
|
|
241
|
+
- Focus State: If the focus ring has a radius of [SC 1.4.11][2]
|
|
242
|
+
- < 3px: >= 4.5.1 between button <> focus <> background
|
|
243
|
+
- > 3px: >= 3.1 button button <> focus <> background
|
|
244
|
+
|
|
245
|
+
## Content
|
|
246
|
+
- Accordion titles **SHOULD** be between 60-80 characters; any more can lose a user's attention or negatively impact neurodivergent users
|
|
247
|
+
|
|
248
|
+
## States
|
|
249
|
+
- Color contrast does not apply to a disabled accordion
|
|
250
|
+
|
|
251
|
+
## Interaction Design
|
|
252
|
+
- **MUST** have keyboard navigation [SC 2.1][3]
|
|
253
|
+
- <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move through accordion headers OR when open, any interactive elements within the accordion
|
|
254
|
+
- <kbd>Space</kbd> and <kbd>Enter</kbd> to collapse or expand the accordion header when focused. In addition, any interactive elements within the accordion that are focused
|
|
255
|
+
|
|
256
|
+
## Implementation
|
|
257
|
+
- Accordion header(summary) **MUST** be kept in the parent/trigger attribute, while all details are kept in the child attribute
|
|
258
|
+
- Screen reader **MUST** announce when accordion is focused [SC 4.1.2][4]
|
|
259
|
+
- Header title
|
|
260
|
+
- Announcement should be made when user successfully closes or expands accordion
|
|
261
|
+
|
|
262
|
+
[1]: https://www.w3.org/TR/WCAG21/#contrast-minimum
|
|
263
|
+
[2]: https://www.w3.org/TR/WCAG21/#non-text-contrast
|
|
264
|
+
[3]: https://www.w3.org/TR/WCAG21/#keyboard-accessible
|
|
265
|
+
[4]: https://www.w3.org/TR/WCAG21/#name-role-value
|
|
266
|
+
|
|
267
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Anchor Menu
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> Image: Illustration of an Anchor Menu.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## When to use this component
|
|
10
|
+
|
|
11
|
+
- When you have long-form content with multiple sections that users need to navigate within a single page.
|
|
12
|
+
- For providing a table of contents or outline view of page content.
|
|
13
|
+
|
|
14
|
+
## When to use another component
|
|
15
|
+
|
|
16
|
+
- For switching between different content views, use [`TabBar`] [1]
|
|
17
|
+
|
|
18
|
+
```mermaid
|
|
19
|
+
graph TD
|
|
20
|
+
accDescr: Decision tree that guides on when to use the Anchor Menu component or something else
|
|
21
|
+
A(Need to split content on the same page?) -- Yes --- B(Is the content hierarchically or thematically related?)
|
|
22
|
+
A -- No --- G(Use standard page layout)
|
|
23
|
+
B -- Yes --- C(Do you want to provide a high-level view of the page’s structure and content and quickly navigate to a section?)
|
|
24
|
+
B -- No --- D(Tab Bar)
|
|
25
|
+
|
|
26
|
+
C -- Yes --- E(Anchor Menu)
|
|
27
|
+
C -- No --- F(Sections without Anchor Menu)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Check out
|
|
31
|
+
- [TabBar] [1]
|
|
32
|
+
|
|
33
|
+
## Behavior
|
|
34
|
+
|
|
35
|
+
### Appearance
|
|
36
|
+
|
|
37
|
+
#### Show the current page
|
|
38
|
+
Indicate where a user is within the navigational hierarchy. Pass the `itemId` to the `activeItemId` prop to set the currently active item to show users which page they have navigated to.
|
|
39
|
+
|
|
40
|
+
> Image: Examples of Anchor Menu active state highlighting. The first example with heart eyes emoji shows proper use of activeItemId to clearly indicate the current page section. The second example with grimacing emoji shows unclear active state indication that doesn
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
#### Spine
|
|
44
|
+
You can hide the side border spine. This is useful when the `AnchorMenu` is placed inside a container with its own border.
|
|
45
|
+
|
|
46
|
+
> Image: Examples of Anchor Menu spine border treatment, one with the spine border and the other without.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Scrolling behavior
|
|
50
|
+
Clicking a menu link scrolls to the corresponding content section and updates the active indicator. The menu remains visible and updates the current location as users scroll through the page.
|
|
51
|
+
|
|
52
|
+
> Image: Example of Anchor Menu scrolling behavior. The example shows the Anchor Menu sticking to the top of the page as the content scrolls down.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### Nesting
|
|
58
|
+
Use [`CollapsiblePanel`] [2] to group `AnchorMenu` links. Limit grouping to 1 level to maintain usability and prevent overwhelming users.
|
|
59
|
+
|
|
60
|
+
> Image: Examples of Anchor Menu nesting with Collapsible Panels.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Links
|
|
64
|
+
Only use `AnchorMenu` to help users navigate within the same page. Don't use them to navigate to different pages.
|
|
65
|
+
|
|
66
|
+
> Image: Examples of Anchor Menu link usage. The first example with heart eyes emoji shows proper same-page navigation with anchor links to content sections. The second example with grimacing emoji shows incorrect use for cross-page navigation that breaks user expectations.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
[1]: ./TabBar
|
|
70
|
+
[2]: ./CollapsiblePanel
|
|
71
|
+
|
|
72
|
+
## Examples
|
|
73
|
+
|
|
74
|
+
import React from 'react';
|
|
75
|
+
|
|
76
|
+
import DocExample from '@splunk/react-docs/DocExample';
|
|
77
|
+
import ExamplesPage from '@splunk/react-docs/ExamplesPage';
|
|
78
|
+
|
|
79
|
+
const examples = require.context('./examples/');
|
|
80
|
+
const examplesRaw = require.context('./examples/?prepareExamples');
|
|
81
|
+
|
|
82
|
+
function ExamplesSection() {
|
|
83
|
+
return (
|
|
84
|
+
<ExamplesPage>
|
|
85
|
+
<DocExample
|
|
86
|
+
key="Basic"
|
|
87
|
+
code={examplesRaw('./Basic')}
|
|
88
|
+
example={examples('./Basic').default}
|
|
89
|
+
/>
|
|
90
|
+
</ExamplesPage>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default ExamplesSection;
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### AnchorMenu API
|
|
101
|
+
|
|
102
|
+
#### Props
|
|
103
|
+
|
|
104
|
+
| Name | Type | Required | Default | Description |
|
|
105
|
+
|------|------|------|------|------|
|
|
106
|
+
| activeItemId | string | no | | The `itemId` prop of the currently active item. |
|
|
107
|
+
| children | React.ReactNode | no | | |
|
|
108
|
+
| elementRef | React.Ref<HTMLElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
109
|
+
| hideSpine | boolean | no | | Hides the side border spine. Useful when the AnchorMenu is placed inside a container with its own border. |
|
|
110
|
+
| label | string \| null | no | _('On this page:') | Label text to display above the menu items. Set to `null` to disable the label. |
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Anchor
|
|
2
|
+
|
|
3
|
+
## Examples
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Basic
|
|
7
|
+
|
|
8
|
+
`Anchor` can be added to any `Heading` level.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import React from 'react';
|
|
12
|
+
|
|
13
|
+
import Anchor from '@splunk/react-ui/Anchor';
|
|
14
|
+
import Heading from '@splunk/react-ui/Heading';
|
|
15
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
16
|
+
import Prose from '@splunk/react-ui/Prose';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function Basic() {
|
|
20
|
+
return (
|
|
21
|
+
<Prose>
|
|
22
|
+
<Heading level={1}>
|
|
23
|
+
<Anchor name="Heading 1">Heading 1</Anchor>
|
|
24
|
+
</Heading>
|
|
25
|
+
<P>This is the content below Heading 1.</P>
|
|
26
|
+
</Prose>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default Basic;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## API
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Anchor API
|
|
40
|
+
|
|
41
|
+
`Anchor` is a utility component used to add a fragment link to an element.
|
|
42
|
+
|
|
43
|
+
#### Props
|
|
44
|
+
|
|
45
|
+
| Name | Type | Required | Default | Description |
|
|
46
|
+
|------|------|------|------|------|
|
|
47
|
+
| children | React.ReactNode | no | | |
|
|
48
|
+
| elementRef | React.Ref<HTMLAnchorElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
49
|
+
| name | string | yes | | The name to give to the anchor for the URL fragment. |
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# AnimationToggle
|
|
2
|
+
|
|
3
|
+
## Examples
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Controlling animation via a provider
|
|
7
|
+
|
|
8
|
+
Shows how to control animation using an AnimationToggleProvider. This can be used to disable animation for most components included in this library.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import React, { Component } from 'react';
|
|
12
|
+
|
|
13
|
+
import { AnimationToggleProvider } from '@splunk/react-ui/AnimationToggle';
|
|
14
|
+
import Button from '@splunk/react-ui/Button';
|
|
15
|
+
import Switch from '@splunk/react-ui/Switch';
|
|
16
|
+
import TransitionOpen from '@splunk/react-ui/TransitionOpen';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Provider extends Component<object, { animatedTransitions: boolean; open: boolean }> {
|
|
20
|
+
constructor(props: object) {
|
|
21
|
+
super(props);
|
|
22
|
+
this.state = {
|
|
23
|
+
open: false,
|
|
24
|
+
animatedTransitions: false,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
handleButtonClick = () => {
|
|
29
|
+
this.setState((state) => ({ open: !state.open }));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
handleSwitchClick = () => {
|
|
33
|
+
this.setState((state) => ({ animatedTransitions: !state.animatedTransitions }));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
render() {
|
|
37
|
+
const style: React.CSSProperties = {
|
|
38
|
+
border: '1px solid black',
|
|
39
|
+
marginTop: 10,
|
|
40
|
+
textAlign: 'center',
|
|
41
|
+
width: 150,
|
|
42
|
+
};
|
|
43
|
+
return (
|
|
44
|
+
<div>
|
|
45
|
+
<Switch onClick={this.handleSwitchClick} selected={this.state.animatedTransitions}>
|
|
46
|
+
Animation enabled
|
|
47
|
+
</Switch>
|
|
48
|
+
<AnimationToggleProvider enabled={this.state.animatedTransitions}>
|
|
49
|
+
<Button onClick={this.handleButtonClick}>Click me!</Button>
|
|
50
|
+
<TransitionOpen animation="expandHeight" open={this.state.open}>
|
|
51
|
+
<div style={style}>
|
|
52
|
+
<p>Hello world</p>
|
|
53
|
+
<p>Hello world</p>
|
|
54
|
+
<p>Hello world</p>
|
|
55
|
+
<p>Hello world</p>
|
|
56
|
+
<p>Hello world</p>
|
|
57
|
+
</div>
|
|
58
|
+
</TransitionOpen>
|
|
59
|
+
</AnimationToggleProvider>
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default Provider;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### Offering animation control with a hook
|
|
71
|
+
|
|
72
|
+
Shows how to use the useAnimationToggle hook to render different content based on current animation settings.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import React, { useState } from 'react';
|
|
76
|
+
|
|
77
|
+
import { AnimationToggleProvider, useAnimationToggle } from '@splunk/react-ui/AnimationToggle';
|
|
78
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
79
|
+
import Switch from '@splunk/react-ui/Switch';
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function Content() {
|
|
83
|
+
const animationToggle = useAnimationToggle();
|
|
84
|
+
const MessageComponent = animationToggle === 'on' ? 'b' : 'span';
|
|
85
|
+
const message = animationToggle === 'on' ? 'Enabled' : 'Disabled';
|
|
86
|
+
return <MessageComponent>{message}</MessageComponent>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function ToggleHook() {
|
|
90
|
+
const [animatedTransitions, setAnimatedTransitions] = useState(false);
|
|
91
|
+
const handleSwitchClick = () => {
|
|
92
|
+
setAnimatedTransitions((state) => !state);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<P>
|
|
97
|
+
<Switch onClick={handleSwitchClick} selected={animatedTransitions}>
|
|
98
|
+
Animation enabled
|
|
99
|
+
</Switch>
|
|
100
|
+
<AnimationToggleProvider enabled={animatedTransitions}>
|
|
101
|
+
<Content />
|
|
102
|
+
</AnimationToggleProvider>
|
|
103
|
+
</P>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export default ToggleHook;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
### Offering animation control with a component
|
|
113
|
+
|
|
114
|
+
Shows how to use the Animation Toggle component to render different content based on current animation settings.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import React, { Component } from 'react';
|
|
118
|
+
|
|
119
|
+
import AnimationToggle, { AnimationToggleProvider } from '@splunk/react-ui/AnimationToggle';
|
|
120
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
121
|
+
import Switch from '@splunk/react-ui/Switch';
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class ToggleComponent extends Component<object, { animatedTransitions: boolean }> {
|
|
125
|
+
constructor(props: object) {
|
|
126
|
+
super(props);
|
|
127
|
+
this.state = {
|
|
128
|
+
animatedTransitions: false,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
handleSwitchClick = () => {
|
|
133
|
+
this.setState((state) => ({ animatedTransitions: !state.animatedTransitions }));
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
render() {
|
|
137
|
+
return (
|
|
138
|
+
<P>
|
|
139
|
+
<Switch onClick={this.handleSwitchClick} selected={this.state.animatedTransitions}>
|
|
140
|
+
Animation enabled
|
|
141
|
+
</Switch>
|
|
142
|
+
<AnimationToggleProvider enabled={this.state.animatedTransitions}>
|
|
143
|
+
<AnimationToggle on={<b>Enabled</b>} off={<span>Disabled</span>} />
|
|
144
|
+
</AnimationToggleProvider>
|
|
145
|
+
</P>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default ToggleComponent;
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
### Support reduced motion with a hook
|
|
156
|
+
|
|
157
|
+
Shows how to use the useAnimationToggle hook to offer an alternative when the user prefers reduced motion. If reduced motion is preferred but animations are disabled useAnimationToggle returns 'off'.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import React from 'react';
|
|
161
|
+
|
|
162
|
+
import { useAnimationToggle } from '@splunk/react-ui/AnimationToggle';
|
|
163
|
+
import List from '@splunk/react-ui/List';
|
|
164
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
const ReducedMotionHook = () => {
|
|
168
|
+
const animationToggle = useAnimationToggle();
|
|
169
|
+
// TODO: Once Prose component is finished, use Prose to add left padding and margin back to List (SUI-5554)
|
|
170
|
+
return (
|
|
171
|
+
<article>
|
|
172
|
+
<P>To reduce animation on macOS:</P>
|
|
173
|
+
<List ordered>
|
|
174
|
+
<List.Item>Go to "System Preferences"</List.Item>
|
|
175
|
+
<List.Item>Choose "Accessibility"</List.Item>
|
|
176
|
+
<List.Item>Select "Display"</List.Item>
|
|
177
|
+
<List.Item>Check "Reduce motion"</List.Item>
|
|
178
|
+
</List>
|
|
179
|
+
<P>
|
|
180
|
+
Animation currently:{' '}
|
|
181
|
+
<b>
|
|
182
|
+
{animationToggle === 'on' && 'On'}
|
|
183
|
+
{animationToggle === 'off' && 'Off'}
|
|
184
|
+
{animationToggle === 'reduced' && 'Reduced'}
|
|
185
|
+
</b>
|
|
186
|
+
</P>
|
|
187
|
+
</article>
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export default ReducedMotionHook;
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### Support reduced motion with a component
|
|
197
|
+
|
|
198
|
+
Shows how to use the Animation Toggle component to offer an alternative when the user prefers reduced motion. If reduced motion is preferred but animations are disabled or no reduced motion alternative is set, Animation Toggle considers animations to be disabled.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import React from 'react';
|
|
202
|
+
|
|
203
|
+
import AnimationToggle from '@splunk/react-ui/AnimationToggle';
|
|
204
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
const ReducedMotionComponent = () => (
|
|
208
|
+
<P>
|
|
209
|
+
Animation currently:{' '}
|
|
210
|
+
<AnimationToggle on={<b>On</b>} off={<b>Off</b>} reduced={<b>Reduced</b>} />
|
|
211
|
+
</P>
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
export default ReducedMotionComponent;
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
## API
|
|
221
|
+
|
|
222
|
+
import React from 'react';
|
|
223
|
+
|
|
224
|
+
import ComponentAPI from '@splunk/react-docs/ComponentAPI';
|
|
225
|
+
import UtilAPI from '@splunk/react-docs/UtilAPI';
|
|
226
|
+
|
|
227
|
+
import animationToggleContextDocs from '!!@splunk/jsdoc-loader!@splunk/react-ui/AnimationToggle/AnimationToggleContext';
|
|
228
|
+
import useAnimationToggleDocs from '!!@splunk/jsdoc-loader!@splunk/react-ui/AnimationToggle/useAnimationToggle';
|
|
229
|
+
import allAnimationToggleDocs from '@splunk/react-ui/AnimationToggle/AnimationToggle?parseDocs';
|
|
230
|
+
import allAnimationToggleProviderDocs from '@splunk/react-ui/AnimationToggle/AnimationToggleProvider?parseDocs';
|
|
231
|
+
|
|
232
|
+
const animationToggleDocs = allAnimationToggleDocs.find(
|
|
233
|
+
(doc) => doc.displayName === 'AnimationToggle'
|
|
234
|
+
);
|
|
235
|
+
const animationToggleProviderDocs = allAnimationToggleProviderDocs.find(
|
|
236
|
+
(doc) => doc.displayName === 'AnimationToggleProvider'
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
function DevelopSection() {
|
|
240
|
+
return [
|
|
241
|
+
<ComponentAPI
|
|
242
|
+
title="AnimationToggleProvider"
|
|
243
|
+
key="AnimationToggleProvider"
|
|
244
|
+
docs={animationToggleProviderDocs}
|
|
245
|
+
/>,
|
|
246
|
+
<ComponentAPI title="AnimationToggle" key="AnimationToggle" docs={animationToggleDocs} />,
|
|
247
|
+
<UtilAPI key="UseAnimationToggleDocs" docs={useAnimationToggleDocs} />,
|
|
248
|
+
<UtilAPI key="AnimationToggleContextDocs" docs={animationToggleContextDocs} />,
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export default DevelopSection;
|
|
253
|
+
|
|
254
|
+
|