@splunk/react-ui 5.7.0 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/Accordion.js +6 -6
  2. package/Box.js +83 -34
  3. package/CHANGELOG.md +34 -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 +204 -185
  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,298 @@
1
+ # Avatar
2
+
3
+ ## Overview
4
+
5
+
6
+ > Image: Illustration of Avatar component showing user profile representations
7
+
8
+
9
+ ## When to use this component
10
+ Use `Avatar` to represent a user in your application interface. It provides a visual identity for users through profile pictures, initials, or icons.
11
+
12
+ - To display user identity in profiles, user lists, or account settings.
13
+ - To show who performed an action in activity feeds or comments.
14
+ - To represent users in collaboration features or team member lists.
15
+ - To provide visual context for user-generated content.
16
+
17
+ ### Additional considerations
18
+ - Always provide a meaningful label for accessibility.
19
+ - Use consistent sizing throughout your application.
20
+ - Consider using initials when profile pictures are not available.
21
+ - Ensure proper contrast between text and background colors.
22
+
23
+ ## When to use another component
24
+ - For display of non-user entities like organizations or systems, use `Image`.
25
+ - For clickable actions that aren't related to user identity, use `Button`.
26
+
27
+ ```mermaid
28
+ graph TD
29
+ accDescr: Decision tree that guides on when to use the Avatar component or something else
30
+ A(Need to represent a user?) -- Yes --- B(Avatar)
31
+ A -- No --- C(Is it a non-identity action?)
32
+ C -- Yes --- D(Button)
33
+ C -- No --- E(Image)
34
+ ```
35
+
36
+ ### Check out
37
+ - [Image][1]
38
+ - [Button][2]
39
+
40
+ ## Behaviors
41
+
42
+ ### Interactive
43
+ When an `onClick` handler or `to` prop is provided, the `Avatar` becomes interactive and can be clicked to navigate or trigger actions.
44
+
45
+ > Image: Examples of interactive Avatars. The first example with heart eyes emoji shows an Avatar with a subtle hover state. The second example with grimacing emoji shows an Avatar without clear interactive feedback.
46
+
47
+
48
+ ### Image fallback
49
+ When an image fails to load, the `Avatar` automatically falls back to displaying initials, providing a consistent user experience.
50
+
51
+ > Image: Examples of image fallback behavior. The first example with heart eyes emoji shows an Avatar that gracefully falls back to initials when the image fails to load. The second example with grimacing emoji shows an Avatar with a broken image placeholder.
52
+
53
+
54
+ ## Usage
55
+
56
+ ### Size consistency
57
+ Use consistent `Avatar` sizes throughout your application. Group related `Avatars` using the same size for visual harmony.
58
+
59
+ > Image: Examples of Avatar size consistency. The first example with heart eyes emoji shows Avatars of consistent size in a user list. The second example with grimacing emoji shows Avatars of varying sizes creating visual inconsistency.
60
+
61
+
62
+ ### Color and contrast
63
+ Ensure initials have sufficient contrast against the background color for accessibility compliance. By default, the component logic handles color contrast automatically.
64
+
65
+ > Image: Examples of proper color contrast. The first example with heart eyes emoji shows Avatars with good contrast between initials and background. The second example with grimacing emoji shows Avatars with poor contrast that are difficult to read.
66
+
67
+
68
+ ## Content
69
+
70
+ ### Meaningful labels
71
+ Always provide descriptive labels that clearly identify what the `Avatar` represents.
72
+
73
+ > Image: Examples of meaningful Avatar labels. The first example with heart eyes emoji shows an Avatar with a clear, descriptive label like
74
+
75
+
76
+ ### Initials best practices
77
+ Use 1-3 characters for initials, typically the first letter of first and last names.
78
+
79
+ > Image: Examples of proper initials usage. The first example with heart eyes emoji shows Avatars with appropriate 1-3 character initials. The second example with grimacing emoji shows Avatars with too many character initials.
80
+
81
+
82
+ ### Image guidelines
83
+ Use high-quality, appropriately sized images that clearly show the person's face.
84
+
85
+ > Image: Examples of proper image usage. The first example with heart eyes emoji shows an Avatar with a clear, well-framed profile picture. The second example with grimacing emoji shows an Avatar with a low-quality or inappropriate image.
86
+
87
+
88
+ ### Capitalization
89
+ Use all caps for `Avatar` labels to ensure consistency and clarity.
90
+
91
+ > Image: Examples of proper capitalization. The first example with heart eyes emoji shows an Avatar label in all caps. The second example with grimacing emoji shows an Avatar label with improper capitalization.
92
+
93
+
94
+ [1]: ./Image
95
+ [2]: ./Button
96
+
97
+ ## Examples
98
+
99
+
100
+ ### Basic
101
+
102
+ An Avatar can show one to three characters. You can use the `getInitials` helper to shorten a name.
103
+
104
+ ```typescript
105
+ import React from 'react';
106
+
107
+ import Avatar, { getInitials } from '@splunk/react-ui/Avatar';
108
+ import Layout from '@splunk/react-ui/Layout';
109
+
110
+
111
+ export default function Basic() {
112
+ return (
113
+ <Layout>
114
+ <Avatar initials="A" label="Amelia's profile" />
115
+ <Avatar initials={getInitials('Amelia Earhart')} label="Amelia Earhart's profile" />
116
+ </Layout>
117
+ );
118
+ }
119
+ ```
120
+
121
+
122
+
123
+ ### Image
124
+
125
+ An Avatar can show an image provided as an icon, <img>, or asset.
126
+
127
+ ```typescript
128
+ import React from 'react';
129
+
130
+ import Portrait from '@splunk/react-icons/Portrait';
131
+ import Avatar from '@splunk/react-ui/Avatar';
132
+ import Layout from '@splunk/react-ui/Layout';
133
+
134
+ import profilePicture from '../assets/profilePicture.png';
135
+
136
+
137
+ export default function Image() {
138
+ return (
139
+ <Layout>
140
+ <Avatar
141
+ initials="AY"
142
+ image={<img src={profilePicture} alt="Anna Yang" />}
143
+ label="Anna Yang's profile"
144
+ />
145
+ <Avatar initials="AE" image={<Portrait />} label="Amelia Earhart's profile" />
146
+ </Layout>
147
+ );
148
+ }
149
+ ```
150
+
151
+
152
+
153
+ ### Background color
154
+
155
+ ```typescript
156
+ import React from 'react';
157
+
158
+ import Avatar from '@splunk/react-ui/Avatar';
159
+ import Layout from '@splunk/react-ui/Layout';
160
+ import { pick, variables } from '@splunk/themes';
161
+
162
+ const avatarColor = pick({
163
+ enterprise: {
164
+ light: variables.diverging3ColorB,
165
+ dark: variables.diverging1ColorA,
166
+ },
167
+ prisma: {
168
+ light: variables.sequential6D7,
169
+ dark: variables.sequential6D3,
170
+ },
171
+ });
172
+
173
+
174
+ export default function BackgroundColor() {
175
+ return (
176
+ <Layout>
177
+ <Avatar backgroundColor={avatarColor} initials="AE" label="Amelia Earhart's profile" />
178
+ <Avatar
179
+ backgroundColor="rgb(255, 103, 123)"
180
+ initials="AE"
181
+ label="Amelia Earhart's profile"
182
+ />
183
+ <Avatar backgroundColor="#2d2d53" initials="AE" label="Amelia Earhart's profile" />
184
+ <Avatar
185
+ backgroundColor="cornflowerblue"
186
+ initials="AE"
187
+ label="Amelia Earhart's profile"
188
+ />
189
+ </Layout>
190
+ );
191
+ }
192
+ ```
193
+
194
+
195
+
196
+ ### Interactive
197
+
198
+ Avatars can be interactive by including the appropriate props to make them buttons or links.
199
+
200
+ ```typescript
201
+ import React from 'react';
202
+
203
+ import Avatar from '@splunk/react-ui/Avatar';
204
+ import Layout from '@splunk/react-ui/Layout';
205
+
206
+ import profilePicture from '../assets/profilePicture.png';
207
+
208
+
209
+ export default function Interactive() {
210
+ return (
211
+ <Layout>
212
+ <Avatar
213
+ image={<img src={profilePicture} alt="Amelia Earhart" />}
214
+ initials="AE"
215
+ label="Amelia Earhart's profile"
216
+ onClick={() => {}}
217
+ />
218
+ <Avatar initials="AY" label="Anna Yang's profile" to="#Interactive" />
219
+ </Layout>
220
+ );
221
+ }
222
+ ```
223
+
224
+
225
+
226
+ ### Size
227
+
228
+ Avatars can be one of three standard sizes: small, medium (default), or large. The size prop can also be a string if the standard size doesn't fit your use case. Note: using a non-standard size may have unexpected layouts when combined with other components.
229
+
230
+ ```typescript
231
+ import React from 'react';
232
+
233
+ import Avatar from '@splunk/react-ui/Avatar';
234
+ import Layout from '@splunk/react-ui/Layout';
235
+
236
+
237
+ export default function Size() {
238
+ return (
239
+ <Layout>
240
+ <Avatar initials="AE" label="Amelia Earhart's profile" size="small" />
241
+ <Avatar initials="AE" label="Amelia Earhart's profile" size="medium" />
242
+ <Avatar initials="AE" label="Amelia Earhart's profile" size="large" />
243
+ </Layout>
244
+ );
245
+ }
246
+ ```
247
+
248
+
249
+
250
+
251
+ ## API
252
+
253
+
254
+ ### Avatar API
255
+
256
+ #### Props
257
+
258
+ | Name | Type | Required | Default | Description |
259
+ |------|------|------|------|------|
260
+ | backgroundColor | \| string \| Interpolation<Enterprise, OptionalThemedProps<Enterprise>> \| Interpolation<Prisma, OptionalThemedProps<Prisma>> | no | | All CSS color definitions are supported, such as `#223344` or `red`. Using `theme` enables the theme default. |
261
+ | elementRef | React.Ref<HTMLAnchorElement \| HTMLButtonElement \| HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts and `null` when it unmounts. |
262
+ | image | React.ReactNode | no | | The image to be displayed inside this `Avatar`, for example an `<img>` or `<svg>`. |
263
+ | initials | string | yes | | The contents of this `Avatar` if the `image` prop is not set or the provided image is not valid. Must not exceed three characters in length. |
264
+ | label | string | yes | | Text to describe what this Avatar represents. |
265
+ | onClick | AvatarClickHandler | no | | Enables interactive mode. |
266
+ | size | 'small' \| 'medium' \| 'large' \| string | no | 'medium' | Adjusts the size of the `Avatar`. |
267
+ | to | string | no | | If set, the component will be rendered as an `<a>` tag with `href` equal to this prop rather than a `<button>` tag. |
268
+ | value | string | no | | The value returned with `onClick` events, which can be used to identify the control when multiple controls share an `onClick` callback. Not to be confused with `initials`. |
269
+
270
+ #### Types
271
+
272
+ | Name | Type | Description |
273
+ |------|------|------|
274
+ | AvatarClickHandler | ( event: React.MouseEvent<HTMLButtonElement>, data: { value?: string } ) => void | |
275
+
276
+
277
+
278
+ #### Utils
279
+
280
+
281
+ #### getInitials(name)
282
+
283
+ Returns a suitable set of initials for a name. Uses the first character of each
284
+ name segment and omits middle segments if the segment count is greater than three.
285
+
286
+ ##### Parameters
287
+
288
+ | Name | Type | Optional | Default | Description |
289
+ |------|------|------|------|------|
290
+ | name | string | no | | The full name. |
291
+
292
+ ##### Returns
293
+
294
+ **string** - Limited to three characters. Empty if `name` is empty.
295
+
296
+
297
+
298
+
@@ -0,0 +1,212 @@
1
+ # Badge
2
+
3
+ ## Overview
4
+
5
+
6
+ > Image: Illustration of a group of three Badges.
7
+
8
+
9
+ ## When to use this component
10
+ Badges serve as visual indicators used to communicate a status, numeric value, or other associated metadata of an object.
11
+
12
+ - To represent a status, property, or specific metadata for an object (e.g., "New", "Beta", "Active", "Warning").
13
+ - To display a count of associated items (e.g., number of unread messages, items in a category).
14
+ - To visually annotate an item, drawing attention to its current state or characteristic.
15
+
16
+ ## When to use another component
17
+
18
+ - When you need to represent input, attribute, or actions of an object, use `Chip`.
19
+
20
+ ### Decision tree
21
+
22
+ ```mermaid
23
+ graph TD
24
+ accDescr: Decision tree that guides on when to use the Badge component or something else
25
+ A(Need a visual indicator?) --- B(For labeling, categorizing,<br/>or organizing objects?)
26
+ A -- No --- G(Paragraph)
27
+ B -- Yes --- C(Chip)
28
+ B -- No --- D(Need multiple elements<br/>in a group?)
29
+ D -- Yes --- C
30
+ D -- No --- E(Visual indicator for status<br/>or description of an element?)
31
+ E -- Yes --- F(Badge)
32
+ ```
33
+
34
+
35
+ ### Check out
36
+ - [Chip][1]
37
+
38
+ ## Usage
39
+
40
+ ### Placement
41
+ Badges are positioned to the side of their associated context.
42
+
43
+ > Image: Example of badge placed next to a text label.
44
+
45
+
46
+ ### Non-interactive
47
+ Badges are non-interactive and serve purely as visual indicators.
48
+
49
+ > Image: The first example with heart eyes emoji shows a badge that is non interactive. The second example with grimacing emoji shows the badge with hover indicating it can be clicked.
50
+
51
+
52
+ ### Standalone
53
+ Do not use multiple badges for similar type of page or object annotations, such as "new," "updated," or "experimental."
54
+
55
+ > Image: The first example with heart eyes emoji shows a heading with a single badge next to it. The second example with grimacing emoji shows a heading with mutliple badges that represent similar type of information next to it.
56
+
57
+
58
+ ### Grouping Multiple Badges
59
+ In scenarios where an object has multiple concurrent states or properties, such as an incident that is "active", critically "severe", and "AI-detected", displaying multiple badges together is appropriate. Grouping badges allows each distinct property to be visually represented without conflating their meanings. Avoid overloading the interface with excessive badges; prioritize the most relevant states (tyipcally 1-3) for display.
60
+
61
+ > Image: The first example with heart eyes emoji shows a heading with a distinct badges. The second example with grimacing emoji shows a heading with a large number of badges next to it.
62
+
63
+
64
+ ### Count Handling
65
+
66
+ #### Showing Zero '0'
67
+ Badges with a zero count should generally not be rendered to avoid unnecessary visual noise. However, there are specific instances where explicitly showing '0' is relevant and provides meaningful context (e.g., indicating "no alerts" or "zero items in a list").
68
+
69
+ > Image: The first example with heart eyes emoji shows a heading with no badge, indicating no objects. The second example with grimacing emoji shows heading with a badge with count zero.
70
+
71
+
72
+
73
+ #### Max count
74
+ When a count exceeds a certain threshold, it is often more effective to display a maximum value (e.g., '99+') rather than the exact large number. To achieve this, use the `truncateNumber` utility from `@splunk/ui-utils`.
75
+
76
+ > Image: The first example with heart eyes emoji shows a heading with badge that shows a max count of
77
+
78
+
79
+ ## Content
80
+
81
+ ### Write concise labels: 1-3 words
82
+ Badges should provide concise information. For text-based Badges, keep the text brief and descriptive. When using icons, ensure they clearly communicate the status or description.
83
+
84
+ > Image: The first example with heart eyes emoji shows a badge with concise text. The second example with grimacing emoji shows a badge with very lengthy text.
85
+
86
+
87
+ ### Follow color contrast guidelines
88
+ When using custom colors, ensure you are following the WCAG guideline of a contrast ratio &gt= 4.5:1 between text and background. [SC 1.4.3][2]
89
+
90
+ > Image: Example of a badge with custom colours. In the first example with heart eyes, the badge label is dark and abide by the 4.5 to 1 contrast guidelines. In the second example with the grimacing face, the badge label is similar to the background colours, breaking the contrast guidelines.
91
+
92
+
93
+
94
+ [1]: ./Chip
95
+ [2]: https://www.w3.org/TR/WCAG21/#contrast-minimum
96
+
97
+ ## Examples
98
+
99
+
100
+ ### Basic
101
+
102
+ ```typescript
103
+ import React from 'react';
104
+
105
+ import Badge from '@splunk/react-ui/Badge';
106
+
107
+
108
+ export default function Basic() {
109
+ return <Badge label="Beta" />;
110
+ }
111
+ ```
112
+
113
+
114
+
115
+ ### Count
116
+
117
+ To set a max count, use the `truncateNumber` util from [@splunk/ui-utils](../ui-utils/Format).
118
+
119
+ ```typescript
120
+ import React from 'react';
121
+
122
+ import Badge from '@splunk/react-ui/Badge';
123
+ import Layout from '@splunk/react-ui/Layout';
124
+ import { truncateNumber } from '@splunk/ui-utils/format';
125
+
126
+
127
+ export default function Count() {
128
+ const count = truncateNumber({ number: 110, max: 99 });
129
+
130
+ return (
131
+ <Layout>
132
+ <Badge label="5" />
133
+ <Badge label={count} />
134
+ </Layout>
135
+ );
136
+ }
137
+ ```
138
+
139
+
140
+
141
+ ### With icons
142
+
143
+ Use the `icon` prop with an icon component (e.g., `@splunk/react-icons`) to add visual context or emphasis alongside the badge's `label`. When using an icon, a label must also be provided.
144
+
145
+ ```typescript
146
+ import React from 'react';
147
+
148
+ import Lightbulb from '@splunk/react-icons/Lightbulb';
149
+ import Badge from '@splunk/react-ui/Badge';
150
+
151
+
152
+ export default function Icon() {
153
+ return <Badge icon={<Lightbulb />} label="Beta" />;
154
+ }
155
+ ```
156
+
157
+
158
+
159
+ ### Custom colors
160
+
161
+ The background and text of Badge can be customized with the `backgroundColor` and `foregroundColor` props. Prefer using variables from `@splunk/themes`, but other valid CSS color values are supported. In all cases, you must check that the chosen colors meet [contrast minimum for text of 4.5:1](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html#user%20interface%20component).
162
+
163
+ ```typescript
164
+ import React from 'react';
165
+
166
+ import Badge from '@splunk/react-ui/Badge';
167
+ import Layout from '@splunk/react-ui/Layout';
168
+ import { variables } from '@splunk/themes';
169
+
170
+
171
+ export default function CustomColors() {
172
+ return (
173
+ <Layout>
174
+ <Badge
175
+ label="RGB"
176
+ backgroundColor="rgb(255, 135, 139)"
177
+ foregroundColor="rgb(0, 0, 0, 0.9)"
178
+ />
179
+ <Badge label="Hexcode" backgroundColor="#1AB2FF" foregroundColor="#000" />
180
+ <Badge
181
+ label="Variables"
182
+ backgroundColor={variables.notificationColorPositive}
183
+ foregroundColor={variables.contentColorInverted}
184
+ />
185
+ <Badge label="Named Colors" backgroundColor="cornflowerblue" foregroundColor="black" />
186
+ </Layout>
187
+ );
188
+ }
189
+ ```
190
+
191
+
192
+
193
+
194
+ ## API
195
+
196
+
197
+ ### Badge API
198
+
199
+ #### Props
200
+
201
+ | Name | Type | Required | Default | Description |
202
+ |------|------|------|------|------|
203
+ | backgroundColor | \| React.CSSProperties['color'] \| Interpolation<AnyTheme, OptionalThemedProps<AnyTheme>> | no | | Changes the background color. Accepts `@splunk/themes` variable or any valid `color` value. |
204
+ | elementRef | React.Ref<HTMLSpanElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
205
+ | foregroundColor | \| React.CSSProperties['color'] \| Interpolation<AnyTheme, OptionalThemedProps<AnyTheme>> | no | | Changes the text and icon color. Accepts `@splunk/themes` variable or any valid `color` value. |
206
+ | icon | React.ReactNode | no | | Icon before the label. |
207
+ | label | string | yes | | The content of the badge. |
208
+
209
+
210
+
211
+
212
+