@splunk/react-ui 5.7.1 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/Accordion.js +6 -6
  2. package/Box.js +83 -34
  3. package/CHANGELOG.md +29 -0
  4. package/CollapsiblePanel.js +11 -11
  5. package/ComboBox.js +31 -27
  6. package/ControlGroup.js +92 -91
  7. package/DefinitionList.js +9 -9
  8. package/Drawer.d.ts +2 -0
  9. package/Drawer.js +679 -0
  10. package/DualListbox.js +1 -1
  11. package/JSONTree.js +73 -72
  12. package/Link.js +2 -2
  13. package/MIGRATION.md +10 -0
  14. package/Menu.js +338 -240
  15. package/Modal.js +127 -109
  16. package/Multiselect.js +437 -351
  17. package/Paginator.js +14 -12
  18. package/Popover.js +4 -1
  19. package/README.md +11 -0
  20. package/RadioBar.js +1 -1
  21. package/Search.js +103 -88
  22. package/Select.js +42 -40
  23. package/SelectBase.js +374 -328
  24. package/SidePanel.js +346 -167
  25. package/SlidingPanels.js +11 -11
  26. package/StepBar.js +7 -7
  27. package/Switch.js +5 -5
  28. package/Text.js +24 -24
  29. package/TextArea.js +7 -7
  30. package/TransitionOpen.js +188 -169
  31. package/docs-llm/Accordion.md +267 -0
  32. package/docs-llm/Anchor Menu.md +115 -0
  33. package/docs-llm/Anchor.md +54 -0
  34. package/docs-llm/AnimationToggle.md +254 -0
  35. package/docs-llm/Avatar.md +298 -0
  36. package/docs-llm/Badge.md +212 -0
  37. package/docs-llm/Breadcrumbs.md +306 -0
  38. package/docs-llm/Button Group.md +53 -0
  39. package/docs-llm/Button.md +361 -0
  40. package/docs-llm/Card Layout.md +286 -0
  41. package/docs-llm/Card.md +619 -0
  42. package/docs-llm/Checkbox.md +218 -0
  43. package/docs-llm/Chip.md +291 -0
  44. package/docs-llm/Clickable.md +160 -0
  45. package/docs-llm/Code.md +292 -0
  46. package/docs-llm/Collapsible Panel.md +744 -0
  47. package/docs-llm/Color.md +253 -0
  48. package/docs-llm/Column Layout.md +391 -0
  49. package/docs-llm/Combo Box.md +540 -0
  50. package/docs-llm/Control Group.md +594 -0
  51. package/docs-llm/Date.md +270 -0
  52. package/docs-llm/Definition List.md +278 -0
  53. package/docs-llm/Divider.md +216 -0
  54. package/docs-llm/Drawer.md +414 -0
  55. package/docs-llm/Dropdown.md +472 -0
  56. package/docs-llm/Dual Listbox.md +325 -0
  57. package/docs-llm/File.md +653 -0
  58. package/docs-llm/Form Rows.md +374 -0
  59. package/docs-llm/Heading.md +179 -0
  60. package/docs-llm/Image.md +109 -0
  61. package/docs-llm/JSON Tree.md +260 -0
  62. package/docs-llm/Layer.md +74 -0
  63. package/docs-llm/Layout.md +50 -0
  64. package/docs-llm/Link.md +318 -0
  65. package/docs-llm/List.md +189 -0
  66. package/docs-llm/Markdown.md +179 -0
  67. package/docs-llm/Menu.md +735 -0
  68. package/docs-llm/Message Bar.md +236 -0
  69. package/docs-llm/Message.md +248 -0
  70. package/docs-llm/Modal.md +443 -0
  71. package/docs-llm/Monogram.md +159 -0
  72. package/docs-llm/Multiselect.md +937 -0
  73. package/docs-llm/Number.md +298 -0
  74. package/docs-llm/Paginator.md +395 -0
  75. package/docs-llm/Paragraph.md +148 -0
  76. package/docs-llm/Phone Number.md +254 -0
  77. package/docs-llm/Popover.md +166 -0
  78. package/docs-llm/Progress.md +141 -0
  79. package/docs-llm/Radio Bar.md +303 -0
  80. package/docs-llm/Radio List.md +350 -0
  81. package/docs-llm/Resize.md +362 -0
  82. package/docs-llm/Screen Reader Content.md +73 -0
  83. package/docs-llm/Scroll Container Context.md +155 -0
  84. package/docs-llm/Scroll.md +152 -0
  85. package/docs-llm/Search.md +381 -0
  86. package/docs-llm/Select.md +985 -0
  87. package/docs-llm/Side Panel.md +777 -0
  88. package/docs-llm/Slider.md +339 -0
  89. package/docs-llm/Sliding Panels.md +340 -0
  90. package/docs-llm/Split Button.md +295 -0
  91. package/docs-llm/Static Content.md +90 -0
  92. package/docs-llm/Step Bar.md +292 -0
  93. package/docs-llm/Switch.md +268 -0
  94. package/docs-llm/Tab Bar.md +439 -0
  95. package/docs-llm/Tab Layout.md +398 -0
  96. package/docs-llm/Table.md +2642 -0
  97. package/docs-llm/Text Area.md +253 -0
  98. package/docs-llm/Text.md +339 -0
  99. package/docs-llm/Tooltip.md +325 -0
  100. package/docs-llm/Transition Open.md +406 -0
  101. package/docs-llm/Tree.md +586 -0
  102. package/docs-llm/Typography.md +125 -0
  103. package/docs-llm/Wait Spinner.md +121 -0
  104. package/docs-llm/llms.txt +97 -0
  105. package/package.json +6 -5
  106. package/types/src/Box/Box.d.ts +2 -10
  107. package/types/src/Drawer/Body.d.ts +17 -0
  108. package/types/src/Drawer/Drawer.d.ts +114 -0
  109. package/types/src/Drawer/DrawerContext.d.ts +11 -0
  110. package/types/src/Drawer/Footer.d.ts +25 -0
  111. package/types/src/Drawer/Header.d.ts +41 -0
  112. package/types/src/Drawer/docs/examples/Basic.d.ts +6 -0
  113. package/types/src/Drawer/docs/examples/ContainerPosition.d.ts +7 -0
  114. package/types/src/Drawer/docs/examples/InitialFocus.d.ts +9 -0
  115. package/types/src/Drawer/docs/examples/InlinePosition.d.ts +7 -0
  116. package/types/src/Drawer/docs/examples/PagePosition.d.ts +7 -0
  117. package/types/src/Drawer/index.d.ts +2 -0
  118. package/types/src/JSONTree/JSONTree.d.ts +12 -5
  119. package/types/src/JSONTree/renderTreeItems.d.ts +2 -1
  120. package/types/src/Menu/Item.d.ts +2 -1
  121. package/types/src/Menu/docs/examples/SelectableCheckbox.d.ts +7 -0
  122. package/types/src/Modal/Modal.d.ts +1 -2
  123. package/types/src/Select/Option.d.ts +6 -3
  124. package/types/src/Select/Select.d.ts +8 -5
  125. package/types/src/Select/docs/examples/Dimmed.d.ts +7 -0
  126. package/types/src/SelectBase/OptionBase.d.ts +6 -3
  127. package/types/src/SelectBase/SelectBase.d.ts +8 -3
  128. package/types/src/SidePanel/SidePanel.d.ts +43 -2
  129. package/types/src/SidePanel/docs/examples/DockLayout.d.ts +17 -0
  130. package/types/src/SidePanel/docs/examples/InitialFocus.d.ts +9 -0
  131. package/types/src/TransitionOpen/TransitionOpen.d.ts +29 -4
  132. package/types/src/useKeyPress/index.d.ts +9 -2
  133. package/types/src/useOnClickOutside/index.d.ts +2 -0
  134. package/types/src/useOnClickOutside/useOnClickOutside.d.ts +4 -0
  135. package/useKeyPress.js +23 -18
  136. package/useOnClickOutside.d.ts +2 -0
  137. package/useOnClickOutside.js +79 -0
  138. package/types/src/RadioList/docs/examples/Row.d.ts +0 -6
