@brightlocal/ui-components 3.0.0 → 3.2.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/README.md +7 -1
- package/component-meta.json +749 -53
- package/deprecations.json +114 -4
- package/dist/accordion.cjs +1 -1
- package/dist/accordion.d.ts +36 -0
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +74 -61
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +32 -3
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +61 -58
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +58 -57
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts +9 -0
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +50 -30
- package/dist/banner.cjs +1 -0
- package/dist/banner.d.ts +81 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/banner.js +176 -0
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +4 -3
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +50 -57
- package/dist/blocks/progress-state.d.ts +2 -2
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +17 -0
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +8 -2
- package/dist/brand-illustration-motif.d.ts +1 -1
- package/dist/button-group.cjs +1 -0
- package/dist/button-group.d.ts +36 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +47 -0
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +105 -7
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +198 -101
- package/dist/chart.cjs +3 -3
- package/dist/chart.d.ts +270 -24
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +497 -322
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.d.ts +1 -1
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +2 -1
- package/dist/chip.cjs +1 -1
- package/dist/chip.d.ts +38 -4
- package/dist/chip.d.ts.map +1 -1
- package/dist/chip.js +95 -81
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.js +2 -2
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +23 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +251 -225
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +201 -23
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +712 -568
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +13 -5
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +54 -53
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +8 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +79 -52
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +105 -13
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +146 -129
- package/dist/grid.d.ts +26 -3
- package/dist/grid.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.cjs +1 -1
- package/dist/hooks/use-breakpoint.d.ts +1 -1
- package/dist/hooks/use-breakpoint.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.js +1 -0
- package/dist/hooks/use-mobile.cjs +1 -0
- package/dist/hooks/use-mobile.js +8 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +594 -553
- package/dist/info-tooltip.cjs +1 -0
- package/dist/info-tooltip.d.ts +39 -0
- package/dist/info-tooltip.d.ts.map +1 -0
- package/dist/info-tooltip.js +41 -0
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.js +1 -1
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +33 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +167 -54
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.js +9 -9
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +45 -15
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +31 -30
- package/dist/input.cjs +1 -1
- package/dist/input.js +10 -10
- package/dist/lib/block-illustration.cjs +1 -1
- package/dist/lib/block-illustration.d.ts +4 -1
- package/dist/lib/block-illustration.d.ts.map +1 -1
- package/dist/lib/block-illustration.js +12 -11
- package/dist/lib/empty-chip.cjs +1 -0
- package/dist/lib/empty-chip.d.ts +4 -0
- package/dist/lib/empty-chip.d.ts.map +1 -0
- package/dist/lib/empty-chip.js +13 -0
- package/dist/lib/utils.cjs +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +4 -3
- package/dist/list.cjs +1 -1
- package/dist/list.js +1 -1
- package/dist/multi-select-filter.cjs +1 -0
- package/dist/multi-select-filter.d.ts +178 -0
- package/dist/multi-select-filter.d.ts.map +1 -0
- package/dist/multi-select-filter.js +463 -0
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +3 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +57 -57
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +123 -16
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +89 -75
- package/dist/rating.cjs +1 -1
- package/dist/rating.js +18 -18
- package/dist/relative-date.cjs +1 -0
- package/dist/relative-date.d.ts +65 -0
- package/dist/relative-date.d.ts.map +1 -0
- package/dist/relative-date.js +128 -0
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +15 -6
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +38 -36
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +24 -3
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +130 -110
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +78 -2
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +192 -85
- package/dist/single-select-filter.cjs +1 -0
- package/dist/single-select-filter.d.ts +81 -0
- package/dist/single-select-filter.d.ts.map +1 -0
- package/dist/single-select-filter.js +226 -0
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +22 -22
- package/dist/split-layout.cjs +1 -1
- package/dist/split-layout.d.ts +1 -1
- package/dist/split-layout.js +13 -13
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +45 -4
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +90 -73
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +12 -1
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +148 -126
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.js +1 -1
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts +38 -36
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +262 -73
- package/dist/typography-heading.cjs +1 -1
- package/dist/typography-heading.d.ts +13 -0
- package/dist/typography-heading.d.ts.map +1 -1
- package/dist/typography-heading.js +32 -21
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +15 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +35 -24
- package/dist/typography.d.ts +1 -1
- package/package.json +5 -6
- package/src/blocks/empty-state.tsx +17 -24
- package/src/blocks/progress-state.tsx +2 -2
- package/src/blocks/sidebar.tsx +26 -2
- package/src/components/accordion.tsx +82 -27
- package/src/components/alert-dialog.tsx +50 -5
- package/src/components/alert.tsx +16 -8
- package/src/components/badge.tsx +40 -3
- package/src/components/banner.tsx +288 -0
- package/src/components/brand-illustration-motif.tsx +1 -1
- package/src/components/button-group.tsx +112 -0
- package/src/components/button.tsx +1 -1
- package/src/components/card.tsx +249 -27
- package/src/components/chart.tsx +586 -53
- package/src/components/checkbox.tsx +1 -1
- package/src/components/chip.tsx +83 -10
- package/src/components/combobox.tsx +2 -2
- package/src/components/command.tsx +56 -4
- package/src/components/data-table.tsx +842 -199
- package/src/components/date-picker.tsx +18 -7
- package/src/components/field.tsx +81 -12
- package/src/components/global-layout.tsx +176 -38
- package/src/components/grid.tsx +34 -3
- package/src/components/info-tooltip.tsx +94 -0
- package/src/components/input-chip.tsx +1 -1
- package/src/components/input-group.tsx +246 -11
- package/src/components/input-otp.tsx +1 -1
- package/src/components/input-password.tsx +56 -22
- package/src/components/input.tsx +1 -1
- package/src/components/list.tsx +1 -1
- package/src/components/multi-select-filter.tsx +912 -0
- package/src/components/pagination.tsx +10 -3
- package/src/components/progress.tsx +190 -31
- package/src/components/rating.tsx +1 -1
- package/src/components/relative-date.tsx +230 -0
- package/src/components/scroll-area.tsx +23 -10
- package/src/components/select.tsx +65 -11
- package/src/components/sheet.tsx +240 -4
- package/src/components/single-select-filter.tsx +443 -0
- package/src/components/sonner.tsx +16 -5
- package/src/components/split-layout.tsx +2 -2
- package/src/components/table.tsx +71 -11
- package/src/components/tabs.tsx +93 -46
- package/src/components/textarea.tsx +1 -1
- package/src/components/tooltip.tsx +440 -68
- package/src/components/typography-heading.tsx +24 -0
- package/src/components/typography-text.tsx +27 -3
- package/src/components/typography.tsx +1 -1
- package/src/hooks/use-breakpoint.ts +2 -1
- package/src/index.ts +6 -0
- package/src/lib/block-illustration.tsx +5 -1
- package/src/lib/empty-chip.ts +24 -0
- package/src/lib/utils.ts +1 -0
package/src/components/chip.tsx
CHANGED
|
@@ -18,6 +18,25 @@ import {
|
|
|
18
18
|
*/
|
|
19
19
|
type ChipSize = "md" | "lg";
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The event a chip removal hands to `onRemove`: a mouse event from the
|
|
23
|
+
* delete button, or a keyboard event from Backspace/Delete on the chip root.
|
|
24
|
+
*/
|
|
25
|
+
type ChipRemoveEvent =
|
|
26
|
+
| React.MouseEvent<HTMLButtonElement>
|
|
27
|
+
| React.KeyboardEvent<HTMLDivElement>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Removal callback. Declared with the bivariance hack — the same shape React
|
|
31
|
+
* uses for its own event handlers — so handlers annotated against the
|
|
32
|
+
* pre-keyboard, mouse-only contract
|
|
33
|
+
* (`(event: React.MouseEvent<HTMLButtonElement>) => void`) stay assignable
|
|
34
|
+
* under strict function-parameter checking (DS-949).
|
|
35
|
+
*/
|
|
36
|
+
type ChipRemoveHandler = {
|
|
37
|
+
bivarianceHack(event: ChipRemoveEvent): void;
|
|
38
|
+
}["bivarianceHack"];
|
|
39
|
+
|
|
21
40
|
const chipVariants = cva(
|
|
22
41
|
[
|
|
23
42
|
// Base styles
|
|
@@ -39,7 +58,7 @@ const chipVariants = cva(
|
|
|
39
58
|
// Hover state
|
|
40
59
|
"hover:bg-secondary/80",
|
|
41
60
|
// Focus state - direct focus on chip (for keyboard navigation)
|
|
42
|
-
"
|
|
61
|
+
"outline-none",
|
|
43
62
|
"focus-visible:shadow-default",
|
|
44
63
|
// Disabled state
|
|
45
64
|
"disabled:pointer-events-none",
|
|
@@ -119,9 +138,10 @@ interface ChipProps extends Omit<React.ComponentProps<"div">, "children"> {
|
|
|
119
138
|
*/
|
|
120
139
|
disabled?: boolean;
|
|
121
140
|
/**
|
|
122
|
-
* Callback when delete button
|
|
141
|
+
* Callback when the chip is removed — via the delete button (click) or
|
|
142
|
+
* the keyboard (Backspace/Delete while the chip is focused).
|
|
123
143
|
*/
|
|
124
|
-
onRemove?:
|
|
144
|
+
onRemove?: ChipRemoveHandler;
|
|
125
145
|
/**
|
|
126
146
|
* Data hook for automated testing (required)
|
|
127
147
|
*/
|
|
@@ -146,15 +166,33 @@ interface ChipProps extends Omit<React.ComponentProps<"div">, "children"> {
|
|
|
146
166
|
loadingLabel?: string;
|
|
147
167
|
/**
|
|
148
168
|
* Accessible label for the remove button.
|
|
149
|
-
* Supports `{name}` placeholder for interpolation.
|
|
169
|
+
* Supports `{name}` placeholder for interpolation. The default `{name}` is
|
|
170
|
+
* derived from string or number children; for a JSX label, pass this prop
|
|
171
|
+
* with the resolved name.
|
|
150
172
|
* @default "Remove {name}"
|
|
151
173
|
*/
|
|
152
174
|
removeAriaLabel?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Accessible label for the chip itself while it is keyboard-removable
|
|
177
|
+
* (focusable, with the Backspace/Delete removal hint).
|
|
178
|
+
* Supports `{name}` placeholder for interpolation. The default `{name}` is
|
|
179
|
+
* derived from string or number children; for a JSX label, pass this prop
|
|
180
|
+
* with the resolved name.
|
|
181
|
+
* @default "{name}, press Delete to remove"
|
|
182
|
+
*/
|
|
183
|
+
removableAriaLabel?: string;
|
|
153
184
|
}
|
|
154
185
|
|
|
155
186
|
/**
|
|
156
187
|
* Chip component for displaying removable tags or selections.
|
|
157
188
|
* Used for filter selections, tag lists, and multi-select values.
|
|
189
|
+
*
|
|
190
|
+
* A removable chip is a single tab stop: the chip itself takes focus and
|
|
191
|
+
* Backspace/Delete removes it (DS-949). The delete button stays mouse-only
|
|
192
|
+
* (`tabIndex={-1}`) so each chip costs one tab stop, not two. When a removal
|
|
193
|
+
* unmounts the focused chip, the consumer hands focus onward per the
|
|
194
|
+
* Filtering pattern's cascade: source control → filter trigger → results
|
|
195
|
+
* region — never `<body>`.
|
|
158
196
|
*/
|
|
159
197
|
const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
|
|
160
198
|
(
|
|
@@ -171,12 +209,32 @@ const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
|
|
|
171
209
|
maxWidth = 200,
|
|
172
210
|
loadingLabel,
|
|
173
211
|
removeAriaLabel,
|
|
212
|
+
removableAriaLabel,
|
|
213
|
+
onKeyDown,
|
|
174
214
|
...props
|
|
175
215
|
},
|
|
176
216
|
ref
|
|
177
217
|
) => {
|
|
178
218
|
const isDisabled = disabled || loading;
|
|
179
219
|
const iconSize = size === "lg" ? 16 : 14;
|
|
220
|
+
// The {name} fallback is derived from plain-text children only; a JSX
|
|
221
|
+
// label must supply removeAriaLabel/removableAriaLabel itself.
|
|
222
|
+
const chipName =
|
|
223
|
+
typeof children === "string" || typeof children === "number"
|
|
224
|
+
? String(children)
|
|
225
|
+
: "chip";
|
|
226
|
+
const removable = onRemove !== undefined && !isDisabled;
|
|
227
|
+
|
|
228
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
229
|
+
onKeyDown?.(event);
|
|
230
|
+
// A composing parent (InputChip's roving focus) that already handled
|
|
231
|
+
// the key marks it consumed via preventDefault.
|
|
232
|
+
if (event.defaultPrevented || !removable) return;
|
|
233
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
onRemove(event);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
180
238
|
const labelRef = React.useRef<HTMLSpanElement>(null);
|
|
181
239
|
const [isTruncated, setIsTruncated] = React.useState(false);
|
|
182
240
|
|
|
@@ -206,14 +264,32 @@ const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
|
|
|
206
264
|
);
|
|
207
265
|
|
|
208
266
|
return (
|
|
267
|
+
/* Keyboard removal lives on the chip root: when removable it carries
|
|
268
|
+
role="group" and tabIndex=0 below — the rule can't see the
|
|
269
|
+
conditional role. */
|
|
270
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
209
271
|
<div
|
|
210
272
|
ref={ref}
|
|
211
273
|
aria-disabled={isDisabled ? "true" : undefined}
|
|
274
|
+
// Keyboard-removable chips are focusable and announce the removal
|
|
275
|
+
// hint. A composing parent (InputChip) overrides all three via
|
|
276
|
+
// props — the spread below wins.
|
|
277
|
+
aria-label={
|
|
278
|
+
removable
|
|
279
|
+
? (removableAriaLabel ?? "{name}, press Delete to remove").replace(
|
|
280
|
+
"{name}",
|
|
281
|
+
chipName
|
|
282
|
+
)
|
|
283
|
+
: undefined
|
|
284
|
+
}
|
|
212
285
|
className={cn(chipVariants({ size }), className)}
|
|
213
286
|
data-hook={dataHook}
|
|
214
287
|
data-slot="chip"
|
|
215
288
|
data-tracking-el={trackingEl}
|
|
216
289
|
data-tracking-label={trackingLabel}
|
|
290
|
+
role={removable ? "group" : undefined}
|
|
291
|
+
tabIndex={removable ? 0 : undefined}
|
|
292
|
+
onKeyDown={handleKeyDown}
|
|
217
293
|
{...props}
|
|
218
294
|
>
|
|
219
295
|
{isTruncated ? (
|
|
@@ -241,11 +317,8 @@ const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
|
|
|
241
317
|
<button
|
|
242
318
|
aria-label={
|
|
243
319
|
removeAriaLabel
|
|
244
|
-
? removeAriaLabel.replace(
|
|
245
|
-
|
|
246
|
-
typeof children === "string" ? children : "chip"
|
|
247
|
-
)
|
|
248
|
-
: `Remove ${typeof children === "string" ? children : "chip"}`
|
|
320
|
+
? removeAriaLabel.replace("{name}", chipName)
|
|
321
|
+
: `Remove ${chipName}`
|
|
249
322
|
}
|
|
250
323
|
className={cn(chipDeleteButtonVariants({ size }))}
|
|
251
324
|
data-slot="chip-delete"
|
|
@@ -266,4 +339,4 @@ const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
|
|
|
266
339
|
Chip.displayName = "Chip";
|
|
267
340
|
|
|
268
341
|
export { Chip, chipVariants };
|
|
269
|
-
export type { ChipProps, ChipSize };
|
|
342
|
+
export type { ChipProps, ChipRemoveEvent, ChipRemoveHandler, ChipSize };
|
|
@@ -384,7 +384,7 @@ const comboboxTriggerVariants = cva([
|
|
|
384
384
|
"dark:bg-white/5 dark:border-white/15",
|
|
385
385
|
|
|
386
386
|
// Typography
|
|
387
|
-
"text-
|
|
387
|
+
"text-field text-foreground",
|
|
388
388
|
|
|
389
389
|
// Placeholder state
|
|
390
390
|
"data-[placeholder=true]:text-muted-foreground",
|
|
@@ -620,7 +620,7 @@ function ComboboxValue<T>({
|
|
|
620
620
|
return (
|
|
621
621
|
<span
|
|
622
622
|
className={cn(
|
|
623
|
-
"text-
|
|
623
|
+
"text-field overflow-hidden text-ellipsis whitespace-nowrap",
|
|
624
624
|
className
|
|
625
625
|
)}
|
|
626
626
|
data-slot="combobox-value"
|
|
@@ -10,6 +10,8 @@ import { Button } from "@brightlocal/ui-components/button";
|
|
|
10
10
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
11
11
|
import { useDevWarning } from "@brightlocal/ui-components/lib/use-dev-warning";
|
|
12
12
|
|
|
13
|
+
import { emptyChipStyles } from "../lib/empty-chip";
|
|
14
|
+
|
|
13
15
|
/* -------------------------------------------------------------------------------------------------
|
|
14
16
|
* Command Context — shared state between CommandInput and CommandVirtualList
|
|
15
17
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -249,7 +251,7 @@ const CommandInput = React.forwardRef<
|
|
|
249
251
|
<CommandPrimitive.Input
|
|
250
252
|
ref={inputRef}
|
|
251
253
|
className={cn(
|
|
252
|
-
"placeholder:text-muted-foreground text-
|
|
254
|
+
"placeholder:text-muted-foreground text-field flex w-full bg-transparent outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
|
253
255
|
className
|
|
254
256
|
)}
|
|
255
257
|
data-slot="command-input"
|
|
@@ -328,15 +330,37 @@ export interface CommandEmptyProps extends React.ComponentProps<
|
|
|
328
330
|
* Data hook for automated testing
|
|
329
331
|
*/
|
|
330
332
|
dataHook?: string;
|
|
333
|
+
/**
|
|
334
|
+
* Icon shown in the muted chip above the message — the same chip as
|
|
335
|
+
* EmptyState, so the popover form matches the card and page forms
|
|
336
|
+
* (Patterns/Empty States). Decorative; the message carries the state.
|
|
337
|
+
*/
|
|
338
|
+
icon?: React.ReactNode;
|
|
339
|
+
/**
|
|
340
|
+
* One quiet muted line under the message, e.g. "Try a different search."
|
|
341
|
+
*/
|
|
342
|
+
description?: React.ReactNode;
|
|
331
343
|
}
|
|
332
344
|
|
|
333
345
|
/**
|
|
334
|
-
* Empty state displayed when no results are found.
|
|
346
|
+
* Empty state displayed when no results are found. Plain `children` render
|
|
347
|
+
* the one-line form; pass `icon` and/or `description` for the compact form
|
|
348
|
+
* the Empty States pattern uses at popover scope — never hand-roll it.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```tsx
|
|
352
|
+
* <CommandEmpty
|
|
353
|
+
* description="Try a different search."
|
|
354
|
+
* icon={<SearchX />}
|
|
355
|
+
* >
|
|
356
|
+
* No locations match “{search}”
|
|
357
|
+
* </CommandEmpty>
|
|
358
|
+
* ```
|
|
335
359
|
*/
|
|
336
360
|
const CommandEmpty = React.forwardRef<
|
|
337
361
|
React.ComponentRef<typeof CommandPrimitive.Empty>,
|
|
338
362
|
CommandEmptyProps
|
|
339
|
-
>(({ dataHook, ...props }, ref) => {
|
|
363
|
+
>(({ children, dataHook, description, icon, ...props }, ref) => {
|
|
340
364
|
// cmdk hardcodes role="presentation" after spreading props, so we
|
|
341
365
|
// override it via a callback ref to satisfy the listbox a11y contract
|
|
342
366
|
// (role="listbox" requires option or group children).
|
|
@@ -358,7 +382,35 @@ const CommandEmpty = React.forwardRef<
|
|
|
358
382
|
data-hook={dataHook}
|
|
359
383
|
data-slot="command-empty"
|
|
360
384
|
{...props}
|
|
361
|
-
|
|
385
|
+
>
|
|
386
|
+
{icon || description ? (
|
|
387
|
+
/* The compact form. Inside role="option" the content is
|
|
388
|
+
presentational, so the message stays a plain line — never a
|
|
389
|
+
heading — and the chip is aria-hidden. */
|
|
390
|
+
<div className="flex flex-col items-center gap-1 px-4">
|
|
391
|
+
{icon ? (
|
|
392
|
+
<span
|
|
393
|
+
aria-hidden="true"
|
|
394
|
+
className={cn(emptyChipStyles(), "mb-1")}
|
|
395
|
+
data-slot="command-empty-icon"
|
|
396
|
+
>
|
|
397
|
+
{icon}
|
|
398
|
+
</span>
|
|
399
|
+
) : null}
|
|
400
|
+
<p data-slot="command-empty-message">{children}</p>
|
|
401
|
+
{description ? (
|
|
402
|
+
<p
|
|
403
|
+
className="text-muted-foreground"
|
|
404
|
+
data-slot="command-empty-description"
|
|
405
|
+
>
|
|
406
|
+
{description}
|
|
407
|
+
</p>
|
|
408
|
+
) : null}
|
|
409
|
+
</div>
|
|
410
|
+
) : (
|
|
411
|
+
children
|
|
412
|
+
)}
|
|
413
|
+
</CommandPrimitive.Empty>
|
|
362
414
|
);
|
|
363
415
|
});
|
|
364
416
|
CommandEmpty.displayName = "CommandEmpty";
|