@brightlocal/ui-components 3.3.0 → 3.5.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/AI_USAGE.md +22 -3
- package/README.md +177 -109
- package/component-meta.json +1307 -113
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +13 -2
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +4 -3
- package/dist/banner.cjs +1 -1
- package/dist/banner.d.ts +47 -11
- package/dist/banner.d.ts.map +1 -1
- package/dist/banner.js +156 -79
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +40 -5
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +59 -52
- package/dist/blocks/input-list.cjs +1 -1
- package/dist/blocks/input-list.d.ts +1 -0
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/input-list.js +39 -39
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +12 -6
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +64 -63
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +47 -43
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +12 -0
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +115 -97
- package/dist/chart.cjs +6 -6
- package/dist/chart.d.ts +6 -10
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +281 -296
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +430 -343
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +23 -2
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +212 -207
- package/dist/count-indicator.cjs +1 -0
- package/dist/count-indicator.d.ts +85 -0
- package/dist/count-indicator.d.ts.map +1 -0
- package/dist/count-indicator.js +72 -0
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +101 -11
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +593 -523
- package/dist/description-list.cjs +1 -0
- package/dist/description-list.d.ts +142 -0
- package/dist/description-list.d.ts.map +1 -0
- package/dist/description-list.js +173 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +26 -3
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +62 -47
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +8 -4
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +37 -38
- package/dist/file-upload.cjs +1 -0
- package/dist/file-upload.d.ts +546 -0
- package/dist/file-upload.d.ts.map +1 -0
- package/dist/file-upload.js +1103 -0
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +7 -2
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +52 -52
- package/dist/hooks/use-file-dropzone.cjs +1 -0
- package/dist/hooks/use-file-dropzone.d.ts +75 -0
- package/dist/hooks/use-file-dropzone.d.ts.map +1 -0
- package/dist/hooks/use-file-dropzone.js +133 -0
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +29 -16
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +153 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +681 -623
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +30 -1
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +131 -115
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +37 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +131 -114
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.js +6 -6
- package/dist/lib/empty-canvas.cjs +1 -1
- package/dist/lib/empty-canvas.d.ts +27 -1
- package/dist/lib/empty-canvas.d.ts.map +1 -1
- package/dist/lib/empty-canvas.js +27 -23
- package/dist/lib/empty-chip.cjs +1 -1
- package/dist/lib/empty-chip.d.ts +19 -2
- package/dist/lib/empty-chip.d.ts.map +1 -1
- package/dist/lib/empty-chip.js +14 -9
- package/dist/lib/field-aria.cjs +1 -1
- package/dist/lib/field-aria.d.ts +4 -4
- package/dist/lib/field-aria.d.ts.map +1 -1
- package/dist/lib/field-aria.js +7 -5
- package/dist/lib/media-viewer-content.cjs +1 -1
- package/dist/lib/media-viewer-content.js +1 -1
- package/dist/lib/motion.cjs +1 -1
- package/dist/lib/motion.js +15 -10
- package/dist/lib/table-internal.cjs +1 -1
- package/dist/lib/table-internal.d.ts +19 -0
- package/dist/lib/table-internal.d.ts.map +1 -1
- package/dist/lib/table-internal.js +22 -7
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts +230 -40
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +301 -66
- package/dist/logo-mark.cjs +1 -1
- package/dist/logo-mark.d.ts +18 -2
- package/dist/logo-mark.d.ts.map +1 -1
- package/dist/logo-mark.js +159 -79
- package/dist/media-empty.cjs +1 -1
- package/dist/media-empty.d.ts +50 -7
- package/dist/media-empty.d.ts.map +1 -1
- package/dist/media-empty.js +14 -13
- package/dist/media-viewer.cjs +1 -1
- package/dist/media-viewer.js +6 -6
- package/dist/multi-select-filter.cjs +1 -1
- package/dist/multi-select-filter.d.ts.map +1 -1
- package/dist/multi-select-filter.js +92 -101
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +11 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +17 -17
- package/dist/relative-date.d.ts +6 -0
- package/dist/relative-date.d.ts.map +1 -1
- package/dist/resizable.d.ts +1 -1
- package/dist/result-count.cjs +1 -1
- package/dist/result-count.d.ts +13 -16
- package/dist/result-count.d.ts.map +1 -1
- package/dist/result-count.js +24 -33
- package/dist/route-progress.cjs +1 -1
- package/dist/route-progress.js +24 -23
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +22 -3
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +152 -125
- package/dist/single-select-filter.cjs +1 -1
- package/dist/single-select-filter.d.ts.map +1 -1
- package/dist/single-select-filter.js +67 -76
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +77 -76
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +39 -3
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +127 -76
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.d.ts +34 -0
- package/dist/textarea.d.ts.map +1 -1
- package/dist/textarea.js +115 -19
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +137 -131
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +6 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +14 -13
- package/package.json +2 -3
- package/src/blocks/empty-state.tsx +108 -48
- package/src/blocks/input-list.tsx +15 -9
- package/src/blocks/sidebar.tsx +39 -16
- package/src/components/alert-dialog.tsx +18 -2
- package/src/components/banner.tsx +247 -68
- package/src/components/button.tsx +27 -10
- package/src/components/card.tsx +89 -7
- package/src/components/chart.tsx +47 -67
- package/src/components/combobox.tsx +221 -12
- package/src/components/command.tsx +83 -37
- package/src/components/count-indicator.tsx +188 -0
- package/src/components/data-table.tsx +506 -159
- package/src/components/description-list.tsx +445 -0
- package/src/components/dialog.tsx +74 -5
- package/src/components/drawer.tsx +52 -32
- package/src/components/file-upload.tsx +2574 -0
- package/src/components/global-layout.tsx +18 -5
- package/src/components/hover-card.tsx +395 -65
- package/src/components/input-chip.tsx +67 -2
- package/src/components/input-group.tsx +89 -6
- package/src/components/list.tsx +720 -72
- package/src/components/logo-mark.tsx +109 -25
- package/src/components/media-empty.tsx +62 -7
- package/src/components/multi-select-filter.tsx +9 -16
- package/src/components/pagination.tsx +15 -2
- package/src/components/relative-date.tsx +6 -0
- package/src/components/result-count.tsx +27 -54
- package/src/components/sheet.tsx +86 -8
- package/src/components/single-select-filter.tsx +9 -16
- package/src/components/table.tsx +16 -1
- package/src/components/tabs.tsx +223 -41
- package/src/components/textarea.tsx +271 -4
- package/src/components/tooltip.tsx +29 -2
- package/src/components/typography-text.tsx +7 -2
- package/src/hooks/use-file-dropzone.ts +325 -0
- package/src/index.ts +4 -0
- package/src/lib/empty-canvas.tsx +47 -20
- package/src/lib/empty-chip.tsx +38 -3
- package/src/lib/field-aria.tsx +11 -6
- package/src/lib/table-internal.ts +38 -0
package/src/components/list.tsx
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
import * as React from "react";
|
|
2
4
|
import { Slot } from "@radix-ui/react-slot";
|
|
3
5
|
import { cva } from "class-variance-authority";
|
|
4
6
|
|
|
7
|
+
import { ChevronRight } from "@brightlocal/icons";
|
|
5
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
6
9
|
import { Skeleton } from "@brightlocal/ui-components/skeleton";
|
|
10
|
+
import {
|
|
11
|
+
Tooltip,
|
|
12
|
+
TooltipContent,
|
|
13
|
+
TooltipTrigger,
|
|
14
|
+
} from "@brightlocal/ui-components/tooltip";
|
|
7
15
|
|
|
8
16
|
/* -------------------------------------------------------------------------------------------------
|
|
9
|
-
*
|
|
17
|
+
* ListItem variants
|
|
10
18
|
* -----------------------------------------------------------------------------------------------*/
|
|
11
19
|
|
|
12
|
-
const
|
|
20
|
+
const listItemVariants = cva(
|
|
13
21
|
[
|
|
22
|
+
"group/item",
|
|
14
23
|
"flex",
|
|
15
24
|
"gap-4",
|
|
16
25
|
"rounded-lg",
|
|
@@ -20,6 +29,10 @@ const itemVariants = cva(
|
|
|
20
29
|
"transition-colors",
|
|
21
30
|
"duration-fast",
|
|
22
31
|
"ease-out",
|
|
32
|
+
// A row that holds an ListItemButton or ListItemLink hands its padding to it, so the
|
|
33
|
+
// whole row is the hit area and the padding never doubles (DS-1166).
|
|
34
|
+
"has-[>[data-slot=item-button]]:p-0",
|
|
35
|
+
"has-[>[data-slot=item-link]]:p-0",
|
|
23
36
|
],
|
|
24
37
|
{
|
|
25
38
|
variants: {
|
|
@@ -54,6 +67,31 @@ export type ListProps = React.ComponentProps<"ul"> & {
|
|
|
54
67
|
* Data hook for automated testing (required).
|
|
55
68
|
*/
|
|
56
69
|
dataHook: string;
|
|
70
|
+
/**
|
|
71
|
+
* Pulls the list out by the row's own inline padding, so the text of plain
|
|
72
|
+
* (`default`) rows lines up with the content edge of the card around it.
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
inset?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Draws a hairline between rows and drops the gap and the row radius, for
|
|
78
|
+
* plain (`default`) rows such as a drill-down list. For a single break
|
|
79
|
+
* between two groups, use `ListSeparator` instead.
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
divided?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Wraps the whole group in one rounded border, for a list that sits on its
|
|
85
|
+
* own as a box (e.g. inside a sheet or dialog). The rows inside stay plain:
|
|
86
|
+
* no gap, no row radius and no row border, so `ListItem variant="outline"`
|
|
87
|
+
* renders as a plain row here instead of doubling the border. Rows get
|
|
88
|
+
* balanced padding inside the box, 16px at the sides and 12px top and
|
|
89
|
+
* bottom (on the ListItemButton / ListItemLink for a pressable row). Pair it with
|
|
90
|
+
* `divided` for a 1px line between rows. For separate bordered rows, use
|
|
91
|
+
* `ListItem variant="outline"` on a list without `bordered`.
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
bordered?: boolean;
|
|
57
95
|
/**
|
|
58
96
|
* Tracking element identifier for analytics.
|
|
59
97
|
*/
|
|
@@ -65,27 +103,83 @@ export type ListProps = React.ComponentProps<"ul"> & {
|
|
|
65
103
|
};
|
|
66
104
|
|
|
67
105
|
/**
|
|
68
|
-
* Vertical list container for rendering a collection of
|
|
106
|
+
* Vertical list container for rendering a collection of ListItem rows.
|
|
69
107
|
*
|
|
70
108
|
* @example
|
|
71
109
|
* ```tsx
|
|
72
110
|
* <List dataHook="keywords-list">
|
|
73
|
-
* <
|
|
74
|
-
* <
|
|
75
|
-
* <
|
|
76
|
-
* </
|
|
77
|
-
* <
|
|
111
|
+
* <ListItem variant="filled" dataHook="item-1">
|
|
112
|
+
* <ListItemContent>
|
|
113
|
+
* <ListItemTitle>Keyword</ListItemTitle>
|
|
114
|
+
* </ListItemContent>
|
|
115
|
+
* <ListItemActions>
|
|
78
116
|
* <Button variant="ghost" size="icon" dataHook="remove"><XIcon /></Button>
|
|
79
|
-
* </
|
|
80
|
-
* </
|
|
117
|
+
* </ListItemActions>
|
|
118
|
+
* </ListItem>
|
|
81
119
|
* </List>
|
|
82
120
|
* ```
|
|
83
121
|
*/
|
|
122
|
+
const listVariants = cva(["flex", "flex-col"], {
|
|
123
|
+
variants: {
|
|
124
|
+
inset: {
|
|
125
|
+
true: ["-mr-2", "-ml-4"],
|
|
126
|
+
false: [],
|
|
127
|
+
},
|
|
128
|
+
divided: {
|
|
129
|
+
true: [
|
|
130
|
+
"gap-0",
|
|
131
|
+
"[&>[data-slot=item]]:rounded-none",
|
|
132
|
+
"[&>[data-slot=item]+[data-slot=item]]:border-t",
|
|
133
|
+
"[&>[data-slot=item]+[data-slot=item]]:border-border",
|
|
134
|
+
],
|
|
135
|
+
false: ["gap-2"],
|
|
136
|
+
},
|
|
137
|
+
bordered: {
|
|
138
|
+
// One box round the group; the rows inside lose their own radius and
|
|
139
|
+
// border (the divided hairline is more specific, so it survives).
|
|
140
|
+
true: [
|
|
141
|
+
"gap-0",
|
|
142
|
+
"overflow-hidden",
|
|
143
|
+
"rounded-lg",
|
|
144
|
+
"border",
|
|
145
|
+
"border-border",
|
|
146
|
+
"[&>[data-slot=item]]:rounded-none",
|
|
147
|
+
"[&>[data-slot=item]]:border-0",
|
|
148
|
+
// Balanced padding inside the box (16px sides, 12px top and bottom)
|
|
149
|
+
// instead of the compact row's 8/8/16. A pressable row hands its
|
|
150
|
+
// padding to its ListItemButton / ListItemLink, so they get it there.
|
|
151
|
+
"[&>[data-slot=item]:not(:has(>[data-slot=item-button])):not(:has(>[data-slot=item-link]))]:px-4",
|
|
152
|
+
"[&>[data-slot=item]:not(:has(>[data-slot=item-button])):not(:has(>[data-slot=item-link]))]:py-3",
|
|
153
|
+
"[&>[data-slot=item]>[data-slot=item-button]]:px-4",
|
|
154
|
+
"[&>[data-slot=item]>[data-slot=item-button]]:py-3",
|
|
155
|
+
"[&>[data-slot=item]>[data-slot=item-link]]:px-4",
|
|
156
|
+
"[&>[data-slot=item]>[data-slot=item-link]]:py-3",
|
|
157
|
+
],
|
|
158
|
+
false: [],
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
defaultVariants: { inset: false, divided: false, bordered: false },
|
|
162
|
+
});
|
|
163
|
+
|
|
84
164
|
const List = React.forwardRef<HTMLUListElement, ListProps>(
|
|
85
|
-
(
|
|
165
|
+
(
|
|
166
|
+
{
|
|
167
|
+
className,
|
|
168
|
+
dataHook,
|
|
169
|
+
trackingEl,
|
|
170
|
+
trackingLabel,
|
|
171
|
+
inset,
|
|
172
|
+
divided,
|
|
173
|
+
bordered,
|
|
174
|
+
...props
|
|
175
|
+
},
|
|
176
|
+
ref
|
|
177
|
+
) => (
|
|
86
178
|
<ul
|
|
87
179
|
ref={ref}
|
|
88
|
-
className={cn(
|
|
180
|
+
className={cn(listVariants({ inset, divided, bordered }), className)}
|
|
181
|
+
data-bordered={bordered ? "" : undefined}
|
|
182
|
+
data-divided={divided ? "" : undefined}
|
|
89
183
|
data-hook={dataHook}
|
|
90
184
|
data-slot="list"
|
|
91
185
|
data-tracking-el={trackingEl}
|
|
@@ -97,14 +191,14 @@ const List = React.forwardRef<HTMLUListElement, ListProps>(
|
|
|
97
191
|
List.displayName = "List";
|
|
98
192
|
|
|
99
193
|
/* -------------------------------------------------------------------------------------------------
|
|
100
|
-
*
|
|
194
|
+
* ListItem
|
|
101
195
|
* -----------------------------------------------------------------------------------------------*/
|
|
102
196
|
|
|
103
197
|
/**
|
|
104
|
-
* Props for an individual
|
|
198
|
+
* Props for an individual ListItem row within a List.
|
|
105
199
|
* Extends native `<li>` props with CVA variant styling and optional testing/analytics attributes.
|
|
106
200
|
*/
|
|
107
|
-
export type
|
|
201
|
+
export type ListItemProps = React.ComponentProps<"li"> & {
|
|
108
202
|
/**
|
|
109
203
|
* Render as the child element instead of `<li>`.
|
|
110
204
|
* Useful when the item is wrapped by another element (e.g. `<motion.li>`).
|
|
@@ -121,7 +215,7 @@ export type ItemProps = React.ComponentProps<"li"> & {
|
|
|
121
215
|
variant?: "default" | "filled" | "outline" | "loading";
|
|
122
216
|
/**
|
|
123
217
|
* Cross-axis alignment of the row's children (media, content, actions).
|
|
124
|
-
* Use `"start"` when
|
|
218
|
+
* Use `"start"` when ListItemMedia (icon, avatar, step number) should pin to the
|
|
125
219
|
* first line of multi-line content instead of centering vertically.
|
|
126
220
|
* @default "center"
|
|
127
221
|
*/
|
|
@@ -142,9 +236,9 @@ export type ItemProps = React.ComponentProps<"li"> & {
|
|
|
142
236
|
|
|
143
237
|
/**
|
|
144
238
|
* Row component within a List. Supports `default`, `filled`, `outline`, and `loading` variants.
|
|
145
|
-
* Compose with
|
|
239
|
+
* Compose with ListItemMedia, ListItemContent, ListItemTitle, ListItemDescription, and ListItemActions.
|
|
146
240
|
*/
|
|
147
|
-
const
|
|
241
|
+
const ListItem = React.forwardRef<HTMLLIElement, ListItemProps>(
|
|
148
242
|
(
|
|
149
243
|
{
|
|
150
244
|
asChild = false,
|
|
@@ -164,7 +258,8 @@ const Item = React.forwardRef<HTMLLIElement, ItemProps>(
|
|
|
164
258
|
return (
|
|
165
259
|
<Comp
|
|
166
260
|
ref={ref}
|
|
167
|
-
className={cn(
|
|
261
|
+
className={cn(listItemVariants({ variant, align }), className)}
|
|
262
|
+
data-align={align ?? "center"}
|
|
168
263
|
data-hook={dataHook}
|
|
169
264
|
data-slot="item"
|
|
170
265
|
data-tracking-el={trackingEl}
|
|
@@ -183,113 +278,354 @@ const Item = React.forwardRef<HTMLLIElement, ItemProps>(
|
|
|
183
278
|
);
|
|
184
279
|
}
|
|
185
280
|
);
|
|
186
|
-
|
|
281
|
+
ListItem.displayName = "ListItem";
|
|
187
282
|
|
|
188
283
|
/* -------------------------------------------------------------------------------------------------
|
|
189
|
-
*
|
|
284
|
+
* ListItemMedia
|
|
190
285
|
* -----------------------------------------------------------------------------------------------*/
|
|
191
286
|
|
|
192
|
-
|
|
193
|
-
|
|
287
|
+
const listItemMediaVariants = cva(["shrink-0"], {
|
|
288
|
+
variants: {
|
|
289
|
+
variant: {
|
|
290
|
+
default: ["group-data-[align=start]/item:mt-1"],
|
|
291
|
+
icon: [
|
|
292
|
+
"inline-flex",
|
|
293
|
+
"size-10",
|
|
294
|
+
"items-center",
|
|
295
|
+
"justify-center",
|
|
296
|
+
"rounded-lg",
|
|
297
|
+
"border",
|
|
298
|
+
"border-border",
|
|
299
|
+
"bg-background",
|
|
300
|
+
],
|
|
301
|
+
image: [
|
|
302
|
+
"size-10",
|
|
303
|
+
"overflow-hidden",
|
|
304
|
+
"rounded-lg",
|
|
305
|
+
"[&_img]:size-full",
|
|
306
|
+
"[&_img]:object-cover",
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
defaultVariants: { variant: "default" },
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
/** Props for the ListItemMedia sub-component — optional left-side media slot. */
|
|
314
|
+
export type ListItemMediaProps = React.ComponentProps<"div"> & {
|
|
315
|
+
/**
|
|
316
|
+
* How the media is framed.
|
|
317
|
+
* - `default` — the icon or avatar as it is
|
|
318
|
+
* - `icon` — a 40px bordered tile, for brand logos and icons
|
|
319
|
+
* - `image` — a 40px rounded crop, for thumbnails
|
|
320
|
+
* @default "default"
|
|
321
|
+
*/
|
|
322
|
+
variant?: "default" | "icon" | "image";
|
|
323
|
+
};
|
|
194
324
|
|
|
195
325
|
/**
|
|
196
|
-
* Optional left-side media slot for icons or
|
|
326
|
+
* Optional left-side media slot for icons, avatars, logo tiles or thumbnails.
|
|
197
327
|
*/
|
|
198
|
-
const
|
|
199
|
-
({ className, ...props }, ref) => (
|
|
328
|
+
const ListItemMedia = React.forwardRef<HTMLDivElement, ListItemMediaProps>(
|
|
329
|
+
({ className, variant, ...props }, ref) => (
|
|
200
330
|
<div
|
|
201
331
|
ref={ref}
|
|
202
|
-
className={cn(
|
|
332
|
+
className={cn(listItemMediaVariants({ variant }), className)}
|
|
203
333
|
data-slot="item-media"
|
|
334
|
+
data-variant={variant ?? "default"}
|
|
204
335
|
{...props}
|
|
205
336
|
/>
|
|
206
337
|
)
|
|
207
338
|
);
|
|
208
|
-
|
|
339
|
+
ListItemMedia.displayName = "ListItemMedia";
|
|
209
340
|
|
|
210
341
|
/* -------------------------------------------------------------------------------------------------
|
|
211
|
-
*
|
|
342
|
+
* ListItemContent
|
|
212
343
|
* -----------------------------------------------------------------------------------------------*/
|
|
213
344
|
|
|
214
|
-
/** Props for the
|
|
215
|
-
export type
|
|
345
|
+
/** Props for the ListItemContent sub-component — flexible content area within an ListItem. */
|
|
346
|
+
export type ListItemContentProps = React.ComponentProps<"div">;
|
|
216
347
|
|
|
217
348
|
/**
|
|
218
349
|
* Flexible content area that grows to fill available space.
|
|
219
|
-
* Place
|
|
350
|
+
* Place ListItemTitle and ListItemDescription inside.
|
|
220
351
|
*/
|
|
221
|
-
const
|
|
352
|
+
const ListItemContent = React.forwardRef<HTMLDivElement, ListItemContentProps>(
|
|
222
353
|
({ className, ...props }, ref) => (
|
|
223
354
|
<div
|
|
224
355
|
ref={ref}
|
|
225
|
-
className={cn("flex flex-1 flex-col gap-1", className)}
|
|
356
|
+
className={cn("flex min-w-0 flex-1 flex-col gap-1", className)}
|
|
226
357
|
data-slot="item-content"
|
|
227
358
|
{...props}
|
|
228
359
|
/>
|
|
229
360
|
)
|
|
230
361
|
);
|
|
231
|
-
|
|
362
|
+
ListItemContent.displayName = "ListItemContent";
|
|
232
363
|
|
|
233
364
|
/* -------------------------------------------------------------------------------------------------
|
|
234
|
-
*
|
|
365
|
+
* Truncated text (shared by ListItemTitle and ListItemDescription)
|
|
235
366
|
* -----------------------------------------------------------------------------------------------*/
|
|
236
367
|
|
|
237
|
-
/**
|
|
238
|
-
|
|
368
|
+
/** The pressable row parts whose keyboard focus also reveals a cut-off text. */
|
|
369
|
+
const PRESSABLE_ROW_SELECTOR =
|
|
370
|
+
'[data-slot="item-button"], [data-slot="item-link"]';
|
|
239
371
|
|
|
240
372
|
/**
|
|
241
|
-
*
|
|
373
|
+
* Whether the element's text is clamped (cut off past its second line).
|
|
374
|
+
* Measured in a ResizeObserver callback, so it follows the element's width and
|
|
375
|
+
* runs again when the text changes (a MutationObserver re-observes).
|
|
242
376
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
377
|
+
function useIsClamped(el: HTMLElement | null, enabled: boolean) {
|
|
378
|
+
const [clamped, setClamped] = React.useState(false);
|
|
379
|
+
|
|
380
|
+
React.useEffect(() => {
|
|
381
|
+
if (!enabled || !el) return;
|
|
382
|
+
const measure = () =>
|
|
383
|
+
setClamped(
|
|
384
|
+
el.scrollHeight > el.clientHeight + 1 ||
|
|
385
|
+
el.scrollWidth > el.clientWidth + 1
|
|
386
|
+
);
|
|
387
|
+
// ResizeObserver fires once on observe, so the first measure is async.
|
|
388
|
+
const resize = new ResizeObserver(measure);
|
|
389
|
+
resize.observe(el);
|
|
390
|
+
const mutation = new MutationObserver(measure);
|
|
391
|
+
mutation.observe(el, {
|
|
392
|
+
characterData: true,
|
|
393
|
+
childList: true,
|
|
394
|
+
subtree: true,
|
|
395
|
+
});
|
|
396
|
+
return () => {
|
|
397
|
+
resize.disconnect();
|
|
398
|
+
mutation.disconnect();
|
|
399
|
+
};
|
|
400
|
+
}, [enabled, el]);
|
|
401
|
+
|
|
402
|
+
return enabled && el !== null && clamped;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Keyboard focus on the row's ListItemButton / ListItemLink. The text itself is
|
|
407
|
+
* never a tab stop: the row stays one interactive target, and focusing it
|
|
408
|
+
* shows the full text of whatever is clamped inside it.
|
|
409
|
+
*/
|
|
410
|
+
function useRowFocusVisible(el: HTMLElement | null, enabled: boolean) {
|
|
411
|
+
const [focusedRow, setFocusedRow] = React.useState<Element | null>(null);
|
|
412
|
+
const row = enabled ? (el?.closest(PRESSABLE_ROW_SELECTOR) ?? null) : null;
|
|
413
|
+
|
|
414
|
+
React.useEffect(() => {
|
|
415
|
+
if (!row) return;
|
|
416
|
+
const onFocus = () =>
|
|
417
|
+
setFocusedRow(
|
|
418
|
+
row === document.activeElement && row.matches(":focus-visible")
|
|
419
|
+
? row
|
|
420
|
+
: null
|
|
421
|
+
);
|
|
422
|
+
const onBlur = () => setFocusedRow(null);
|
|
423
|
+
// The row may already hold focus when the listeners go in (it was
|
|
424
|
+
// focused before the text became clamped), so read the current state too.
|
|
425
|
+
onFocus();
|
|
426
|
+
row.addEventListener("focus", onFocus);
|
|
427
|
+
row.addEventListener("blur", onBlur);
|
|
428
|
+
return () => {
|
|
429
|
+
row.removeEventListener("focus", onFocus);
|
|
430
|
+
row.removeEventListener("blur", onBlur);
|
|
431
|
+
};
|
|
432
|
+
}, [row]);
|
|
433
|
+
|
|
434
|
+
return row !== null && focusedRow === row;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
type TruncatableTextProps = React.ComponentProps<"div"> & {
|
|
438
|
+
asChild?: boolean;
|
|
439
|
+
truncate?: boolean;
|
|
440
|
+
partSlot: "item-title" | "item-description";
|
|
441
|
+
tooltipSide: "top" | "bottom";
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Renders the text, and when `truncate` is on and the text runs past two
|
|
446
|
+
* lines (clamped with an ellipsis), wraps it in a Tooltip with the full text. Hover opens it with a
|
|
447
|
+
* mouse; keyboard focus on the row opens it; a tap opens it only when the
|
|
448
|
+
* text is not inside a button, link or label, so a tap on a pressable row
|
|
449
|
+
* still does what the row does. The full text stays in the DOM for screen
|
|
450
|
+
* readers, so nothing extra is announced.
|
|
451
|
+
*/
|
|
452
|
+
const TruncatableText = React.forwardRef<HTMLDivElement, TruncatableTextProps>(
|
|
453
|
+
(
|
|
454
|
+
{
|
|
455
|
+
asChild = false,
|
|
456
|
+
truncate = false,
|
|
457
|
+
partSlot,
|
|
458
|
+
tooltipSide,
|
|
459
|
+
className,
|
|
460
|
+
children,
|
|
461
|
+
...props
|
|
462
|
+
},
|
|
463
|
+
forwardedRef
|
|
464
|
+
) => {
|
|
465
|
+
// The node lives in state, not a ref: wrapping the text in the Tooltip
|
|
466
|
+
// remounts it, and the observers must follow the new node.
|
|
467
|
+
const [node, setNode] = React.useState<HTMLDivElement | null>(null);
|
|
468
|
+
const setRefs = React.useCallback(
|
|
469
|
+
(el: HTMLDivElement | null) => {
|
|
470
|
+
setNode(el);
|
|
471
|
+
if (typeof forwardedRef === "function") forwardedRef(el);
|
|
472
|
+
else if (forwardedRef) forwardedRef.current = el;
|
|
473
|
+
},
|
|
474
|
+
[forwardedRef]
|
|
475
|
+
);
|
|
476
|
+
const truncated = useIsClamped(node, truncate);
|
|
477
|
+
const rowFocused = useRowFocusVisible(node, truncated);
|
|
478
|
+
const [hoverOpen, setHoverOpen] = React.useState(false);
|
|
479
|
+
// Escape closes the tooltip even while the row keeps focus; it stays
|
|
480
|
+
// closed until the next focus or hover asks for it again.
|
|
481
|
+
const [dismissed, setDismissed] = React.useState(false);
|
|
482
|
+
const [prevRowFocused, setPrevRowFocused] = React.useState(rowFocused);
|
|
483
|
+
if (rowFocused !== prevRowFocused) {
|
|
484
|
+
setPrevRowFocused(rowFocused);
|
|
485
|
+
if (rowFocused) setDismissed(false);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const Comp = asChild ? Slot : "div";
|
|
489
|
+
const text = (
|
|
490
|
+
<Comp
|
|
491
|
+
ref={setRefs}
|
|
492
|
+
className={cn(truncate && "line-clamp-2", className)}
|
|
493
|
+
data-slot={partSlot}
|
|
494
|
+
data-truncated={truncated ? "" : undefined}
|
|
495
|
+
{...props}
|
|
496
|
+
>
|
|
497
|
+
{children}
|
|
498
|
+
</Comp>
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
if (!truncated) return text;
|
|
502
|
+
|
|
503
|
+
return (
|
|
504
|
+
<Tooltip
|
|
505
|
+
open={!dismissed && (hoverOpen || rowFocused)}
|
|
506
|
+
onOpenChange={(open) => {
|
|
507
|
+
if (open) setDismissed(false);
|
|
508
|
+
setHoverOpen(open);
|
|
509
|
+
}}
|
|
510
|
+
>
|
|
511
|
+
<TooltipTrigger
|
|
512
|
+
asChild
|
|
513
|
+
onPointerDown={(event) => {
|
|
514
|
+
// Inside a button, link or label a tap belongs to that control:
|
|
515
|
+
// stop the tooltip from claiming it. The click still fires.
|
|
516
|
+
const target = event.currentTarget as HTMLElement;
|
|
517
|
+
if (
|
|
518
|
+
event.pointerType === "touch" &&
|
|
519
|
+
(target.closest("button, a, label") || target.tagName === "LABEL")
|
|
520
|
+
) {
|
|
521
|
+
event.preventDefault();
|
|
522
|
+
}
|
|
523
|
+
}}
|
|
524
|
+
>
|
|
525
|
+
{text}
|
|
526
|
+
</TooltipTrigger>
|
|
527
|
+
<TooltipContent
|
|
528
|
+
dataHook={`list-${partSlot}-tooltip`}
|
|
529
|
+
side={tooltipSide}
|
|
530
|
+
sideOffset={4}
|
|
531
|
+
onEscapeKeyDown={() => setDismissed(true)}
|
|
532
|
+
>
|
|
533
|
+
{children}
|
|
534
|
+
</TooltipContent>
|
|
535
|
+
</Tooltip>
|
|
536
|
+
);
|
|
537
|
+
}
|
|
252
538
|
);
|
|
253
|
-
|
|
539
|
+
TruncatableText.displayName = "TruncatableText";
|
|
254
540
|
|
|
255
541
|
/* -------------------------------------------------------------------------------------------------
|
|
256
|
-
*
|
|
542
|
+
* ListItemTitle
|
|
257
543
|
* -----------------------------------------------------------------------------------------------*/
|
|
258
544
|
|
|
259
|
-
/** Props for the
|
|
260
|
-
export type
|
|
545
|
+
/** Props for the ListItemTitle sub-component — primary text label within a ListItem. */
|
|
546
|
+
export type ListItemTitleProps = React.ComponentProps<"div"> & {
|
|
547
|
+
/**
|
|
548
|
+
* Render as the child element, e.g. a `<label>` that names the row's Switch.
|
|
549
|
+
* Works together with `truncate`.
|
|
550
|
+
*/
|
|
551
|
+
asChild?: boolean;
|
|
552
|
+
/**
|
|
553
|
+
* Wrap the title to at most two lines and clamp the rest with an ellipsis.
|
|
554
|
+
* When it is clamped, hovering it (or focusing the row's ListItemButton /
|
|
555
|
+
* ListItemLink) shows the full title in a Tooltip. Two lines that fit get
|
|
556
|
+
* no tooltip.
|
|
557
|
+
* @default false
|
|
558
|
+
*/
|
|
559
|
+
truncate?: boolean;
|
|
560
|
+
};
|
|
261
561
|
|
|
262
562
|
/**
|
|
263
|
-
*
|
|
563
|
+
* Primary text label within a ListItem.
|
|
264
564
|
*/
|
|
265
|
-
const
|
|
565
|
+
const ListItemTitle = React.forwardRef<HTMLDivElement, ListItemTitleProps>(
|
|
266
566
|
({ className, ...props }, ref) => (
|
|
267
|
-
<
|
|
567
|
+
<TruncatableText
|
|
268
568
|
ref={ref}
|
|
269
|
-
className={cn("text-
|
|
270
|
-
|
|
569
|
+
className={cn("text-foreground text-body", className)}
|
|
570
|
+
partSlot="item-title"
|
|
571
|
+
tooltipSide="top"
|
|
271
572
|
{...props}
|
|
272
573
|
/>
|
|
273
574
|
)
|
|
274
575
|
);
|
|
275
|
-
|
|
576
|
+
ListItemTitle.displayName = "ListItemTitle";
|
|
577
|
+
|
|
578
|
+
/* -------------------------------------------------------------------------------------------------
|
|
579
|
+
* ListItemDescription
|
|
580
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
581
|
+
|
|
582
|
+
/** Props for the ListItemDescription sub-component — supporting text beneath ListItemTitle. */
|
|
583
|
+
export type ListItemDescriptionProps = React.ComponentProps<"div"> & {
|
|
584
|
+
/**
|
|
585
|
+
* Wrap the description to at most two lines and clamp the rest with an
|
|
586
|
+
* ellipsis. When it is clamped, hovering it (or focusing the row's
|
|
587
|
+
* ListItemButton / ListItemLink) shows the full text in a Tooltip. Two lines
|
|
588
|
+
* that fit get no tooltip.
|
|
589
|
+
* @default false
|
|
590
|
+
*/
|
|
591
|
+
truncate?: boolean;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Supporting description text beneath ListItemTitle.
|
|
596
|
+
*/
|
|
597
|
+
const ListItemDescription = React.forwardRef<
|
|
598
|
+
HTMLDivElement,
|
|
599
|
+
ListItemDescriptionProps
|
|
600
|
+
>(({ className, ...props }, ref) => (
|
|
601
|
+
<TruncatableText
|
|
602
|
+
ref={ref}
|
|
603
|
+
className={cn("text-body-sm text-muted-foreground", className)}
|
|
604
|
+
partSlot="item-description"
|
|
605
|
+
tooltipSide="bottom"
|
|
606
|
+
{...props}
|
|
607
|
+
/>
|
|
608
|
+
));
|
|
609
|
+
ListItemDescription.displayName = "ListItemDescription";
|
|
276
610
|
|
|
277
611
|
/* -------------------------------------------------------------------------------------------------
|
|
278
|
-
*
|
|
612
|
+
* ListItemActions
|
|
279
613
|
* -----------------------------------------------------------------------------------------------*/
|
|
280
614
|
|
|
281
|
-
/** Props for the
|
|
282
|
-
export type
|
|
615
|
+
/** Props for the ListItemActions sub-component — right-side slot for action controls. */
|
|
616
|
+
export type ListItemActionsProps = React.ComponentProps<"div">;
|
|
283
617
|
|
|
284
618
|
/**
|
|
285
|
-
* Right-side slot for
|
|
619
|
+
* Right-side slot for trailing content: an icon button, a menu, a Switch, a
|
|
620
|
+
* Badge or Status, a text Button, or several of them side by side. It is at
|
|
621
|
+
* least 36px square, so a single icon button keeps its place.
|
|
286
622
|
*/
|
|
287
|
-
const
|
|
623
|
+
const ListItemActions = React.forwardRef<HTMLDivElement, ListItemActionsProps>(
|
|
288
624
|
({ className, ...props }, ref) => (
|
|
289
625
|
<div
|
|
290
626
|
ref={ref}
|
|
291
627
|
className={cn(
|
|
292
|
-
"text-muted-foreground flex
|
|
628
|
+
"text-muted-foreground flex min-h-9 min-w-9 shrink-0 items-center justify-center gap-2",
|
|
293
629
|
className
|
|
294
630
|
)}
|
|
295
631
|
data-slot="item-actions"
|
|
@@ -297,14 +633,14 @@ const ItemActions = React.forwardRef<HTMLDivElement, ItemActionsProps>(
|
|
|
297
633
|
/>
|
|
298
634
|
)
|
|
299
635
|
);
|
|
300
|
-
|
|
636
|
+
ListItemActions.displayName = "ListItemActions";
|
|
301
637
|
|
|
302
638
|
/* -------------------------------------------------------------------------------------------------
|
|
303
|
-
*
|
|
639
|
+
* ListSubheader
|
|
304
640
|
* -----------------------------------------------------------------------------------------------*/
|
|
305
641
|
|
|
306
|
-
/** Props for the
|
|
307
|
-
export type
|
|
642
|
+
/** Props for the ListSubheader sub-component — section heading within a List. */
|
|
643
|
+
export type ListSubheaderProps = React.ComponentProps<"li"> & {
|
|
308
644
|
/**
|
|
309
645
|
* Data hook for automated testing.
|
|
310
646
|
*/
|
|
@@ -318,12 +654,12 @@ export type ItemSubheaderProps = React.ComponentProps<"li"> & {
|
|
|
318
654
|
* @example
|
|
319
655
|
* ```tsx
|
|
320
656
|
* <List dataHook="actions-list">
|
|
321
|
-
* <
|
|
322
|
-
* <
|
|
657
|
+
* <ListSubheader>Suggestions</ListSubheader>
|
|
658
|
+
* <ListItem variant="default" dataHook="item-1">...</ListItem>
|
|
323
659
|
* </List>
|
|
324
660
|
* ```
|
|
325
661
|
*/
|
|
326
|
-
const
|
|
662
|
+
const ListSubheader = React.forwardRef<HTMLLIElement, ListSubheaderProps>(
|
|
327
663
|
({ className, dataHook, ...props }, ref) => (
|
|
328
664
|
<li
|
|
329
665
|
ref={ref}
|
|
@@ -347,7 +683,304 @@ const ItemSubheader = React.forwardRef<HTMLLIElement, ItemSubheaderProps>(
|
|
|
347
683
|
/>
|
|
348
684
|
)
|
|
349
685
|
);
|
|
350
|
-
|
|
686
|
+
ListSubheader.displayName = "ListSubheader";
|
|
687
|
+
|
|
688
|
+
/* -------------------------------------------------------------------------------------------------
|
|
689
|
+
* ListItemButton / ListItemLink
|
|
690
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
691
|
+
|
|
692
|
+
/* The pressable part of a row. The ListItem stays the <li>, so the list keeps its
|
|
693
|
+
semantics, and this fills it: it takes over the row's padding and gap
|
|
694
|
+
(ListItem drops its own padding while it holds one) and carries the hover and
|
|
695
|
+
focus states. Align follows the parent ListItem through data-align. */
|
|
696
|
+
const listItemPressableClasses = [
|
|
697
|
+
"flex",
|
|
698
|
+
"w-full",
|
|
699
|
+
"min-w-0",
|
|
700
|
+
"items-center",
|
|
701
|
+
"group-data-[align=start]/item:items-start",
|
|
702
|
+
"gap-4",
|
|
703
|
+
"rounded-[inherit]",
|
|
704
|
+
"py-2",
|
|
705
|
+
"pr-2",
|
|
706
|
+
"pl-4",
|
|
707
|
+
"text-left",
|
|
708
|
+
"cursor-pointer",
|
|
709
|
+
"outline-none",
|
|
710
|
+
"hover:bg-accent",
|
|
711
|
+
"focus-visible:shadow-default",
|
|
712
|
+
"transition-colors",
|
|
713
|
+
"duration-fast",
|
|
714
|
+
"ease-out",
|
|
715
|
+
"disabled:pointer-events-none",
|
|
716
|
+
"disabled:cursor-not-allowed",
|
|
717
|
+
"disabled:opacity-50",
|
|
718
|
+
"aria-disabled:pointer-events-none",
|
|
719
|
+
"aria-disabled:cursor-not-allowed",
|
|
720
|
+
"aria-disabled:opacity-50",
|
|
721
|
+
];
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* A row marked `aria-disabled` stays focusable (so it is still announced), but
|
|
725
|
+
* must not activate. Enter on a button or link fires a click, so blocking the
|
|
726
|
+
* click covers keyboard and pointer. It runs in the capture phase, before any
|
|
727
|
+
* child handler (a router link under `asChild`), and router links skip
|
|
728
|
+
* navigation once the default is prevented.
|
|
729
|
+
*/
|
|
730
|
+
function blockDisabledClick(
|
|
731
|
+
event: React.MouseEvent<HTMLElement>,
|
|
732
|
+
onClickCapture?: React.MouseEventHandler<HTMLElement>
|
|
733
|
+
) {
|
|
734
|
+
const disabled = event.currentTarget.getAttribute("aria-disabled");
|
|
735
|
+
if (disabled === "true" || disabled === "") {
|
|
736
|
+
event.preventDefault();
|
|
737
|
+
event.stopPropagation();
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
onClickCapture?.(event);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/** Props for ListItemButton — a row that runs an action (opens a sheet, a drill-down level). */
|
|
744
|
+
export type ListItemButtonProps = React.ComponentProps<"button"> & {
|
|
745
|
+
/**
|
|
746
|
+
* Data hook for automated testing.
|
|
747
|
+
*/
|
|
748
|
+
dataHook?: string;
|
|
749
|
+
/**
|
|
750
|
+
* Tracking element identifier for analytics.
|
|
751
|
+
*/
|
|
752
|
+
trackingEl?: string;
|
|
753
|
+
/**
|
|
754
|
+
* Tracking label for analytics context.
|
|
755
|
+
*/
|
|
756
|
+
trackingLabel?: string;
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Makes the whole row a button. Place it as the only child of an ListItem and put
|
|
761
|
+
* the row's parts (ListItemMedia, ListItemContent, ListItemValue, ListItemChevron) inside it.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```tsx
|
|
765
|
+
* <ListItem variant="default" dataHook="location">
|
|
766
|
+
* <ListItemButton dataHook="location-row" onClick={open}>
|
|
767
|
+
* <ListItemContent><ListItemTitle>Location</ListItemTitle></ListItemContent>
|
|
768
|
+
* <ListItemValue>London, UK</ListItemValue>
|
|
769
|
+
* <ListItemChevron />
|
|
770
|
+
* </ListItemButton>
|
|
771
|
+
* </ListItem>
|
|
772
|
+
* ```
|
|
773
|
+
*/
|
|
774
|
+
const ListItemButton = React.forwardRef<HTMLButtonElement, ListItemButtonProps>(
|
|
775
|
+
(
|
|
776
|
+
{
|
|
777
|
+
className,
|
|
778
|
+
type = "button",
|
|
779
|
+
dataHook,
|
|
780
|
+
trackingEl,
|
|
781
|
+
trackingLabel,
|
|
782
|
+
onClickCapture,
|
|
783
|
+
...props
|
|
784
|
+
},
|
|
785
|
+
ref
|
|
786
|
+
) => (
|
|
787
|
+
<button
|
|
788
|
+
ref={ref}
|
|
789
|
+
className={cn(listItemPressableClasses, className)}
|
|
790
|
+
data-hook={dataHook}
|
|
791
|
+
data-slot="item-button"
|
|
792
|
+
data-tracking-el={trackingEl}
|
|
793
|
+
data-tracking-label={trackingLabel}
|
|
794
|
+
type={type}
|
|
795
|
+
onClickCapture={(event) => blockDisabledClick(event, onClickCapture)}
|
|
796
|
+
{...props}
|
|
797
|
+
/>
|
|
798
|
+
)
|
|
799
|
+
);
|
|
800
|
+
ListItemButton.displayName = "ListItemButton";
|
|
801
|
+
|
|
802
|
+
/** Props for ListItemLink — a row that navigates. */
|
|
803
|
+
export type ListItemLinkProps = React.ComponentProps<"a"> & {
|
|
804
|
+
/**
|
|
805
|
+
* Render as the child element, e.g. a router `<Link>`.
|
|
806
|
+
*/
|
|
807
|
+
asChild?: boolean;
|
|
808
|
+
/**
|
|
809
|
+
* Data hook for automated testing.
|
|
810
|
+
*/
|
|
811
|
+
dataHook?: string;
|
|
812
|
+
/**
|
|
813
|
+
* Tracking element identifier for analytics.
|
|
814
|
+
*/
|
|
815
|
+
trackingEl?: string;
|
|
816
|
+
/**
|
|
817
|
+
* Tracking label for analytics context.
|
|
818
|
+
*/
|
|
819
|
+
trackingLabel?: string;
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Makes the whole row a link. Place it as the only child of an ListItem; use
|
|
824
|
+
* `asChild` to render a router link.
|
|
825
|
+
*
|
|
826
|
+
* @example
|
|
827
|
+
* ```tsx
|
|
828
|
+
* <ListItem variant="outline" dataHook="billing">
|
|
829
|
+
* <ListItemLink asChild dataHook="billing-link">
|
|
830
|
+
* <NextLink href="/settings/billing">
|
|
831
|
+
* <ListItemContent><ListItemTitle>Billing</ListItemTitle></ListItemContent>
|
|
832
|
+
* <ListItemChevron />
|
|
833
|
+
* </NextLink>
|
|
834
|
+
* </ListItemLink>
|
|
835
|
+
* </ListItem>
|
|
836
|
+
* ```
|
|
837
|
+
*/
|
|
838
|
+
const ListItemLink = React.forwardRef<HTMLAnchorElement, ListItemLinkProps>(
|
|
839
|
+
(
|
|
840
|
+
{
|
|
841
|
+
className,
|
|
842
|
+
asChild = false,
|
|
843
|
+
dataHook,
|
|
844
|
+
trackingEl,
|
|
845
|
+
trackingLabel,
|
|
846
|
+
onClickCapture,
|
|
847
|
+
...props
|
|
848
|
+
},
|
|
849
|
+
ref
|
|
850
|
+
) => {
|
|
851
|
+
const Comp = asChild ? Slot : "a";
|
|
852
|
+
return (
|
|
853
|
+
<Comp
|
|
854
|
+
ref={ref}
|
|
855
|
+
className={cn(listItemPressableClasses, className)}
|
|
856
|
+
data-hook={dataHook}
|
|
857
|
+
data-slot="item-link"
|
|
858
|
+
data-tracking-el={trackingEl}
|
|
859
|
+
data-tracking-label={trackingLabel}
|
|
860
|
+
onClickCapture={(event: React.MouseEvent<HTMLAnchorElement>) =>
|
|
861
|
+
blockDisabledClick(event, onClickCapture)
|
|
862
|
+
}
|
|
863
|
+
{...props}
|
|
864
|
+
/>
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
ListItemLink.displayName = "ListItemLink";
|
|
869
|
+
|
|
870
|
+
/* -------------------------------------------------------------------------------------------------
|
|
871
|
+
* ListItemValue
|
|
872
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
873
|
+
|
|
874
|
+
/** Props for ListItemValue — the current value shown at the end of a drill-down row. */
|
|
875
|
+
export type ListItemValueProps = React.ComponentProps<"span">;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* The row's current value, before the chevron: muted, right-aligned, and cut
|
|
879
|
+
* off with an ellipsis past half the row so the title always keeps its room.
|
|
880
|
+
*/
|
|
881
|
+
const ListItemValue = React.forwardRef<HTMLSpanElement, ListItemValueProps>(
|
|
882
|
+
({ className, ...props }, ref) => (
|
|
883
|
+
<span
|
|
884
|
+
ref={ref}
|
|
885
|
+
className={cn(
|
|
886
|
+
"text-muted-foreground text-body-sm max-w-1/2 min-w-0 shrink truncate text-right",
|
|
887
|
+
className
|
|
888
|
+
)}
|
|
889
|
+
data-slot="item-value"
|
|
890
|
+
{...props}
|
|
891
|
+
/>
|
|
892
|
+
)
|
|
893
|
+
);
|
|
894
|
+
ListItemValue.displayName = "ListItemValue";
|
|
895
|
+
|
|
896
|
+
/* -------------------------------------------------------------------------------------------------
|
|
897
|
+
* ListItemChevron
|
|
898
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
899
|
+
|
|
900
|
+
/** Props for ListItemChevron — the trailing arrow of a row that opens something. */
|
|
901
|
+
export type ListItemChevronProps = React.ComponentProps<typeof ChevronRight>;
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Trailing chevron for a row that navigates or drills down. Decorative: the
|
|
905
|
+
* row's button or link carries the meaning.
|
|
906
|
+
*/
|
|
907
|
+
const ListItemChevron = React.forwardRef<SVGSVGElement, ListItemChevronProps>(
|
|
908
|
+
({ className, ...props }, ref) => (
|
|
909
|
+
<ChevronRight
|
|
910
|
+
ref={ref}
|
|
911
|
+
aria-hidden
|
|
912
|
+
className={cn("text-muted-foreground shrink-0", className)}
|
|
913
|
+
data-slot="item-chevron"
|
|
914
|
+
{...props}
|
|
915
|
+
/>
|
|
916
|
+
)
|
|
917
|
+
);
|
|
918
|
+
ListItemChevron.displayName = "ListItemChevron";
|
|
919
|
+
|
|
920
|
+
/* -------------------------------------------------------------------------------------------------
|
|
921
|
+
* ListSeparator
|
|
922
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
923
|
+
|
|
924
|
+
/** Props for ListSeparator — a hairline between two rows or groups. */
|
|
925
|
+
export type ListSeparatorProps = React.ComponentProps<"li">;
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* A hairline between rows. Hidden from assistive tech so the list's item
|
|
929
|
+
* count stays the number of rows. For a line between every row, use
|
|
930
|
+
* `<List divided>` instead.
|
|
931
|
+
*/
|
|
932
|
+
const ListSeparator = React.forwardRef<HTMLLIElement, ListSeparatorProps>(
|
|
933
|
+
({ className, ...props }, ref) => (
|
|
934
|
+
<li
|
|
935
|
+
ref={ref}
|
|
936
|
+
aria-hidden
|
|
937
|
+
className={cn("bg-border h-px w-full shrink-0", className)}
|
|
938
|
+
data-slot="item-separator"
|
|
939
|
+
{...props}
|
|
940
|
+
/>
|
|
941
|
+
)
|
|
942
|
+
);
|
|
943
|
+
ListSeparator.displayName = "ListSeparator";
|
|
944
|
+
|
|
945
|
+
/* -------------------------------------------------------------------------------------------------
|
|
946
|
+
* Exports
|
|
947
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
948
|
+
|
|
949
|
+
/* -------------------------------------------------------------------------------------------------
|
|
950
|
+
* Deprecated names (removed in 4.0)
|
|
951
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
952
|
+
|
|
953
|
+
/** @deprecated Use `ListItem`. Removed in 4.0. */
|
|
954
|
+
const Item = ListItem;
|
|
955
|
+
/** @deprecated Use `ListItemMedia`. Removed in 4.0. */
|
|
956
|
+
const ItemMedia = ListItemMedia;
|
|
957
|
+
/** @deprecated Use `ListItemContent`. Removed in 4.0. */
|
|
958
|
+
const ItemContent = ListItemContent;
|
|
959
|
+
/** @deprecated Use `ListItemTitle`. Removed in 4.0. */
|
|
960
|
+
const ItemTitle = ListItemTitle;
|
|
961
|
+
/** @deprecated Use `ListItemDescription`. Removed in 4.0. */
|
|
962
|
+
const ItemDescription = ListItemDescription;
|
|
963
|
+
/** @deprecated Use `ListItemActions`. Removed in 4.0. */
|
|
964
|
+
const ItemActions = ListItemActions;
|
|
965
|
+
/** @deprecated Use `ListSubheader`. Removed in 4.0. */
|
|
966
|
+
const ItemSubheader = ListSubheader;
|
|
967
|
+
/** @deprecated Use `listItemVariants`. Removed in 4.0. */
|
|
968
|
+
const itemVariants = listItemVariants;
|
|
969
|
+
|
|
970
|
+
/** @deprecated Use `ListItemProps`. Removed in 4.0. */
|
|
971
|
+
export type ItemProps = ListItemProps;
|
|
972
|
+
/** @deprecated Use `ListItemMediaProps`. Removed in 4.0. */
|
|
973
|
+
export type ItemMediaProps = ListItemMediaProps;
|
|
974
|
+
/** @deprecated Use `ListItemContentProps`. Removed in 4.0. */
|
|
975
|
+
export type ItemContentProps = ListItemContentProps;
|
|
976
|
+
/** @deprecated Use `ListItemTitleProps`. Removed in 4.0. */
|
|
977
|
+
export type ItemTitleProps = ListItemTitleProps;
|
|
978
|
+
/** @deprecated Use `ListItemDescriptionProps`. Removed in 4.0. */
|
|
979
|
+
export type ItemDescriptionProps = ListItemDescriptionProps;
|
|
980
|
+
/** @deprecated Use `ListItemActionsProps`. Removed in 4.0. */
|
|
981
|
+
export type ItemActionsProps = ListItemActionsProps;
|
|
982
|
+
/** @deprecated Use `ListSubheaderProps`. Removed in 4.0. */
|
|
983
|
+
export type ItemSubheaderProps = ListSubheaderProps;
|
|
351
984
|
|
|
352
985
|
/* -------------------------------------------------------------------------------------------------
|
|
353
986
|
* Exports
|
|
@@ -355,6 +988,21 @@ ItemSubheader.displayName = "ItemSubheader";
|
|
|
355
988
|
|
|
356
989
|
export {
|
|
357
990
|
List,
|
|
991
|
+
ListItem,
|
|
992
|
+
ListItemButton,
|
|
993
|
+
ListItemLink,
|
|
994
|
+
ListItemMedia,
|
|
995
|
+
ListItemContent,
|
|
996
|
+
ListItemTitle,
|
|
997
|
+
ListItemDescription,
|
|
998
|
+
ListItemValue,
|
|
999
|
+
ListItemChevron,
|
|
1000
|
+
ListItemActions,
|
|
1001
|
+
ListSubheader,
|
|
1002
|
+
ListSeparator,
|
|
1003
|
+
listVariants,
|
|
1004
|
+
listItemVariants,
|
|
1005
|
+
listItemMediaVariants,
|
|
358
1006
|
Item,
|
|
359
1007
|
ItemMedia,
|
|
360
1008
|
ItemContent,
|