@@ -0,0 +1,148 @@
1
+ # Paragraph
2
+
3
+ ## Overview
4
+
5
+
6
+ > Image: Illustration of Paragraph component.
7
+
8
+
9
+ ## When to use this component
10
+ - To provide a structured layout for textual sentence-style information.
11
+
12
+ ## When to use another component
13
+ - If the content involves listing or numbering items, using `List` improves readability and organization.
14
+ - If the content involves related data elements, using `Definition List` provides a structured visual representation for key-value pairs.
15
+
16
+ ```mermaid
17
+ graph TD
18
+ accDescr: Decision tree that guides on when to use the Paragraph component or something else
19
+ A(Does the content involve listing items?) -- Yes --- B(List or Definition List)
20
+ A -- No --- C(Paragraph)
21
+ ```
22
+
23
+ ### Check out
24
+ - [List][1]
25
+ - [Definition List][2]
26
+
27
+ ## Usage
28
+
29
+ ### Break paragraphs into small chunks
30
+ Shorter paragraphs improves readability and reduces eye fatigue.
31
+
32
+ > Image: Examples of Paragraph components. In the first example with heart eyes emoji, the text is formatted into two smaller paragraphs. In the second example with grimacing emoji the text is formatted in one longer paragraph.
33
+
34
+
35
+ ### Avoid standalone paragraphs
36
+ Paragraphs should be accompanied by a header that summarizes the content, guides the user’s attention and allows screen readers to navigate to the content.
37
+
38
+ > Image: Examples of Paragraph components. In the first example with heart eyes emoji, the paragraph is accompanied by a header, while the second example with grimacing emoji is a stand alone paragraph.
39
+
40
+
41
+ ## Content guidelines
42
+ Follow writing best practices outlined in the [UI text style guidelines][3]
43
+
44
+ [1]: ./List
45
+ [2]: ./DefinitionList
46
+ [3]: https://docs.splunk.com/Documentation/StyleGuide/current/StyleGuide/UIGuidelines
47
+
48
+
49
+ ## Examples
50
+
51
+
52
+ ### Basic
53
+
54
+ Paragraph provides default fonts, line heights, and spacing. Margins can be removed when necessary.
55
+
56
+ ```typescript
57
+ import React from 'react';
58
+
59
+ import Link from '@splunk/react-ui/Link';
60
+ import P from '@splunk/react-ui/Paragraph';
61
+
62
+
63
+ function Basic() {
64
+ return (
65
+ <>
66
+ <P>
67
+ Use Splunk products to take advantage of one platform for all your security and
68
+ observability data needs. In an ever-changing world, Splunk delivers insights to
69
+ unlock innovation, enhance security and drive resilience.
70
+ </P>
71
+ <P>
72
+ <Link to="https://www.splunk.com/en_us/products/platform.html" openInNewContext>
73
+ The Splunk Platform
74
+ </Link>{' '}
75
+ allows you turn data into doing to unlock innovation, enhance security and drive
76
+ resilience.{' '}
77
+ <Link
78
+ to="https://www.splunk.com/en_us/products/cyber-security.html"
79
+ openInNewContext
80
+ >
81
+ Splunk Security
82
+ </Link>{' '}
83
+ protects your business and modernize your security operations with a best-in-class
84
+ data platform, advanced analytics and automated investigations and response.{' '}
85
+ <Link
86
+ to="https://www.splunk.com/en_us/products/observability.html"
87
+ openInNewContext
88
+ >
89
+ Splunk Observability
90
+ </Link>{' '}
91
+ solves problems in seconds with the only full-stack, analytics-powered and
92
+ OpenTelemetry-native observability solution.
93
+ </P>
94
+ </>
95
+ );
96
+ }
97
+
98
+ export default Basic;
99
+ ```
100
+
101
+
102
+
103
+
104
+ ## API
105
+
106
+
107
+ ### Paragraph API
108
+
109
+ #### Props
110
+
111
+ | Name | Type | Required | Default | Description |
112
+ |------|------|------|------|------|
113
+ | children | React.ReactNode | no | | Generally text, but might also include `Link`s. |
114
+ | elementRef | React.Ref<HTMLParagraphElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
115
+
116
+
117
+
118
+
119
+
120
+ ## Accessibility
121
+
122
+ ## Visual Design
123
+ - Color contrast ratio **MUST** be [SC 1.4.3][1]
124
+ - &gt= 4.5:1 for normal text: 14 pt (typically 18.66px) and bold or larger
125
+ - &gt= 3:1 for large text: 18 pt (typically 24px) or larger
126
+ - For high contrast mode, ratios **MUST** be &gt=7:1 for normal text and &gt=4.5:1 for large text [SC 1.4.6][2]
127
+
128
+ ## States
129
+ - Color contrast guidelines do NOT apply to disabled text
130
+
131
+ ## Interaction Model
132
+ - **MUST NOT** lose content or functionality when the user adapts [SC 1.4.12][3]
133
+ - Line height (line spacing) to at least 1.5 times the font size;
134
+ - Spacing following paragraphs to at least 2 times the font size;
135
+ - Letter spacing (tracking) to at least 0.12 times the font size;
136
+ - Word spacing to at least 0.16 times the font size
137
+ - Line spacing (leading) **MUST** be at least space-and-a-half within paragraphs, and paragraph spacing is at least 1.5 times larger than the line spacing [SC 1.4.8][4]
138
+
139
+ ## Implementation
140
+ - **SHOULD** use correct [phrasing elements][5] to describe the semantics of the content
141
+
142
+ [1]: https://www.w3.org/WAI/GL/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
143
+ [2]: https://www.w3.org/TR/WCAG21/#contrast-enhanced
144
+ [3]: https://www.w3.org/TR/WCAG21/#text-spacing
145
+ [4]: https://www.w3.org/TR/WCAG21/#visual-presentation
146
+ [5]: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#phrasing_content
147
+
148
+
@@ -0,0 +1,254 @@
1
+ # Phone Number
2
+
3
+ ## Overview
4
+
5
+
6
+ > Image: Illustration of a Phone Number component.
7
+
8
+
9
+ <Message appearance="fill" type="info">
10
+ <div>All data entry components should be wrapped in a [Control Group](ControlGroup) 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 collecting phone numbers from users
15
+ - When forms or pages require a validated phone number input
16
+
17
+ ## When to use another component
18
+ - If the input doesn't require formatting, a country code, or is not specifically for phone numbers, consider using Text
19
+
20
+ ```mermaid
21
+ graph TD
22
+ accDescr: Decision tree that guides on when to use the Phone Number component or something else
23
+ A(Do you need to collect a phone number?) -- Yes --- B(Use Phone Number)
24
+ A -- No --- C(Is the input freeform text?)
25
+ C -- Yes --- D(Use Text)
26
+ C -- No --- E(Use Select)
27
+ ```
28
+
29
+ ### Check out
30
+ - [Select][1]
31
+ - [Text][2]
32
+
33
+ ## Behaviors
34
+
35
+ ### Validation
36
+ Validates phone number format and length based on the selected country.
37
+ Use <Link to="ControlGroup">Control Group</Link> to display validation results.
38
+ > Image: Example of phone number validation.
39
+
40
+
41
+ ### Locale
42
+ Defaults the country code and formatting based on the user’s locale.
43
+ > Image: Example of locale-based default.
44
+
45
+
46
+ ### Searchable dropdown
47
+ Allows users to filter the country code list by typing either a country name or a dial code.
48
+ > Image: Examples of filtering country codes in the dropdown.
49
+
50
+
51
+ ## Usage
52
+
53
+ ### Use clear and visible labels
54
+ Use a visible label like “Phone Number” to clearly describe the input. Avoid using placeholder phone numbers as a substitute for labeling to maintain accessibility.
55
+ > Image: Examples of Phone Number labeling. The first example with heart eyes shows a clearly labeled input. The second example with a grimacing face shows a placeholder used instead of a label, reducing accessibility.
56
+
57
+
58
+ ### Match input width to phone number length
59
+ Match the width of the input to the expected phone number length. Avoid stretching the component across the full page or making it too short to view the full value at a glance.
60
+ > Image: Examples of Phone Number input width. The first example with heart eyes shows a field sized to match a typical phone number. The second example with a grimacing face shows an overly wide field that reduces readability.
61
+
62
+
63
+ [1]: ./Select
64
+ [2]: ./Text
65
+
66
+
67
+
68
+ ## Examples
69
+
70
+
71
+ ### Controlled
72
+
73
+ Phone Number requires a `value` prop and an `onChange` callback to update the value prop for most use cases.
74
+
75
+ ```typescript
76
+ import React, { useState } from 'react';
77
+
78
+ import PhoneNumber, { PhoneNumberChangeHandler } from '@splunk/react-ui/PhoneNumber';
79
+
80
+
81
+ const Controlled = () => {
82
+ const [value, setValue] = useState('2345678910');
83
+
84
+ const handleChange: PhoneNumberChangeHandler = (e, { value: newValue }) => {
85
+ setValue(newValue);
86
+ };
87
+
88
+ return <PhoneNumber value={value} onChange={handleChange} />;
89
+ };
90
+
91
+ export default Controlled;
92
+ ```
93
+
94
+
95
+
96
+ ### Uncontrolled
97
+
98
+ Alternatively, Phone Number can be uncontrolled and optionally provided a `defaultValue`. The `onChange` callback still fires. The `value` prop cannot be set or updated externally.
99
+
100
+ ```typescript
101
+ import React from 'react';
102
+
103
+ import PhoneNumber from '@splunk/react-ui/PhoneNumber';
104
+
105
+
106
+ function Uncontrolled() {
107
+ return <PhoneNumber defaultValue="2345678910" />;
108
+ }
109
+
110
+ export default Uncontrolled;
111
+ ```
112
+
113
+
114
+
115
+ ### Default Country
116
+
117
+ Phone Number can have a different default country set.
118
+
119
+ ```typescript
120
+ import React, { useState } from 'react';
121
+
122
+ import PhoneNumber, { PhoneNumberChangeHandler } from '@splunk/react-ui/PhoneNumber';
123
+
124
+
125
+ const DefaultCountry = () => {
126
+ const [value, setValue] = useState('2345678910');
127
+
128
+ const handleChange: PhoneNumberChangeHandler = (e, { value: newValue }) => {
129
+ setValue(newValue);
130
+ };
131
+
132
+ return <PhoneNumber defaultCountry="CA" value={value} onChange={handleChange} />;
133
+ };
134
+
135
+ export default DefaultCountry;
136
+ ```
137
+
138
+
139
+
140
+ ### Inline
141
+
142
+ The `inline` prop will render the component inline at a consistent width with other inputs.
143
+
144
+ ```typescript
145
+ import React, { useState } from 'react';
146
+
147
+ import PhoneNumber, { PhoneNumberChangeHandler } from '@splunk/react-ui/PhoneNumber';
148
+
149
+
150
+ const Inline = () => {
151
+ const [value, setValue] = useState('2345678910');
152
+
153
+ const handleChange: PhoneNumberChangeHandler = (e, { value: newValue }) => {
154
+ setValue(newValue);
155
+ };
156
+
157
+ return <PhoneNumber inline value={value} onChange={handleChange} />;
158
+ };
159
+
160
+ export default Inline;
161
+ ```
162
+
163
+
164
+
165
+ ### Error
166
+
167
+ ```typescript
168
+ import React, { useState } from 'react';
169
+
170
+ import PhoneNumber, { PhoneNumberChangeHandler } from '@splunk/react-ui/PhoneNumber';
171
+
172
+
173
+ const Error = () => {
174
+ const [value, setValue] = useState('2345678910');
175
+
176
+ const handleChange: PhoneNumberChangeHandler = (e, { value: newValue }) => {
177
+ setValue(newValue);
178
+ };
179
+
180
+ return <PhoneNumber error value={value} onChange={handleChange} />;
181
+ };
182
+
183
+ export default Error;
184
+ ```
185
+
186
+
187
+
188
+ ### Disabled
189
+
190
+ ```typescript
191
+ import React, { useState } from 'react';
192
+
193
+ import PhoneNumber, { PhoneNumberChangeHandler } from '@splunk/react-ui/PhoneNumber';
194
+
195
+
196
+ const Disabled = () => {
197
+ const [value, setValue] = useState('2345678910');
198
+
199
+ const handleChange: PhoneNumberChangeHandler = (e, { value: newValue }) => {
200
+ setValue(newValue);
201
+ };
202
+
203
+ return <PhoneNumber disabled value={value} onChange={handleChange} />;
204
+ };
205
+
206
+ export default Disabled;
207
+ ```
208
+
209
+
210
+
211
+
212
+ ## API
213
+
214
+
215
+ ### PhoneNumber API
216
+
217
+ #### Props
218
+
219
+ | Name | Type | Required | Default | Description |
220
+ |------|------|------|------|------|
221
+ | append | boolean | no | | Append removes rounded corners and the border from the right side. |
222
+ | canClear | boolean | no | true | Include an "X" button to clear the value. |
223
+ | defaultCountry | string | no | | The iso2 country code to use for the phone number input. |
224
+ | defaultValue | string | no | | Set this property instead of value to make the value uncontrolled. |
225
+ | describedBy | string | no | | The id of the description. When placed in a ControlGroup, this is automatically set to the ControlGroup's help component. |
226
+ | disabled | boolean | no | | Determines whether or not the input is disabled. |
227
+ | elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts, and null when it unmounts. |
228
+ | error | boolean | no | | Highlight the field as having an error. |
229
+ | inline | boolean | no | | When true, displays inline with a default width. |
230
+ | inputId | string | no | | An id for the text input. |
231
+ | inputRef | React.Ref<HTMLInputElement> | no | | A React ref which is set to the text input element when the component mounts, and null when it unmounts. |
232
+ | labelledBy | string | no | | The id of the label. When placed in a ControlGroup, this is automatically set to the ControlGroup's label. |
233
+ | name | string | no | | |
234
+ | onBlur | PhoneNumberBlurHandler | no | | A callback for when the input loses focus. |
235
+ | onChange | PhoneNumberChangeHandler | no | | Called whenever the value changes. If the value prop is set, this callback is required. |
236
+ | onClick | React.MouseEventHandler<HTMLInputElement> | no | | A callback for when the input is clicked. |
237
+ | onFocus | PhoneNumberFocusHandler | no | | A callback for when the input takes focus. |
238
+ | onSelect | React.ReactEventHandler<HTMLInputElement> | no | | A callback for when the user selects text. |
239
+ | prepend | boolean | no | | Prepend removes rounded borders from the left side. |
240
+ | toggleRef | React.Ref<HTMLButtonElement> | no | | A React ref which is set to the dropdown toggle when the component mounts and null when it unmounts. |
241
+ | value | string | no | | The contents of the input. Setting this value makes the input controlled. A callback is required. |
242
+
243
+ #### Types
244
+
245
+ | Name | Type | Description |
246
+ |------|------|------|
247
+ | PhoneNumberBlurHandler | ( event: React.FocusEvent<HTMLInputElement>, data: { name?: string; value: string; displayValue: string; country?: string; isPossibleNumber: boolean; isValidNumber: boolean; internationalFormat: string; } ) => void | |
248
+ | PhoneNumberChangeHandler | ( event: \| React.ChangeEvent<HTMLInputElement> \| React.KeyboardEvent<HTMLInputElement> \| React.MouseEvent<HTMLButtonElement \| HTMLSpanElement>, data: { name?: string; value: string; displayValue: string; country?: string; isPossibleNumber: boolean; isValidNumber: boolean; internationalFormat: string; } ) => void | |
249
+ | PhoneNumberFocusHandler | ( event: React.FocusEvent<HTMLInputElement>, data: { name?: string; value: string; displayValue: string; country?: string; isPossibleNumber: boolean; isValidNumber: boolean; internationalFormat: string; } ) => void | |
250
+
251
+
252
+
253
+
254
+
@@ -0,0 +1,166 @@
1
+ # Popover
2
+
3
+ ## Overview
4
+
5
+
6
+
7
+ > Image: Illustration of a popover component.
8
+
9
+
10
+
11
+ ## When to use this component
12
+ - Use a Popover for brief, persistent hints tied to an element.
13
+ - To provide non-essential supporting information for specific elements on a page.
14
+ - To provide additional interactions with the supporting information.
15
+
16
+ ## When to use another component
17
+ - When you have multiple steps that the user needs to go through, implement a [Modal][2].
18
+ - If the content is critical and should always be visible, keep the content visible on a page.
19
+ - If the content is critical or must remain visible use [Message][4] or [Message Bar][5].
20
+
21
+ ```mermaid
22
+ graph TD
23
+ accDescr: Decision tree that guides on when to use the Popover component or something else
24
+ A(Is the content secondary and shown on demand?) -- Yes --- B(Does the content include interactive elements?)
25
+ B -- Yes --- C(Does the user need to select an option from a list?)
26
+ C -- Yes --- D(Select, Multiselect, or Radio List)
27
+ C -- No --- E(Popover)
28
+ B -- No --- F(Tooltip)
29
+ A -- No --- G(Keep the content visible on the page)
30
+ ```
31
+
32
+ ### Check out
33
+ - [Tooltip][1]
34
+ - [Modal] [2]
35
+ - [Dropdown][3]
36
+ - [Message][4]
37
+ - [Message Bar][5]
38
+
39
+ ## Behaviors
40
+
41
+ ### Interactive
42
+ Popovers include interactive content, and must be activated on click rather than hover.
43
+
44
+ > Image: Illustration of two Popovers. The first example with heart eyes emoji shows a Popover with multiple interactive elements that is activated on click. The second example with grimacing emoji shows a Popover with multiple interactive elements that is activated on hover.
45
+
46
+
47
+ ## Usage
48
+
49
+ ### Limit content
50
+ Use Popover for brief, task-related content like definitions or quick actions. Avoid long text, complex interactions, or stacking Popovers.
51
+
52
+ > Image: Illustration of two Popovers. The first example with heart eyes emoji shows a Popover announcing a new feature, and a single call-to-action labeled as ‘Continue’. The second example with grimacing emoji shows two stacked Popovers with multiple interactive elements.
53
+
54
+
55
+ ### Supplemental
56
+ Supports content that is nonessential to the primary task.
57
+ > Image: Illustration of two Popovers. The first example with heart eyes emoji shows a Popover in a focus state with the header ‘New Feature Available’. The second example with grimacing emoji shows a Popover opening on hover with buttons and multiple steps.
58
+
59
+
60
+
61
+ [1]: ./Tooltip
62
+ [2]: ./Modal
63
+ [3]: ./Dropdown
64
+ [4]: ./Message
65
+ [5]: ./MessageBar
66
+
67
+
68
+
69
+ ## Examples
70
+
71
+
72
+ ### Basic
73
+
74
+ Click the button to view the Popover.
75
+
76
+ ```typescript
77
+ import React, { useState, useCallback } from 'react';
78
+
79
+ import Button from '@splunk/react-ui/Button';
80
+ import Popover from '@splunk/react-ui/Popover';
81
+
82
+
83
+ function Example() {
84
+ const [open, setOpen] = useState(false);
85
+ const [anchor, setAnchor] = useState<HTMLButtonElement>();
86
+
87
+ const anchorRef = useCallback((el: HTMLButtonElement) => setAnchor(el), []);
88
+ const handleOpen = useCallback(() => setOpen(true), []);
89
+ const handleRequestClose = useCallback(() => setOpen(false), []);
90
+
91
+ return (
92
+ <>
93
+ <Button onClick={handleOpen} elementRef={anchorRef} label="Click me" />
94
+ <Popover open={open} anchor={anchor} onRequestClose={handleRequestClose}>
95
+ <div style={{ padding: '20px', width: '300px' }}>
96
+ This is the content of the popover. You can place any information here.
97
+ </div>
98
+ </Popover>
99
+ </>
100
+ );
101
+ }
102
+
103
+ export default Example;
104
+ ```
105
+
106
+
107
+
108
+
109
+ ## API
110
+
111
+
112
+ ### Popover API
113
+
114
+ `Popover` is used to create layovers such as dropdowns, contextual menus, or tooltips. Use
115
+ this only when the other components don't provide sufficient functionality or control. A controlled
116
+ `Dropdown` covers use cases where you might consider using `Popover` directly.
117
+
118
+ #### Props
119
+
120
+ | Name | Type | Required | Default | Description |
121
+ |------|------|------|------|------|
122
+ | anchor | HTMLElement \| null | no | | The element used to set the position of the `Popover`. It is required when the `Popover` is open and must be mounted. |
123
+ | animation | boolean | no | true | If `true`, the popover applies transitions when it is added to the DOM. |
124
+ | appearance | 'normal' \| 'inverted' \| 'none' | no | 'normal' | **DEPRECATED**: Value 'inverted' `'normal'` is the default appearance.`'none'` is a transparent box. The 'inverted' value is deprecated and will be removed in a future major version. |
125
+ | autoCloseWhenOffScreen | boolean | no | true | If `true`, the `Popover` hides when the anchor is scrolled off the screen. |
126
+ | canCoverAnchor | boolean | no | | If there isn't enough room to render the `Popover` in a direction, this option enables it to be rendered over the anchor. |
127
+ | children | React.ReactNode \| PopoverChildrenRenderer | no | | The content of the `Popover`. If a function is provided, it is invoked with an object containing `anchorHeight`, `anchorWidth`, `maxHeight`, `maxWidth`, and `placement`, and is expected to return renderable content. |
128
+ | closeReasons | PopoverPossibleCloseReason[] | no | [ 'clickAway', 'escapeKey', 'offScreen', 'tabKey', ] | An array of reasons for which this `Popover` should close. |
129
+ | defaultPlacement | PopoverPlacement | no | 'below' | The default placement of the `Popover`. It might be rendered in a different direction depending upon the space available and the `repositionMode`. |
130
+ | elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
131
+ | hideArrow | boolean | no | | Whether or not to hide the arrow pointing to the anchor. The arrow is always hidden when `appearance="none"`. |
132
+ | onRequestClose | PopoverRequestCloseHandler | no | | Callback function fired when the popover is requested to be closed. |
133
+ | open | boolean | no | | If `true`, the `Popover` is visible. |
134
+ | pointTo | { x?: number; y?: number } | no | | Allows the `Popover` to point to and align with a different part of the anchor. The x and y values are relative to the upper left corner of the anchor. This property overides `align`. When positioned above or below, only `x` is used. When positioned left or right, `y` is used. |
135
+ | repositionMode | 'none' \| 'flip' \| 'any' | no | 'flip' | If the `Popover` doesn't fit in the `defaultPlacement`, `repositionMode` determines if and how the `Popover` repositions itself to fit on the page. `none` doesn't reposition the `Popover`. It always renders in the `defaultPlacement` direction. `flip` allows the `Popover` to reposition to the opposite of the `defaultPlacement` if it can fit there and not in the `defaultPlacement`. `any` allows the `Popover` to reposition in any direction if it can fit on the page. |
136
+ | retainFocus | boolean | no | true | Keeps focus within the `Popover` while open. |
137
+ | splunkTheme | | no | | |
138
+ | takeFocus | boolean | no | | When `true`, the `Popover` automatically takes focus when 'open' changes to `true`. Disable this for a `Popover` that has shows on hover, such as a tooltip. |
139
+
140
+ #### Types
141
+
142
+ | Name | Type | Description |
143
+ |------|------|------|
144
+ | PopoverChildrenRenderer | (data: { anchorHeight: number \| null; anchorWidth: number \| null; maxHeight: number \| null; maxWidth: number \| null; placement: PopoverPlacementStatus \| null; toggleId?: string; }) => React.ReactNode | |
145
+ | PopoverPlacement | 'above' \| 'below' \| 'left' \| 'right' \| 'vertical' \| 'horizontal' | |
146
+ | PopoverPlacementStatus | 'above' \| 'below' \| 'left' \| 'right' \| 'misaligned' | |
147
+ | PopoverPossibleCloseReason | 'clickAway' \| 'escapeKey' \| 'offScreen' \| 'tabKey' | |
148
+ | PopoverRequestCloseHandler | (data: { event?: MouseEvent \| KeyboardEvent \| TouchEvent; reason: PopoverPossibleCloseReason; }) => void | |
149
+
150
+
151
+
152
+ ### PopoverProvider API
153
+
154
+ Provides a method for controlling certain `Popover` props in components that use `Popover`.
155
+
156
+ #### Props
157
+
158
+ | Name | Type | Required | Default | Description |
159
+ |------|------|------|------|------|
160
+ | children | React.ReactNode | no | | |
161
+ | hideArrow | boolean | no | | Whether or not to hide the arrow pointing to the `Popover` anchor. `Popover`'s `hideArrow` prop takes priority over this. |
162
+
163
+
164
+
165
+
166
+