@underpin/ui 2.0.0 → 2.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/components/bulk-action-bar.d.ts +21 -0
- package/components/bulk-action-bar.js +38 -0
- package/components/bulk-action-bar.js.map +1 -0
- package/components/button-group.d.ts +11 -7
- package/components/button-group.js +13 -8
- package/components/button-group.js.map +1 -1
- package/components/button.d.ts +1 -1
- package/components/button.js +29 -12
- package/components/button.js.map +1 -1
- package/components/data-table.d.ts +128 -0
- package/components/data-table.js +347 -0
- package/components/data-table.js.map +1 -0
- package/components/pagination.d.ts +65 -7
- package/components/pagination.js +186 -37
- package/components/pagination.js.map +1 -1
- package/components/table-toolbar.d.ts +55 -0
- package/components/table-toolbar.js +119 -0
- package/components/table-toolbar.js.map +1 -0
- package/components/table.d.ts +293 -0
- package/components/table.js +598 -0
- package/components/table.js.map +1 -0
- package/components/tabs.d.ts +21 -3
- package/components/tabs.js +63 -8
- package/components/tabs.js.map +1 -1
- package/lib/data-table-state.d.ts +87 -0
- package/lib/data-table-state.js +92 -0
- package/lib/data-table-state.js.map +1 -0
- package/lib/icons.d.ts +8 -0
- package/lib/icons.js +10 -2
- package/lib/icons.js.map +1 -1
- package/lib/load-more.d.ts +14 -0
- package/lib/load-more.js +27 -0
- package/lib/load-more.js.map +1 -0
- package/package.json +13 -1
- package/styles.css +11 -0
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { rowPressClasses } from "../lib/classes.js";
|
|
3
|
+
import { AlertIcon, ArrowDownIcon, ArrowUpIcon, FilterIcon, MoreIcon, RefreshIcon } from "../lib/icons.js";
|
|
4
|
+
import { cn, variants } from "../lib/variants.js";
|
|
5
|
+
import { Button } from "./button.js";
|
|
6
|
+
import { Checkbox } from "./checkbox.js";
|
|
7
|
+
import { CopyButton } from "./copy-button.js";
|
|
8
|
+
import { EmptyState } from "./empty-state.js";
|
|
9
|
+
import { Menu, MenuContent, MenuTrigger } from "./menu.js";
|
|
10
|
+
import { Skeleton } from "./skeleton.js";
|
|
11
|
+
import { Sparkline } from "./sparkline.js";
|
|
12
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
14
|
+
import { Children, createContext, use } from "react";
|
|
15
|
+
// src/components/table.tsx
|
|
16
|
+
const TableContext = createContext({
|
|
17
|
+
layout: "table",
|
|
18
|
+
columns: []
|
|
19
|
+
});
|
|
20
|
+
const TableColumnScopeContext = createContext({});
|
|
21
|
+
/**
|
|
22
|
+
* The classes that hide a cell of a column with a priority, on its head and on every cell, so
|
|
23
|
+
* the column drops out whole. `Table` drops its track from the grid at the same widths.
|
|
24
|
+
*/
|
|
25
|
+
const tableColumnPriorityClasses = {
|
|
26
|
+
medium: "@max-2xl:hidden",
|
|
27
|
+
low: "@max-4xl:hidden",
|
|
28
|
+
lowest: "@max-6xl:hidden"
|
|
29
|
+
};
|
|
30
|
+
function formatColumnTemplate(columns, hidden) {
|
|
31
|
+
return columns.filter((column) => !column.priority || !hidden.includes(column.priority)).map((column) => column.width).join(" ");
|
|
32
|
+
}
|
|
33
|
+
const ROW_GRID_CLASSES = "col-span-full grid grid-cols-subgrid";
|
|
34
|
+
const tableVariants = variants({
|
|
35
|
+
slots: {
|
|
36
|
+
container: "@container relative",
|
|
37
|
+
table: [
|
|
38
|
+
"grid w-full text-control text-ink",
|
|
39
|
+
"grid-cols-(--table-columns) @2xl:grid-cols-(--table-columns-md) @4xl:grid-cols-(--table-columns-lg) @6xl:grid-cols-(--table-columns-xl)",
|
|
40
|
+
"has-[>[data-sticky]]:[--table-header-height:--spacing(10)]"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
variants: { variant: {
|
|
44
|
+
card: { container: "overflow-clip rounded-lg border bg-surface shadow-card" },
|
|
45
|
+
flush: {}
|
|
46
|
+
} },
|
|
47
|
+
defaultVariants: { variant: "card" }
|
|
48
|
+
});
|
|
49
|
+
const tableRowVariants = variants({
|
|
50
|
+
base: [
|
|
51
|
+
ROW_GRID_CLASSES,
|
|
52
|
+
"group/row relative items-center border-t border-edge-subtle",
|
|
53
|
+
"has-[[data-row-link]:not(:active)]:hover:bg-canvas has-[[data-row-link]:focus-visible:not(:active)]:bg-canvas",
|
|
54
|
+
rowPressClasses,
|
|
55
|
+
"data-selected:bg-fill-subtle data-selected:hover:bg-fill-subtle",
|
|
56
|
+
"*:has-[[data-row-link]]:z-1",
|
|
57
|
+
"data-inactive:*:not-data-[slot=actions]:not-data-[slot=checkbox]:not-data-[slot=mono]:opacity-50"
|
|
58
|
+
],
|
|
59
|
+
variants: { size: {
|
|
60
|
+
/** 32px, for a feed or a dense list. */
|
|
61
|
+
compact: "h-8",
|
|
62
|
+
/** 44px, a one-line row. */
|
|
63
|
+
default: "h-11",
|
|
64
|
+
/** 52px, for a two-line name cell. */
|
|
65
|
+
identity: "h-13"
|
|
66
|
+
} },
|
|
67
|
+
defaultVariants: { size: "default" }
|
|
68
|
+
});
|
|
69
|
+
const tableCellVariants = variants({
|
|
70
|
+
base: [
|
|
71
|
+
"flex min-w-0 items-center gap-2 px-2 first:pl-5 last:pr-5",
|
|
72
|
+
"@max-6xl:[&:not(:has(~:not([data-priority=lowest])))]:pr-5",
|
|
73
|
+
"@max-4xl:[&:not(:has(~:not([data-priority=low]):not([data-priority=lowest])))]:pr-5",
|
|
74
|
+
"@max-2xl:[&:not(:has(~:not([data-priority])))]:pr-5"
|
|
75
|
+
],
|
|
76
|
+
variants: {
|
|
77
|
+
align: {
|
|
78
|
+
start: "justify-start text-left",
|
|
79
|
+
end: "justify-end text-right"
|
|
80
|
+
},
|
|
81
|
+
priority: tableColumnPriorityClasses
|
|
82
|
+
},
|
|
83
|
+
defaultVariants: { align: "start" }
|
|
84
|
+
});
|
|
85
|
+
/** Varied widths for a skeleton row's first line, so a stack of them does not read as stripes. */
|
|
86
|
+
const SKELETON_NAME_WIDTHS = [
|
|
87
|
+
"w-36",
|
|
88
|
+
"w-28",
|
|
89
|
+
"w-40",
|
|
90
|
+
"w-32",
|
|
91
|
+
"w-24"
|
|
92
|
+
];
|
|
93
|
+
const MESSAGE_ICONS = {
|
|
94
|
+
filtered: /* @__PURE__ */ jsx(FilterIcon, {}),
|
|
95
|
+
error: /* @__PURE__ */ jsx(AlertIcon, {})
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* A table on a CSS grid. The root sets one grid template from `columns`, and the header and
|
|
99
|
+
* every row take it as a subgrid, so the columns line up however the rows are grouped. A row
|
|
100
|
+
* stays a positioned box, which a real table row is not in Safari, so a stretched link can
|
|
101
|
+
* fill it (`TableRowLink`). Columns with a `priority` drop out as the table's own box narrows.
|
|
102
|
+
* Set `--table-sticky-top` on it when a sticky header must clear a bar pinned above it.
|
|
103
|
+
*/
|
|
104
|
+
function Table({ columns, layout = "table", variant, footer, className, containerClassName, style, children, ...props }) {
|
|
105
|
+
const styles = tableVariants({ variant });
|
|
106
|
+
const template = {
|
|
107
|
+
"--table-columns": formatColumnTemplate(columns, [
|
|
108
|
+
"medium",
|
|
109
|
+
"low",
|
|
110
|
+
"lowest"
|
|
111
|
+
]),
|
|
112
|
+
"--table-columns-md": formatColumnTemplate(columns, ["low", "lowest"]),
|
|
113
|
+
"--table-columns-lg": formatColumnTemplate(columns, ["lowest"]),
|
|
114
|
+
"--table-columns-xl": formatColumnTemplate(columns, []),
|
|
115
|
+
...style
|
|
116
|
+
};
|
|
117
|
+
const Root = layout === "list" ? "div" : "table";
|
|
118
|
+
return /* @__PURE__ */ jsx(TableContext, {
|
|
119
|
+
value: {
|
|
120
|
+
layout,
|
|
121
|
+
columns
|
|
122
|
+
},
|
|
123
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
124
|
+
className: styles.container({ className: containerClassName }),
|
|
125
|
+
children: [/* @__PURE__ */ jsx(Root, {
|
|
126
|
+
role: layout === "list" ? "list" : "table",
|
|
127
|
+
className: styles.table({ className }),
|
|
128
|
+
style: template,
|
|
129
|
+
...props,
|
|
130
|
+
children
|
|
131
|
+
}), footer]
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The row of column names: 40px, on the surface, with one line under it in the card's edge
|
|
137
|
+
* colour. The first row draws no line of its own, so the two never stack. A list has none, and
|
|
138
|
+
* renders nothing for one.
|
|
139
|
+
*/
|
|
140
|
+
function TableHeader({ sticky, className, children, ...props }) {
|
|
141
|
+
if (use(TableContext).layout === "list") return null;
|
|
142
|
+
return /* @__PURE__ */ jsx("thead", {
|
|
143
|
+
role: "rowgroup",
|
|
144
|
+
"data-sticky": sticky ? "" : void 0,
|
|
145
|
+
className: cn(ROW_GRID_CLASSES, "border-b bg-surface", sticky && "sticky top-(--table-sticky-top,0px) z-20", className),
|
|
146
|
+
...props,
|
|
147
|
+
children: /* @__PURE__ */ jsx("tr", {
|
|
148
|
+
role: "row",
|
|
149
|
+
className: cn(ROW_GRID_CLASSES, "h-10 items-center"),
|
|
150
|
+
children
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The rows. A table cut into runs (days, workspaces) takes one body per run, each opening with
|
|
156
|
+
* its `TableGroupHeader`, so the heading sticks while its own rows are in view.
|
|
157
|
+
*/
|
|
158
|
+
function TableBody({ className, ...props }) {
|
|
159
|
+
const { layout } = use(TableContext);
|
|
160
|
+
return /* @__PURE__ */ jsx(layout === "list" ? "div" : "tbody", {
|
|
161
|
+
role: layout === "list" ? "presentation" : "rowgroup",
|
|
162
|
+
className: cn(ROW_GRID_CLASSES, "[&:first-of-type>:first-child]:border-t-0", className),
|
|
163
|
+
...props
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* One record. A row whose name is a `TableRowLink` opens it from anywhere on the row and takes
|
|
168
|
+
* the hover fill; a row without one keeps its background under the pointer.
|
|
169
|
+
*/
|
|
170
|
+
function TableRow({ size, selected, inactive, className, ...props }) {
|
|
171
|
+
const { layout } = use(TableContext);
|
|
172
|
+
return /* @__PURE__ */ jsx(layout === "list" ? "div" : "tr", {
|
|
173
|
+
role: layout === "list" ? "listitem" : "row",
|
|
174
|
+
"data-selected": selected ? "" : void 0,
|
|
175
|
+
"data-inactive": inactive ? "" : void 0,
|
|
176
|
+
className: tableRowVariants({
|
|
177
|
+
size,
|
|
178
|
+
className
|
|
179
|
+
}),
|
|
180
|
+
...props
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* A column name, in the control weight. A sortable column is a button, with the arrow of its
|
|
185
|
+
* order while the table is sorted by it; unsorted, it looks like any other name.
|
|
186
|
+
*/
|
|
187
|
+
function TableHead({ align, priority, sort, onSort, className, children, ...props }) {
|
|
188
|
+
const sorted = sort === "ascending" || sort === "descending";
|
|
189
|
+
const Arrow = sort === "ascending" ? ArrowUpIcon : ArrowDownIcon;
|
|
190
|
+
return /* @__PURE__ */ jsx("th", {
|
|
191
|
+
role: "columnheader",
|
|
192
|
+
scope: "col",
|
|
193
|
+
"data-priority": priority,
|
|
194
|
+
"aria-sort": sort,
|
|
195
|
+
className: tableCellVariants({
|
|
196
|
+
align,
|
|
197
|
+
priority,
|
|
198
|
+
className: cn("gap-1 font-medium text-control text-ink", className)
|
|
199
|
+
}),
|
|
200
|
+
...props,
|
|
201
|
+
children: onSort ? /* @__PURE__ */ jsxs("button", {
|
|
202
|
+
type: "button",
|
|
203
|
+
className: "inline-flex min-w-0 cursor-pointer items-center gap-1 rounded-xs hover:text-ink-secondary",
|
|
204
|
+
onClick: onSort,
|
|
205
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
206
|
+
className: "truncate",
|
|
207
|
+
children
|
|
208
|
+
}), sorted && /* @__PURE__ */ jsx(Arrow, { className: "size-3 shrink-0" })]
|
|
209
|
+
}) : children
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* One cell, the Text type: a line of ink that ends in an ellipsis. Every other cell type is
|
|
214
|
+
* built on it. Give it the `align` and `priority` of its column's head.
|
|
215
|
+
*/
|
|
216
|
+
function TableCell({ align, priority, className, children, ...props }) {
|
|
217
|
+
const { layout } = use(TableContext);
|
|
218
|
+
const scope = use(TableColumnScopeContext);
|
|
219
|
+
const columnPriority = priority ?? scope.priority;
|
|
220
|
+
const Cell = layout === "list" ? "div" : "td";
|
|
221
|
+
const text = typeof children === "string" || typeof children === "number";
|
|
222
|
+
return /* @__PURE__ */ jsx(Cell, {
|
|
223
|
+
role: layout === "list" ? void 0 : "cell",
|
|
224
|
+
"data-priority": columnPriority,
|
|
225
|
+
className: tableCellVariants({
|
|
226
|
+
align: align ?? scope.align,
|
|
227
|
+
priority: columnPriority,
|
|
228
|
+
className
|
|
229
|
+
}),
|
|
230
|
+
...props,
|
|
231
|
+
children: text ? /* @__PURE__ */ jsx("span", {
|
|
232
|
+
className: "truncate",
|
|
233
|
+
children
|
|
234
|
+
}) : children
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Hands the cells inside it their column's `align` and `priority`, for a cell rendered by code
|
|
239
|
+
* that knows nothing of its column (a `DataTable` column's `cell`). A cell's own props win.
|
|
240
|
+
*/
|
|
241
|
+
function TableColumnScope({ align, priority, children }) {
|
|
242
|
+
return /* @__PURE__ */ jsx(TableColumnScopeContext, {
|
|
243
|
+
value: {
|
|
244
|
+
align,
|
|
245
|
+
priority
|
|
246
|
+
},
|
|
247
|
+
children
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The record's name as a link that covers the whole row: its box stretches over the row, and
|
|
252
|
+
* the focus ring is drawn round the row. The checkbox, the menu and any other link in the row
|
|
253
|
+
* sit above it (`relative z-10`, as the checkbox and actions cells do), so each keeps its own
|
|
254
|
+
* click. Pass `render` for a router's link.
|
|
255
|
+
*/
|
|
256
|
+
function TableRowLink({ render, className, ...props }) {
|
|
257
|
+
return useRender({
|
|
258
|
+
render,
|
|
259
|
+
defaultTagName: "a",
|
|
260
|
+
props: {
|
|
261
|
+
"data-row-link": "",
|
|
262
|
+
"data-press-target": "",
|
|
263
|
+
className: cn("truncate outline-none after:absolute after:inset-0", "focus-visible:after:outline-2 focus-visible:after:-outline-offset-2 focus-visible:after:outline-focus", className),
|
|
264
|
+
...props
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/** The name column: the leading mark, the name in the control weight and a muted line. */
|
|
269
|
+
function TableIdentityCell({ leading, title, detail, extras, className, ...props }) {
|
|
270
|
+
return /* @__PURE__ */ jsxs(TableCell, {
|
|
271
|
+
className: cn("gap-3", className),
|
|
272
|
+
...props,
|
|
273
|
+
children: [leading && /* @__PURE__ */ jsx("span", {
|
|
274
|
+
className: "flex shrink-0",
|
|
275
|
+
children: leading
|
|
276
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
277
|
+
className: "flex min-w-0 flex-col gap-0.5",
|
|
278
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
279
|
+
className: "flex min-w-0 items-center gap-1.5",
|
|
280
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
281
|
+
className: "min-w-0 truncate font-medium",
|
|
282
|
+
children: title
|
|
283
|
+
}), extras && /* @__PURE__ */ jsx("span", {
|
|
284
|
+
className: "flex shrink-0 items-center gap-1.5",
|
|
285
|
+
children: extras
|
|
286
|
+
})]
|
|
287
|
+
}), detail && /* @__PURE__ */ jsx("span", {
|
|
288
|
+
className: "truncate text-ink-muted text-xs",
|
|
289
|
+
children: detail
|
|
290
|
+
})]
|
|
291
|
+
})]
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* A figure, Number or Money: end-aligned in tabular figures. The caller formats the value, a
|
|
296
|
+
* sum of money with its currency.
|
|
297
|
+
*/
|
|
298
|
+
function TableNumberCell({ align, className, ...props }) {
|
|
299
|
+
const scope = use(TableColumnScopeContext);
|
|
300
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
301
|
+
align: align ?? scope.align ?? "end",
|
|
302
|
+
className: cn("tabular-nums", className),
|
|
303
|
+
...props
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/** A date, muted: pass a `RelativeTime`, which keeps the exact moment for its tooltip. */
|
|
307
|
+
function TableDateCell({ className, ...props }) {
|
|
308
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
309
|
+
className: cn("text-ink-muted tabular-nums", className),
|
|
310
|
+
...props
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/** A status: pass one `Badge`. */
|
|
314
|
+
function TableBadgeCell(props) {
|
|
315
|
+
return /* @__PURE__ */ jsx(TableCell, { ...props });
|
|
316
|
+
}
|
|
317
|
+
/** Tags: the first two, then a count of the rest. */
|
|
318
|
+
function TableTagsCell({ tags, max = 2, className, ...props }) {
|
|
319
|
+
const rest = tags.length - max;
|
|
320
|
+
return /* @__PURE__ */ jsxs(TableCell, {
|
|
321
|
+
className: cn("gap-1", className),
|
|
322
|
+
...props,
|
|
323
|
+
children: [Children.toArray(tags.slice(0, max)), rest > 0 && /* @__PURE__ */ jsxs("span", {
|
|
324
|
+
className: "shrink-0 text-ink-muted text-xs tabular-nums",
|
|
325
|
+
children: ["+", rest]
|
|
326
|
+
})]
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
/** A trend: a `Sparkline` across the cell, 32px tall. */
|
|
330
|
+
function TableSparklineCell({ data, ...props }) {
|
|
331
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
332
|
+
...props,
|
|
333
|
+
children: /* @__PURE__ */ jsx(Sparkline, {
|
|
334
|
+
data,
|
|
335
|
+
className: "h-8 w-full"
|
|
336
|
+
})
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
const METER_TONES = {
|
|
340
|
+
neutral: {
|
|
341
|
+
bar: "bg-ink",
|
|
342
|
+
ring: "stroke-ink"
|
|
343
|
+
},
|
|
344
|
+
brand: {
|
|
345
|
+
bar: "bg-brand",
|
|
346
|
+
ring: "stroke-brand"
|
|
347
|
+
},
|
|
348
|
+
warning: {
|
|
349
|
+
bar: "bg-warning",
|
|
350
|
+
ring: "stroke-warning"
|
|
351
|
+
},
|
|
352
|
+
danger: {
|
|
353
|
+
bar: "bg-danger",
|
|
354
|
+
ring: "stroke-danger"
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
/** The ring's radius in its 16px box, and the length of its circle. */
|
|
358
|
+
const RING_RADIUS = 6;
|
|
359
|
+
const RING_LENGTH = 2 * Math.PI * RING_RADIUS;
|
|
360
|
+
/** Usage against a limit: a bar or a ring, then the figure. It turns warning past 90%. */
|
|
361
|
+
function TableMeterCell({ value, max, label, tone, layout = "bar", className, ...props }) {
|
|
362
|
+
const share = max > 0 ? Math.min(value / max, 1) : 0;
|
|
363
|
+
const tones = METER_TONES[tone ?? (share > .9 ? "warning" : "neutral")];
|
|
364
|
+
const ring = layout === "ring";
|
|
365
|
+
return /* @__PURE__ */ jsxs(TableCell, {
|
|
366
|
+
className: cn(ring ? "gap-1.5" : "gap-2", className),
|
|
367
|
+
...props,
|
|
368
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
369
|
+
role: "meter",
|
|
370
|
+
"aria-valuenow": value,
|
|
371
|
+
"aria-valuemin": 0,
|
|
372
|
+
"aria-valuemax": max,
|
|
373
|
+
"aria-label": typeof label === "string" ? label : void 0,
|
|
374
|
+
className: cn("shrink-0", ring ? "flex size-3.5" : "h-1 w-12 overflow-hidden rounded-full bg-fill"),
|
|
375
|
+
children: ring ? /* @__PURE__ */ jsxs("svg", {
|
|
376
|
+
"aria-hidden": true,
|
|
377
|
+
viewBox: "0 0 16 16",
|
|
378
|
+
fill: "none",
|
|
379
|
+
className: "size-full -rotate-90",
|
|
380
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
381
|
+
cx: "8",
|
|
382
|
+
cy: "8",
|
|
383
|
+
r: RING_RADIUS,
|
|
384
|
+
strokeWidth: "2.5",
|
|
385
|
+
className: "stroke-fill-strong"
|
|
386
|
+
}), share > 0 && /* @__PURE__ */ jsx("circle", {
|
|
387
|
+
cx: "8",
|
|
388
|
+
cy: "8",
|
|
389
|
+
r: RING_RADIUS,
|
|
390
|
+
strokeWidth: "2.5",
|
|
391
|
+
strokeLinecap: "round",
|
|
392
|
+
strokeDasharray: `${share * RING_LENGTH} ${RING_LENGTH}`,
|
|
393
|
+
className: tones.ring
|
|
394
|
+
})]
|
|
395
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
396
|
+
className: cn("block h-full rounded-full", tones.bar),
|
|
397
|
+
style: { width: `${share * 100}%` }
|
|
398
|
+
})
|
|
399
|
+
}), label && /* @__PURE__ */ jsx("span", {
|
|
400
|
+
className: cn("truncate tabular-nums", !ring && "text-ink-muted text-xs"),
|
|
401
|
+
children: label
|
|
402
|
+
})]
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/** A country: its flag and its name. */
|
|
406
|
+
function TableCountryCell({ flag, name, ...props }) {
|
|
407
|
+
return /* @__PURE__ */ jsxs(TableCell, {
|
|
408
|
+
...props,
|
|
409
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
410
|
+
className: "flex shrink-0",
|
|
411
|
+
children: flag
|
|
412
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
413
|
+
className: "truncate",
|
|
414
|
+
children: name
|
|
415
|
+
})]
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
/** A machine string (a key, an id) in mono, with a copy button that sits above the row link. */
|
|
419
|
+
function TableMonoCell({ value, copy, className, ...props }) {
|
|
420
|
+
return /* @__PURE__ */ jsxs(TableCell, {
|
|
421
|
+
"data-slot": "mono",
|
|
422
|
+
className: cn("gap-1", className),
|
|
423
|
+
...props,
|
|
424
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
425
|
+
className: "truncate font-mono text-ink-secondary text-xs in-data-inactive:opacity-50",
|
|
426
|
+
children: value
|
|
427
|
+
}), copy && /* @__PURE__ */ jsx(CopyButton, {
|
|
428
|
+
value,
|
|
429
|
+
variant: "ghost",
|
|
430
|
+
size: "xs",
|
|
431
|
+
className: "relative z-10 in-data-inactive:opacity-50"
|
|
432
|
+
})]
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/** A person on one line: a 20px avatar and the name. */
|
|
436
|
+
function TablePersonCell({ avatar, name, ...props }) {
|
|
437
|
+
return /* @__PURE__ */ jsxs(TableCell, {
|
|
438
|
+
...props,
|
|
439
|
+
children: [avatar && /* @__PURE__ */ jsx("span", {
|
|
440
|
+
className: "flex shrink-0",
|
|
441
|
+
children: avatar
|
|
442
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
443
|
+
className: "truncate",
|
|
444
|
+
children: name
|
|
445
|
+
})]
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* The row's menu, end-aligned above the row link. It shows on hover, on keyboard focus, while
|
|
450
|
+
* open, and always on a touch screen, which has no hover to give.
|
|
451
|
+
*/
|
|
452
|
+
function TableActionsCell({ align, className, children, ...props }) {
|
|
453
|
+
const scope = use(TableColumnScopeContext);
|
|
454
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
455
|
+
"data-slot": "actions",
|
|
456
|
+
align: align ?? scope.align ?? "end",
|
|
457
|
+
className,
|
|
458
|
+
...props,
|
|
459
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
460
|
+
className: cn("relative z-10 flex", "opacity-0 group-hover/row:opacity-100 focus-within:opacity-100 has-data-popup-open:opacity-100 pointer-coarse:opacity-100"),
|
|
461
|
+
children
|
|
462
|
+
})
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* The row's "…" menu, for a `TableActionsCell`: a quiet ghost trigger that grows to finger size
|
|
467
|
+
* on a touch screen, and a menu aligned to the row's end.
|
|
468
|
+
*/
|
|
469
|
+
function TableActionsMenu({ label, className, children }) {
|
|
470
|
+
return /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, { render: /* @__PURE__ */ jsx(Button, {
|
|
471
|
+
"aria-label": label,
|
|
472
|
+
variant: "ghost",
|
|
473
|
+
size: "sm",
|
|
474
|
+
prefix: /* @__PURE__ */ jsx(MoreIcon, {}),
|
|
475
|
+
className: cn("text-ink-muted pointer-coarse:size-10", className)
|
|
476
|
+
}) }), /* @__PURE__ */ jsx(MenuContent, {
|
|
477
|
+
label,
|
|
478
|
+
align: "end",
|
|
479
|
+
children
|
|
480
|
+
})] });
|
|
481
|
+
}
|
|
482
|
+
/** Selects the row, or every row on the page in the header. */
|
|
483
|
+
function TableCheckboxCell({ label, header: headerProp, checked, indeterminate, disabled, onCheckedChange, className, ...props }) {
|
|
484
|
+
const { layout } = use(TableContext);
|
|
485
|
+
const header = headerProp && layout === "table";
|
|
486
|
+
const box = /* @__PURE__ */ jsx(Checkbox, {
|
|
487
|
+
"aria-label": label,
|
|
488
|
+
checked,
|
|
489
|
+
indeterminate,
|
|
490
|
+
disabled,
|
|
491
|
+
className: "relative z-10 in-data-inactive:opacity-50",
|
|
492
|
+
onCheckedChange
|
|
493
|
+
});
|
|
494
|
+
const classes = cn("pr-0 first:pl-4", className);
|
|
495
|
+
if (header) {
|
|
496
|
+
const { align, priority, ...headProps } = props;
|
|
497
|
+
return /* @__PURE__ */ jsx("th", {
|
|
498
|
+
role: "columnheader",
|
|
499
|
+
scope: "col",
|
|
500
|
+
"data-slot": "checkbox",
|
|
501
|
+
className: tableCellVariants({
|
|
502
|
+
align,
|
|
503
|
+
priority,
|
|
504
|
+
className: classes
|
|
505
|
+
}),
|
|
506
|
+
...headProps,
|
|
507
|
+
children: box
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
511
|
+
"data-slot": "checkbox",
|
|
512
|
+
className: classes,
|
|
513
|
+
...props,
|
|
514
|
+
children: box
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* A heading row for the run of rows under it: a day of a feed, a workspace of a list. It sticks
|
|
519
|
+
* under the header while its own body is in view, and the next one pushes it out. Opaque, so the
|
|
520
|
+
* rows slide under it.
|
|
521
|
+
*/
|
|
522
|
+
function TableGroupHeader({ className, children, ...props }) {
|
|
523
|
+
const { layout } = use(TableContext);
|
|
524
|
+
const list = layout === "list";
|
|
525
|
+
const Row = list ? "div" : "tr";
|
|
526
|
+
const Heading = list ? "div" : "th";
|
|
527
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
528
|
+
role: list ? "listitem" : "row",
|
|
529
|
+
className: cn(ROW_GRID_CLASSES, "sticky top-[calc(var(--table-sticky-top,0px)+var(--table-header-height,0px))] z-15", "h-7 border-t border-edge-subtle bg-fill-subtle", className),
|
|
530
|
+
...props,
|
|
531
|
+
children: /* @__PURE__ */ jsx(Heading, {
|
|
532
|
+
role: list ? "heading" : "rowheader",
|
|
533
|
+
"aria-level": list ? 3 : void 0,
|
|
534
|
+
scope: list ? void 0 : "rowgroup",
|
|
535
|
+
className: "col-span-full flex items-center px-5 text-left font-medium text-ink-secondary text-xs",
|
|
536
|
+
children
|
|
537
|
+
})
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* A loading row the size of the rows it stands in for, one stand-in per column of the table.
|
|
542
|
+
* Put five in the body on a first load; while a later page loads, keep the old rows and dim them.
|
|
543
|
+
*/
|
|
544
|
+
function TableSkeletonRow({ size, index = 0 }) {
|
|
545
|
+
const { columns } = use(TableContext);
|
|
546
|
+
const nameWidth = SKELETON_NAME_WIDTHS[index % SKELETON_NAME_WIDTHS.length];
|
|
547
|
+
const nameColumn = columns.findIndex((column) => column.skeleton !== false);
|
|
548
|
+
return /* @__PURE__ */ jsx(TableRow, {
|
|
549
|
+
size,
|
|
550
|
+
"aria-hidden": true,
|
|
551
|
+
children: columns.map((column, position) => /* @__PURE__ */ jsx(TableCell, {
|
|
552
|
+
align: column.align,
|
|
553
|
+
priority: column.priority,
|
|
554
|
+
className: "gap-2",
|
|
555
|
+
children: column.skeleton === false ? null : position === nameColumn && size === "identity" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Skeleton, { className: "size-7 shrink-0 rounded-md" }), /* @__PURE__ */ jsxs("span", {
|
|
556
|
+
className: "flex flex-col gap-1.5",
|
|
557
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: cn("h-3", nameWidth) }), /* @__PURE__ */ jsx(Skeleton, { className: "h-2.5 w-24" })]
|
|
558
|
+
})] }) : /* @__PURE__ */ jsx(Skeleton, { className: cn("h-3", position === nameColumn ? nameWidth : "w-16") })
|
|
559
|
+
}, position))
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Stands in for the rows: the small empty state across every column, under the header, which
|
|
564
|
+
* keeps its line. Put it inside `TableBody`.
|
|
565
|
+
*/
|
|
566
|
+
function TableMessage({ kind, icon, title, description, action, onRetry, retryLabel = "Try again" }) {
|
|
567
|
+
const { layout } = use(TableContext);
|
|
568
|
+
const list = layout === "list";
|
|
569
|
+
const Row = list ? "div" : "tr";
|
|
570
|
+
const Cell = list ? "div" : "td";
|
|
571
|
+
const retry = kind === "error" && onRetry && /* @__PURE__ */ jsx(Button, {
|
|
572
|
+
variant: "secondary",
|
|
573
|
+
size: "sm",
|
|
574
|
+
prefix: /* @__PURE__ */ jsx(RefreshIcon, {}),
|
|
575
|
+
onClick: onRetry,
|
|
576
|
+
children: retryLabel
|
|
577
|
+
});
|
|
578
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
579
|
+
role: list ? "listitem" : "row",
|
|
580
|
+
"data-kind": kind,
|
|
581
|
+
className: cn(ROW_GRID_CLASSES, "border-t border-edge-subtle"),
|
|
582
|
+
children: /* @__PURE__ */ jsx(Cell, {
|
|
583
|
+
role: list ? void 0 : "cell",
|
|
584
|
+
className: "col-span-full py-5",
|
|
585
|
+
children: /* @__PURE__ */ jsx(EmptyState, {
|
|
586
|
+
size: "sm",
|
|
587
|
+
role: kind === "error" ? "alert" : void 0,
|
|
588
|
+
icon: icon ?? (kind === "empty" ? void 0 : MESSAGE_ICONS[kind]),
|
|
589
|
+
title,
|
|
590
|
+
description,
|
|
591
|
+
action: action ?? retry
|
|
592
|
+
})
|
|
593
|
+
})
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
export { Table, TableActionsCell, TableActionsMenu, TableBadgeCell, TableBody, TableCell, TableCheckboxCell, TableColumnScope, TableCountryCell, TableDateCell, TableGroupHeader, TableHead, TableHeader, TableIdentityCell, TableMessage, TableMeterCell, TableMonoCell, TableNumberCell, TablePersonCell, TableRow, TableRowLink, TableSkeletonRow, TableSparklineCell, TableTagsCell, tableColumnPriorityClasses };
|
|
597
|
+
|
|
598
|
+
//# sourceMappingURL=table.js.map
|