@splunk/react-ui 5.7.1 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Accordion.js +6 -6
- package/Box.js +83 -34
- package/CHANGELOG.md +29 -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 +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 +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,216 @@
|
|
|
1
|
+
# Divider
|
|
2
|
+
|
|
3
|
+
## Examples
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### StyledContainer
|
|
7
|
+
|
|
8
|
+
```typescript
|
|
9
|
+
import React from 'react';
|
|
10
|
+
|
|
11
|
+
import styled from 'styled-components';
|
|
12
|
+
|
|
13
|
+
import Divider from '@splunk/react-ui/Divider';
|
|
14
|
+
import Paragraph from '@splunk/react-ui/Paragraph';
|
|
15
|
+
import { variables } from '@splunk/themes';
|
|
16
|
+
|
|
17
|
+
const StyledContainer = styled.div`
|
|
18
|
+
width: 400px;
|
|
19
|
+
|
|
20
|
+
* + * {
|
|
21
|
+
margin-block-start: ${variables.spacingMedium};
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function Basic() {
|
|
27
|
+
return (
|
|
28
|
+
<StyledContainer>
|
|
29
|
+
<Paragraph>
|
|
30
|
+
This is the first paragraph. It demonstrates how content can be separated using a
|
|
31
|
+
divider component.
|
|
32
|
+
</Paragraph>
|
|
33
|
+
<Divider />
|
|
34
|
+
<Paragraph>
|
|
35
|
+
The divider provides a clear visual break between sections of related content.
|
|
36
|
+
</Paragraph>
|
|
37
|
+
</StyledContainer>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default Basic;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### StyledDivider
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import React from 'react';
|
|
50
|
+
|
|
51
|
+
import styled from 'styled-components';
|
|
52
|
+
|
|
53
|
+
import Divider from '@splunk/react-ui/Divider';
|
|
54
|
+
import Paragraph from '@splunk/react-ui/Paragraph';
|
|
55
|
+
import { variables } from '@splunk/themes';
|
|
56
|
+
|
|
57
|
+
const StyledDivider = styled(Divider)`
|
|
58
|
+
margin: 0 ${variables.spacingMedium};
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const StyledContainer = styled.div`
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-direction: row;
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
const StyledParagraph = styled(Paragraph)`
|
|
67
|
+
margin: 0;
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
function Vertical() {
|
|
72
|
+
return (
|
|
73
|
+
<StyledContainer>
|
|
74
|
+
<StyledParagraph>First section</StyledParagraph>
|
|
75
|
+
<StyledDivider orientation="vertical" />
|
|
76
|
+
<StyledParagraph>Second section</StyledParagraph>
|
|
77
|
+
</StyledContainer>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default Vertical;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### StyledContainer
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import React from 'react';
|
|
90
|
+
|
|
91
|
+
import styled from 'styled-components';
|
|
92
|
+
|
|
93
|
+
import Divider from '@splunk/react-ui/Divider';
|
|
94
|
+
import Paragraph from '@splunk/react-ui/Paragraph';
|
|
95
|
+
|
|
96
|
+
const StyledContainer = styled.div`
|
|
97
|
+
display: flex;
|
|
98
|
+
flex-direction: column;
|
|
99
|
+
gap: 10px;
|
|
100
|
+
width: 400px;
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
function Appearance() {
|
|
105
|
+
return (
|
|
106
|
+
<StyledContainer>
|
|
107
|
+
<Paragraph>Default</Paragraph>
|
|
108
|
+
<Divider />
|
|
109
|
+
<Paragraph>Strong</Paragraph>
|
|
110
|
+
<Divider appearance="strong" />
|
|
111
|
+
<Paragraph>Weak</Paragraph>
|
|
112
|
+
<Divider appearance="weak" />
|
|
113
|
+
</StyledContainer>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default Appearance;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
### StyledContainer
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import React from 'react';
|
|
126
|
+
|
|
127
|
+
import styled from 'styled-components';
|
|
128
|
+
|
|
129
|
+
import Divider from '@splunk/react-ui/Divider';
|
|
130
|
+
import Paragraph from '@splunk/react-ui/Paragraph';
|
|
131
|
+
import { variables } from '@splunk/themes';
|
|
132
|
+
|
|
133
|
+
const StyledContainer = styled.div`
|
|
134
|
+
width: 400px;
|
|
135
|
+
|
|
136
|
+
* + * {
|
|
137
|
+
margin-block-start: ${variables.spacingMedium};
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
|
|
141
|
+
const StyledDivider = styled(Divider)`
|
|
142
|
+
border-color: ${variables.contentColorMuted};
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
function CustomStyle() {
|
|
147
|
+
return (
|
|
148
|
+
<StyledContainer>
|
|
149
|
+
<Paragraph>
|
|
150
|
+
This is a paragraph above a custom-styled divider. You can change the divider color
|
|
151
|
+
and style to match your theme.
|
|
152
|
+
</Paragraph>
|
|
153
|
+
<StyledDivider />
|
|
154
|
+
<Paragraph>This is a paragraph below a custom-styled divider.</Paragraph>
|
|
155
|
+
</StyledContainer>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export default CustomStyle;
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
### StyledContainer
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import React from 'react';
|
|
168
|
+
|
|
169
|
+
import styled from 'styled-components';
|
|
170
|
+
|
|
171
|
+
import Divider from '@splunk/react-ui/Divider';
|
|
172
|
+
import Heading from '@splunk/react-ui/Heading';
|
|
173
|
+
import Paragraph from '@splunk/react-ui/Paragraph';
|
|
174
|
+
|
|
175
|
+
const StyledContainer = styled.div`
|
|
176
|
+
width: 400px;
|
|
177
|
+
`;
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
function Decorative() {
|
|
181
|
+
return (
|
|
182
|
+
<StyledContainer>
|
|
183
|
+
<Heading level={4}>Heading level</Heading>
|
|
184
|
+
<Divider decorative />
|
|
185
|
+
<Paragraph>
|
|
186
|
+
This paragraph follows a decorative divider. Use the decorative prop when the
|
|
187
|
+
divider is only for visual separation and not for semantic structure.
|
|
188
|
+
</Paragraph>
|
|
189
|
+
</StyledContainer>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export default Decorative;
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
## API
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
### Divider API
|
|
203
|
+
|
|
204
|
+
#### Props
|
|
205
|
+
|
|
206
|
+
| Name | Type | Required | Default | Description |
|
|
207
|
+
|------|------|------|------|------|
|
|
208
|
+
| appearance | 'default' \| 'weak' \| 'strong' | no | 'default' | Changes the border color of the `Divider`. `Divider`s with `appearance="weak"` will not meet accessibility requirements to be perceivable. If the component should be perceivable, consider the other contrast compliant `appearance` values. Otherwise, apply the `decorative` prop. |
|
|
209
|
+
| decorative | boolean | no | false | Remove semantics of the divider. |
|
|
210
|
+
| elementRef | React.Ref<HTMLHRElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
211
|
+
| orientation | 'horizontal' \| 'vertical' | no | 'horizontal' | Sets the orientation of this `Divider`. |
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
# Drawer
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> Image: Illustration of a Drawer component
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## When to use this component
|
|
10
|
+
A drawer presents supplementary content without taking users away from the main page. Use it for navigation, filters, settings, previews, or contextual tools. Do not use a drawer to replace a primary view.
|
|
11
|
+
|
|
12
|
+
## When to use another component
|
|
13
|
+
A drawer should not be used when the content or actions are critical to the user’s main task or require immediate attention, as drawers are best suited for supplementary information.
|
|
14
|
+
|
|
15
|
+
```mermaid
|
|
16
|
+
graph TD
|
|
17
|
+
accDescr: Decision tree that guides on when to use the Drawer component or something else
|
|
18
|
+
A(Displays supplementary content or provide additional controls?) -- Yes --- B(Drawer)
|
|
19
|
+
A -- No --- E(Use a modal or new page)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Check out
|
|
23
|
+
- [Modal] [1]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Close drawer
|
|
29
|
+
Provide a clear and recognizable way for users to close the drawer:
|
|
30
|
+
- **Escape key**: Pressing Esc closes the drawer when `position="page"`.
|
|
31
|
+
- **Close button**: A close button should be rendered in the top right corner of the drawer.
|
|
32
|
+
|
|
33
|
+
> Image: Examples of a clear method for closing a drawer: The first example, which includes a heart eyes emoji, features a close button in the top right corner of the drawer and a button group in the bottom right offering both primary and secondary actions. The second example, with a grimacing face emoji, lacks a close button in the top right corner of the drawer and only has a button group providing a primary and secondary action.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Primary action
|
|
37
|
+
The final interactive element in a drawer should be the primary action.
|
|
38
|
+
> Image: Examples illustrating the placement of a primary action in drawers. The first example, marked with a heart eyes emoji, displays a drawer with a button group located in the bottom right corner; this group includes both primary and secondary actions, with the primary action designated as the second button. The second example, identified by a grimacing face emoji, presents a drawer with a secondary button in the bottom right and a button group in the bottom left corner for primary and tertiary actions. In the group, the primary action is again the second button.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Content
|
|
42
|
+
|
|
43
|
+
### Title text
|
|
44
|
+
Titles should be brief yet accurately reflect the drawer content and its purpose. Use sentence-style capitalization for all titles.
|
|
45
|
+
> Image: Content examples of using sentence style in drawer titles. The first with heart eyes emoji reads
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Body text
|
|
49
|
+
Include only content that is directly related to completing the task at hand. Don’t repeat or rephrase the title. Drawer body content should be easy to scan and avoid lengthy text blocks, such as terms and conditions or manuals. The content is scrollable and flexible, while the header and footer remain fixed.
|
|
50
|
+
> Image: Content example for drawer body text that is related to the task at hand. The first example with heart eyes emoji that reads
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Actions
|
|
54
|
+
Use a precise verb to describe the action instead of vague words like Done or OK when possible.
|
|
55
|
+
> Image: Content example for actions in drawers using a precise verb. The first example with heart eyes emoji reads
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
[1]: ./Modal
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Examples
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Basic
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import React, { useRef, useState } from 'react';
|
|
68
|
+
|
|
69
|
+
import Button from '@splunk/react-ui/Button';
|
|
70
|
+
import Drawer from '@splunk/react-ui/Drawer';
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
function Basic() {
|
|
74
|
+
const [open, setOpen] = useState(false);
|
|
75
|
+
const drawerToggle = useRef<HTMLButtonElement | null>(null);
|
|
76
|
+
|
|
77
|
+
const handleRequestOpen = () => {
|
|
78
|
+
setOpen(true);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleRequestClose = () => {
|
|
82
|
+
setOpen(false);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
<Button onClick={handleRequestOpen} elementRef={drawerToggle} label="Click me" />
|
|
88
|
+
<Drawer returnFocus={drawerToggle} onRequestClose={handleRequestClose} open={open}>
|
|
89
|
+
<Drawer.Header title="Basic Drawer" />
|
|
90
|
+
<Drawer.Body>
|
|
91
|
+
Drawers are great for supplemental content, like forms or additional
|
|
92
|
+
information.
|
|
93
|
+
</Drawer.Body>
|
|
94
|
+
</Drawer>
|
|
95
|
+
</>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default Basic;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Initial focus
|
|
105
|
+
|
|
106
|
+
Initial focus can be set to a different element using the `initialFocus` prop. Use `'first'` to focus the first focusable element, `'container'` to focus the drawer itself, or pass a ref to a specific element.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import React, { useCallback, useState, useRef } from 'react';
|
|
110
|
+
|
|
111
|
+
import Button from '@splunk/react-ui/Button';
|
|
112
|
+
import Drawer from '@splunk/react-ui/Drawer';
|
|
113
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
function InitialFocus() {
|
|
117
|
+
const [acceptButton, setAcceptButton] = useState<HTMLButtonElement | null>(null);
|
|
118
|
+
const acceptButtonRef = useCallback((el: HTMLButtonElement | null) => setAcceptButton(el), []);
|
|
119
|
+
|
|
120
|
+
const [open, setOpen] = useState(false);
|
|
121
|
+
const drawerToggle = useRef<HTMLButtonElement | null>(null);
|
|
122
|
+
|
|
123
|
+
const handleRequestOpen = () => {
|
|
124
|
+
setOpen(true);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const handleRequestClose = () => {
|
|
128
|
+
setOpen(false);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<>
|
|
133
|
+
<Button onClick={handleRequestOpen} elementRef={drawerToggle} label="Click me" />
|
|
134
|
+
<Drawer
|
|
135
|
+
initialFocus={acceptButton}
|
|
136
|
+
onRequestClose={handleRequestClose}
|
|
137
|
+
open={open}
|
|
138
|
+
returnFocus={drawerToggle}
|
|
139
|
+
>
|
|
140
|
+
<Drawer.Header title="Header" />
|
|
141
|
+
<Drawer.Body>
|
|
142
|
+
<P>This drawer demonstrates how to set initial focus to a specific element.</P>
|
|
143
|
+
</Drawer.Body>
|
|
144
|
+
<Drawer.Footer>
|
|
145
|
+
<Button appearance="secondary" onClick={handleRequestClose} label="Cancel" />
|
|
146
|
+
<Button appearance="primary" elementRef={acceptButtonRef} label="Accept" />
|
|
147
|
+
</Drawer.Footer>
|
|
148
|
+
</Drawer>
|
|
149
|
+
</>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default InitialFocus;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
### PagePosition
|
|
159
|
+
|
|
160
|
+
The `page` position (default) renders the drawer relative to the viewport using a portal.
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import React, { useRef, useState } from 'react';
|
|
164
|
+
|
|
165
|
+
import Button from '@splunk/react-ui/Button';
|
|
166
|
+
import Drawer from '@splunk/react-ui/Drawer';
|
|
167
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
function PagePosition() {
|
|
171
|
+
const [open, setOpen] = useState(false);
|
|
172
|
+
const drawerToggle = useRef<HTMLButtonElement | null>(null);
|
|
173
|
+
|
|
174
|
+
const handleRequestOpen = () => {
|
|
175
|
+
setOpen(true);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const handleRequestClose = () => {
|
|
179
|
+
setOpen(false);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<>
|
|
184
|
+
<Button onClick={handleRequestOpen} elementRef={drawerToggle} label="Open Drawer" />
|
|
185
|
+
<Drawer
|
|
186
|
+
position="page"
|
|
187
|
+
open={open}
|
|
188
|
+
onRequestClose={handleRequestClose}
|
|
189
|
+
returnFocus={drawerToggle}
|
|
190
|
+
>
|
|
191
|
+
<Drawer.Header title="Page Position" subtitle="Relative to viewport" />
|
|
192
|
+
<Drawer.Body>
|
|
193
|
+
<P>
|
|
194
|
+
This drawer is positioned relative to the viewport. It overlays all page
|
|
195
|
+
content.
|
|
196
|
+
</P>
|
|
197
|
+
</Drawer.Body>
|
|
198
|
+
<Drawer.Footer>
|
|
199
|
+
<Button appearance="primary" label="Close" onClick={handleRequestClose} />
|
|
200
|
+
</Drawer.Footer>
|
|
201
|
+
</Drawer>
|
|
202
|
+
</>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default PagePosition;
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
### ContainerPosition
|
|
212
|
+
|
|
213
|
+
The `container` position renders the drawer relative to its nearest positioned ancestor.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import React, { useRef, useState } from 'react';
|
|
217
|
+
|
|
218
|
+
import Button from '@splunk/react-ui/Button';
|
|
219
|
+
import Drawer from '@splunk/react-ui/Drawer';
|
|
220
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
function ContainerPosition() {
|
|
224
|
+
const [open, setOpen] = useState(false);
|
|
225
|
+
const drawerToggle = useRef<HTMLButtonElement | null>(null);
|
|
226
|
+
|
|
227
|
+
const handleRequestOpen = () => {
|
|
228
|
+
setOpen(true);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const handleRequestClose = () => {
|
|
232
|
+
setOpen(false);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
return (
|
|
236
|
+
<div
|
|
237
|
+
style={{
|
|
238
|
+
position: 'relative',
|
|
239
|
+
height: '300px',
|
|
240
|
+
width: '600px',
|
|
241
|
+
border: '2px dashed #ccc',
|
|
242
|
+
}}
|
|
243
|
+
>
|
|
244
|
+
<div style={{ padding: '16px' }}>
|
|
245
|
+
<P>
|
|
246
|
+
The drawer will be contained within this bordered area rather than covering the
|
|
247
|
+
entire viewport.
|
|
248
|
+
</P>
|
|
249
|
+
<br />
|
|
250
|
+
<Button onClick={handleRequestOpen} elementRef={drawerToggle} label="Open Drawer" />
|
|
251
|
+
</div>
|
|
252
|
+
<Drawer
|
|
253
|
+
position="container"
|
|
254
|
+
open={open}
|
|
255
|
+
onRequestClose={handleRequestClose}
|
|
256
|
+
width="250px"
|
|
257
|
+
returnFocus={drawerToggle}
|
|
258
|
+
>
|
|
259
|
+
<Drawer.Header title="Container Position" subtitle="Relative to ancestor" />
|
|
260
|
+
<Drawer.Body>
|
|
261
|
+
<P>
|
|
262
|
+
This drawer is positioned within its container. Useful for split-pane
|
|
263
|
+
layouts or panels within a larger application.
|
|
264
|
+
</P>
|
|
265
|
+
</Drawer.Body>
|
|
266
|
+
<Drawer.Footer>
|
|
267
|
+
<Button appearance="primary" label="Close" onClick={handleRequestClose} />
|
|
268
|
+
</Drawer.Footer>
|
|
269
|
+
</Drawer>
|
|
270
|
+
</div>
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export default ContainerPosition;
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
### InlinePosition
|
|
280
|
+
|
|
281
|
+
The `inline` position renders the drawer inline. Content reflows around the drawer.
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import React, { useRef, useState } from 'react';
|
|
285
|
+
|
|
286
|
+
import Button from '@splunk/react-ui/Button';
|
|
287
|
+
import Drawer from '@splunk/react-ui/Drawer';
|
|
288
|
+
import P from '@splunk/react-ui/Paragraph';
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
function InlinePosition() {
|
|
292
|
+
const [open, setOpen] = useState(false);
|
|
293
|
+
const drawerToggle = useRef<HTMLButtonElement | null>(null);
|
|
294
|
+
|
|
295
|
+
const handleRequestOpen = () => {
|
|
296
|
+
setOpen(true);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const handleRequestClose = () => {
|
|
300
|
+
setOpen(false);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<div
|
|
305
|
+
style={{ display: 'flex', height: '300px', width: '600px', border: '2px dashed #ccc' }}
|
|
306
|
+
>
|
|
307
|
+
<div style={{ flex: '1 0 0', padding: '16px', overflow: 'auto' }}>
|
|
308
|
+
<P>
|
|
309
|
+
The inline position renders the drawer as part of the layout. Content reflows
|
|
310
|
+
around the drawer when it opens or closes.
|
|
311
|
+
</P>
|
|
312
|
+
<br />
|
|
313
|
+
<Button onClick={handleRequestOpen} elementRef={drawerToggle} label="Open Drawer" />
|
|
314
|
+
</div>
|
|
315
|
+
<Drawer
|
|
316
|
+
position="inline"
|
|
317
|
+
open={open}
|
|
318
|
+
onRequestClose={handleRequestClose}
|
|
319
|
+
width="250px"
|
|
320
|
+
returnFocus={drawerToggle}
|
|
321
|
+
>
|
|
322
|
+
<Drawer.Header title="Inline Position" subtitle="Content reflows" />
|
|
323
|
+
<Drawer.Body>
|
|
324
|
+
<P>
|
|
325
|
+
This drawer renders inline and pushes content aside rather than overlaying
|
|
326
|
+
it. Ideal for persistent sidebars or detail panels.
|
|
327
|
+
</P>
|
|
328
|
+
</Drawer.Body>
|
|
329
|
+
<Drawer.Footer>
|
|
330
|
+
<Button appearance="primary" label="Close" onClick={handleRequestClose} />
|
|
331
|
+
</Drawer.Footer>
|
|
332
|
+
</Drawer>
|
|
333
|
+
</div>
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export default InlinePosition;
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
## API
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
### Drawer API
|
|
349
|
+
|
|
350
|
+
#### Props
|
|
351
|
+
|
|
352
|
+
| Name | Type | Required | Default | Description |
|
|
353
|
+
|------|------|------|------|------|
|
|
354
|
+
| children | React.ReactNode | no | | Any renderable children can be passed to the `Drawer`. To use the default `Drawer` styles, use the `Drawer.Header`, `Drawer.Body`, and `Drawer.Footer`. |
|
|
355
|
+
| closeOnClickAway | boolean | no | false | Set to `true` to enable closing the Drawer by clicking the scrim (overlay). Only applies to `position="page"` because other position modes do not have a scrim. When `false` (default), the scrim is still displayed to block interaction with underlying content, but clicking it will not close the Drawer. Closing on click away should be avoided as it can lead to accidental dismissal of the drawer causing data loss or disruption of a user's workflow. Only enable click outside to dismiss when: - The drawer content is non-critical or purely informational - Accidental dismissal will not result in loss of progress, data, or important context When enabled, `onRequestClose` will receive an event with reason `clickAway`. |
|
|
356
|
+
| divider | 'header' \| 'footer' \| 'both' \| 'none' | no | 'both' | Show dividers between header, body and footer. |
|
|
357
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
358
|
+
| initialFocus | \| 'first' \| 'container' \| (React.Component & { focus: () => void }) \| HTMLElement \| null | no | 'first' | Allows focus to be set to a component other than the default. Supports `first` (first focusable element in the drawer), `container` (focus the drawer itself), or a ref. |
|
|
359
|
+
| onRequestClose | DrawerRequestCloseHandler | no | | Called when a close event occurs. The callback is passed the event and a reason, which is `escapeKey`, `clickAway`, or `clickCloseButton`. Generally, use this callback to toggle the `open` prop. |
|
|
360
|
+
| open | boolean | no | false | Set `open` to `true` to open the drawer and `false` to close it. |
|
|
361
|
+
| position | 'page' \| 'container' \| 'inline' | no | 'page' | The layout mode for the drawer. - `page`: Positions relative to the viewport (default) - `container`: Positions relative to nearest positioned ancestor - `inline`: Renders inline without portal, allowing content to reflow around the drawer |
|
|
362
|
+
| returnFocus | \| React.MutableRefObject<(React.Component & { focus: () => void }) \| HTMLElement \| null> \| (() => void) | no | | Pass the ref of the invoking element (or other element that follows the logical flow of the application) to automatically move focus to the invoking element on `Drawer` close. If using a ref is not possible, you *must* pass a function that sets focus to the appropriate element. This function will be called after `onRequestClose`. Recommended when `position` is `page` to ensure proper focus management. |
|
|
363
|
+
| width | string | no | '300px' | Width of the drawer. |
|
|
364
|
+
|
|
365
|
+
#### Types
|
|
366
|
+
|
|
367
|
+
| Name | Type | Description |
|
|
368
|
+
|------|------|------|
|
|
369
|
+
| DrawerRequestCloseHandler | (data: { event: \| React.MouseEvent<HTMLDivElement \| HTMLAnchorElement \| HTMLButtonElement> \| MouseEvent \| KeyboardEvent \| TouchEvent; reason: 'clickAway' \| 'escapeKey' \| 'clickCloseButton'; }) => void | |
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
### Drawer.Header API
|
|
374
|
+
|
|
375
|
+
A styled container for `Drawer` header content.
|
|
376
|
+
|
|
377
|
+
#### Props
|
|
378
|
+
|
|
379
|
+
| Name | Type | Required | Default | Description |
|
|
380
|
+
|------|------|------|------|------|
|
|
381
|
+
| children | React.ReactNode | no | | `children` might be passed instead of a title. Note that `children` aren't rendered if a title is provided. |
|
|
382
|
+
| hideCloseButton | boolean | no | false | Hide the closeButton in the Header if `onRequestClose` is provided to `Drawer`. |
|
|
383
|
+
| icon | React.ReactNode | no | | The icon to show before the title. |
|
|
384
|
+
| subtitle | React.ReactNode | no | | Used as the subheading. Only shown if `title` is also present. |
|
|
385
|
+
| title | string | no | | Used as the main heading. |
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
### Drawer.Body API
|
|
390
|
+
|
|
391
|
+
A styled container for `Drawer` body content.
|
|
392
|
+
|
|
393
|
+
#### Props
|
|
394
|
+
|
|
395
|
+
| Name | Type | Required | Default | Description |
|
|
396
|
+
|------|------|------|------|------|
|
|
397
|
+
| children | React.ReactNode | no | | |
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
### Drawer.Footer API
|
|
402
|
+
|
|
403
|
+
A styled container for `Drawer` footer content.
|
|
404
|
+
|
|
405
|
+
#### Props
|
|
406
|
+
|
|
407
|
+
| Name | Type | Required | Default | Description |
|
|
408
|
+
|------|------|------|------|------|
|
|
409
|
+
| children | React.ReactNode | no | | |
|
|
410
|
+
| layout | 'auto' \| 'none' | no | 'auto' | Controls the layout and styling for children. `auto` will style children for common use cases, such as: buttons; controls; documentation links; or a combination. Set `none` when custom styling is needed. |
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|