@brightlocal/ui-components 3.1.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 +6 -1
- package/component-meta.json +663 -38
- package/deprecations.json +1 -1
- 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 +21 -20
- 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/card.cjs +1 -1
- package/dist/card.d.ts +86 -6
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +185 -96
- package/dist/chart.cjs +3 -3
- package/dist/chart.d.ts +231 -13
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +466 -306
- 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/combobox.cjs +1 -1
- package/dist/combobox.js +2 -2
- package/dist/command.cjs +1 -1
- package/dist/command.js +1 -1
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +169 -22
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +695 -561
- package/dist/grid.d.ts +24 -1
- 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/index.cjs +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +593 -561
- 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 +28 -6
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +5 -5
- 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/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/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/select.cjs +2 -2
- package/dist/select.d.ts +11 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +97 -81
- 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-text.d.ts +1 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography.d.ts +1 -1
- package/package.json +5 -6
- package/src/blocks/empty-state.tsx +8 -3
- package/src/blocks/progress-state.tsx +2 -2
- package/src/blocks/sidebar.tsx +26 -2
- 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/card.tsx +211 -24
- package/src/components/chart.tsx +523 -35
- package/src/components/checkbox.tsx +1 -1
- package/src/components/combobox.tsx +2 -2
- package/src/components/command.tsx +1 -1
- package/src/components/data-table.tsx +778 -195
- package/src/components/grid.tsx +32 -1
- 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 +33 -11
- 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/progress.tsx +190 -31
- package/src/components/rating.tsx +1 -1
- package/src/components/relative-date.tsx +230 -0
- package/src/components/select.tsx +35 -5
- 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-text.tsx +1 -2
- package/src/components/typography.tsx +1 -1
- package/src/hooks/use-breakpoint.ts +2 -1
- package/src/index.ts +5 -0
- package/src/lib/block-illustration.tsx +5 -1
- package/src/lib/utils.ts +1 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { VariantProps } from "class-variance-authority";
|
|
5
|
+
|
|
6
|
+
import { ChevronDown } from "@brightlocal/icons";
|
|
7
|
+
import { Button } from "@brightlocal/ui-components/button";
|
|
8
|
+
import {
|
|
9
|
+
Drawer,
|
|
10
|
+
DrawerBody,
|
|
11
|
+
DrawerClose,
|
|
12
|
+
DrawerContent,
|
|
13
|
+
DrawerDescription,
|
|
14
|
+
DrawerFooter,
|
|
15
|
+
DrawerHeader,
|
|
16
|
+
DrawerTitle,
|
|
17
|
+
DrawerTrigger,
|
|
18
|
+
} from "@brightlocal/ui-components/drawer";
|
|
19
|
+
import { useIsBelowBreakpoint } from "@brightlocal/ui-components/hooks/use-breakpoint";
|
|
20
|
+
import { Label } from "@brightlocal/ui-components/label";
|
|
21
|
+
import {
|
|
22
|
+
RadioGroup,
|
|
23
|
+
RadioGroupItem,
|
|
24
|
+
} from "@brightlocal/ui-components/radio-group";
|
|
25
|
+
import {
|
|
26
|
+
Select,
|
|
27
|
+
SelectContent,
|
|
28
|
+
SelectItem,
|
|
29
|
+
SelectTrigger,
|
|
30
|
+
SelectValue,
|
|
31
|
+
} from "@brightlocal/ui-components/select";
|
|
32
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
33
|
+
import { multiSelectFilterTriggerVariants } from "@brightlocal/ui-components/multi-select-filter";
|
|
34
|
+
|
|
35
|
+
/* SingleSelectFilter — the Filtering pattern's single-value dimension
|
|
36
|
+
(Patterns/Data Manipulation/Filtering → Which control → Dropdown filter):
|
|
37
|
+
one value from one dimension, e.g. time period, interval, source type.
|
|
38
|
+
|
|
39
|
+
Desktop. A DS Select reads its chosen label and opens a native listbox —
|
|
40
|
+
the same dropdown the form Select uses, wearing the filter trigger look
|
|
41
|
+
(multiSelectFilterTriggerVariants) so it sits beside a MultiSelectFilter
|
|
42
|
+
in a toolbar row without looking different.
|
|
43
|
+
|
|
44
|
+
Mobile. Below the md breakpoint (or when presentation="drawer") the
|
|
45
|
+
trigger opens a bottom Drawer with RadioGroup in two columns — the same
|
|
46
|
+
anatomy as MultiSelectFilter's drawer, using radios instead of checkboxes
|
|
47
|
+
because only one value can be active. Picking any radio applies at once;
|
|
48
|
+
Clear resets to defaultValue; Done closes.
|
|
49
|
+
|
|
50
|
+
Commit model matches MultiSelectFilter: onValueChange fires on every
|
|
51
|
+
pick so client data can reflect immediately. */
|
|
52
|
+
|
|
53
|
+
/* ------------------------------------------------------------------------ */
|
|
54
|
+
/* Types */
|
|
55
|
+
/* ------------------------------------------------------------------------ */
|
|
56
|
+
|
|
57
|
+
interface SingleSelectFilterOption<Value extends string = string> {
|
|
58
|
+
value: Value;
|
|
59
|
+
label: string;
|
|
60
|
+
count?: number;
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Glyph before the label in the menu and the drawer — the option's own
|
|
64
|
+
* mark (a source's logo, a period's clock), 16px. The trigger wears the
|
|
65
|
+
* picked option's glyph when no `icon` is set. Hidden from assistive tech.
|
|
66
|
+
*/
|
|
67
|
+
icon?: React.ReactNode;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface SingleSelectFilterProps<Value extends string = string>
|
|
71
|
+
extends
|
|
72
|
+
Omit<
|
|
73
|
+
React.ComponentPropsWithoutRef<"button">,
|
|
74
|
+
"value" | "defaultValue" | "onChange" | "children"
|
|
75
|
+
>,
|
|
76
|
+
VariantProps<typeof multiSelectFilterTriggerVariants> {
|
|
77
|
+
/** Data hook for automated testing (REQUIRED). */
|
|
78
|
+
dataHook: string;
|
|
79
|
+
/**
|
|
80
|
+
* The dimension's name — drawer title, Select accessible label.
|
|
81
|
+
* Use the product's words ("Time period"), never an internal field name.
|
|
82
|
+
*/
|
|
83
|
+
label: string;
|
|
84
|
+
/**
|
|
85
|
+
* The selectable options, in the dimension's own order. Values must be
|
|
86
|
+
* non-empty — `""` means "nothing picked", so make "All" an explicit value.
|
|
87
|
+
*/
|
|
88
|
+
options: readonly SingleSelectFilterOption<Value>[];
|
|
89
|
+
/** Controlled selected value. */
|
|
90
|
+
value?: Value;
|
|
91
|
+
/**
|
|
92
|
+
* Initial value for uncontrolled mode.
|
|
93
|
+
* @default ""
|
|
94
|
+
*/
|
|
95
|
+
defaultValue?: Value;
|
|
96
|
+
/** Callback on every pick. */
|
|
97
|
+
onValueChange?: (value: Value) => void;
|
|
98
|
+
/** Controlled open state. */
|
|
99
|
+
open?: boolean;
|
|
100
|
+
/** Callback when the surface opens or closes. */
|
|
101
|
+
onOpenChange?: (open: boolean) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Fixed glyph leading the trigger — the dimension's own icon (a calendar,
|
|
104
|
+
* a funnel), 16px. Without it the trigger wears the picked option's
|
|
105
|
+
* `option.icon`. Hidden from assistive tech.
|
|
106
|
+
*/
|
|
107
|
+
icon?: React.ReactNode;
|
|
108
|
+
/**
|
|
109
|
+
* How the options open: the DS Select `menu`, a bottom `drawer`, or `auto`
|
|
110
|
+
* — the menu from the md breakpoint up and the drawer below it.
|
|
111
|
+
* @default "menu"
|
|
112
|
+
*/
|
|
113
|
+
presentation?: "menu" | "drawer" | "auto";
|
|
114
|
+
/** Disables the trigger. */
|
|
115
|
+
disabled?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Label of the clear action inside the drawer.
|
|
118
|
+
* @default "Clear filters"
|
|
119
|
+
*/
|
|
120
|
+
clearLabel?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Label of the drawer's Done button.
|
|
123
|
+
* @default "Done"
|
|
124
|
+
*/
|
|
125
|
+
doneLabel?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Screen-reader description of the drawer.
|
|
128
|
+
* @default "Pick one option."
|
|
129
|
+
*/
|
|
130
|
+
drawerDescription?: string;
|
|
131
|
+
/** Analytics element identifier. @default "single-select-filter" */
|
|
132
|
+
trackingEl?: string;
|
|
133
|
+
/** Analytics label */
|
|
134
|
+
trackingLabel?: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* ------------------------------------------------------------------------ */
|
|
138
|
+
/* Engine */
|
|
139
|
+
/* ------------------------------------------------------------------------ */
|
|
140
|
+
|
|
141
|
+
interface UseSingleSelectFilterStateOptions<Value extends string = string> {
|
|
142
|
+
value?: Value;
|
|
143
|
+
defaultValue: Value;
|
|
144
|
+
onValueChange?: (value: Value) => void;
|
|
145
|
+
open?: boolean;
|
|
146
|
+
onOpenChange?: (open: boolean) => void;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function useSingleSelectFilterState<Value extends string = string>({
|
|
150
|
+
value: controlledValue,
|
|
151
|
+
defaultValue,
|
|
152
|
+
onValueChange,
|
|
153
|
+
open: controlledOpen,
|
|
154
|
+
onOpenChange,
|
|
155
|
+
}: UseSingleSelectFilterStateOptions<Value>) {
|
|
156
|
+
const [uncontrolledValue, setUncontrolledValue] =
|
|
157
|
+
React.useState<Value>(defaultValue);
|
|
158
|
+
const isControlled = controlledValue !== undefined;
|
|
159
|
+
const value = isControlled ? controlledValue : uncontrolledValue;
|
|
160
|
+
|
|
161
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
|
|
162
|
+
const isOpenControlled = controlledOpen !== undefined;
|
|
163
|
+
const open = isOpenControlled ? controlledOpen : uncontrolledOpen;
|
|
164
|
+
|
|
165
|
+
const setValue = React.useCallback(
|
|
166
|
+
(next: Value) => {
|
|
167
|
+
if (!isControlled) setUncontrolledValue(next);
|
|
168
|
+
onValueChange?.(next);
|
|
169
|
+
},
|
|
170
|
+
[isControlled, onValueChange]
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const handleOpenChange = React.useCallback(
|
|
174
|
+
(next: boolean) => {
|
|
175
|
+
if (!isOpenControlled) setUncontrolledOpen(next);
|
|
176
|
+
onOpenChange?.(next);
|
|
177
|
+
},
|
|
178
|
+
[isOpenControlled, onOpenChange]
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
clear: () => setValue(defaultValue),
|
|
183
|
+
onOpenChange: handleOpenChange,
|
|
184
|
+
open,
|
|
185
|
+
setValue,
|
|
186
|
+
value,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* ------------------------------------------------------------------------ */
|
|
191
|
+
/* Pieces */
|
|
192
|
+
/* ------------------------------------------------------------------------ */
|
|
193
|
+
|
|
194
|
+
function OptionCount({ count }: { count: number }) {
|
|
195
|
+
return (
|
|
196
|
+
<span className="text-muted-foreground text-label-sm ml-auto tabular-nums">
|
|
197
|
+
{count}
|
|
198
|
+
</span>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function Glyph({
|
|
203
|
+
children,
|
|
204
|
+
dataHook,
|
|
205
|
+
}: {
|
|
206
|
+
children: React.ReactNode;
|
|
207
|
+
dataHook: string;
|
|
208
|
+
}) {
|
|
209
|
+
return (
|
|
210
|
+
<span
|
|
211
|
+
aria-hidden="true"
|
|
212
|
+
className="flex shrink-0 items-center [&_svg]:size-4"
|
|
213
|
+
data-hook={dataHook}
|
|
214
|
+
>
|
|
215
|
+
{children}
|
|
216
|
+
</span>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* ------------------------------------------------------------------------ */
|
|
221
|
+
/* Component */
|
|
222
|
+
/* ------------------------------------------------------------------------ */
|
|
223
|
+
|
|
224
|
+
function SingleSelectFilterInner<Value extends string = string>({
|
|
225
|
+
className,
|
|
226
|
+
dataHook,
|
|
227
|
+
label,
|
|
228
|
+
options,
|
|
229
|
+
value: controlledValue,
|
|
230
|
+
defaultValue = "" as Value,
|
|
231
|
+
onValueChange,
|
|
232
|
+
open: controlledOpen,
|
|
233
|
+
onOpenChange,
|
|
234
|
+
size = "default",
|
|
235
|
+
icon,
|
|
236
|
+
presentation = "menu",
|
|
237
|
+
disabled = false,
|
|
238
|
+
clearLabel,
|
|
239
|
+
doneLabel,
|
|
240
|
+
drawerDescription,
|
|
241
|
+
trackingEl,
|
|
242
|
+
trackingLabel,
|
|
243
|
+
"aria-label": ariaLabelProp,
|
|
244
|
+
ref,
|
|
245
|
+
...props
|
|
246
|
+
}: SingleSelectFilterProps<Value> & {
|
|
247
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
248
|
+
}) {
|
|
249
|
+
const state = useSingleSelectFilterState<Value>({
|
|
250
|
+
defaultValue,
|
|
251
|
+
onOpenChange,
|
|
252
|
+
onValueChange,
|
|
253
|
+
open: controlledOpen,
|
|
254
|
+
value: controlledValue,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const belowMd = useIsBelowBreakpoint("md");
|
|
258
|
+
const useDrawer =
|
|
259
|
+
presentation === "drawer" || (presentation === "auto" && belowMd);
|
|
260
|
+
const idPrefix = React.useId();
|
|
261
|
+
|
|
262
|
+
const selected =
|
|
263
|
+
state.value === ""
|
|
264
|
+
? undefined
|
|
265
|
+
: options.find((option) => option.value === state.value);
|
|
266
|
+
const selectedLabel = selected?.label;
|
|
267
|
+
const hasValue = selected !== undefined;
|
|
268
|
+
|
|
269
|
+
const triggerText = hasValue ? selectedLabel : label;
|
|
270
|
+
const triggerIcon = icon ?? selected?.icon;
|
|
271
|
+
const triggerGlyph = triggerIcon ? (
|
|
272
|
+
<Glyph dataHook={`${dataHook}-icon`}>{triggerIcon}</Glyph>
|
|
273
|
+
) : null;
|
|
274
|
+
|
|
275
|
+
const computedAriaLabel = hasValue ? `${label}: ${selectedLabel}` : label;
|
|
276
|
+
|
|
277
|
+
/* ------- Drawer mode ------- */
|
|
278
|
+
if (useDrawer) {
|
|
279
|
+
const triggerNode = (
|
|
280
|
+
<button
|
|
281
|
+
ref={ref}
|
|
282
|
+
aria-label={ariaLabelProp ?? computedAriaLabel}
|
|
283
|
+
className={cn(multiSelectFilterTriggerVariants({ size }), className)}
|
|
284
|
+
data-hook={dataHook}
|
|
285
|
+
data-slot="single-select-filter"
|
|
286
|
+
data-tracking-el={trackingEl ?? "single-select-filter"}
|
|
287
|
+
data-tracking-label={trackingLabel}
|
|
288
|
+
disabled={disabled}
|
|
289
|
+
type="button"
|
|
290
|
+
{...props}
|
|
291
|
+
>
|
|
292
|
+
{triggerGlyph}
|
|
293
|
+
<span data-hook={`${dataHook}-summary`}>{triggerText}</span>
|
|
294
|
+
<ChevronDown aria-hidden="true" className="text-muted-foreground" />
|
|
295
|
+
</button>
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<Drawer open={state.open} onOpenChange={state.onOpenChange}>
|
|
300
|
+
<DrawerTrigger asChild>{triggerNode}</DrawerTrigger>
|
|
301
|
+
<DrawerContent dataHook={`${dataHook}-drawer`}>
|
|
302
|
+
<DrawerHeader>
|
|
303
|
+
<DrawerTitle>{label}</DrawerTitle>
|
|
304
|
+
<DrawerDescription className="sr-only">
|
|
305
|
+
{drawerDescription ?? "Pick one option."}
|
|
306
|
+
</DrawerDescription>
|
|
307
|
+
</DrawerHeader>
|
|
308
|
+
<DrawerBody className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pb-2">
|
|
309
|
+
<RadioGroup
|
|
310
|
+
className="grid grid-cols-2 gap-x-4 gap-y-3"
|
|
311
|
+
dataHook={`${dataHook}-radio-group`}
|
|
312
|
+
value={state.value}
|
|
313
|
+
onValueChange={(next) => {
|
|
314
|
+
state.setValue(next as Value);
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
{options.map((option, index) => {
|
|
318
|
+
const optionDisabled = option.disabled || option.count === 0;
|
|
319
|
+
const optionId = `${idPrefix}-${index}`;
|
|
320
|
+
return (
|
|
321
|
+
<div key={option.value} className="flex items-center gap-2">
|
|
322
|
+
<RadioGroupItem
|
|
323
|
+
data-hook={`${dataHook}-option-${option.value}`}
|
|
324
|
+
disabled={optionDisabled}
|
|
325
|
+
id={optionId}
|
|
326
|
+
value={option.value}
|
|
327
|
+
/>
|
|
328
|
+
<Label className="flex-1 gap-2" htmlFor={optionId}>
|
|
329
|
+
{option.icon ? (
|
|
330
|
+
<Glyph
|
|
331
|
+
dataHook={`${dataHook}-option-${option.value}-icon`}
|
|
332
|
+
>
|
|
333
|
+
{option.icon}
|
|
334
|
+
</Glyph>
|
|
335
|
+
) : null}
|
|
336
|
+
{option.label}
|
|
337
|
+
</Label>
|
|
338
|
+
{option.count !== undefined ? (
|
|
339
|
+
<OptionCount count={option.count} />
|
|
340
|
+
) : null}
|
|
341
|
+
</div>
|
|
342
|
+
);
|
|
343
|
+
})}
|
|
344
|
+
</RadioGroup>
|
|
345
|
+
{hasValue && state.value !== defaultValue ? (
|
|
346
|
+
<Button
|
|
347
|
+
dataHook={`${dataHook}-clear`}
|
|
348
|
+
variant="ghost"
|
|
349
|
+
onClick={() => state.clear()}
|
|
350
|
+
>
|
|
351
|
+
{clearLabel ?? "Clear filters"}
|
|
352
|
+
</Button>
|
|
353
|
+
) : null}
|
|
354
|
+
</DrawerBody>
|
|
355
|
+
<DrawerFooter>
|
|
356
|
+
<DrawerClose asChild>
|
|
357
|
+
<Button dataHook={`${dataHook}-done`}>
|
|
358
|
+
{doneLabel ?? "Done"}
|
|
359
|
+
</Button>
|
|
360
|
+
</DrawerClose>
|
|
361
|
+
</DrawerFooter>
|
|
362
|
+
</DrawerContent>
|
|
363
|
+
</Drawer>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/* ------- Select mode (desktop) ------- */
|
|
368
|
+
return (
|
|
369
|
+
<span
|
|
370
|
+
data-hook={dataHook}
|
|
371
|
+
data-slot="single-select-filter"
|
|
372
|
+
data-tracking-el={trackingEl ?? "single-select-filter"}
|
|
373
|
+
data-tracking-label={trackingLabel}
|
|
374
|
+
>
|
|
375
|
+
<Select
|
|
376
|
+
disabled={disabled}
|
|
377
|
+
open={state.open}
|
|
378
|
+
value={state.value}
|
|
379
|
+
onOpenChange={state.onOpenChange}
|
|
380
|
+
onValueChange={(next) => state.setValue(next as Value)}
|
|
381
|
+
>
|
|
382
|
+
<SelectTrigger
|
|
383
|
+
ref={ref}
|
|
384
|
+
className={cn(
|
|
385
|
+
multiSelectFilterTriggerVariants({ size }),
|
|
386
|
+
// A filter reads the dimension name like a value, never muted.
|
|
387
|
+
"data-[placeholder]:text-foreground w-auto",
|
|
388
|
+
className
|
|
389
|
+
)}
|
|
390
|
+
dataHook={`${dataHook}-trigger`}
|
|
391
|
+
selectLabel={ariaLabelProp ?? computedAriaLabel}
|
|
392
|
+
{...props}
|
|
393
|
+
>
|
|
394
|
+
{triggerGlyph}
|
|
395
|
+
{/* Children replace Radix's mirror of the picked item, so the
|
|
396
|
+
trigger shows only the label — never the item's icon or count. */}
|
|
397
|
+
<SelectValue placeholder={label}>{selectedLabel}</SelectValue>
|
|
398
|
+
</SelectTrigger>
|
|
399
|
+
<SelectContent align="start">
|
|
400
|
+
{options.map((option) => {
|
|
401
|
+
const optionDisabled = option.disabled || option.count === 0;
|
|
402
|
+
return (
|
|
403
|
+
<SelectItem
|
|
404
|
+
key={option.value}
|
|
405
|
+
data-hook={`${dataHook}-option-${option.value}`}
|
|
406
|
+
disabled={optionDisabled}
|
|
407
|
+
hint={
|
|
408
|
+
option.count !== undefined ? (
|
|
409
|
+
<span className="tabular-nums">{option.count}</span>
|
|
410
|
+
) : undefined
|
|
411
|
+
}
|
|
412
|
+
value={option.value}
|
|
413
|
+
>
|
|
414
|
+
<span className="flex items-center gap-2">
|
|
415
|
+
{option.icon ? (
|
|
416
|
+
<Glyph dataHook={`${dataHook}-option-${option.value}-icon`}>
|
|
417
|
+
{option.icon}
|
|
418
|
+
</Glyph>
|
|
419
|
+
) : null}
|
|
420
|
+
{option.label}
|
|
421
|
+
</span>
|
|
422
|
+
</SelectItem>
|
|
423
|
+
);
|
|
424
|
+
})}
|
|
425
|
+
</SelectContent>
|
|
426
|
+
</Select>
|
|
427
|
+
</span>
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// No forwardRef: it erases the Value generic; React 19 passes ref as a prop.
|
|
432
|
+
const SingleSelectFilter = SingleSelectFilterInner as <
|
|
433
|
+
Value extends string = string,
|
|
434
|
+
>(
|
|
435
|
+
props: SingleSelectFilterProps<Value> & {
|
|
436
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
437
|
+
}
|
|
438
|
+
) => React.ReactElement | null;
|
|
439
|
+
|
|
440
|
+
SingleSelectFilterInner.displayName = "SingleSelectFilter";
|
|
441
|
+
|
|
442
|
+
export { SingleSelectFilter, type SingleSelectFilterOption };
|
|
443
|
+
export type { SingleSelectFilterProps };
|
|
@@ -69,6 +69,17 @@ type ToastInput = Omit<ToastProps, "id"> & { id?: string | number };
|
|
|
69
69
|
const DEFAULT_DURATION = 4000;
|
|
70
70
|
|
|
71
71
|
// CVA variant definitions extracted for reusability and testing
|
|
72
|
+
//
|
|
73
|
+
// The success colour schema repeats `text-success-foreground
|
|
74
|
+
// dark:text-green-100` across title, description and icon rather than sharing a
|
|
75
|
+
// constant: the token-drift scanner classifies utility strings per source line
|
|
76
|
+
// and does not resolve identifiers, so a constant would hide these three
|
|
77
|
+
// usages from the audit instead of tokenising them.
|
|
78
|
+
//
|
|
79
|
+
// `dark:text-green-100` stays a palette class on purpose. The success toast
|
|
80
|
+
// sits on the `popover` surface in dark, and no semantic token resolves to
|
|
81
|
+
// green-100 (#e7faeb) there — `success-foreground` is green-200 (#baf5c8) in
|
|
82
|
+
// dark, so switching would change the rendered colour.
|
|
72
83
|
const CONTAINER_VARIANTS = cva(
|
|
73
84
|
[
|
|
74
85
|
"flex",
|
|
@@ -87,8 +98,8 @@ const CONTAINER_VARIANTS = cva(
|
|
|
87
98
|
{
|
|
88
99
|
variants: {
|
|
89
100
|
colorSchema: {
|
|
90
|
-
default: "bg-
|
|
91
|
-
success: "bg-
|
|
101
|
+
default: "bg-popover",
|
|
102
|
+
success: "bg-success-background dark:bg-popover",
|
|
92
103
|
},
|
|
93
104
|
},
|
|
94
105
|
defaultVariants: {
|
|
@@ -101,7 +112,7 @@ const TITLE_VARIANTS = cva("text-heading-compact", {
|
|
|
101
112
|
variants: {
|
|
102
113
|
colorSchema: {
|
|
103
114
|
default: "text-foreground",
|
|
104
|
-
success: "text-
|
|
115
|
+
success: "text-success-foreground dark:text-green-100",
|
|
105
116
|
},
|
|
106
117
|
},
|
|
107
118
|
defaultVariants: {
|
|
@@ -113,7 +124,7 @@ const DESCRIPTION_VARIANTS = cva("text-body-sm", {
|
|
|
113
124
|
variants: {
|
|
114
125
|
colorSchema: {
|
|
115
126
|
default: "text-muted-foreground",
|
|
116
|
-
success: "text-
|
|
127
|
+
success: "text-success-foreground dark:text-green-100",
|
|
117
128
|
},
|
|
118
129
|
},
|
|
119
130
|
defaultVariants: {
|
|
@@ -125,7 +136,7 @@ const ICON_VARIANTS = cva("", {
|
|
|
125
136
|
variants: {
|
|
126
137
|
colorSchema: {
|
|
127
138
|
default: "text-foreground",
|
|
128
|
-
success: "text-
|
|
139
|
+
success: "text-success-foreground dark:text-green-100",
|
|
129
140
|
},
|
|
130
141
|
},
|
|
131
142
|
defaultVariants: {
|
|
@@ -223,7 +223,7 @@ interface SplitLayoutContentRightProps extends React.ComponentProps<"div"> {
|
|
|
223
223
|
* SplitLayoutContentRight - Right/secondary section within a SplitLayout.
|
|
224
224
|
*
|
|
225
225
|
* Hidden on mobile/tablet (<1024px), visible on desktop (≥1024px).
|
|
226
|
-
* Uses
|
|
226
|
+
* Uses the muted background colour (bg-muted).
|
|
227
227
|
* Self-positions in the second column, spanning all rows of the grid.
|
|
228
228
|
*
|
|
229
229
|
* Set `flush` to remove padding for full-bleed content (e.g. images).
|
|
@@ -236,7 +236,7 @@ const SplitLayoutContentRight = React.forwardRef<
|
|
|
236
236
|
<div
|
|
237
237
|
ref={ref}
|
|
238
238
|
className={cn(
|
|
239
|
-
"bg-
|
|
239
|
+
"bg-muted hidden lg:col-start-2 lg:row-span-full lg:row-start-1",
|
|
240
240
|
flush
|
|
241
241
|
? "relative overflow-hidden lg:block"
|
|
242
242
|
: "p-section-sm min-h-0 items-center justify-center overflow-auto lg:flex",
|
package/src/components/table.tsx
CHANGED
|
@@ -49,6 +49,33 @@ const tableHeadVariants = cva(
|
|
|
49
49
|
}
|
|
50
50
|
);
|
|
51
51
|
|
|
52
|
+
/* -------------------------------------------------------------------------------------------------
|
|
53
|
+
* Scroll-region semantics (shared)
|
|
54
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Focusable scroll-region semantics for a table's scroll container:
|
|
58
|
+
* `role="region"` with an accessible name plus `tabIndex={0}`, so keyboard
|
|
59
|
+
* users can focus the container and scroll it (axe:
|
|
60
|
+
* scrollable-region-focusable).
|
|
61
|
+
*
|
|
62
|
+
* Single source of the contract and its "Scrollable table" default.
|
|
63
|
+
* `Table` applies it to its own wrapper (`scrollOwner="self"` + `minWidth`);
|
|
64
|
+
* `DataTable` / `VirtualizedDataTable` apply it to their outer wrapper,
|
|
65
|
+
* which owns scrolling instead. The caller decides *when* the container is
|
|
66
|
+
* a scroll region; this helper only says *what* that means.
|
|
67
|
+
*
|
|
68
|
+
* @internal Exported only so the DataTable module shares one copy — not a
|
|
69
|
+
* public contract; its shape may change without a major release.
|
|
70
|
+
*/
|
|
71
|
+
function scrollRegionProps(scrollRegionLabel: string | undefined) {
|
|
72
|
+
return {
|
|
73
|
+
role: "region",
|
|
74
|
+
"aria-label": scrollRegionLabel ?? "Scrollable table",
|
|
75
|
+
tabIndex: 0,
|
|
76
|
+
} as const;
|
|
77
|
+
}
|
|
78
|
+
|
|
52
79
|
/* -------------------------------------------------------------------------------------------------
|
|
53
80
|
* Table
|
|
54
81
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -81,16 +108,37 @@ interface TableProps extends React.ComponentProps<"table"> {
|
|
|
81
108
|
* Minimum width for the table (e.g., "600px", "40rem").
|
|
82
109
|
* Prevents columns from compressing on narrow viewports and enables
|
|
83
110
|
* horizontal scroll via the built-in overflow container.
|
|
84
|
-
*
|
|
85
|
-
* keyboard accessibility
|
|
111
|
+
* With `scrollOwner="self"` (the default) the wrapper then becomes a
|
|
112
|
+
* focusable scroll region for keyboard accessibility; with
|
|
113
|
+
* `scrollOwner="parent"` the scrolling ancestor must carry those
|
|
114
|
+
* semantics itself (`DataTable` does).
|
|
86
115
|
*/
|
|
87
116
|
minWidth?: string;
|
|
88
117
|
/**
|
|
89
118
|
* Accessible label for the scroll container region.
|
|
90
|
-
* Used when `minWidth` is set
|
|
119
|
+
* Used when `minWidth` is set with `scrollOwner="self"` (the default).
|
|
120
|
+
* Ignored with `scrollOwner="parent"` — the scrolling ancestor owns the
|
|
121
|
+
* region and its label there.
|
|
122
|
+
*
|
|
123
|
+
* Give each table on a page a distinct label — several region landmarks
|
|
124
|
+
* sharing the default name violate axe's landmark-unique rule.
|
|
91
125
|
* @default "Scrollable table"
|
|
92
126
|
*/
|
|
93
127
|
scrollRegionLabel?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Which element owns the table's scrolling.
|
|
130
|
+
* - `"self"` (default) — the built-in `table-container` wrapper scrolls
|
|
131
|
+
* horizontally and (with `minWidth`) carries the focusable
|
|
132
|
+
* scroll-region semantics. Standalone Table behavior.
|
|
133
|
+
* - `"parent"` — no internal scroll container is created: the wrapper
|
|
134
|
+
* stays a plain positioned block, so the nearest scrolling ancestor
|
|
135
|
+
* owns both axes. A `sticky` header then sticks to that ancestor, and
|
|
136
|
+
* the ancestor must carry the scroll-region semantics itself when
|
|
137
|
+
* `minWidth` is set. `DataTable` / `VirtualizedDataTable` render Table
|
|
138
|
+
* this way — their outer wrapper is the single scroll container.
|
|
139
|
+
* @default "self"
|
|
140
|
+
*/
|
|
141
|
+
scrollOwner?: "self" | "parent";
|
|
94
142
|
}
|
|
95
143
|
|
|
96
144
|
const Table = React.forwardRef<HTMLTableElement, TableProps>(
|
|
@@ -103,24 +151,32 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
|
|
|
103
151
|
layout = "auto",
|
|
104
152
|
minWidth,
|
|
105
153
|
scrollRegionLabel,
|
|
154
|
+
scrollOwner = "self",
|
|
106
155
|
style,
|
|
107
156
|
...props
|
|
108
157
|
},
|
|
109
158
|
ref
|
|
110
159
|
) => {
|
|
160
|
+
const ownsScroll = scrollOwner === "self";
|
|
111
161
|
return (
|
|
112
162
|
<div
|
|
113
163
|
className={cn(
|
|
114
|
-
"relative w-full
|
|
115
|
-
|
|
164
|
+
"relative w-full",
|
|
165
|
+
// `overflow-x-auto` makes the wrapper a scroll container in BOTH
|
|
166
|
+
// axes (an `auto` axis forces the other out of `visible`), which
|
|
167
|
+
// would confine a sticky <thead> here. With a parent scroll owner
|
|
168
|
+
// the wrapper must stay overflow-visible so sticky positioning
|
|
169
|
+
// and height bounds resolve against that ancestor (DS-912).
|
|
170
|
+
// `scrollbar` themes the native scrollbar with DS colors — the
|
|
171
|
+
// Command/Combobox treatment for bounded scroll containers.
|
|
172
|
+
ownsScroll && "scrollbar overflow-x-auto",
|
|
173
|
+
ownsScroll &&
|
|
174
|
+
minWidth &&
|
|
175
|
+
"focus-visible:shadow-default rounded-md outline-none"
|
|
116
176
|
)}
|
|
117
177
|
data-slot="table-container"
|
|
118
|
-
{...(minWidth
|
|
119
|
-
?
|
|
120
|
-
role: "region",
|
|
121
|
-
"aria-label": scrollRegionLabel ?? "Scrollable table",
|
|
122
|
-
tabIndex: 0,
|
|
123
|
-
}
|
|
178
|
+
{...(ownsScroll && minWidth
|
|
179
|
+
? scrollRegionProps(scrollRegionLabel)
|
|
124
180
|
: undefined)}
|
|
125
181
|
>
|
|
126
182
|
<table
|
|
@@ -426,6 +482,10 @@ export {
|
|
|
426
482
|
TableRow,
|
|
427
483
|
TableCell,
|
|
428
484
|
TableCaption,
|
|
485
|
+
// Shared scroll-region contract — consumed by DataTable/VirtualizedDataTable
|
|
486
|
+
// for their outer scroll container. Not a component (lowercase, so it stays
|
|
487
|
+
// out of the component registry).
|
|
488
|
+
scrollRegionProps,
|
|
429
489
|
};
|
|
430
490
|
|
|
431
491
|
export type {
|