@designa8/vibedesign-openai-internal-v1-2-176b 0.0.4 → 0.0.5
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 +1 -1
- package/dist/index.cjs +98 -27
- package/dist/index.js +98 -27
- package/dist/styles.css +6 -0
- package/package.json +1 -1
- package/src/atoms/Button/Button.tsx +36 -11
- package/src/atoms/DataTable/DataTable.tsx +6 -1
- package/src/atoms/DataTable/preview.tsx +61 -2
- package/src/atoms/DataTableDesktop/DataTableDesktop.tsx +47 -4
- package/src/atoms/DataTableMobile/DataTableMobile.tsx +46 -10
- package/src/atoms/TableRow/TableRow.tsx +35 -7
- package/src/atoms/TableRow/preview.tsx +73 -27
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @designa8/vibedesign-openai-internal-v1-2-176b
|
|
2
2
|
|
|
3
|
-
Complete design system generated by Atoms Design, version **0.0.
|
|
3
|
+
Complete design system generated by Atoms Design, version **0.0.5**.
|
|
4
4
|
Tokens, atoms, molecules, organisms, and templates — import from the package root;
|
|
5
5
|
never hardcode visual values in consumer code.
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -520,6 +520,7 @@ var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
|
520
520
|
var cn3 = (...parts) => parts.filter(Boolean).join(" ");
|
|
521
521
|
var base = "relative inline-flex shrink-0 items-center justify-center whitespace-nowrap border select-none cursor-pointer transition duration-150 ease-out active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue focus-visible:ring-offset-0 disabled:cursor-not-allowed disabled:opacity-50 disabled:active:scale-100";
|
|
522
522
|
var rowBase = "relative flex w-full min-w-0 select-none items-center justify-start whitespace-nowrap border text-left cursor-pointer transition-colors duration-150 ease-out focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50";
|
|
523
|
+
var bareBase = "relative flex w-full min-w-0 select-none items-start justify-start whitespace-normal border-transparent text-left cursor-pointer transition-colors duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue disabled:cursor-not-allowed disabled:opacity-50";
|
|
523
524
|
var isRow = (v) => v === "field" || v === "item";
|
|
524
525
|
var rowSizes = {
|
|
525
526
|
field: {
|
|
@@ -533,6 +534,11 @@ var rowSizes = {
|
|
|
533
534
|
lg: "h-9 gap-sm px-sm text-body-md"
|
|
534
535
|
}
|
|
535
536
|
};
|
|
537
|
+
var bareSizes = {
|
|
538
|
+
sm: "gap-xxs p-0 text-body-sm",
|
|
539
|
+
md: "gap-xxs p-0 text-body-md",
|
|
540
|
+
lg: "gap-xxs p-0 text-body-md"
|
|
541
|
+
};
|
|
536
542
|
var variants = {
|
|
537
543
|
primary: "bg-primary text-on-primary border-transparent hover:bg-primary-hover active:bg-primary-active disabled:bg-primary-disabled disabled:text-muted-soft",
|
|
538
544
|
secondary: "bg-canvas text-ink border-hairline-strong hover:bg-surface-strong hover:border-transparent active:bg-primary active:text-on-primary active:border-transparent focus-visible:border-focus-blue disabled:bg-surface-strong disabled:text-muted-soft disabled:border-transparent",
|
|
@@ -542,7 +548,8 @@ var variants = {
|
|
|
542
548
|
accent: "bg-accent text-on-accent border-transparent hover:bg-accent-hover active:bg-accent-hover",
|
|
543
549
|
danger: "bg-semantic-error text-on-primary border-transparent hover:opacity-90 active:opacity-100",
|
|
544
550
|
field: "bg-canvas text-ink border-hairline-strong enabled:hover:border-muted-soft focus-visible:border-focus-blue aria-expanded:border-focus-blue enabled:hover:aria-expanded:border-focus-blue aria-invalid:border-semantic-error disabled:bg-surface-strong disabled:border-transparent disabled:text-muted-soft",
|
|
545
|
-
item: "bg-transparent text-ink border-transparent enabled:hover:bg-surface-soft enabled:active:bg-surface-strong focus-visible:bg-surface-soft aria-selected:bg-surface-strong disabled:text-muted-soft"
|
|
551
|
+
item: "bg-transparent text-ink border-transparent enabled:hover:bg-surface-soft enabled:active:bg-surface-strong focus-visible:bg-surface-soft aria-selected:bg-surface-strong disabled:text-muted-soft",
|
|
552
|
+
bare: "rounded-none bg-transparent text-ink border-transparent disabled:text-muted-soft"
|
|
546
553
|
};
|
|
547
554
|
var sizes = {
|
|
548
555
|
sm: "h-7 gap-xs px-md text-body-sm",
|
|
@@ -578,6 +585,8 @@ var Button = React5.forwardRef(
|
|
|
578
585
|
...props
|
|
579
586
|
}, ref) => {
|
|
580
587
|
const isDisabled = Boolean(disabled);
|
|
588
|
+
const isBare = variant === "bare";
|
|
589
|
+
const row = isRow(variant);
|
|
581
590
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
582
591
|
"button",
|
|
583
592
|
{
|
|
@@ -594,9 +603,9 @@ var Button = React5.forwardRef(
|
|
|
594
603
|
onClick?.(e);
|
|
595
604
|
},
|
|
596
605
|
className: cn3(
|
|
597
|
-
|
|
606
|
+
isBare ? bareBase : row ? rowBase : base,
|
|
598
607
|
variants[variant],
|
|
599
|
-
|
|
608
|
+
isBare ? bareSizes[size] : row ? rowSizes[variant][size] : iconOnly ? squareSizes[size] : sizes[size],
|
|
600
609
|
shape === "pill" ? "rounded-full" : radii[size],
|
|
601
610
|
fullWidth && "w-full",
|
|
602
611
|
loading && "cursor-progress",
|
|
@@ -604,7 +613,7 @@ var Button = React5.forwardRef(
|
|
|
604
613
|
),
|
|
605
614
|
...props,
|
|
606
615
|
children: [
|
|
607
|
-
!
|
|
616
|
+
!row || loading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
608
617
|
"span",
|
|
609
618
|
{
|
|
610
619
|
"aria-hidden": "true",
|
|
@@ -616,7 +625,7 @@ var Button = React5.forwardRef(
|
|
|
616
625
|
}
|
|
617
626
|
) : null,
|
|
618
627
|
leadingIcon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "aria-hidden": "true", className: "inline-flex items-center", children: leadingIcon }) : null,
|
|
619
|
-
children != null && !(iconOnly && loading) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className:
|
|
628
|
+
children != null && !(iconOnly && loading) ? isBare ? children : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: row ? "min-w-0 flex-1 truncate" : "inline-flex items-center", children }) : null,
|
|
620
629
|
trailingIcon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "aria-hidden": "true", className: "inline-flex items-center", children: trailingIcon }) : null
|
|
621
630
|
]
|
|
622
631
|
}
|
|
@@ -3004,22 +3013,40 @@ var React32 = __toESM(require("react"));
|
|
|
3004
3013
|
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
3005
3014
|
var cn28 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3006
3015
|
var isCell = (c) => typeof c === "object" && c !== null && !React32.isValidElement(c) && "content" in c;
|
|
3016
|
+
var NESTED_INTERACTIVE = "button, a, input, select, textarea, label, [role='button'], [role='link'], [role='checkbox'], [role='switch'], [role='menuitem'], [role='option']";
|
|
3007
3017
|
var TableRow = React32.forwardRef(
|
|
3008
|
-
({ cells, selected = false, onSelect, className, onKeyDown, ...props }, ref) => {
|
|
3009
|
-
const
|
|
3018
|
+
({ cells, selected = false, onSelect, onRowClick, className, onClick, onKeyDown, ...props }, ref) => {
|
|
3019
|
+
const rowClickable = Boolean(onRowClick);
|
|
3020
|
+
const interactive = Boolean(onSelect) || rowClickable;
|
|
3021
|
+
const handleClick = (event) => {
|
|
3022
|
+
onClick?.(event);
|
|
3023
|
+
if (event.defaultPrevented || !interactive) return;
|
|
3024
|
+
const nested = Boolean(event.target?.closest(NESTED_INTERACTIVE));
|
|
3025
|
+
if (rowClickable) {
|
|
3026
|
+
if (nested) return;
|
|
3027
|
+
onSelect?.();
|
|
3028
|
+
onRowClick?.();
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
onSelect?.();
|
|
3032
|
+
};
|
|
3010
3033
|
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
3011
3034
|
"tr",
|
|
3012
3035
|
{
|
|
3013
3036
|
ref,
|
|
3014
|
-
"aria-selected":
|
|
3037
|
+
"aria-selected": onSelect ? selected : void 0,
|
|
3015
3038
|
tabIndex: interactive ? 0 : void 0,
|
|
3016
|
-
onClick:
|
|
3039
|
+
onClick: handleClick,
|
|
3017
3040
|
onKeyDown: (e) => {
|
|
3018
3041
|
onKeyDown?.(e);
|
|
3019
|
-
if (!interactive) return;
|
|
3020
|
-
if (e.key === "Enter"
|
|
3042
|
+
if (!interactive || e.defaultPrevented) return;
|
|
3043
|
+
if (e.key === "Enter") {
|
|
3044
|
+
e.preventDefault();
|
|
3045
|
+
if (rowClickable) onRowClick?.();
|
|
3046
|
+
else onSelect?.();
|
|
3047
|
+
} else if (e.key === " " && onSelect) {
|
|
3021
3048
|
e.preventDefault();
|
|
3022
|
-
onSelect
|
|
3049
|
+
onSelect();
|
|
3023
3050
|
}
|
|
3024
3051
|
},
|
|
3025
3052
|
className: cn28(
|
|
@@ -3128,12 +3155,22 @@ Pagination.displayName = "Pagination";
|
|
|
3128
3155
|
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
3129
3156
|
var cn30 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3130
3157
|
function useDataTableState(props) {
|
|
3131
|
-
const {
|
|
3158
|
+
const {
|
|
3159
|
+
columns,
|
|
3160
|
+
rows,
|
|
3161
|
+
filterKey,
|
|
3162
|
+
selected,
|
|
3163
|
+
onSelectedChange,
|
|
3164
|
+
pageSize = 5,
|
|
3165
|
+
defaultSort,
|
|
3166
|
+
page: controlledPage,
|
|
3167
|
+
onPageChange
|
|
3168
|
+
} = props;
|
|
3132
3169
|
const [query, setQuery] = React34.useState("");
|
|
3133
3170
|
const [sort, setSort] = React34.useState(
|
|
3134
3171
|
defaultSort ?? { key: "", direction: "none" }
|
|
3135
3172
|
);
|
|
3136
|
-
const [
|
|
3173
|
+
const [innerPage, setInnerPage] = React34.useState(1);
|
|
3137
3174
|
const [innerSel, setInnerSel] = React34.useState([]);
|
|
3138
3175
|
const sel = selected ?? innerSel;
|
|
3139
3176
|
const setSel = (ids) => {
|
|
@@ -3161,7 +3198,12 @@ function useDataTableState(props) {
|
|
|
3161
3198
|
});
|
|
3162
3199
|
}, [filtered, sort]);
|
|
3163
3200
|
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
3164
|
-
const
|
|
3201
|
+
const requestedPage = controlledPage ?? innerPage;
|
|
3202
|
+
const safePage = Math.min(Math.max(1, requestedPage), pageCount);
|
|
3203
|
+
const setPage = (next) => {
|
|
3204
|
+
if (controlledPage === void 0) setInnerPage(next);
|
|
3205
|
+
onPageChange?.(next);
|
|
3206
|
+
};
|
|
3165
3207
|
const pageRows = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
3166
3208
|
const allOnPage = pageRows.length > 0 && pageRows.every((r) => sel.includes(r.id));
|
|
3167
3209
|
const someOnPage = pageRows.some((r) => sel.includes(r.id));
|
|
@@ -3194,13 +3236,19 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3194
3236
|
views,
|
|
3195
3237
|
view,
|
|
3196
3238
|
onViewChange,
|
|
3239
|
+
toolbarStart,
|
|
3197
3240
|
filterKey,
|
|
3198
3241
|
filterPlaceholder = "Filter",
|
|
3199
3242
|
selectable = false,
|
|
3200
3243
|
selected: _selected,
|
|
3201
3244
|
onSelectedChange: _onSel,
|
|
3245
|
+
onRowClick,
|
|
3246
|
+
page: _page,
|
|
3247
|
+
onPageChange: _onPageChange,
|
|
3202
3248
|
pageSize: _ps,
|
|
3203
3249
|
defaultSort: _ds,
|
|
3250
|
+
mobileDescription: _mobileDescription,
|
|
3251
|
+
resultLabel,
|
|
3204
3252
|
emptyState = {
|
|
3205
3253
|
icon: "file",
|
|
3206
3254
|
title: "Nothing here yet",
|
|
@@ -3214,8 +3262,10 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3214
3262
|
const filterId = React34.useId();
|
|
3215
3263
|
const filterLabel = columns.find((c) => c.key === filterKey)?.label.toLowerCase() ?? "";
|
|
3216
3264
|
const isEmpty = rows.length === 0;
|
|
3265
|
+
const resultsText = resultLabel ? resultLabel(s.total) : `${s.total} ${s.total === 1 ? "result" : "results"}`;
|
|
3217
3266
|
const body = /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex w-full flex-col gap-md", children: [
|
|
3218
3267
|
!isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex w-full flex-wrap items-center gap-sm", children: [
|
|
3268
|
+
toolbarStart,
|
|
3219
3269
|
filterKey ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "w-64", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
3220
3270
|
Input,
|
|
3221
3271
|
{
|
|
@@ -3239,11 +3289,7 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3239
3289
|
"aria-label": `Remove filter ${filterLabel}: ${s.query.trim()}`
|
|
3240
3290
|
}
|
|
3241
3291
|
) : null,
|
|
3242
|
-
/* @__PURE__ */ (0, import_jsx_runtime34.
|
|
3243
|
-
s.total,
|
|
3244
|
-
" ",
|
|
3245
|
-
s.total === 1 ? "result" : "results"
|
|
3246
|
-
] })
|
|
3292
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: "ml-auto text-body-sm text-muted", "aria-live": "polite", children: resultsText })
|
|
3247
3293
|
] }) : null,
|
|
3248
3294
|
isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex w-full flex-col items-center gap-xs rounded-lg border border-hairline bg-surface px-lg py-xxl text-center", children: [
|
|
3249
3295
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: "mb-sm flex size-10 items-center justify-center rounded-md border border-hairline bg-canvas shadow-sm", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Icon, { name: emptyState.icon ?? "file", size: 18 }) }),
|
|
@@ -3290,6 +3336,7 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3290
3336
|
TableRow,
|
|
3291
3337
|
{
|
|
3292
3338
|
className: isSel ? "bg-surface-soft" : void 0,
|
|
3339
|
+
onRowClick: onRowClick ? () => onRowClick(row) : void 0,
|
|
3293
3340
|
cells: selectable ? [
|
|
3294
3341
|
{
|
|
3295
3342
|
content: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
@@ -3572,13 +3619,19 @@ function DataTableMobileInner(props, ref) {
|
|
|
3572
3619
|
views,
|
|
3573
3620
|
view,
|
|
3574
3621
|
onViewChange,
|
|
3622
|
+
toolbarStart,
|
|
3575
3623
|
filterKey,
|
|
3576
3624
|
filterPlaceholder = "Filter",
|
|
3577
3625
|
selectable = false,
|
|
3578
3626
|
selected: _selected,
|
|
3579
3627
|
onSelectedChange: _onSel,
|
|
3628
|
+
onRowClick,
|
|
3629
|
+
page: _page,
|
|
3630
|
+
onPageChange: _onPageChange,
|
|
3580
3631
|
pageSize: _ps,
|
|
3581
3632
|
defaultSort: _ds,
|
|
3633
|
+
mobileDescription,
|
|
3634
|
+
resultLabel,
|
|
3582
3635
|
emptyState = { icon: "file", title: "Nothing here yet" },
|
|
3583
3636
|
caption = "Data table",
|
|
3584
3637
|
className,
|
|
@@ -3594,6 +3647,7 @@ function DataTableMobileInner(props, ref) {
|
|
|
3594
3647
|
const c = columns.find((x) => x.key === key);
|
|
3595
3648
|
return c?.render ? c.render(row) : String(row[key] ?? "");
|
|
3596
3649
|
};
|
|
3650
|
+
const resultsText = resultLabel ? resultLabel(s.total) : `${s.total} ${s.total === 1 ? "result" : "results"}`;
|
|
3597
3651
|
const sortValue = s.sort.direction === "none" ? "" : `${s.sort.key}:${s.sort.direction}`;
|
|
3598
3652
|
const sortOptions = sortable.flatMap((c) => [
|
|
3599
3653
|
{ value: `${c.key}:descending`, label: `${c.label} \u2193` },
|
|
@@ -3601,6 +3655,7 @@ function DataTableMobileInner(props, ref) {
|
|
|
3601
3655
|
]);
|
|
3602
3656
|
const body = /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex w-full flex-col gap-md", children: [
|
|
3603
3657
|
!isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex w-full flex-col gap-sm", children: [
|
|
3658
|
+
toolbarStart ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "flex w-full flex-wrap items-center gap-sm", children: toolbarStart }) : null,
|
|
3604
3659
|
filterKey ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
3605
3660
|
Input,
|
|
3606
3661
|
{
|
|
@@ -3627,11 +3682,7 @@ function DataTableMobileInner(props, ref) {
|
|
|
3627
3682
|
}
|
|
3628
3683
|
}
|
|
3629
3684
|
) }) : null,
|
|
3630
|
-
/* @__PURE__ */ (0, import_jsx_runtime36.
|
|
3631
|
-
s.total,
|
|
3632
|
-
" ",
|
|
3633
|
-
s.total === 1 ? "result" : "results"
|
|
3634
|
-
] })
|
|
3685
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "ml-auto shrink-0 text-body-sm text-muted", "aria-live": "polite", children: resultsText })
|
|
3635
3686
|
] }),
|
|
3636
3687
|
s.query.trim() ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
3637
3688
|
Chip,
|
|
@@ -3668,11 +3719,13 @@ function DataTableMobileInner(props, ref) {
|
|
|
3668
3719
|
] }) : null,
|
|
3669
3720
|
s.pageRows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("p", { className: "px-base py-lg text-center text-body-sm text-muted", children: "No rows match this filter." }) : /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("ul", { "aria-label": caption, className: "divide-y divide-hairline-soft", children: s.pageRows.map((row) => {
|
|
3670
3721
|
const isSel = s.sel.includes(row.id);
|
|
3722
|
+
const description = mobileDescription ? mobileDescription(row) : null;
|
|
3671
3723
|
return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
|
|
3672
3724
|
"li",
|
|
3673
3725
|
{
|
|
3674
3726
|
className: cn32(
|
|
3675
3727
|
"flex items-start gap-md px-base py-sm transition-colors duration-150 ease-out",
|
|
3728
|
+
onRowClick ? "hover:bg-surface-soft active:bg-surface-strong" : null,
|
|
3676
3729
|
isSel ? "bg-surface-soft" : "bg-surface"
|
|
3677
3730
|
),
|
|
3678
3731
|
children: [
|
|
@@ -3685,9 +3738,27 @@ function DataTableMobileInner(props, ref) {
|
|
|
3685
3738
|
onCheckedChange: () => s.toggleRow(row.id)
|
|
3686
3739
|
}
|
|
3687
3740
|
) }) : null,
|
|
3688
|
-
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
|
|
3741
|
+
onRowClick ? /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
|
|
3742
|
+
Button,
|
|
3743
|
+
{
|
|
3744
|
+
variant: "bare",
|
|
3745
|
+
size: "md",
|
|
3746
|
+
className: "min-w-0 flex-1 flex-col items-start",
|
|
3747
|
+
onClick: () => onRowClick(row),
|
|
3748
|
+
children: [
|
|
3749
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "w-full min-w-0 truncate text-left text-body-md text-ink", children: cell(row, primary.key) }),
|
|
3750
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "w-full min-w-0 truncate text-left text-body-sm text-muted", children: description }) : secondary ? /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "w-full min-w-0 truncate text-left text-body-sm text-muted", children: [
|
|
3751
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "sr-only", children: [
|
|
3752
|
+
secondary.label,
|
|
3753
|
+
": "
|
|
3754
|
+
] }),
|
|
3755
|
+
cell(row, secondary.key)
|
|
3756
|
+
] }) : null
|
|
3757
|
+
]
|
|
3758
|
+
}
|
|
3759
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-xxs", children: [
|
|
3689
3760
|
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "min-w-0 truncate text-body-md text-ink", children: cell(row, primary.key) }),
|
|
3690
|
-
secondary ? /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "truncate text-body-sm text-muted", children: [
|
|
3761
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "min-w-0 truncate text-body-sm text-muted", children: description }) : secondary ? /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "truncate text-body-sm text-muted", children: [
|
|
3691
3762
|
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "sr-only", children: [
|
|
3692
3763
|
secondary.label,
|
|
3693
3764
|
": "
|
package/dist/index.js
CHANGED
|
@@ -395,6 +395,7 @@ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
|
395
395
|
var cn3 = (...parts) => parts.filter(Boolean).join(" ");
|
|
396
396
|
var base = "relative inline-flex shrink-0 items-center justify-center whitespace-nowrap border select-none cursor-pointer transition duration-150 ease-out active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue focus-visible:ring-offset-0 disabled:cursor-not-allowed disabled:opacity-50 disabled:active:scale-100";
|
|
397
397
|
var rowBase = "relative flex w-full min-w-0 select-none items-center justify-start whitespace-nowrap border text-left cursor-pointer transition-colors duration-150 ease-out focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50";
|
|
398
|
+
var bareBase = "relative flex w-full min-w-0 select-none items-start justify-start whitespace-normal border-transparent text-left cursor-pointer transition-colors duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue disabled:cursor-not-allowed disabled:opacity-50";
|
|
398
399
|
var isRow = (v) => v === "field" || v === "item";
|
|
399
400
|
var rowSizes = {
|
|
400
401
|
field: {
|
|
@@ -408,6 +409,11 @@ var rowSizes = {
|
|
|
408
409
|
lg: "h-9 gap-sm px-sm text-body-md"
|
|
409
410
|
}
|
|
410
411
|
};
|
|
412
|
+
var bareSizes = {
|
|
413
|
+
sm: "gap-xxs p-0 text-body-sm",
|
|
414
|
+
md: "gap-xxs p-0 text-body-md",
|
|
415
|
+
lg: "gap-xxs p-0 text-body-md"
|
|
416
|
+
};
|
|
411
417
|
var variants = {
|
|
412
418
|
primary: "bg-primary text-on-primary border-transparent hover:bg-primary-hover active:bg-primary-active disabled:bg-primary-disabled disabled:text-muted-soft",
|
|
413
419
|
secondary: "bg-canvas text-ink border-hairline-strong hover:bg-surface-strong hover:border-transparent active:bg-primary active:text-on-primary active:border-transparent focus-visible:border-focus-blue disabled:bg-surface-strong disabled:text-muted-soft disabled:border-transparent",
|
|
@@ -417,7 +423,8 @@ var variants = {
|
|
|
417
423
|
accent: "bg-accent text-on-accent border-transparent hover:bg-accent-hover active:bg-accent-hover",
|
|
418
424
|
danger: "bg-semantic-error text-on-primary border-transparent hover:opacity-90 active:opacity-100",
|
|
419
425
|
field: "bg-canvas text-ink border-hairline-strong enabled:hover:border-muted-soft focus-visible:border-focus-blue aria-expanded:border-focus-blue enabled:hover:aria-expanded:border-focus-blue aria-invalid:border-semantic-error disabled:bg-surface-strong disabled:border-transparent disabled:text-muted-soft",
|
|
420
|
-
item: "bg-transparent text-ink border-transparent enabled:hover:bg-surface-soft enabled:active:bg-surface-strong focus-visible:bg-surface-soft aria-selected:bg-surface-strong disabled:text-muted-soft"
|
|
426
|
+
item: "bg-transparent text-ink border-transparent enabled:hover:bg-surface-soft enabled:active:bg-surface-strong focus-visible:bg-surface-soft aria-selected:bg-surface-strong disabled:text-muted-soft",
|
|
427
|
+
bare: "rounded-none bg-transparent text-ink border-transparent disabled:text-muted-soft"
|
|
421
428
|
};
|
|
422
429
|
var sizes = {
|
|
423
430
|
sm: "h-7 gap-xs px-md text-body-sm",
|
|
@@ -453,6 +460,8 @@ var Button = React5.forwardRef(
|
|
|
453
460
|
...props
|
|
454
461
|
}, ref) => {
|
|
455
462
|
const isDisabled = Boolean(disabled);
|
|
463
|
+
const isBare = variant === "bare";
|
|
464
|
+
const row = isRow(variant);
|
|
456
465
|
return /* @__PURE__ */ jsxs4(
|
|
457
466
|
"button",
|
|
458
467
|
{
|
|
@@ -469,9 +478,9 @@ var Button = React5.forwardRef(
|
|
|
469
478
|
onClick?.(e);
|
|
470
479
|
},
|
|
471
480
|
className: cn3(
|
|
472
|
-
|
|
481
|
+
isBare ? bareBase : row ? rowBase : base,
|
|
473
482
|
variants[variant],
|
|
474
|
-
|
|
483
|
+
isBare ? bareSizes[size] : row ? rowSizes[variant][size] : iconOnly ? squareSizes[size] : sizes[size],
|
|
475
484
|
shape === "pill" ? "rounded-full" : radii[size],
|
|
476
485
|
fullWidth && "w-full",
|
|
477
486
|
loading && "cursor-progress",
|
|
@@ -479,7 +488,7 @@ var Button = React5.forwardRef(
|
|
|
479
488
|
),
|
|
480
489
|
...props,
|
|
481
490
|
children: [
|
|
482
|
-
!
|
|
491
|
+
!row || loading ? /* @__PURE__ */ jsx5(
|
|
483
492
|
"span",
|
|
484
493
|
{
|
|
485
494
|
"aria-hidden": "true",
|
|
@@ -491,7 +500,7 @@ var Button = React5.forwardRef(
|
|
|
491
500
|
}
|
|
492
501
|
) : null,
|
|
493
502
|
leadingIcon ? /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", className: "inline-flex items-center", children: leadingIcon }) : null,
|
|
494
|
-
children != null && !(iconOnly && loading) ? /* @__PURE__ */ jsx5("span", { className:
|
|
503
|
+
children != null && !(iconOnly && loading) ? isBare ? children : /* @__PURE__ */ jsx5("span", { className: row ? "min-w-0 flex-1 truncate" : "inline-flex items-center", children }) : null,
|
|
495
504
|
trailingIcon ? /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", className: "inline-flex items-center", children: trailingIcon }) : null
|
|
496
505
|
]
|
|
497
506
|
}
|
|
@@ -2879,22 +2888,40 @@ import * as React32 from "react";
|
|
|
2879
2888
|
import { jsx as jsx32 } from "react/jsx-runtime";
|
|
2880
2889
|
var cn28 = (...parts) => parts.filter(Boolean).join(" ");
|
|
2881
2890
|
var isCell = (c) => typeof c === "object" && c !== null && !React32.isValidElement(c) && "content" in c;
|
|
2891
|
+
var NESTED_INTERACTIVE = "button, a, input, select, textarea, label, [role='button'], [role='link'], [role='checkbox'], [role='switch'], [role='menuitem'], [role='option']";
|
|
2882
2892
|
var TableRow = React32.forwardRef(
|
|
2883
|
-
({ cells, selected = false, onSelect, className, onKeyDown, ...props }, ref) => {
|
|
2884
|
-
const
|
|
2893
|
+
({ cells, selected = false, onSelect, onRowClick, className, onClick, onKeyDown, ...props }, ref) => {
|
|
2894
|
+
const rowClickable = Boolean(onRowClick);
|
|
2895
|
+
const interactive = Boolean(onSelect) || rowClickable;
|
|
2896
|
+
const handleClick = (event) => {
|
|
2897
|
+
onClick?.(event);
|
|
2898
|
+
if (event.defaultPrevented || !interactive) return;
|
|
2899
|
+
const nested = Boolean(event.target?.closest(NESTED_INTERACTIVE));
|
|
2900
|
+
if (rowClickable) {
|
|
2901
|
+
if (nested) return;
|
|
2902
|
+
onSelect?.();
|
|
2903
|
+
onRowClick?.();
|
|
2904
|
+
return;
|
|
2905
|
+
}
|
|
2906
|
+
onSelect?.();
|
|
2907
|
+
};
|
|
2885
2908
|
return /* @__PURE__ */ jsx32(
|
|
2886
2909
|
"tr",
|
|
2887
2910
|
{
|
|
2888
2911
|
ref,
|
|
2889
|
-
"aria-selected":
|
|
2912
|
+
"aria-selected": onSelect ? selected : void 0,
|
|
2890
2913
|
tabIndex: interactive ? 0 : void 0,
|
|
2891
|
-
onClick:
|
|
2914
|
+
onClick: handleClick,
|
|
2892
2915
|
onKeyDown: (e) => {
|
|
2893
2916
|
onKeyDown?.(e);
|
|
2894
|
-
if (!interactive) return;
|
|
2895
|
-
if (e.key === "Enter"
|
|
2917
|
+
if (!interactive || e.defaultPrevented) return;
|
|
2918
|
+
if (e.key === "Enter") {
|
|
2919
|
+
e.preventDefault();
|
|
2920
|
+
if (rowClickable) onRowClick?.();
|
|
2921
|
+
else onSelect?.();
|
|
2922
|
+
} else if (e.key === " " && onSelect) {
|
|
2896
2923
|
e.preventDefault();
|
|
2897
|
-
onSelect
|
|
2924
|
+
onSelect();
|
|
2898
2925
|
}
|
|
2899
2926
|
},
|
|
2900
2927
|
className: cn28(
|
|
@@ -3003,12 +3030,22 @@ Pagination.displayName = "Pagination";
|
|
|
3003
3030
|
import { jsx as jsx34, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
3004
3031
|
var cn30 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3005
3032
|
function useDataTableState(props) {
|
|
3006
|
-
const {
|
|
3033
|
+
const {
|
|
3034
|
+
columns,
|
|
3035
|
+
rows,
|
|
3036
|
+
filterKey,
|
|
3037
|
+
selected,
|
|
3038
|
+
onSelectedChange,
|
|
3039
|
+
pageSize = 5,
|
|
3040
|
+
defaultSort,
|
|
3041
|
+
page: controlledPage,
|
|
3042
|
+
onPageChange
|
|
3043
|
+
} = props;
|
|
3007
3044
|
const [query, setQuery] = React34.useState("");
|
|
3008
3045
|
const [sort, setSort] = React34.useState(
|
|
3009
3046
|
defaultSort ?? { key: "", direction: "none" }
|
|
3010
3047
|
);
|
|
3011
|
-
const [
|
|
3048
|
+
const [innerPage, setInnerPage] = React34.useState(1);
|
|
3012
3049
|
const [innerSel, setInnerSel] = React34.useState([]);
|
|
3013
3050
|
const sel = selected ?? innerSel;
|
|
3014
3051
|
const setSel = (ids) => {
|
|
@@ -3036,7 +3073,12 @@ function useDataTableState(props) {
|
|
|
3036
3073
|
});
|
|
3037
3074
|
}, [filtered, sort]);
|
|
3038
3075
|
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
3039
|
-
const
|
|
3076
|
+
const requestedPage = controlledPage ?? innerPage;
|
|
3077
|
+
const safePage = Math.min(Math.max(1, requestedPage), pageCount);
|
|
3078
|
+
const setPage = (next) => {
|
|
3079
|
+
if (controlledPage === void 0) setInnerPage(next);
|
|
3080
|
+
onPageChange?.(next);
|
|
3081
|
+
};
|
|
3040
3082
|
const pageRows = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
3041
3083
|
const allOnPage = pageRows.length > 0 && pageRows.every((r) => sel.includes(r.id));
|
|
3042
3084
|
const someOnPage = pageRows.some((r) => sel.includes(r.id));
|
|
@@ -3069,13 +3111,19 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3069
3111
|
views,
|
|
3070
3112
|
view,
|
|
3071
3113
|
onViewChange,
|
|
3114
|
+
toolbarStart,
|
|
3072
3115
|
filterKey,
|
|
3073
3116
|
filterPlaceholder = "Filter",
|
|
3074
3117
|
selectable = false,
|
|
3075
3118
|
selected: _selected,
|
|
3076
3119
|
onSelectedChange: _onSel,
|
|
3120
|
+
onRowClick,
|
|
3121
|
+
page: _page,
|
|
3122
|
+
onPageChange: _onPageChange,
|
|
3077
3123
|
pageSize: _ps,
|
|
3078
3124
|
defaultSort: _ds,
|
|
3125
|
+
mobileDescription: _mobileDescription,
|
|
3126
|
+
resultLabel,
|
|
3079
3127
|
emptyState = {
|
|
3080
3128
|
icon: "file",
|
|
3081
3129
|
title: "Nothing here yet",
|
|
@@ -3089,8 +3137,10 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3089
3137
|
const filterId = React34.useId();
|
|
3090
3138
|
const filterLabel = columns.find((c) => c.key === filterKey)?.label.toLowerCase() ?? "";
|
|
3091
3139
|
const isEmpty = rows.length === 0;
|
|
3140
|
+
const resultsText = resultLabel ? resultLabel(s.total) : `${s.total} ${s.total === 1 ? "result" : "results"}`;
|
|
3092
3141
|
const body = /* @__PURE__ */ jsxs30("div", { className: "flex w-full flex-col gap-md", children: [
|
|
3093
3142
|
!isEmpty ? /* @__PURE__ */ jsxs30("div", { className: "flex w-full flex-wrap items-center gap-sm", children: [
|
|
3143
|
+
toolbarStart,
|
|
3094
3144
|
filterKey ? /* @__PURE__ */ jsx34("div", { className: "w-64", children: /* @__PURE__ */ jsx34(
|
|
3095
3145
|
Input,
|
|
3096
3146
|
{
|
|
@@ -3114,11 +3164,7 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3114
3164
|
"aria-label": `Remove filter ${filterLabel}: ${s.query.trim()}`
|
|
3115
3165
|
}
|
|
3116
3166
|
) : null,
|
|
3117
|
-
/* @__PURE__ */
|
|
3118
|
-
s.total,
|
|
3119
|
-
" ",
|
|
3120
|
-
s.total === 1 ? "result" : "results"
|
|
3121
|
-
] })
|
|
3167
|
+
/* @__PURE__ */ jsx34("span", { className: "ml-auto text-body-sm text-muted", "aria-live": "polite", children: resultsText })
|
|
3122
3168
|
] }) : null,
|
|
3123
3169
|
isEmpty ? /* @__PURE__ */ jsxs30("div", { className: "flex w-full flex-col items-center gap-xs rounded-lg border border-hairline bg-surface px-lg py-xxl text-center", children: [
|
|
3124
3170
|
/* @__PURE__ */ jsx34("span", { className: "mb-sm flex size-10 items-center justify-center rounded-md border border-hairline bg-canvas shadow-sm", children: /* @__PURE__ */ jsx34(Icon, { name: emptyState.icon ?? "file", size: 18 }) }),
|
|
@@ -3165,6 +3211,7 @@ function DataTableDesktopInner(props, ref) {
|
|
|
3165
3211
|
TableRow,
|
|
3166
3212
|
{
|
|
3167
3213
|
className: isSel ? "bg-surface-soft" : void 0,
|
|
3214
|
+
onRowClick: onRowClick ? () => onRowClick(row) : void 0,
|
|
3168
3215
|
cells: selectable ? [
|
|
3169
3216
|
{
|
|
3170
3217
|
content: /* @__PURE__ */ jsx34(
|
|
@@ -3447,13 +3494,19 @@ function DataTableMobileInner(props, ref) {
|
|
|
3447
3494
|
views,
|
|
3448
3495
|
view,
|
|
3449
3496
|
onViewChange,
|
|
3497
|
+
toolbarStart,
|
|
3450
3498
|
filterKey,
|
|
3451
3499
|
filterPlaceholder = "Filter",
|
|
3452
3500
|
selectable = false,
|
|
3453
3501
|
selected: _selected,
|
|
3454
3502
|
onSelectedChange: _onSel,
|
|
3503
|
+
onRowClick,
|
|
3504
|
+
page: _page,
|
|
3505
|
+
onPageChange: _onPageChange,
|
|
3455
3506
|
pageSize: _ps,
|
|
3456
3507
|
defaultSort: _ds,
|
|
3508
|
+
mobileDescription,
|
|
3509
|
+
resultLabel,
|
|
3457
3510
|
emptyState = { icon: "file", title: "Nothing here yet" },
|
|
3458
3511
|
caption = "Data table",
|
|
3459
3512
|
className,
|
|
@@ -3469,6 +3522,7 @@ function DataTableMobileInner(props, ref) {
|
|
|
3469
3522
|
const c = columns.find((x) => x.key === key);
|
|
3470
3523
|
return c?.render ? c.render(row) : String(row[key] ?? "");
|
|
3471
3524
|
};
|
|
3525
|
+
const resultsText = resultLabel ? resultLabel(s.total) : `${s.total} ${s.total === 1 ? "result" : "results"}`;
|
|
3472
3526
|
const sortValue = s.sort.direction === "none" ? "" : `${s.sort.key}:${s.sort.direction}`;
|
|
3473
3527
|
const sortOptions = sortable.flatMap((c) => [
|
|
3474
3528
|
{ value: `${c.key}:descending`, label: `${c.label} \u2193` },
|
|
@@ -3476,6 +3530,7 @@ function DataTableMobileInner(props, ref) {
|
|
|
3476
3530
|
]);
|
|
3477
3531
|
const body = /* @__PURE__ */ jsxs32("div", { className: "flex w-full flex-col gap-md", children: [
|
|
3478
3532
|
!isEmpty ? /* @__PURE__ */ jsxs32("div", { className: "flex w-full flex-col gap-sm", children: [
|
|
3533
|
+
toolbarStart ? /* @__PURE__ */ jsx36("div", { className: "flex w-full flex-wrap items-center gap-sm", children: toolbarStart }) : null,
|
|
3479
3534
|
filterKey ? /* @__PURE__ */ jsx36(
|
|
3480
3535
|
Input,
|
|
3481
3536
|
{
|
|
@@ -3502,11 +3557,7 @@ function DataTableMobileInner(props, ref) {
|
|
|
3502
3557
|
}
|
|
3503
3558
|
}
|
|
3504
3559
|
) }) : null,
|
|
3505
|
-
/* @__PURE__ */
|
|
3506
|
-
s.total,
|
|
3507
|
-
" ",
|
|
3508
|
-
s.total === 1 ? "result" : "results"
|
|
3509
|
-
] })
|
|
3560
|
+
/* @__PURE__ */ jsx36("span", { className: "ml-auto shrink-0 text-body-sm text-muted", "aria-live": "polite", children: resultsText })
|
|
3510
3561
|
] }),
|
|
3511
3562
|
s.query.trim() ? /* @__PURE__ */ jsx36("div", { children: /* @__PURE__ */ jsx36(
|
|
3512
3563
|
Chip,
|
|
@@ -3543,11 +3594,13 @@ function DataTableMobileInner(props, ref) {
|
|
|
3543
3594
|
] }) : null,
|
|
3544
3595
|
s.pageRows.length === 0 ? /* @__PURE__ */ jsx36("p", { className: "px-base py-lg text-center text-body-sm text-muted", children: "No rows match this filter." }) : /* @__PURE__ */ jsx36("ul", { "aria-label": caption, className: "divide-y divide-hairline-soft", children: s.pageRows.map((row) => {
|
|
3545
3596
|
const isSel = s.sel.includes(row.id);
|
|
3597
|
+
const description = mobileDescription ? mobileDescription(row) : null;
|
|
3546
3598
|
return /* @__PURE__ */ jsxs32(
|
|
3547
3599
|
"li",
|
|
3548
3600
|
{
|
|
3549
3601
|
className: cn32(
|
|
3550
3602
|
"flex items-start gap-md px-base py-sm transition-colors duration-150 ease-out",
|
|
3603
|
+
onRowClick ? "hover:bg-surface-soft active:bg-surface-strong" : null,
|
|
3551
3604
|
isSel ? "bg-surface-soft" : "bg-surface"
|
|
3552
3605
|
),
|
|
3553
3606
|
children: [
|
|
@@ -3560,9 +3613,27 @@ function DataTableMobileInner(props, ref) {
|
|
|
3560
3613
|
onCheckedChange: () => s.toggleRow(row.id)
|
|
3561
3614
|
}
|
|
3562
3615
|
) }) : null,
|
|
3563
|
-
/* @__PURE__ */ jsxs32(
|
|
3616
|
+
onRowClick ? /* @__PURE__ */ jsxs32(
|
|
3617
|
+
Button,
|
|
3618
|
+
{
|
|
3619
|
+
variant: "bare",
|
|
3620
|
+
size: "md",
|
|
3621
|
+
className: "min-w-0 flex-1 flex-col items-start",
|
|
3622
|
+
onClick: () => onRowClick(row),
|
|
3623
|
+
children: [
|
|
3624
|
+
/* @__PURE__ */ jsx36("span", { className: "w-full min-w-0 truncate text-left text-body-md text-ink", children: cell(row, primary.key) }),
|
|
3625
|
+
description ? /* @__PURE__ */ jsx36("span", { className: "w-full min-w-0 truncate text-left text-body-sm text-muted", children: description }) : secondary ? /* @__PURE__ */ jsxs32("span", { className: "w-full min-w-0 truncate text-left text-body-sm text-muted", children: [
|
|
3626
|
+
/* @__PURE__ */ jsxs32("span", { className: "sr-only", children: [
|
|
3627
|
+
secondary.label,
|
|
3628
|
+
": "
|
|
3629
|
+
] }),
|
|
3630
|
+
cell(row, secondary.key)
|
|
3631
|
+
] }) : null
|
|
3632
|
+
]
|
|
3633
|
+
}
|
|
3634
|
+
) : /* @__PURE__ */ jsxs32("div", { className: "flex min-w-0 flex-1 flex-col gap-xxs", children: [
|
|
3564
3635
|
/* @__PURE__ */ jsx36("div", { className: "min-w-0 truncate text-body-md text-ink", children: cell(row, primary.key) }),
|
|
3565
|
-
secondary ? /* @__PURE__ */ jsxs32("div", { className: "truncate text-body-sm text-muted", children: [
|
|
3636
|
+
description ? /* @__PURE__ */ jsx36("div", { className: "min-w-0 truncate text-body-sm text-muted", children: description }) : secondary ? /* @__PURE__ */ jsxs32("div", { className: "truncate text-body-sm text-muted", children: [
|
|
3566
3637
|
/* @__PURE__ */ jsxs32("span", { className: "sr-only", children: [
|
|
3567
3638
|
secondary.label,
|
|
3568
3639
|
": "
|
package/dist/styles.css
CHANGED
|
@@ -735,6 +735,9 @@
|
|
|
735
735
|
.w-16 {
|
|
736
736
|
width: calc(var(--spacing) * 16);
|
|
737
737
|
}
|
|
738
|
+
.w-36 {
|
|
739
|
+
width: calc(var(--spacing) * 36);
|
|
740
|
+
}
|
|
738
741
|
.w-40 {
|
|
739
742
|
width: calc(var(--spacing) * 40);
|
|
740
743
|
}
|
|
@@ -1557,6 +1560,9 @@
|
|
|
1557
1560
|
--tw-tracking: var(--tracking-overline);
|
|
1558
1561
|
letter-spacing: var(--tracking-overline);
|
|
1559
1562
|
}
|
|
1563
|
+
.whitespace-normal {
|
|
1564
|
+
white-space: normal;
|
|
1565
|
+
}
|
|
1560
1566
|
.whitespace-nowrap {
|
|
1561
1567
|
white-space: nowrap;
|
|
1562
1568
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,8 @@ export type ButtonVariant =
|
|
|
10
10
|
| "accent"
|
|
11
11
|
| "danger"
|
|
12
12
|
| "field"
|
|
13
|
-
| "item"
|
|
13
|
+
| "item"
|
|
14
|
+
| "bare";
|
|
14
15
|
export type ButtonSize = "sm" | "md" | "lg";
|
|
15
16
|
export type ButtonShape = "rounded" | "pill";
|
|
16
17
|
|
|
@@ -20,6 +21,8 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
|
|
|
20
21
|
* `field` is a full-width, left-aligned select / combobox trigger (one border, recolored on
|
|
21
22
|
* focus or while `aria-expanded`). `item` is a full-width menu or listbox row. Both rows
|
|
22
23
|
* never scale on press; their press is a background change only.
|
|
24
|
+
* `bare` is a chrome-free, full-width reset target — no border, fill, padding or radius — for
|
|
25
|
+
* embedding a row or cell's activation inside a surface that owns the hover styling.
|
|
23
26
|
*/
|
|
24
27
|
variant?: ButtonVariant;
|
|
25
28
|
size?: ButtonSize;
|
|
@@ -50,6 +53,12 @@ const rowBase =
|
|
|
50
53
|
"transition-colors duration-150 ease-out focus-visible:outline-none " +
|
|
51
54
|
"disabled:cursor-not-allowed disabled:opacity-50";
|
|
52
55
|
|
|
56
|
+
/** Chrome-free reset target (`bare`): no border, fill, padding or radius; wraps larger content. */
|
|
57
|
+
const bareBase =
|
|
58
|
+
"relative flex w-full min-w-0 select-none items-start justify-start whitespace-normal border-transparent text-left cursor-pointer " +
|
|
59
|
+
"transition-colors duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue " +
|
|
60
|
+
"disabled:cursor-not-allowed disabled:opacity-50";
|
|
61
|
+
|
|
53
62
|
const isRow = (v: ButtonVariant) => v === "field" || v === "item";
|
|
54
63
|
|
|
55
64
|
const rowSizes: Record<"field" | "item", Record<ButtonSize, string>> = {
|
|
@@ -65,6 +74,12 @@ const rowSizes: Record<"field" | "item", Record<ButtonSize, string>> = {
|
|
|
65
74
|
},
|
|
66
75
|
};
|
|
67
76
|
|
|
77
|
+
const bareSizes: Record<ButtonSize, string> = {
|
|
78
|
+
sm: "gap-xxs p-0 text-body-sm",
|
|
79
|
+
md: "gap-xxs p-0 text-body-md",
|
|
80
|
+
lg: "gap-xxs p-0 text-body-md",
|
|
81
|
+
};
|
|
82
|
+
|
|
68
83
|
const variants: Record<ButtonVariant, string> = {
|
|
69
84
|
primary:
|
|
70
85
|
"bg-primary text-on-primary border-transparent hover:bg-primary-hover active:bg-primary-active " +
|
|
@@ -94,6 +109,8 @@ const variants: Record<ButtonVariant, string> = {
|
|
|
94
109
|
item:
|
|
95
110
|
"bg-transparent text-ink border-transparent enabled:hover:bg-surface-soft enabled:active:bg-surface-strong " +
|
|
96
111
|
"focus-visible:bg-surface-soft aria-selected:bg-surface-strong disabled:text-muted-soft",
|
|
112
|
+
bare:
|
|
113
|
+
"rounded-none bg-transparent text-ink border-transparent disabled:text-muted-soft",
|
|
97
114
|
};
|
|
98
115
|
|
|
99
116
|
const sizes: Record<ButtonSize, string> = {
|
|
@@ -137,6 +154,8 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
137
154
|
ref,
|
|
138
155
|
) => {
|
|
139
156
|
const isDisabled = Boolean(disabled);
|
|
157
|
+
const isBare = variant === "bare";
|
|
158
|
+
const row = isRow(variant);
|
|
140
159
|
return (
|
|
141
160
|
<button
|
|
142
161
|
ref={ref}
|
|
@@ -152,13 +171,15 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
152
171
|
onClick?.(e);
|
|
153
172
|
}}
|
|
154
173
|
className={cn(
|
|
155
|
-
|
|
174
|
+
isBare ? bareBase : row ? rowBase : base,
|
|
156
175
|
variants[variant],
|
|
157
|
-
|
|
158
|
-
?
|
|
159
|
-
:
|
|
160
|
-
?
|
|
161
|
-
:
|
|
176
|
+
isBare
|
|
177
|
+
? bareSizes[size]
|
|
178
|
+
: row
|
|
179
|
+
? rowSizes[variant as "field" | "item"][size]
|
|
180
|
+
: iconOnly
|
|
181
|
+
? squareSizes[size]
|
|
182
|
+
: sizes[size],
|
|
162
183
|
shape === "pill" ? "rounded-full" : radii[size],
|
|
163
184
|
fullWidth && "w-full",
|
|
164
185
|
loading && "cursor-progress",
|
|
@@ -166,7 +187,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
166
187
|
)}
|
|
167
188
|
{...props}
|
|
168
189
|
>
|
|
169
|
-
{!
|
|
190
|
+
{!row || loading ? (
|
|
170
191
|
<span
|
|
171
192
|
aria-hidden="true"
|
|
172
193
|
className={cn(
|
|
@@ -183,9 +204,13 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
183
204
|
</span>
|
|
184
205
|
) : null}
|
|
185
206
|
{children != null && !(iconOnly && loading) ? (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
207
|
+
isBare ? (
|
|
208
|
+
children
|
|
209
|
+
) : (
|
|
210
|
+
<span className={row ? "min-w-0 flex-1 truncate" : "inline-flex items-center"}>
|
|
211
|
+
{children}
|
|
212
|
+
</span>
|
|
213
|
+
)
|
|
189
214
|
) : null}
|
|
190
215
|
{trailingIcon ? (
|
|
191
216
|
<span aria-hidden="true" className="inline-flex items-center">
|
|
@@ -4,7 +4,12 @@ import { DataTableMobile } from "../DataTableMobile";
|
|
|
4
4
|
|
|
5
5
|
export type { DataTableProps };
|
|
6
6
|
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Responsive data table: the full table from `md` up, a stacked row list below.
|
|
9
|
+
* Every prop is forwarded to both variants — `toolbarStart` sits inline in the desktop
|
|
10
|
+
* toolbar and on its own row above the mobile filter, and `mobileDescription` only
|
|
11
|
+
* affects the mobile list.
|
|
12
|
+
*/
|
|
8
13
|
function DataTableInner<Row extends { id: string }>(
|
|
9
14
|
{ className, ...props }: DataTableProps<Row>,
|
|
10
15
|
ref: React.ForwardedRef<HTMLDivElement>,
|
|
@@ -2,6 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { DataTable } from "./DataTable";
|
|
3
3
|
import type { DataTableColumn } from "../DataTableDesktop";
|
|
4
4
|
import { Icon } from "../Icon";
|
|
5
|
+
import { Dropdown } from "../Dropdown";
|
|
5
6
|
|
|
6
7
|
interface LogRow {
|
|
7
8
|
id: string;
|
|
@@ -27,7 +28,7 @@ const inputs = [
|
|
|
27
28
|
"Generate test data for orders",
|
|
28
29
|
"Plan a weekend in Kyoto",
|
|
29
30
|
];
|
|
30
|
-
const
|
|
31
|
+
const allRows: LogRow[] = inputs.map((input, i) => ({
|
|
31
32
|
id: `log-${i + 1}`,
|
|
32
33
|
input,
|
|
33
34
|
model: i % 3 === 0 ? "reasoning-large" : "fast-mini",
|
|
@@ -53,11 +54,31 @@ const columns: DataTableColumn<LogRow>[] = [
|
|
|
53
54
|
{ key: "created", label: "Created", sortable: true, render: (r) => fmt(r.created) },
|
|
54
55
|
];
|
|
55
56
|
|
|
57
|
+
const statusOptions = [
|
|
58
|
+
{ value: "all", label: "All statuses" },
|
|
59
|
+
{ value: "success", label: "Success" },
|
|
60
|
+
{ value: "error", label: "Error" },
|
|
61
|
+
];
|
|
62
|
+
const modelOptions = [
|
|
63
|
+
{ value: "all", label: "All models" },
|
|
64
|
+
{ value: "fast-mini", label: "fast-mini" },
|
|
65
|
+
{ value: "reasoning-large", label: "reasoning-large" },
|
|
66
|
+
];
|
|
67
|
+
|
|
56
68
|
export default function DataTablePreview() {
|
|
57
69
|
const [view, setView] = React.useState("logs");
|
|
58
70
|
const [selected, setSelected] = React.useState<string[]>(["log-2"]);
|
|
71
|
+
const [page, setPage] = React.useState(1);
|
|
72
|
+
const [status, setStatus] = React.useState("all");
|
|
73
|
+
const [model, setModel] = React.useState("all");
|
|
74
|
+
|
|
75
|
+
const rows = React.useMemo(
|
|
76
|
+
() => (model === "all" ? allRows : allRows.filter((r) => r.model === model)),
|
|
77
|
+
[model],
|
|
78
|
+
);
|
|
79
|
+
|
|
59
80
|
return (
|
|
60
|
-
<div className="w-full p-lg">
|
|
81
|
+
<div className="w-full max-w-5xl mx-auto space-y-lg p-lg">
|
|
61
82
|
<DataTable
|
|
62
83
|
caption="Logs"
|
|
63
84
|
columns={columns}
|
|
@@ -69,13 +90,48 @@ export default function DataTablePreview() {
|
|
|
69
90
|
]}
|
|
70
91
|
view={view}
|
|
71
92
|
onViewChange={setView}
|
|
93
|
+
toolbarStart={
|
|
94
|
+
<>
|
|
95
|
+
<div className="w-36">
|
|
96
|
+
<Dropdown
|
|
97
|
+
aria-label="Filter by status"
|
|
98
|
+
placeholder="Status"
|
|
99
|
+
size="sm"
|
|
100
|
+
options={statusOptions}
|
|
101
|
+
defaultValue={status}
|
|
102
|
+
onValueChange={(v) => {
|
|
103
|
+
setStatus(v);
|
|
104
|
+
setPage(1);
|
|
105
|
+
}}
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
|
+
<div className="w-40">
|
|
109
|
+
<Dropdown
|
|
110
|
+
aria-label="Filter by model"
|
|
111
|
+
placeholder="Model"
|
|
112
|
+
size="sm"
|
|
113
|
+
options={modelOptions}
|
|
114
|
+
defaultValue={model}
|
|
115
|
+
onValueChange={(v) => {
|
|
116
|
+
setModel(v);
|
|
117
|
+
setPage(1);
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
</>
|
|
122
|
+
}
|
|
72
123
|
filterKey="input"
|
|
73
124
|
filterPlaceholder="Filter by input"
|
|
74
125
|
selectable
|
|
75
126
|
selected={selected}
|
|
76
127
|
onSelectedChange={setSelected}
|
|
128
|
+
page={page}
|
|
129
|
+
onPageChange={setPage}
|
|
77
130
|
pageSize={5}
|
|
78
131
|
defaultSort={{ key: "created", direction: "descending" }}
|
|
132
|
+
onRowClick={(row) => console.log("open /logs/" + row.id)}
|
|
133
|
+
mobileDescription={(row) => `${row.model} · ${fmt(row.created)}`}
|
|
134
|
+
resultLabel={(count) => `${count} log${count === 1 ? "" : "s"}`}
|
|
79
135
|
emptyState={{
|
|
80
136
|
icon: "file",
|
|
81
137
|
title: "Your logs will appear here",
|
|
@@ -83,6 +139,9 @@ export default function DataTablePreview() {
|
|
|
83
139
|
linkLabel: "Learn more",
|
|
84
140
|
}}
|
|
85
141
|
/>
|
|
142
|
+
<p className="text-body-sm text-muted">
|
|
143
|
+
Page {page} · click a row to open its log detail · resize below md for the stacked list.
|
|
144
|
+
</p>
|
|
86
145
|
</div>
|
|
87
146
|
);
|
|
88
147
|
}
|
|
@@ -44,6 +44,11 @@ export interface DataTableProps<Row extends { id: string }>
|
|
|
44
44
|
views?: DataTableView[];
|
|
45
45
|
view?: string;
|
|
46
46
|
onViewChange?: (view: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Slot rendered at the start of the toolbar row, before the filter field on desktop
|
|
49
|
+
* and as its own row above the filter on mobile — e.g. `Dropdown` filters.
|
|
50
|
+
*/
|
|
51
|
+
toolbarStart?: React.ReactNode;
|
|
47
52
|
/** Column key the filter field searches. Omit to hide the filter. */
|
|
48
53
|
filterKey?: string;
|
|
49
54
|
filterPlaceholder?: string;
|
|
@@ -51,8 +56,20 @@ export interface DataTableProps<Row extends { id: string }>
|
|
|
51
56
|
selectable?: boolean;
|
|
52
57
|
selected?: string[];
|
|
53
58
|
onSelectedChange?: (ids: string[]) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Makes every row an activation target: click on the row (not its checkbox, buttons
|
|
61
|
+
* or links) or press Enter on the focused row. Rows then read as clickable.
|
|
62
|
+
*/
|
|
63
|
+
onRowClick?: (row: Row) => void;
|
|
64
|
+
/** Controlled page (1-based). Pair with `onPageChange`. */
|
|
65
|
+
page?: number;
|
|
66
|
+
onPageChange?: (page: number) => void;
|
|
54
67
|
pageSize?: number;
|
|
55
68
|
defaultSort?: { key: string; direction: Exclude<SortDirection, "none"> };
|
|
69
|
+
/** Mobile only: replaces the last-column second line under each row's title. */
|
|
70
|
+
mobileDescription?: (row: Row) => React.ReactNode;
|
|
71
|
+
/** Formats the "N results" text in the toolbar. */
|
|
72
|
+
resultLabel?: (count: number) => string;
|
|
56
73
|
emptyState?: DataTableEmptyState;
|
|
57
74
|
/** Accessible table caption. */
|
|
58
75
|
caption?: string;
|
|
@@ -62,12 +79,22 @@ const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
|
62
79
|
parts.filter(Boolean).join(" ");
|
|
63
80
|
|
|
64
81
|
export function useDataTableState<Row extends { id: string }>(props: DataTableProps<Row>) {
|
|
65
|
-
const {
|
|
82
|
+
const {
|
|
83
|
+
columns,
|
|
84
|
+
rows,
|
|
85
|
+
filterKey,
|
|
86
|
+
selected,
|
|
87
|
+
onSelectedChange,
|
|
88
|
+
pageSize = 5,
|
|
89
|
+
defaultSort,
|
|
90
|
+
page: controlledPage,
|
|
91
|
+
onPageChange,
|
|
92
|
+
} = props;
|
|
66
93
|
const [query, setQuery] = React.useState("");
|
|
67
94
|
const [sort, setSort] = React.useState<{ key: string; direction: SortDirection }>(
|
|
68
95
|
defaultSort ?? { key: "", direction: "none" },
|
|
69
96
|
);
|
|
70
|
-
const [
|
|
97
|
+
const [innerPage, setInnerPage] = React.useState(1);
|
|
71
98
|
const [innerSel, setInnerSel] = React.useState<string[]>([]);
|
|
72
99
|
const sel = selected ?? innerSel;
|
|
73
100
|
const setSel = (ids: string[]) => {
|
|
@@ -101,7 +128,12 @@ export function useDataTableState<Row extends { id: string }>(props: DataTablePr
|
|
|
101
128
|
}, [filtered, sort]);
|
|
102
129
|
|
|
103
130
|
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
104
|
-
const
|
|
131
|
+
const requestedPage = controlledPage ?? innerPage;
|
|
132
|
+
const safePage = Math.min(Math.max(1, requestedPage), pageCount);
|
|
133
|
+
const setPage = (next: number) => {
|
|
134
|
+
if (controlledPage === undefined) setInnerPage(next);
|
|
135
|
+
onPageChange?.(next);
|
|
136
|
+
};
|
|
105
137
|
const pageRows = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
106
138
|
const allOnPage = pageRows.length > 0 && pageRows.every((r) => sel.includes(r.id));
|
|
107
139
|
const someOnPage = pageRows.some((r) => sel.includes(r.id));
|
|
@@ -142,13 +174,19 @@ function DataTableDesktopInner<Row extends { id: string }>(
|
|
|
142
174
|
views,
|
|
143
175
|
view,
|
|
144
176
|
onViewChange,
|
|
177
|
+
toolbarStart,
|
|
145
178
|
filterKey,
|
|
146
179
|
filterPlaceholder = "Filter",
|
|
147
180
|
selectable = false,
|
|
148
181
|
selected: _selected,
|
|
149
182
|
onSelectedChange: _onSel,
|
|
183
|
+
onRowClick,
|
|
184
|
+
page: _page,
|
|
185
|
+
onPageChange: _onPageChange,
|
|
150
186
|
pageSize: _ps,
|
|
151
187
|
defaultSort: _ds,
|
|
188
|
+
mobileDescription: _mobileDescription,
|
|
189
|
+
resultLabel,
|
|
152
190
|
emptyState = {
|
|
153
191
|
icon: "file",
|
|
154
192
|
title: "Nothing here yet",
|
|
@@ -162,11 +200,15 @@ function DataTableDesktopInner<Row extends { id: string }>(
|
|
|
162
200
|
const filterId = React.useId();
|
|
163
201
|
const filterLabel = columns.find((c) => c.key === filterKey)?.label.toLowerCase() ?? "";
|
|
164
202
|
const isEmpty = rows.length === 0;
|
|
203
|
+
const resultsText = resultLabel
|
|
204
|
+
? resultLabel(s.total)
|
|
205
|
+
: `${s.total} ${s.total === 1 ? "result" : "results"}`;
|
|
165
206
|
|
|
166
207
|
const body = (
|
|
167
208
|
<div className="flex w-full flex-col gap-md">
|
|
168
209
|
{!isEmpty ? (
|
|
169
210
|
<div className="flex w-full flex-wrap items-center gap-sm">
|
|
211
|
+
{toolbarStart}
|
|
170
212
|
{filterKey ? (
|
|
171
213
|
<div className="w-64">
|
|
172
214
|
<Input
|
|
@@ -191,7 +233,7 @@ function DataTableDesktopInner<Row extends { id: string }>(
|
|
|
191
233
|
/>
|
|
192
234
|
) : null}
|
|
193
235
|
<span className="ml-auto text-body-sm text-muted" aria-live="polite">
|
|
194
|
-
{
|
|
236
|
+
{resultsText}
|
|
195
237
|
</span>
|
|
196
238
|
</div>
|
|
197
239
|
) : null}
|
|
@@ -257,6 +299,7 @@ function DataTableDesktopInner<Row extends { id: string }>(
|
|
|
257
299
|
<TableRow
|
|
258
300
|
key={row.id}
|
|
259
301
|
className={isSel ? "bg-surface-soft" : undefined}
|
|
302
|
+
onRowClick={onRowClick ? () => onRowClick(row) : undefined}
|
|
260
303
|
cells={
|
|
261
304
|
selectable
|
|
262
305
|
? [
|
|
@@ -7,6 +7,7 @@ import { Chip } from "../Chip";
|
|
|
7
7
|
import { Dropdown } from "../Dropdown";
|
|
8
8
|
import { Icon } from "../Icon";
|
|
9
9
|
import { Link } from "../Link";
|
|
10
|
+
import { Button } from "../Button";
|
|
10
11
|
import { useDataTableState, type DataTableProps } from "../DataTableDesktop";
|
|
11
12
|
|
|
12
13
|
export type DataTableMobileProps<Row extends { id: string }> = DataTableProps<Row>;
|
|
@@ -24,13 +25,19 @@ function DataTableMobileInner<Row extends { id: string }>(
|
|
|
24
25
|
views,
|
|
25
26
|
view,
|
|
26
27
|
onViewChange,
|
|
28
|
+
toolbarStart,
|
|
27
29
|
filterKey,
|
|
28
30
|
filterPlaceholder = "Filter",
|
|
29
31
|
selectable = false,
|
|
30
32
|
selected: _selected,
|
|
31
33
|
onSelectedChange: _onSel,
|
|
34
|
+
onRowClick,
|
|
35
|
+
page: _page,
|
|
36
|
+
onPageChange: _onPageChange,
|
|
32
37
|
pageSize: _ps,
|
|
33
38
|
defaultSort: _ds,
|
|
39
|
+
mobileDescription,
|
|
40
|
+
resultLabel,
|
|
34
41
|
emptyState = { icon: "file", title: "Nothing here yet" },
|
|
35
42
|
caption = "Data table",
|
|
36
43
|
className,
|
|
@@ -46,6 +53,9 @@ function DataTableMobileInner<Row extends { id: string }>(
|
|
|
46
53
|
const c = columns.find((x) => x.key === key);
|
|
47
54
|
return c?.render ? c.render(row) : String((row as unknown as Record<string, unknown>)[key] ?? "");
|
|
48
55
|
};
|
|
56
|
+
const resultsText = resultLabel
|
|
57
|
+
? resultLabel(s.total)
|
|
58
|
+
: `${s.total} ${s.total === 1 ? "result" : "results"}`;
|
|
49
59
|
|
|
50
60
|
const sortValue = s.sort.direction === "none" ? "" : `${s.sort.key}:${s.sort.direction}`;
|
|
51
61
|
const sortOptions = sortable.flatMap((c) => [
|
|
@@ -57,6 +67,7 @@ function DataTableMobileInner<Row extends { id: string }>(
|
|
|
57
67
|
<div className="flex w-full flex-col gap-md">
|
|
58
68
|
{!isEmpty ? (
|
|
59
69
|
<div className="flex w-full flex-col gap-sm">
|
|
70
|
+
{toolbarStart ? <div className="flex w-full flex-wrap items-center gap-sm">{toolbarStart}</div> : null}
|
|
60
71
|
{filterKey ? (
|
|
61
72
|
<Input
|
|
62
73
|
size="md"
|
|
@@ -84,7 +95,7 @@ function DataTableMobileInner<Row extends { id: string }>(
|
|
|
84
95
|
</div>
|
|
85
96
|
) : null}
|
|
86
97
|
<span className="ml-auto shrink-0 text-body-sm text-muted" aria-live="polite">
|
|
87
|
-
{
|
|
98
|
+
{resultsText}
|
|
88
99
|
</span>
|
|
89
100
|
</div>
|
|
90
101
|
{s.query.trim() ? (
|
|
@@ -134,11 +145,13 @@ function DataTableMobileInner<Row extends { id: string }>(
|
|
|
134
145
|
<ul aria-label={caption} className="divide-y divide-hairline-soft">
|
|
135
146
|
{s.pageRows.map((row) => {
|
|
136
147
|
const isSel = s.sel.includes(row.id);
|
|
148
|
+
const description = mobileDescription ? mobileDescription(row) : null;
|
|
137
149
|
return (
|
|
138
150
|
<li
|
|
139
151
|
key={row.id}
|
|
140
152
|
className={cn(
|
|
141
153
|
"flex items-start gap-md px-base py-sm transition-colors duration-150 ease-out",
|
|
154
|
+
onRowClick ? "hover:bg-surface-soft active:bg-surface-strong" : null,
|
|
142
155
|
isSel ? "bg-surface-soft" : "bg-surface",
|
|
143
156
|
)}
|
|
144
157
|
>
|
|
@@ -152,15 +165,38 @@ function DataTableMobileInner<Row extends { id: string }>(
|
|
|
152
165
|
/>
|
|
153
166
|
</span>
|
|
154
167
|
) : null}
|
|
155
|
-
|
|
156
|
-
<
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
{onRowClick ? (
|
|
169
|
+
<Button
|
|
170
|
+
variant="bare"
|
|
171
|
+
size="md"
|
|
172
|
+
className="min-w-0 flex-1 flex-col items-start"
|
|
173
|
+
onClick={() => onRowClick(row)}
|
|
174
|
+
>
|
|
175
|
+
<span className="w-full min-w-0 truncate text-left text-body-md text-ink">
|
|
176
|
+
{cell(row, primary.key)}
|
|
177
|
+
</span>
|
|
178
|
+
{description ? (
|
|
179
|
+
<span className="w-full min-w-0 truncate text-left text-body-sm text-muted">{description}</span>
|
|
180
|
+
) : secondary ? (
|
|
181
|
+
<span className="w-full min-w-0 truncate text-left text-body-sm text-muted">
|
|
182
|
+
<span className="sr-only">{secondary.label}: </span>
|
|
183
|
+
{cell(row, secondary.key)}
|
|
184
|
+
</span>
|
|
185
|
+
) : null}
|
|
186
|
+
</Button>
|
|
187
|
+
) : (
|
|
188
|
+
<div className="flex min-w-0 flex-1 flex-col gap-xxs">
|
|
189
|
+
<div className="min-w-0 truncate text-body-md text-ink">{cell(row, primary.key)}</div>
|
|
190
|
+
{description ? (
|
|
191
|
+
<div className="min-w-0 truncate text-body-sm text-muted">{description}</div>
|
|
192
|
+
) : secondary ? (
|
|
193
|
+
<div className="truncate text-body-sm text-muted">
|
|
194
|
+
<span className="sr-only">{secondary.label}: </span>
|
|
195
|
+
{cell(row, secondary.key)}
|
|
196
|
+
</div>
|
|
197
|
+
) : null}
|
|
198
|
+
</div>
|
|
199
|
+
)}
|
|
164
200
|
</li>
|
|
165
201
|
);
|
|
166
202
|
})}
|
|
@@ -14,6 +14,11 @@ export interface TableRowProps extends Omit<React.HTMLAttributes<HTMLTableRowEle
|
|
|
14
14
|
selected?: boolean;
|
|
15
15
|
/** Makes the row selectable with click, Enter, or Space. */
|
|
16
16
|
onSelect?: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Makes the whole row an activation target (click on the row, or Enter while focused).
|
|
19
|
+
* Clicks on controls inside the row — checkboxes, buttons, links — are ignored.
|
|
20
|
+
*/
|
|
21
|
+
onRowClick?: () => void;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
@@ -22,21 +27,44 @@ const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
|
22
27
|
const isCell = (c: unknown): c is TableRowCell =>
|
|
23
28
|
typeof c === "object" && c !== null && !React.isValidElement(c) && "content" in (c as object);
|
|
24
29
|
|
|
30
|
+
/** Controls that live inside a row and must own their own click. */
|
|
31
|
+
const NESTED_INTERACTIVE =
|
|
32
|
+
"button, a, input, select, textarea, label, [role='button'], [role='link'], [role='checkbox'], [role='switch'], [role='menuitem'], [role='option']";
|
|
33
|
+
|
|
25
34
|
export const TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(
|
|
26
|
-
({ cells, selected = false, onSelect, className, onKeyDown, ...props }, ref) => {
|
|
27
|
-
const
|
|
35
|
+
({ cells, selected = false, onSelect, onRowClick, className, onClick, onKeyDown, ...props }, ref) => {
|
|
36
|
+
const rowClickable = Boolean(onRowClick);
|
|
37
|
+
const interactive = Boolean(onSelect) || rowClickable;
|
|
38
|
+
|
|
39
|
+
const handleClick = (event: React.MouseEvent<HTMLTableRowElement>) => {
|
|
40
|
+
onClick?.(event);
|
|
41
|
+
if (event.defaultPrevented || !interactive) return;
|
|
42
|
+
const nested = Boolean((event.target as HTMLElement | null)?.closest(NESTED_INTERACTIVE));
|
|
43
|
+
if (rowClickable) {
|
|
44
|
+
if (nested) return;
|
|
45
|
+
onSelect?.();
|
|
46
|
+
onRowClick?.();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
onSelect?.();
|
|
50
|
+
};
|
|
51
|
+
|
|
28
52
|
return (
|
|
29
53
|
<tr
|
|
30
54
|
ref={ref}
|
|
31
|
-
aria-selected={
|
|
55
|
+
aria-selected={onSelect ? selected : undefined}
|
|
32
56
|
tabIndex={interactive ? 0 : undefined}
|
|
33
|
-
onClick={
|
|
57
|
+
onClick={handleClick}
|
|
34
58
|
onKeyDown={(e) => {
|
|
35
59
|
onKeyDown?.(e);
|
|
36
|
-
if (!interactive) return;
|
|
37
|
-
if (e.key === "Enter"
|
|
60
|
+
if (!interactive || e.defaultPrevented) return;
|
|
61
|
+
if (e.key === "Enter") {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
if (rowClickable) onRowClick?.();
|
|
64
|
+
else onSelect?.();
|
|
65
|
+
} else if (e.key === " " && onSelect) {
|
|
38
66
|
e.preventDefault();
|
|
39
|
-
onSelect
|
|
67
|
+
onSelect();
|
|
40
68
|
}
|
|
41
69
|
}}
|
|
42
70
|
className={cn(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { TableRow } from "./TableRow";
|
|
3
3
|
import { Badge } from "../Badge";
|
|
4
|
+
import { Checkbox } from "../Checkbox";
|
|
4
5
|
|
|
5
6
|
const rows = [
|
|
6
7
|
{ id: "r1", name: "SFO to Tokyo on March 10", model: "gpt-4.1-2025-04-14", time: "Feb 26, 10:50 AM" },
|
|
@@ -10,37 +11,82 @@ const rows = [
|
|
|
10
11
|
|
|
11
12
|
export default function TableRowPreview() {
|
|
12
13
|
const [selected, setSelected] = React.useState<string | null>("r1");
|
|
14
|
+
const [checked, setChecked] = React.useState<string[]>(["r2"]);
|
|
15
|
+
const [opened, setOpened] = React.useState<string | null>(null);
|
|
16
|
+
|
|
17
|
+
const toggle = (id: string) =>
|
|
18
|
+
setChecked((prev) => (prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id]));
|
|
19
|
+
|
|
13
20
|
return (
|
|
14
|
-
<div className="w-full max-w-3xl mx-auto p-lg bg-canvas text-ink">
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
<div className="w-full max-w-3xl mx-auto space-y-lg p-lg bg-canvas text-ink">
|
|
22
|
+
<section className="space-y-sm">
|
|
23
|
+
<h2 className="text-body-lg text-ink">Selectable rows</h2>
|
|
24
|
+
<div className="overflow-hidden rounded-md border border-hairline bg-surface">
|
|
25
|
+
<div className="overflow-x-auto">
|
|
26
|
+
<table className="w-full border-collapse">
|
|
27
|
+
<tbody>
|
|
28
|
+
{rows.map((r) => (
|
|
29
|
+
<TableRow
|
|
30
|
+
key={r.id}
|
|
31
|
+
selected={selected === r.id}
|
|
32
|
+
onSelect={() => setSelected(r.id)}
|
|
33
|
+
cells={[r.name, r.model, { content: r.time, align: "right" }]}
|
|
34
|
+
/>
|
|
35
|
+
))}
|
|
20
36
|
<TableRow
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
cells={[
|
|
38
|
+
"SFO to Tokyo on March 10",
|
|
39
|
+
{
|
|
40
|
+
content: (
|
|
41
|
+
<Badge tone="success" variant="dot" size="sm">
|
|
42
|
+
Succeeded
|
|
43
|
+
</Badge>
|
|
44
|
+
),
|
|
45
|
+
},
|
|
46
|
+
{ content: "Feb 26, 10:50 AM", align: "right" },
|
|
47
|
+
]}
|
|
25
48
|
/>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
</tbody>
|
|
50
|
+
</table>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</section>
|
|
54
|
+
|
|
55
|
+
<section className="space-y-sm">
|
|
56
|
+
<h2 className="text-body-lg text-ink">Row click (checkbox keeps its own click)</h2>
|
|
57
|
+
<div className="overflow-hidden rounded-md border border-hairline bg-surface">
|
|
58
|
+
<div className="overflow-x-auto">
|
|
59
|
+
<table className="w-full border-collapse">
|
|
60
|
+
<tbody>
|
|
61
|
+
{rows.map((r) => (
|
|
62
|
+
<TableRow
|
|
63
|
+
key={r.id}
|
|
64
|
+
onRowClick={() => setOpened(r.id)}
|
|
65
|
+
className={opened === r.id ? "bg-surface-soft" : undefined}
|
|
66
|
+
cells={[
|
|
67
|
+
{
|
|
68
|
+
content: (
|
|
69
|
+
<Checkbox
|
|
70
|
+
size="sm"
|
|
71
|
+
aria-label={`Select ${r.name}`}
|
|
72
|
+
checked={checked.includes(r.id)}
|
|
73
|
+
onCheckedChange={() => toggle(r.id)}
|
|
74
|
+
/>
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
r.name,
|
|
78
|
+
r.model,
|
|
79
|
+
]}
|
|
80
|
+
/>
|
|
81
|
+
))}
|
|
82
|
+
</tbody>
|
|
83
|
+
</table>
|
|
84
|
+
</div>
|
|
42
85
|
</div>
|
|
43
|
-
|
|
86
|
+
<p className="text-body-sm text-muted" aria-live="polite">
|
|
87
|
+
{opened ? `Opened ${opened} — click the checkbox to select without opening.` : "Click a row, or focus one and press Enter."}
|
|
88
|
+
</p>
|
|
89
|
+
</section>
|
|
44
90
|
</div>
|
|
45
91
|
);
|
|
46
92
|
}
|