@designa8/vibedesign-linear-internal-v1-2-176b 0.0.3 → 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 +101 -48
- package/dist/index.js +101 -48
- package/dist/styles.css +5 -0
- package/package.json +1 -1
- package/src/atoms/DataTable/preview.tsx +8 -1
- package/src/atoms/DataTableDesktop/DataTableDesktop.tsx +9 -0
- package/src/atoms/DataTableMobile/DataTableMobile.tsx +8 -0
- package/src/atoms/Modal/Modal.tsx +41 -6
- package/src/atoms/Modal/preview.tsx +108 -0
- package/src/atoms/TableRow/TableRow.tsx +93 -42
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @designa8/vibedesign-linear-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
|
@@ -2573,6 +2573,20 @@ var React31 = __toESM(require("react"));
|
|
|
2573
2573
|
var React27 = __toESM(require("react"));
|
|
2574
2574
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
2575
2575
|
var cn20 = (...parts) => parts.filter(Boolean).join(" ");
|
|
2576
|
+
var INTERACTIVE_SELECTOR = [
|
|
2577
|
+
"button",
|
|
2578
|
+
"a",
|
|
2579
|
+
"input",
|
|
2580
|
+
"textarea",
|
|
2581
|
+
"select",
|
|
2582
|
+
"label",
|
|
2583
|
+
"[role='button']",
|
|
2584
|
+
"[role='checkbox']",
|
|
2585
|
+
"[role='switch']",
|
|
2586
|
+
"[role='link']",
|
|
2587
|
+
"[role='menuitem']",
|
|
2588
|
+
"[contenteditable='true']"
|
|
2589
|
+
].join(", ");
|
|
2576
2590
|
var TableRow = React27.forwardRef(
|
|
2577
2591
|
({
|
|
2578
2592
|
cells,
|
|
@@ -2580,51 +2594,74 @@ var TableRow = React27.forwardRef(
|
|
|
2580
2594
|
selected = false,
|
|
2581
2595
|
onSelectedChange,
|
|
2582
2596
|
selectLabel = "Select row",
|
|
2597
|
+
onRowActivate,
|
|
2583
2598
|
className,
|
|
2599
|
+
onClick,
|
|
2600
|
+
onKeyDown,
|
|
2584
2601
|
...rest
|
|
2585
|
-
}, ref) =>
|
|
2586
|
-
"
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
)
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2602
|
+
}, ref) => {
|
|
2603
|
+
const interactive = typeof onRowActivate === "function";
|
|
2604
|
+
const fromChildControl = (target) => target instanceof Element && target.closest(INTERACTIVE_SELECTOR) !== null;
|
|
2605
|
+
const handleClick = (event) => {
|
|
2606
|
+
onClick?.(event);
|
|
2607
|
+
if (!interactive || event.defaultPrevented || fromChildControl(event.target)) return;
|
|
2608
|
+
onRowActivate?.();
|
|
2609
|
+
};
|
|
2610
|
+
const handleKeyDown = (event) => {
|
|
2611
|
+
onKeyDown?.(event);
|
|
2612
|
+
if (!interactive || event.defaultPrevented) return;
|
|
2613
|
+
if (event.key !== "Enter" || event.target !== event.currentTarget) return;
|
|
2614
|
+
event.preventDefault();
|
|
2615
|
+
onRowActivate?.();
|
|
2616
|
+
};
|
|
2617
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
|
2618
|
+
"tr",
|
|
2619
|
+
{
|
|
2620
|
+
ref,
|
|
2621
|
+
"aria-selected": selectable ? selected : void 0,
|
|
2622
|
+
"data-state": selected ? "selected" : void 0,
|
|
2623
|
+
tabIndex: interactive ? 0 : void 0,
|
|
2624
|
+
onClick: interactive ? handleClick : onClick,
|
|
2625
|
+
onKeyDown: interactive ? handleKeyDown : onKeyDown,
|
|
2626
|
+
className: cn20(
|
|
2627
|
+
"h-10 border-b border-hairline-soft text-body-sm text-ink transition-colors duration-150 ease-out last:border-b-0",
|
|
2628
|
+
"hover:bg-surface-soft data-[state=selected]:bg-primary-soft",
|
|
2629
|
+
interactive && "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue",
|
|
2630
|
+
className
|
|
2631
|
+
),
|
|
2632
|
+
...rest,
|
|
2633
|
+
children: [
|
|
2634
|
+
selectable && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("td", { className: "w-10 pl-base pr-xs align-middle", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2635
|
+
Checkbox,
|
|
2611
2636
|
{
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2637
|
+
size: "md",
|
|
2638
|
+
checked: selected,
|
|
2639
|
+
onCheckedChange: (v) => onSelectedChange?.(v),
|
|
2640
|
+
"aria-label": selectLabel
|
|
2641
|
+
}
|
|
2642
|
+
) }),
|
|
2643
|
+
cells.map((cell, i) => {
|
|
2644
|
+
const Tag = cell.rowHeader ? "th" : "td";
|
|
2645
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2646
|
+
Tag,
|
|
2647
|
+
{
|
|
2648
|
+
scope: cell.rowHeader ? "row" : void 0,
|
|
2649
|
+
className: cn20(
|
|
2650
|
+
"px-base align-middle text-body-sm",
|
|
2651
|
+
cell.rowHeader ? "text-ink font-weight-body-md" : "text-body",
|
|
2652
|
+
cell.align === "right" ? "text-right tabular-nums" : "text-left",
|
|
2653
|
+
i === 0 && !selectable && "pl-base",
|
|
2654
|
+
i === cells.length - 1 && "pr-base"
|
|
2655
|
+
),
|
|
2656
|
+
children: cell.content
|
|
2657
|
+
},
|
|
2658
|
+
cell.key
|
|
2659
|
+
);
|
|
2660
|
+
})
|
|
2661
|
+
]
|
|
2662
|
+
}
|
|
2663
|
+
);
|
|
2664
|
+
}
|
|
2628
2665
|
);
|
|
2629
2666
|
TableRow.displayName = "TableRow";
|
|
2630
2667
|
|
|
@@ -3047,6 +3084,7 @@ function DataTableDesktopInner({
|
|
|
3047
3084
|
selectable = false,
|
|
3048
3085
|
selectedIds = [],
|
|
3049
3086
|
onSelectedIdsChange,
|
|
3087
|
+
onRowClick,
|
|
3050
3088
|
page = 1,
|
|
3051
3089
|
totalPages = 1,
|
|
3052
3090
|
onPageChange,
|
|
@@ -3146,6 +3184,7 @@ function DataTableDesktopInner({
|
|
|
3146
3184
|
selected: selectedIds.includes(id),
|
|
3147
3185
|
onSelectedChange: (on) => toggleRow(id, on),
|
|
3148
3186
|
selectLabel: `Select row ${id}`,
|
|
3187
|
+
onRowActivate: onRowClick ? () => onRowClick(row) : void 0,
|
|
3149
3188
|
cells: columns.map((col) => ({
|
|
3150
3189
|
key: col.key,
|
|
3151
3190
|
content: col.render(row),
|
|
@@ -3192,6 +3231,7 @@ function DataTableMobileInner({
|
|
|
3192
3231
|
selectable = true,
|
|
3193
3232
|
selectedIds = [],
|
|
3194
3233
|
onSelectedIdsChange,
|
|
3234
|
+
onRowClick,
|
|
3195
3235
|
page = 1,
|
|
3196
3236
|
totalPages = 1,
|
|
3197
3237
|
onPageChange,
|
|
@@ -3262,6 +3302,7 @@ function DataTableMobileInner({
|
|
|
3262
3302
|
onSelectedChange: (on) => toggleRow(id, on),
|
|
3263
3303
|
selectLabel: `Select row ${id}`,
|
|
3264
3304
|
className: "h-11",
|
|
3305
|
+
onRowActivate: onRowClick ? () => onRowClick(row) : void 0,
|
|
3265
3306
|
cells: [
|
|
3266
3307
|
...primary ? [{ key: primary.key, content: primary.render(row), rowHeader: true }] : [],
|
|
3267
3308
|
...trailing.map((c) => ({
|
|
@@ -5104,6 +5145,8 @@ var Modal = React52.forwardRef(
|
|
|
5104
5145
|
description,
|
|
5105
5146
|
footer,
|
|
5106
5147
|
size = "md",
|
|
5148
|
+
placement = "center",
|
|
5149
|
+
hideHeader = false,
|
|
5107
5150
|
showClose = true,
|
|
5108
5151
|
closeLabel = "Close dialog",
|
|
5109
5152
|
"aria-label": ariaLabel,
|
|
@@ -5146,13 +5189,20 @@ var Modal = React52.forwardRef(
|
|
|
5146
5189
|
}, [open, onOpenChange, closeOnScrimClick]);
|
|
5147
5190
|
const state = open ? "open" : "closed";
|
|
5148
5191
|
const hasTitle = title !== void 0 && title !== null;
|
|
5149
|
-
const
|
|
5192
|
+
const headerHidden = hideHeader;
|
|
5193
|
+
const hasHeader = !headerHidden && (hasTitle || showClose);
|
|
5194
|
+
const visibleTitle = hasTitle && !headerHidden;
|
|
5195
|
+
const srOnlyTitle = hasTitle && headerHidden && !ariaLabel;
|
|
5196
|
+
const labelledBy = visibleTitle || srOnlyTitle ? titleId : void 0;
|
|
5150
5197
|
const node = /* @__PURE__ */ (0, import_jsx_runtime52.jsxs)(
|
|
5151
5198
|
"div",
|
|
5152
5199
|
{
|
|
5153
5200
|
"data-state": state,
|
|
5154
5201
|
"aria-hidden": open ? void 0 : true,
|
|
5155
|
-
className:
|
|
5202
|
+
className: cn40(
|
|
5203
|
+
"fixed inset-0 flex justify-center p-base data-[state=closed]:pointer-events-none",
|
|
5204
|
+
placement === "top" ? "items-end sm:items-start sm:pt-[12dvh]" : "items-end sm:items-center"
|
|
5205
|
+
),
|
|
5156
5206
|
style: { zIndex: "var(--z-modal, 1200)" },
|
|
5157
5207
|
children: [
|
|
5158
5208
|
/* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
|
|
@@ -5173,19 +5223,21 @@ var Modal = React52.forwardRef(
|
|
|
5173
5223
|
},
|
|
5174
5224
|
role: "dialog",
|
|
5175
5225
|
"aria-modal": "true",
|
|
5176
|
-
"aria-labelledby":
|
|
5177
|
-
"aria-label":
|
|
5178
|
-
"aria-describedby": description ? descId : void 0,
|
|
5226
|
+
"aria-labelledby": labelledBy,
|
|
5227
|
+
"aria-label": labelledBy ? void 0 : ariaLabel,
|
|
5228
|
+
"aria-describedby": description && hasHeader ? descId : void 0,
|
|
5179
5229
|
"data-state": state,
|
|
5180
5230
|
"data-modal": "",
|
|
5181
5231
|
className: cn40(
|
|
5182
5232
|
"relative flex max-h-[calc(100dvh-2rem)] w-full flex-col overflow-hidden rounded-xl border border-hairline bg-canvas text-ink shadow-modal",
|
|
5183
5233
|
"transition duration-200 ease-out data-[state=open]:translate-y-0 data-[state=open]:scale-100 data-[state=open]:opacity-100 data-[state=closed]:invisible data-[state=closed]:translate-y-2 data-[state=closed]:scale-[0.98] data-[state=closed]:opacity-0",
|
|
5234
|
+
placement === "top" && "sm:max-h-[calc(88dvh-2rem)]",
|
|
5184
5235
|
WIDTH[size],
|
|
5185
5236
|
className
|
|
5186
5237
|
),
|
|
5187
5238
|
...rest,
|
|
5188
5239
|
children: [
|
|
5240
|
+
srOnlyTitle && /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("span", { id: titleId, className: "sr-only", children: title }),
|
|
5189
5241
|
hasHeader && /* @__PURE__ */ (0, import_jsx_runtime52.jsxs)("div", { className: "flex shrink-0 items-start justify-between gap-sm px-lg pb-sm pt-lg", children: [
|
|
5190
5242
|
/* @__PURE__ */ (0, import_jsx_runtime52.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-xxs", children: [
|
|
5191
5243
|
hasTitle && /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("h2", { id: titleId, className: "text-heading-sm text-ink", children: title }),
|
|
@@ -5206,7 +5258,8 @@ var Modal = React52.forwardRef(
|
|
|
5206
5258
|
"div",
|
|
5207
5259
|
{
|
|
5208
5260
|
className: cn40(
|
|
5209
|
-
"min-h-0 flex-1 overflow-y-auto overscroll-contain px-lg pb-lg
|
|
5261
|
+
"min-h-0 flex-1 overflow-y-auto overscroll-contain px-lg pb-lg",
|
|
5262
|
+
hasHeader ? "pt-xs" : "pt-lg",
|
|
5210
5263
|
bodyClassName
|
|
5211
5264
|
),
|
|
5212
5265
|
children
|
package/dist/index.js
CHANGED
|
@@ -2451,6 +2451,20 @@ import * as React31 from "react";
|
|
|
2451
2451
|
import * as React27 from "react";
|
|
2452
2452
|
import { jsx as jsx27, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
2453
2453
|
var cn20 = (...parts) => parts.filter(Boolean).join(" ");
|
|
2454
|
+
var INTERACTIVE_SELECTOR = [
|
|
2455
|
+
"button",
|
|
2456
|
+
"a",
|
|
2457
|
+
"input",
|
|
2458
|
+
"textarea",
|
|
2459
|
+
"select",
|
|
2460
|
+
"label",
|
|
2461
|
+
"[role='button']",
|
|
2462
|
+
"[role='checkbox']",
|
|
2463
|
+
"[role='switch']",
|
|
2464
|
+
"[role='link']",
|
|
2465
|
+
"[role='menuitem']",
|
|
2466
|
+
"[contenteditable='true']"
|
|
2467
|
+
].join(", ");
|
|
2454
2468
|
var TableRow = React27.forwardRef(
|
|
2455
2469
|
({
|
|
2456
2470
|
cells,
|
|
@@ -2458,51 +2472,74 @@ var TableRow = React27.forwardRef(
|
|
|
2458
2472
|
selected = false,
|
|
2459
2473
|
onSelectedChange,
|
|
2460
2474
|
selectLabel = "Select row",
|
|
2475
|
+
onRowActivate,
|
|
2461
2476
|
className,
|
|
2477
|
+
onClick,
|
|
2478
|
+
onKeyDown,
|
|
2462
2479
|
...rest
|
|
2463
|
-
}, ref) =>
|
|
2464
|
-
"
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
)
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2480
|
+
}, ref) => {
|
|
2481
|
+
const interactive = typeof onRowActivate === "function";
|
|
2482
|
+
const fromChildControl = (target) => target instanceof Element && target.closest(INTERACTIVE_SELECTOR) !== null;
|
|
2483
|
+
const handleClick = (event) => {
|
|
2484
|
+
onClick?.(event);
|
|
2485
|
+
if (!interactive || event.defaultPrevented || fromChildControl(event.target)) return;
|
|
2486
|
+
onRowActivate?.();
|
|
2487
|
+
};
|
|
2488
|
+
const handleKeyDown = (event) => {
|
|
2489
|
+
onKeyDown?.(event);
|
|
2490
|
+
if (!interactive || event.defaultPrevented) return;
|
|
2491
|
+
if (event.key !== "Enter" || event.target !== event.currentTarget) return;
|
|
2492
|
+
event.preventDefault();
|
|
2493
|
+
onRowActivate?.();
|
|
2494
|
+
};
|
|
2495
|
+
return /* @__PURE__ */ jsxs21(
|
|
2496
|
+
"tr",
|
|
2497
|
+
{
|
|
2498
|
+
ref,
|
|
2499
|
+
"aria-selected": selectable ? selected : void 0,
|
|
2500
|
+
"data-state": selected ? "selected" : void 0,
|
|
2501
|
+
tabIndex: interactive ? 0 : void 0,
|
|
2502
|
+
onClick: interactive ? handleClick : onClick,
|
|
2503
|
+
onKeyDown: interactive ? handleKeyDown : onKeyDown,
|
|
2504
|
+
className: cn20(
|
|
2505
|
+
"h-10 border-b border-hairline-soft text-body-sm text-ink transition-colors duration-150 ease-out last:border-b-0",
|
|
2506
|
+
"hover:bg-surface-soft data-[state=selected]:bg-primary-soft",
|
|
2507
|
+
interactive && "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue",
|
|
2508
|
+
className
|
|
2509
|
+
),
|
|
2510
|
+
...rest,
|
|
2511
|
+
children: [
|
|
2512
|
+
selectable && /* @__PURE__ */ jsx27("td", { className: "w-10 pl-base pr-xs align-middle", children: /* @__PURE__ */ jsx27(
|
|
2513
|
+
Checkbox,
|
|
2489
2514
|
{
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2515
|
+
size: "md",
|
|
2516
|
+
checked: selected,
|
|
2517
|
+
onCheckedChange: (v) => onSelectedChange?.(v),
|
|
2518
|
+
"aria-label": selectLabel
|
|
2519
|
+
}
|
|
2520
|
+
) }),
|
|
2521
|
+
cells.map((cell, i) => {
|
|
2522
|
+
const Tag = cell.rowHeader ? "th" : "td";
|
|
2523
|
+
return /* @__PURE__ */ jsx27(
|
|
2524
|
+
Tag,
|
|
2525
|
+
{
|
|
2526
|
+
scope: cell.rowHeader ? "row" : void 0,
|
|
2527
|
+
className: cn20(
|
|
2528
|
+
"px-base align-middle text-body-sm",
|
|
2529
|
+
cell.rowHeader ? "text-ink font-weight-body-md" : "text-body",
|
|
2530
|
+
cell.align === "right" ? "text-right tabular-nums" : "text-left",
|
|
2531
|
+
i === 0 && !selectable && "pl-base",
|
|
2532
|
+
i === cells.length - 1 && "pr-base"
|
|
2533
|
+
),
|
|
2534
|
+
children: cell.content
|
|
2535
|
+
},
|
|
2536
|
+
cell.key
|
|
2537
|
+
);
|
|
2538
|
+
})
|
|
2539
|
+
]
|
|
2540
|
+
}
|
|
2541
|
+
);
|
|
2542
|
+
}
|
|
2506
2543
|
);
|
|
2507
2544
|
TableRow.displayName = "TableRow";
|
|
2508
2545
|
|
|
@@ -2925,6 +2962,7 @@ function DataTableDesktopInner({
|
|
|
2925
2962
|
selectable = false,
|
|
2926
2963
|
selectedIds = [],
|
|
2927
2964
|
onSelectedIdsChange,
|
|
2965
|
+
onRowClick,
|
|
2928
2966
|
page = 1,
|
|
2929
2967
|
totalPages = 1,
|
|
2930
2968
|
onPageChange,
|
|
@@ -3024,6 +3062,7 @@ function DataTableDesktopInner({
|
|
|
3024
3062
|
selected: selectedIds.includes(id),
|
|
3025
3063
|
onSelectedChange: (on) => toggleRow(id, on),
|
|
3026
3064
|
selectLabel: `Select row ${id}`,
|
|
3065
|
+
onRowActivate: onRowClick ? () => onRowClick(row) : void 0,
|
|
3027
3066
|
cells: columns.map((col) => ({
|
|
3028
3067
|
key: col.key,
|
|
3029
3068
|
content: col.render(row),
|
|
@@ -3070,6 +3109,7 @@ function DataTableMobileInner({
|
|
|
3070
3109
|
selectable = true,
|
|
3071
3110
|
selectedIds = [],
|
|
3072
3111
|
onSelectedIdsChange,
|
|
3112
|
+
onRowClick,
|
|
3073
3113
|
page = 1,
|
|
3074
3114
|
totalPages = 1,
|
|
3075
3115
|
onPageChange,
|
|
@@ -3140,6 +3180,7 @@ function DataTableMobileInner({
|
|
|
3140
3180
|
onSelectedChange: (on) => toggleRow(id, on),
|
|
3141
3181
|
selectLabel: `Select row ${id}`,
|
|
3142
3182
|
className: "h-11",
|
|
3183
|
+
onRowActivate: onRowClick ? () => onRowClick(row) : void 0,
|
|
3143
3184
|
cells: [
|
|
3144
3185
|
...primary ? [{ key: primary.key, content: primary.render(row), rowHeader: true }] : [],
|
|
3145
3186
|
...trailing.map((c) => ({
|
|
@@ -4982,6 +5023,8 @@ var Modal = React52.forwardRef(
|
|
|
4982
5023
|
description,
|
|
4983
5024
|
footer,
|
|
4984
5025
|
size = "md",
|
|
5026
|
+
placement = "center",
|
|
5027
|
+
hideHeader = false,
|
|
4985
5028
|
showClose = true,
|
|
4986
5029
|
closeLabel = "Close dialog",
|
|
4987
5030
|
"aria-label": ariaLabel,
|
|
@@ -5024,13 +5067,20 @@ var Modal = React52.forwardRef(
|
|
|
5024
5067
|
}, [open, onOpenChange, closeOnScrimClick]);
|
|
5025
5068
|
const state = open ? "open" : "closed";
|
|
5026
5069
|
const hasTitle = title !== void 0 && title !== null;
|
|
5027
|
-
const
|
|
5070
|
+
const headerHidden = hideHeader;
|
|
5071
|
+
const hasHeader = !headerHidden && (hasTitle || showClose);
|
|
5072
|
+
const visibleTitle = hasTitle && !headerHidden;
|
|
5073
|
+
const srOnlyTitle = hasTitle && headerHidden && !ariaLabel;
|
|
5074
|
+
const labelledBy = visibleTitle || srOnlyTitle ? titleId : void 0;
|
|
5028
5075
|
const node = /* @__PURE__ */ jsxs46(
|
|
5029
5076
|
"div",
|
|
5030
5077
|
{
|
|
5031
5078
|
"data-state": state,
|
|
5032
5079
|
"aria-hidden": open ? void 0 : true,
|
|
5033
|
-
className:
|
|
5080
|
+
className: cn40(
|
|
5081
|
+
"fixed inset-0 flex justify-center p-base data-[state=closed]:pointer-events-none",
|
|
5082
|
+
placement === "top" ? "items-end sm:items-start sm:pt-[12dvh]" : "items-end sm:items-center"
|
|
5083
|
+
),
|
|
5034
5084
|
style: { zIndex: "var(--z-modal, 1200)" },
|
|
5035
5085
|
children: [
|
|
5036
5086
|
/* @__PURE__ */ jsx52(
|
|
@@ -5051,19 +5101,21 @@ var Modal = React52.forwardRef(
|
|
|
5051
5101
|
},
|
|
5052
5102
|
role: "dialog",
|
|
5053
5103
|
"aria-modal": "true",
|
|
5054
|
-
"aria-labelledby":
|
|
5055
|
-
"aria-label":
|
|
5056
|
-
"aria-describedby": description ? descId : void 0,
|
|
5104
|
+
"aria-labelledby": labelledBy,
|
|
5105
|
+
"aria-label": labelledBy ? void 0 : ariaLabel,
|
|
5106
|
+
"aria-describedby": description && hasHeader ? descId : void 0,
|
|
5057
5107
|
"data-state": state,
|
|
5058
5108
|
"data-modal": "",
|
|
5059
5109
|
className: cn40(
|
|
5060
5110
|
"relative flex max-h-[calc(100dvh-2rem)] w-full flex-col overflow-hidden rounded-xl border border-hairline bg-canvas text-ink shadow-modal",
|
|
5061
5111
|
"transition duration-200 ease-out data-[state=open]:translate-y-0 data-[state=open]:scale-100 data-[state=open]:opacity-100 data-[state=closed]:invisible data-[state=closed]:translate-y-2 data-[state=closed]:scale-[0.98] data-[state=closed]:opacity-0",
|
|
5112
|
+
placement === "top" && "sm:max-h-[calc(88dvh-2rem)]",
|
|
5062
5113
|
WIDTH[size],
|
|
5063
5114
|
className
|
|
5064
5115
|
),
|
|
5065
5116
|
...rest,
|
|
5066
5117
|
children: [
|
|
5118
|
+
srOnlyTitle && /* @__PURE__ */ jsx52("span", { id: titleId, className: "sr-only", children: title }),
|
|
5067
5119
|
hasHeader && /* @__PURE__ */ jsxs46("div", { className: "flex shrink-0 items-start justify-between gap-sm px-lg pb-sm pt-lg", children: [
|
|
5068
5120
|
/* @__PURE__ */ jsxs46("div", { className: "flex min-w-0 flex-1 flex-col gap-xxs", children: [
|
|
5069
5121
|
hasTitle && /* @__PURE__ */ jsx52("h2", { id: titleId, className: "text-heading-sm text-ink", children: title }),
|
|
@@ -5084,7 +5136,8 @@ var Modal = React52.forwardRef(
|
|
|
5084
5136
|
"div",
|
|
5085
5137
|
{
|
|
5086
5138
|
className: cn40(
|
|
5087
|
-
"min-h-0 flex-1 overflow-y-auto overscroll-contain px-lg pb-lg
|
|
5139
|
+
"min-h-0 flex-1 overflow-y-auto overscroll-contain px-lg pb-lg",
|
|
5140
|
+
hasHeader ? "pt-xs" : "pt-lg",
|
|
5088
5141
|
bodyClassName
|
|
5089
5142
|
),
|
|
5090
5143
|
children
|
package/dist/styles.css
CHANGED
package/package.json
CHANGED
|
@@ -69,16 +69,23 @@ export default function DataTablePreview() {
|
|
|
69
69
|
const [view, setView] = React.useState<string | null>("all");
|
|
70
70
|
const [page, setPage] = React.useState(1);
|
|
71
71
|
const [panel, setPanel] = React.useState(false);
|
|
72
|
+
const [opened, setOpened] = React.useState<string | null>(null);
|
|
73
|
+
|
|
72
74
|
const rows = sort
|
|
73
75
|
? [...ALL].sort((a, b) => (a.name > b.name ? 1 : -1) * (sort.direction === "descending" ? -1 : 1))
|
|
74
76
|
: ALL;
|
|
77
|
+
|
|
75
78
|
return (
|
|
76
|
-
<div className="w-full p-lg text-ink">
|
|
79
|
+
<div className="w-full max-w-4xl mx-auto space-y-md p-lg text-ink">
|
|
80
|
+
<div className="min-h-[1.25rem] text-body-sm text-muted" aria-live="polite">
|
|
81
|
+
{opened ? `Opened row: ${opened}` : "Click a row (or focus it and press Enter) to open it."}
|
|
82
|
+
</div>
|
|
77
83
|
<DataTable
|
|
78
84
|
caption="Projects"
|
|
79
85
|
columns={COLUMNS}
|
|
80
86
|
rows={rows}
|
|
81
87
|
getRowId={(p) => p.id}
|
|
88
|
+
onRowClick={(p) => setOpened(p.name)}
|
|
82
89
|
sort={sort}
|
|
83
90
|
onSortChange={setSort}
|
|
84
91
|
viewOptions={[
|
|
@@ -60,6 +60,13 @@ export interface DataTableDesktopProps<T = Record<string, unknown>>
|
|
|
60
60
|
selectedIds?: string[];
|
|
61
61
|
onSelectedIdsChange?: (ids: string[]) => void;
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Makes every body row a click target — the row becomes focusable, Enter
|
|
65
|
+
* activates it, and clicks inside the checkbox or any other control are
|
|
66
|
+
* ignored. Omit it and rows stay static.
|
|
67
|
+
*/
|
|
68
|
+
onRowClick?: (row: T) => void;
|
|
69
|
+
|
|
63
70
|
page?: number;
|
|
64
71
|
totalPages?: number;
|
|
65
72
|
onPageChange?: (page: number) => void;
|
|
@@ -96,6 +103,7 @@ function DataTableDesktopInner<T>(
|
|
|
96
103
|
selectable = false,
|
|
97
104
|
selectedIds = [],
|
|
98
105
|
onSelectedIdsChange,
|
|
106
|
+
onRowClick,
|
|
99
107
|
page = 1,
|
|
100
108
|
totalPages = 1,
|
|
101
109
|
onPageChange,
|
|
@@ -221,6 +229,7 @@ function DataTableDesktopInner<T>(
|
|
|
221
229
|
selected={selectedIds.includes(id)}
|
|
222
230
|
onSelectedChange={(on) => toggleRow(id, on)}
|
|
223
231
|
selectLabel={`Select row ${id}`}
|
|
232
|
+
onRowActivate={onRowClick ? () => onRowClick(row) : undefined}
|
|
224
233
|
cells={columns.map((col) => ({
|
|
225
234
|
key: col.key,
|
|
226
235
|
content: col.render(row),
|
|
@@ -47,6 +47,12 @@ export interface DataTableMobileProps<T = Record<string, unknown>>
|
|
|
47
47
|
selectable?: boolean;
|
|
48
48
|
selectedIds?: string[];
|
|
49
49
|
onSelectedIdsChange?: (ids: string[]) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Makes every body row a click target — the row becomes focusable, Enter
|
|
52
|
+
* activates it, and clicks inside the checkbox or any other control are
|
|
53
|
+
* ignored. Omit it and rows stay static.
|
|
54
|
+
*/
|
|
55
|
+
onRowClick?: (row: T) => void;
|
|
50
56
|
page?: number;
|
|
51
57
|
totalPages?: number;
|
|
52
58
|
onPageChange?: (page: number) => void;
|
|
@@ -81,6 +87,7 @@ function DataTableMobileInner<T>(
|
|
|
81
87
|
selectable = true,
|
|
82
88
|
selectedIds = [],
|
|
83
89
|
onSelectedIdsChange,
|
|
90
|
+
onRowClick,
|
|
84
91
|
page = 1,
|
|
85
92
|
totalPages = 1,
|
|
86
93
|
onPageChange,
|
|
@@ -180,6 +187,7 @@ function DataTableMobileInner<T>(
|
|
|
180
187
|
onSelectedChange={(on) => toggleRow(id, on)}
|
|
181
188
|
selectLabel={`Select row ${id}`}
|
|
182
189
|
className="h-11"
|
|
190
|
+
onRowActivate={onRowClick ? () => onRowClick(row) : undefined}
|
|
183
191
|
cells={[
|
|
184
192
|
...(primary
|
|
185
193
|
? [{ key: primary.key, content: primary.render(row), rowHeader: true }]
|
|
@@ -4,6 +4,8 @@ import { IconButton } from "../IconButton";
|
|
|
4
4
|
|
|
5
5
|
export type ModalSize = "sm" | "md" | "lg";
|
|
6
6
|
|
|
7
|
+
export type ModalPlacement = "center" | "top";
|
|
8
|
+
|
|
7
9
|
export interface ModalProps
|
|
8
10
|
extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
|
|
9
11
|
/** Controlled open state. */
|
|
@@ -17,6 +19,19 @@ export interface ModalProps
|
|
|
17
19
|
footer?: React.ReactNode;
|
|
18
20
|
/** Panel width: sm 400px, md 520px, lg 680px (full width minus the gutter on phones). */
|
|
19
21
|
size?: ModalSize;
|
|
22
|
+
/**
|
|
23
|
+
* Vertical placement. `center` (default) centers the panel from `sm` up with
|
|
24
|
+
* the mobile bottom-sheet layout below that. `top` anchors the panel near the
|
|
25
|
+
* top of the viewport from `sm` up — the way a command palette opens — while
|
|
26
|
+
* the panel height stays capped and only the body scrolls.
|
|
27
|
+
*/
|
|
28
|
+
placement?: ModalPlacement;
|
|
29
|
+
/**
|
|
30
|
+
* Drop the header row entirely (title, description and close button) while
|
|
31
|
+
* keeping the accessible name from `aria-label`. Useful when the first row of
|
|
32
|
+
* the panel is its own search field, e.g. a command palette.
|
|
33
|
+
*/
|
|
34
|
+
hideHeader?: boolean;
|
|
20
35
|
/** Show the close (x) button in the header. Default true. */
|
|
21
36
|
showClose?: boolean;
|
|
22
37
|
closeLabel?: string;
|
|
@@ -46,6 +61,8 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
|
46
61
|
description,
|
|
47
62
|
footer,
|
|
48
63
|
size = "md",
|
|
64
|
+
placement = "center",
|
|
65
|
+
hideHeader = false,
|
|
49
66
|
showClose = true,
|
|
50
67
|
closeLabel = "Close dialog",
|
|
51
68
|
"aria-label": ariaLabel,
|
|
@@ -93,13 +110,24 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
|
93
110
|
|
|
94
111
|
const state = open ? "open" : "closed";
|
|
95
112
|
const hasTitle = title !== undefined && title !== null;
|
|
96
|
-
const
|
|
113
|
+
const headerHidden = hideHeader;
|
|
114
|
+
const hasHeader = !headerHidden && (hasTitle || showClose);
|
|
115
|
+
// A visible title names the dialog; a headerless dialog prefers aria-label and
|
|
116
|
+
// falls back to a visually hidden title so the name is never missing.
|
|
117
|
+
const visibleTitle = hasTitle && !headerHidden;
|
|
118
|
+
const srOnlyTitle = hasTitle && headerHidden && !ariaLabel;
|
|
119
|
+
const labelledBy = visibleTitle || srOnlyTitle ? titleId : undefined;
|
|
97
120
|
|
|
98
121
|
const node = (
|
|
99
122
|
<div
|
|
100
123
|
data-state={state}
|
|
101
124
|
aria-hidden={open ? undefined : true}
|
|
102
|
-
className=
|
|
125
|
+
className={cn(
|
|
126
|
+
"fixed inset-0 flex justify-center p-base data-[state=closed]:pointer-events-none",
|
|
127
|
+
placement === "top"
|
|
128
|
+
? "items-end sm:items-start sm:pt-[12dvh]"
|
|
129
|
+
: "items-end sm:items-center",
|
|
130
|
+
)}
|
|
103
131
|
style={{ zIndex: "var(--z-modal, 1200)" }}
|
|
104
132
|
>
|
|
105
133
|
<div
|
|
@@ -115,19 +143,25 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
|
115
143
|
}}
|
|
116
144
|
role="dialog"
|
|
117
145
|
aria-modal="true"
|
|
118
|
-
aria-labelledby={
|
|
119
|
-
aria-label={
|
|
120
|
-
aria-describedby={description ? descId : undefined}
|
|
146
|
+
aria-labelledby={labelledBy}
|
|
147
|
+
aria-label={labelledBy ? undefined : ariaLabel}
|
|
148
|
+
aria-describedby={description && hasHeader ? descId : undefined}
|
|
121
149
|
data-state={state}
|
|
122
150
|
data-modal=""
|
|
123
151
|
className={cn(
|
|
124
152
|
"relative flex max-h-[calc(100dvh-2rem)] w-full flex-col overflow-hidden rounded-xl border border-hairline bg-canvas text-ink shadow-modal",
|
|
125
153
|
"transition duration-200 ease-out data-[state=open]:translate-y-0 data-[state=open]:scale-100 data-[state=open]:opacity-100 data-[state=closed]:invisible data-[state=closed]:translate-y-2 data-[state=closed]:scale-[0.98] data-[state=closed]:opacity-0",
|
|
154
|
+
placement === "top" && "sm:max-h-[calc(88dvh-2rem)]",
|
|
126
155
|
WIDTH[size],
|
|
127
156
|
className,
|
|
128
157
|
)}
|
|
129
158
|
{...rest}
|
|
130
159
|
>
|
|
160
|
+
{srOnlyTitle && (
|
|
161
|
+
<span id={titleId} className="sr-only">
|
|
162
|
+
{title}
|
|
163
|
+
</span>
|
|
164
|
+
)}
|
|
131
165
|
{hasHeader && (
|
|
132
166
|
<div className="flex shrink-0 items-start justify-between gap-sm px-lg pb-sm pt-lg">
|
|
133
167
|
<div className="flex min-w-0 flex-1 flex-col gap-xxs">
|
|
@@ -156,7 +190,8 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
|
156
190
|
{children != null && children !== false && (
|
|
157
191
|
<div
|
|
158
192
|
className={cn(
|
|
159
|
-
"min-h-0 flex-1 overflow-y-auto overscroll-contain px-lg pb-lg
|
|
193
|
+
"min-h-0 flex-1 overflow-y-auto overscroll-contain px-lg pb-lg",
|
|
194
|
+
hasHeader ? "pt-xs" : "pt-lg",
|
|
160
195
|
bodyClassName,
|
|
161
196
|
)}
|
|
162
197
|
>
|
|
@@ -5,14 +5,55 @@ import { Icon } from "../Icon";
|
|
|
5
5
|
import { Input } from "../Input";
|
|
6
6
|
import { Textarea } from "../Textarea";
|
|
7
7
|
import { Dropdown } from "../Dropdown";
|
|
8
|
+
import { SearchBar } from "../SearchBar";
|
|
9
|
+
import { ListItem } from "../ListItem";
|
|
10
|
+
import { Badge } from "../Badge";
|
|
11
|
+
|
|
12
|
+
type Command = {
|
|
13
|
+
id: string;
|
|
14
|
+
icon: "plus" | "search" | "user";
|
|
15
|
+
title: string;
|
|
16
|
+
meta: string;
|
|
17
|
+
shortcut: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const COMMANDS: Command[] = [
|
|
21
|
+
{
|
|
22
|
+
id: "new-issue",
|
|
23
|
+
icon: "plus",
|
|
24
|
+
title: "New issue",
|
|
25
|
+
meta: "Create an issue in this project",
|
|
26
|
+
shortcut: "C",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "search",
|
|
30
|
+
icon: "search",
|
|
31
|
+
title: "Search issues",
|
|
32
|
+
meta: "Find by title, label or assignee",
|
|
33
|
+
shortcut: "/",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "members",
|
|
37
|
+
icon: "user",
|
|
38
|
+
title: "Manage members",
|
|
39
|
+
meta: "Invite people and set roles",
|
|
40
|
+
shortcut: "G then M",
|
|
41
|
+
},
|
|
42
|
+
];
|
|
8
43
|
|
|
9
44
|
export default function ModalPreview() {
|
|
10
45
|
const [issueOpen, setIssueOpen] = React.useState(false);
|
|
11
46
|
const [confirmOpen, setConfirmOpen] = React.useState(false);
|
|
47
|
+
const [paletteOpen, setPaletteOpen] = React.useState(false);
|
|
12
48
|
const [title, setTitle] = React.useState("Create a habit tracker");
|
|
13
49
|
const [details, setDetails] = React.useState("");
|
|
14
50
|
const [assignee, setAssignee] = React.useState<string | null>("me");
|
|
15
51
|
const [status, setStatus] = React.useState<string | null>("backlog");
|
|
52
|
+
const [query, setQuery] = React.useState("");
|
|
53
|
+
|
|
54
|
+
const commands = COMMANDS.filter((command) =>
|
|
55
|
+
`${command.title} ${command.meta}`.toLowerCase().includes(query.toLowerCase()),
|
|
56
|
+
);
|
|
16
57
|
|
|
17
58
|
return (
|
|
18
59
|
<div className="w-full max-w-3xl mx-auto p-lg">
|
|
@@ -32,6 +73,17 @@ export default function ModalPreview() {
|
|
|
32
73
|
>
|
|
33
74
|
Delete issue
|
|
34
75
|
</Button>
|
|
76
|
+
<Button
|
|
77
|
+
variant="secondary"
|
|
78
|
+
leadingIcon={<Icon name="search" size={16} />}
|
|
79
|
+
aria-expanded={paletteOpen}
|
|
80
|
+
onClick={() => {
|
|
81
|
+
setQuery("");
|
|
82
|
+
setPaletteOpen(true);
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
Command palette
|
|
86
|
+
</Button>
|
|
35
87
|
</div>
|
|
36
88
|
|
|
37
89
|
<Modal
|
|
@@ -100,6 +152,62 @@ export default function ModalPreview() {
|
|
|
100
152
|
</>
|
|
101
153
|
}
|
|
102
154
|
/>
|
|
155
|
+
|
|
156
|
+
<Modal
|
|
157
|
+
open={paletteOpen}
|
|
158
|
+
onOpenChange={setPaletteOpen}
|
|
159
|
+
placement="top"
|
|
160
|
+
hideHeader
|
|
161
|
+
aria-label="Command palette"
|
|
162
|
+
closeLabel="Close command palette"
|
|
163
|
+
footer={
|
|
164
|
+
<div className="flex w-full flex-wrap items-center justify-between gap-sm">
|
|
165
|
+
<span className="text-body-sm text-muted">
|
|
166
|
+
Jump to anything in the project
|
|
167
|
+
</span>
|
|
168
|
+
<span className="text-body-sm text-muted">Esc to close</span>
|
|
169
|
+
</div>
|
|
170
|
+
}
|
|
171
|
+
>
|
|
172
|
+
<div className="flex flex-col gap-sm">
|
|
173
|
+
<SearchBar
|
|
174
|
+
value={query}
|
|
175
|
+
onValueChange={setQuery}
|
|
176
|
+
placeholder="Type a command or search…"
|
|
177
|
+
aria-label="Search commands"
|
|
178
|
+
actionLabel={null}
|
|
179
|
+
clearable
|
|
180
|
+
/>
|
|
181
|
+
<div className="flex flex-col gap-xxs">
|
|
182
|
+
<p className="px-xs text-caption text-muted">Commands</p>
|
|
183
|
+
{commands.length > 0 ? (
|
|
184
|
+
commands.map((command) => (
|
|
185
|
+
<ListItem
|
|
186
|
+
key={command.id}
|
|
187
|
+
variant="plain"
|
|
188
|
+
icon={command.icon}
|
|
189
|
+
title={command.title}
|
|
190
|
+
meta={command.meta}
|
|
191
|
+
href={undefined}
|
|
192
|
+
onClick={(event) => {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
setPaletteOpen(false);
|
|
195
|
+
}}
|
|
196
|
+
trailing={
|
|
197
|
+
<Badge tone="neutral" size="sm">
|
|
198
|
+
{command.shortcut}
|
|
199
|
+
</Badge>
|
|
200
|
+
}
|
|
201
|
+
/>
|
|
202
|
+
))
|
|
203
|
+
) : (
|
|
204
|
+
<p className="px-xs py-md text-body-sm text-muted">
|
|
205
|
+
No commands match that search.
|
|
206
|
+
</p>
|
|
207
|
+
)}
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
</Modal>
|
|
103
211
|
</div>
|
|
104
212
|
);
|
|
105
213
|
}
|
|
@@ -20,11 +20,33 @@ export interface TableRowProps
|
|
|
20
20
|
onSelectedChange?: (selected: boolean) => void;
|
|
21
21
|
/** Accessible name for the row checkbox, e.g. "Select SLM". */
|
|
22
22
|
selectLabel?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Makes the whole row a click target. The row becomes focusable and Enter
|
|
25
|
+
* activates it; clicks landing inside a checkbox, button, link, or field are
|
|
26
|
+
* ignored so those controls keep working.
|
|
27
|
+
*/
|
|
28
|
+
onRowActivate?: () => void;
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
26
32
|
parts.filter(Boolean).join(" ");
|
|
27
33
|
|
|
34
|
+
/** Controls inside a row that own their own activation. */
|
|
35
|
+
const INTERACTIVE_SELECTOR = [
|
|
36
|
+
"button",
|
|
37
|
+
"a",
|
|
38
|
+
"input",
|
|
39
|
+
"textarea",
|
|
40
|
+
"select",
|
|
41
|
+
"label",
|
|
42
|
+
"[role='button']",
|
|
43
|
+
"[role='checkbox']",
|
|
44
|
+
"[role='switch']",
|
|
45
|
+
"[role='link']",
|
|
46
|
+
"[role='menuitem']",
|
|
47
|
+
"[contenteditable='true']",
|
|
48
|
+
].join(", ");
|
|
49
|
+
|
|
28
50
|
/**
|
|
29
51
|
* One compact data row. Hover and selection only change the row background,
|
|
30
52
|
* which runs edge to edge; the first and last cells carry the inset.
|
|
@@ -37,51 +59,80 @@ export const TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(
|
|
|
37
59
|
selected = false,
|
|
38
60
|
onSelectedChange,
|
|
39
61
|
selectLabel = "Select row",
|
|
62
|
+
onRowActivate,
|
|
40
63
|
className,
|
|
64
|
+
onClick,
|
|
65
|
+
onKeyDown,
|
|
41
66
|
...rest
|
|
42
67
|
},
|
|
43
68
|
ref,
|
|
44
|
-
) =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
) => {
|
|
70
|
+
const interactive = typeof onRowActivate === "function";
|
|
71
|
+
|
|
72
|
+
const fromChildControl = (target: EventTarget | null) =>
|
|
73
|
+
target instanceof Element && target.closest(INTERACTIVE_SELECTOR) !== null;
|
|
74
|
+
|
|
75
|
+
const handleClick = (event: React.MouseEvent<HTMLTableRowElement>) => {
|
|
76
|
+
onClick?.(event);
|
|
77
|
+
if (!interactive || event.defaultPrevented || fromChildControl(event.target)) return;
|
|
78
|
+
onRowActivate?.();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLTableRowElement>) => {
|
|
82
|
+
onKeyDown?.(event);
|
|
83
|
+
if (!interactive || event.defaultPrevented) return;
|
|
84
|
+
if (event.key !== "Enter" || event.target !== event.currentTarget) return;
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
onRowActivate?.();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<tr
|
|
91
|
+
ref={ref}
|
|
92
|
+
aria-selected={selectable ? selected : undefined}
|
|
93
|
+
data-state={selected ? "selected" : undefined}
|
|
94
|
+
tabIndex={interactive ? 0 : undefined}
|
|
95
|
+
onClick={interactive ? handleClick : onClick}
|
|
96
|
+
onKeyDown={interactive ? handleKeyDown : onKeyDown}
|
|
97
|
+
className={cn(
|
|
98
|
+
"h-10 border-b border-hairline-soft text-body-sm text-ink transition-colors duration-150 ease-out last:border-b-0",
|
|
99
|
+
"hover:bg-surface-soft data-[state=selected]:bg-primary-soft",
|
|
100
|
+
interactive &&
|
|
101
|
+
"cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue",
|
|
102
|
+
className,
|
|
103
|
+
)}
|
|
104
|
+
{...rest}
|
|
105
|
+
>
|
|
106
|
+
{selectable && (
|
|
107
|
+
<td className="w-10 pl-base pr-xs align-middle">
|
|
108
|
+
<Checkbox
|
|
109
|
+
size="md"
|
|
110
|
+
checked={selected}
|
|
111
|
+
onCheckedChange={(v) => onSelectedChange?.(v)}
|
|
112
|
+
aria-label={selectLabel}
|
|
113
|
+
/>
|
|
114
|
+
</td>
|
|
115
|
+
)}
|
|
116
|
+
{cells.map((cell, i) => {
|
|
117
|
+
const Tag = cell.rowHeader ? "th" : "td";
|
|
118
|
+
return (
|
|
119
|
+
<Tag
|
|
120
|
+
key={cell.key}
|
|
121
|
+
scope={cell.rowHeader ? "row" : undefined}
|
|
122
|
+
className={cn(
|
|
123
|
+
"px-base align-middle text-body-sm",
|
|
124
|
+
cell.rowHeader ? "text-ink font-weight-body-md" : "text-body",
|
|
125
|
+
cell.align === "right" ? "text-right tabular-nums" : "text-left",
|
|
126
|
+
i === 0 && !selectable && "pl-base",
|
|
127
|
+
i === cells.length - 1 && "pr-base",
|
|
128
|
+
)}
|
|
129
|
+
>
|
|
130
|
+
{cell.content}
|
|
131
|
+
</Tag>
|
|
132
|
+
);
|
|
133
|
+
})}
|
|
134
|
+
</tr>
|
|
135
|
+
);
|
|
136
|
+
},
|
|
86
137
|
);
|
|
87
138
|
TableRow.displayName = "TableRow";
|