@neasg/design-system 0.4.16 → 0.4.18
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/dist/calendar.d.ts +1 -1
- package/dist/calendar.js +2 -2
- package/dist/date-input.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/table.d.ts +17 -1
- package/dist/table.js +83 -42
- package/package.json +1 -1
package/dist/calendar.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { DayButton, DayPicker } from "react-day-picker";
|
|
3
3
|
import { Button } from "./button";
|
|
4
4
|
declare function CalendarDayButton({ className, day, modifiers, children, disabled, onClick, onFocus, onBlur, onKeyDown, onMouseEnter, onMouseLeave, tabIndex, type, "aria-label": ariaLabel, "aria-pressed": ariaPressed, "aria-selected": ariaSelected, }: React.ComponentProps<typeof DayButton>): import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
declare function Calendar({ className, classNames, showOutsideDays, captionLayout, buttonVariant, formatters, components, ...props }: React.ComponentProps<typeof DayPicker> & {
|
|
5
|
+
declare function Calendar({ className, classNames, showOutsideDays, fixedWeeks, captionLayout, buttonVariant, formatters, components, ...props }: React.ComponentProps<typeof DayPicker> & {
|
|
6
6
|
buttonVariant?: React.ComponentProps<typeof Button>["variant"];
|
|
7
7
|
}): import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
export { Calendar, CalendarDayButton };
|
package/dist/calendar.js
CHANGED
|
@@ -18,9 +18,9 @@ function CalendarDayButton({ className, day, modifiers, children, disabled, onCl
|
|
|
18
18
|
!modifiers.range_end &&
|
|
19
19
|
!modifiers.range_middle, "data-range-start": modifiers.range_start, "data-range-end": modifiers.range_end, "data-range-middle": modifiers.range_middle, className: cn("inline-flex cursor-pointer items-center justify-center rounded-control outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", "data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-primary/10 data-[range-middle=true]:text-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 aspect-square w-full min-w-[--cell-size] data-[range-end=true]:rounded-control data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-control group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px]", defaultClassNames.day, className), children: _jsx(Typography, { as: "span", variant: "bodySm", color: "inherit", children: children }) }));
|
|
20
20
|
}
|
|
21
|
-
function Calendar({ className, classNames, showOutsideDays = true, captionLayout = "label", buttonVariant = "ghost", formatters, components, ...props }) {
|
|
21
|
+
function Calendar({ className, classNames, showOutsideDays = true, fixedWeeks = true, captionLayout = "label", buttonVariant = "ghost", formatters, components, ...props }) {
|
|
22
22
|
const defaultClassNames = getDefaultClassNames();
|
|
23
|
-
return (_jsx(DayPicker, { showOutsideDays: showOutsideDays, className: cn("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent", String.raw `rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw `rtl:**:[.rdp-button\_previous>svg]:rotate-180`, className), captionLayout: captionLayout, formatters: {
|
|
23
|
+
return (_jsx(DayPicker, { showOutsideDays: showOutsideDays, fixedWeeks: fixedWeeks, className: cn("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent", String.raw `rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw `rtl:**:[.rdp-button\_previous>svg]:rotate-180`, className), captionLayout: captionLayout, formatters: {
|
|
24
24
|
formatMonthDropdown: (date) => date.toLocaleString("default", { month: "short" }),
|
|
25
25
|
...formatters,
|
|
26
26
|
}, classNames: {
|
package/dist/date-input.js
CHANGED
|
@@ -164,7 +164,7 @@ const DateInput = React.forwardRef((props, ref) => {
|
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
166
|
const disabledDays = (date) => isDateOutsideBounds(date, minDate, maxDate);
|
|
167
|
-
const calendarContent = (_jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: props.mode === "range" ? (_jsx(Calendar, { mode: "range", selected: selectedRange, onSelect: handleRangeSelect, disabled: disabledDays, defaultMonth: (_b = selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.from) !== null && _b !== void 0 ? _b : selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.to, numberOfMonths: (_c = props.numberOfMonths) !== null && _c !== void 0 ? _c : 2, autoFocus: true })) : (_jsx(Calendar, { mode: "single", selected: selectedDate, onSelect: handleSelect, disabled: disabledDays, defaultMonth: selectedDate, autoFocus: true })) }));
|
|
167
|
+
const calendarContent = (_jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: props.mode === "range" ? (_jsx(Calendar, { mode: "range", selected: selectedRange, onSelect: handleRangeSelect, disabled: disabledDays, defaultMonth: (_b = selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.from) !== null && _b !== void 0 ? _b : selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange.to, numberOfMonths: (_c = props.numberOfMonths) !== null && _c !== void 0 ? _c : 2, showOutsideDays: false, autoFocus: true })) : (_jsx(Calendar, { mode: "single", selected: selectedDate, onSelect: handleSelect, disabled: disabledDays, defaultMonth: selectedDate, autoFocus: true })) }));
|
|
168
168
|
if (appearance === "inline") {
|
|
169
169
|
return (_jsxs("span", { className: cn("inline-flex", className), "data-disabled": disabled ? "true" : undefined, "data-invalid": isInvalid ? "true" : undefined, children: [_jsxs(PopoverRoot, { open: open, onOpenChange: handleOpenChange, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: inputId, disabled: disabled, "aria-invalid": isInvalid ? "true" : undefined, "aria-describedby": [descriptionId, errorId].filter(Boolean).join(" ") || undefined, className: cn("inline-flex cursor-pointer items-baseline rounded-sm border-0 bg-transparent p-0 font-medium text-primary underline decoration-primary/40 underline-offset-4 transition-colors hover:decoration-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50", !displayValue && "text-muted-foreground decoration-border", isInvalid && "text-destructive decoration-destructive", triggerClassName), children: [_jsxs("span", { className: "sr-only", children: [label, ": "] }), _jsx("span", { children: displayValue !== null && displayValue !== void 0 ? displayValue : placeholder })] }) }), calendarContent] }), showDescription ? (_jsx("span", { id: descriptionId, className: "sr-only", children: description })) : null, error ? (_jsx("span", { id: errorId, role: "alert", className: "sr-only", children: error })) : null] }));
|
|
170
170
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -132,7 +132,7 @@ export type { TableColumnVisibilityMenuProps } from "./table-column-visibility";
|
|
|
132
132
|
export { useTableSort } from "./use-table-sort";
|
|
133
133
|
export type { UseTableSortOptions, UseTableSortReturn, } from "./use-table-sort";
|
|
134
134
|
export { Table, TableRoot, TableContainer, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, TableRowSkeleton, TABLE_SKELETON_PRESETS, } from "./table";
|
|
135
|
-
export type { TableColumn, TableColumnWidths, TableProps, TableResizeMode, TableRowTone, TableSortDirection, TableSortingProps, TableSkeletonConfig, TableRowSkeletonProps, } from "./table";
|
|
135
|
+
export type { TableColumn, TableColumnWidths, TableProps, TableResizeMode, TableRowExpansionProps, TableRowTone, TableSortDirection, TableSortingProps, TableSkeletonConfig, TableRowSkeletonProps, } from "./table";
|
|
136
136
|
export { Tabs, TabsRoot, TabWithDropdown, type TabsItem, type TabsItemLabel, type TabsItemLabelProps, type TabsProps, TabsList, TabsTrigger, TabsContent, type TabWithDropdownProps, useTabsContext, type TabDropdownSection, } from "./tabs";
|
|
137
137
|
export { Tooltip, TooltipRoot, TooltipTrigger, TooltipContent, TooltipProvider, type TooltipProps, } from "./tooltip";
|
|
138
138
|
export { Toaster, toast } from "./toaster";
|
package/dist/table.d.ts
CHANGED
|
@@ -94,6 +94,20 @@ export interface TableSortingProps {
|
|
|
94
94
|
direction: TableSortDirection;
|
|
95
95
|
onSort: (field: string) => void;
|
|
96
96
|
}
|
|
97
|
+
export interface TableRowExpansionProps<Row> {
|
|
98
|
+
/** Renders the full-width content below an expanded parent row. */
|
|
99
|
+
renderExpandedContent: (row: Row, rowIndex: number) => React.ReactNode;
|
|
100
|
+
/** Controls which rows can be expanded. Every row is expandable by default. */
|
|
101
|
+
isRowExpandable?: (row: Row, rowIndex: number) => boolean;
|
|
102
|
+
/** Controlled list of expanded row keys. */
|
|
103
|
+
expandedRowKeys?: readonly string[];
|
|
104
|
+
/** Initially expanded row keys for uncontrolled usage. */
|
|
105
|
+
defaultExpandedRowKeys?: readonly string[];
|
|
106
|
+
/** Called when a row expansion toggle changes the expanded key list. */
|
|
107
|
+
onExpandedRowKeysChange?: (expandedRowKeys: string[]) => void;
|
|
108
|
+
/** Accessible label for a row's expansion toggle. */
|
|
109
|
+
getToggleLabel?: (row: Row, rowIndex: number, expanded: boolean) => string;
|
|
110
|
+
}
|
|
97
111
|
interface SortableTableHeadProps<T extends string> {
|
|
98
112
|
field: T;
|
|
99
113
|
children: React.ReactNode;
|
|
@@ -159,8 +173,10 @@ export interface TableProps<Row> extends Omit<React.HTMLAttributes<HTMLDivElemen
|
|
|
159
173
|
emptyStateMinHeight?: React.CSSProperties["minHeight"];
|
|
160
174
|
/** When true, applies alternating row backgrounds for easier scanning. */
|
|
161
175
|
striped?: boolean;
|
|
176
|
+
/** Adds a disclosure column and full-width expandable content for nested tables or row details. */
|
|
177
|
+
rowExpansion?: TableRowExpansionProps<Row>;
|
|
162
178
|
/** When set, rows become interactive: cursor-pointer, hover highlight, and click handling. */
|
|
163
179
|
onRowClick?: (row: Row, index: number) => void;
|
|
164
180
|
}
|
|
165
|
-
declare function Table<Row>({ columns, rows, getRowKey, emptyState, toolbar, caption, className, containerClassName, tableClassName, rowClassName, rowTone, maxHeight, minHeight, sorting, pagination, loading, loadingRows, visibleColumnKeys, resizableColumns, columnResizeMode, columnWidths, defaultColumnWidths, onColumnWidthsChange, renderColumnResizeHandle, tableLayout, centerEmptyState, emptyStateMinHeight, striped, onRowClick, onScroll, style, ...props }: TableProps<Row>): import("react/jsx-runtime").JSX.Element;
|
|
181
|
+
declare function Table<Row>({ columns, rows, getRowKey, emptyState, toolbar, caption, className, containerClassName, tableClassName, rowClassName, rowTone, maxHeight, minHeight, sorting, pagination, loading, loadingRows, visibleColumnKeys, resizableColumns, columnResizeMode, columnWidths, defaultColumnWidths, onColumnWidthsChange, renderColumnResizeHandle, tableLayout, centerEmptyState, emptyStateMinHeight, striped, rowExpansion, onRowClick, onScroll, style, ...props }: TableProps<Row>): import("react/jsx-runtime").JSX.Element;
|
|
166
182
|
export { Table, TableRoot, TableContainer, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, SortableTableHead, TableRowSkeleton, };
|
package/dist/table.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { ArrowUpDown } from "lucide-react";
|
|
3
|
+
import { ArrowUpDown, ChevronRight } from "lucide-react";
|
|
4
4
|
import { ArrowDownIcon } from "./animated-icons/arrow-down";
|
|
5
5
|
import { ArrowUpIcon } from "./animated-icons/arrow-up";
|
|
6
6
|
import { EmptyState } from "./empty-state";
|
|
@@ -14,6 +14,7 @@ TableContainer.displayName = "TableContainer";
|
|
|
14
14
|
const DEFAULT_COLUMN_RESIZE_MIN_WIDTH = 64;
|
|
15
15
|
const DEFAULT_COLUMN_RESIZE_START_WIDTH = 160;
|
|
16
16
|
const COLUMN_RESIZE_KEYBOARD_STEP = 16;
|
|
17
|
+
const TABLE_EXPANSION_COLUMN_WIDTH = 48;
|
|
17
18
|
const TABLE_MIN_WIDTH_CSS_VAR = "--table-min-width";
|
|
18
19
|
const DEFAULT_TABLE_MIN_HEIGHT = "var(--table-min-height, var(--app-table-min-height, 24rem))";
|
|
19
20
|
const DEFAULT_CENTERED_EMPTY_STATE_MIN_HEIGHT = "calc(var(--table-min-height, var(--app-table-min-height, 24rem)) - var(--table-empty-state-offset, var(--app-table-empty-state-offset, 5.75rem)))";
|
|
@@ -109,7 +110,7 @@ function hasColumnWidthOverrides(columnWidths) {
|
|
|
109
110
|
}
|
|
110
111
|
function getMeasuredColumnWidths(resizeHandle, columns, fallbackColumnWidths) {
|
|
111
112
|
const table = resizeHandle.closest("table");
|
|
112
|
-
const headerCells = table === null || table === void 0 ? void 0 : table.querySelectorAll(
|
|
113
|
+
const headerCells = table === null || table === void 0 ? void 0 : table.querySelectorAll('thead th:not([data-slot="table-expansion-head"])');
|
|
113
114
|
if (!(headerCells === null || headerCells === void 0 ? void 0 : headerCells.length)) {
|
|
114
115
|
return fallbackColumnWidths;
|
|
115
116
|
}
|
|
@@ -327,8 +328,9 @@ function getVisibleColumns(columns, visibleColumnKeys) {
|
|
|
327
328
|
function isStickyResizeBoundary(column, nextColumn) {
|
|
328
329
|
return Boolean(column.sticky === "right" || nextColumn.sticky);
|
|
329
330
|
}
|
|
330
|
-
function Table({ columns, rows, getRowKey, emptyState = (_jsx(EmptyState, { message: "No data available", description: "There are no rows to display in this table yet.", className: "border-0 bg-transparent px-0 py-6" })), toolbar, caption, className, containerClassName, tableClassName, rowClassName, rowTone, maxHeight, minHeight, sorting, pagination, loading = false, loadingRows = 5, visibleColumnKeys, resizableColumns = false, columnResizeMode = "pair", columnWidths, defaultColumnWidths, onColumnWidthsChange, renderColumnResizeHandle, tableLayout, centerEmptyState = false, emptyStateMinHeight = DEFAULT_CENTERED_EMPTY_STATE_MIN_HEIGHT, striped = false, onRowClick, onScroll, style, ...props }) {
|
|
331
|
+
function Table({ columns, rows, getRowKey, emptyState = (_jsx(EmptyState, { message: "No data available", description: "There are no rows to display in this table yet.", className: "border-0 bg-transparent px-0 py-6" })), toolbar, caption, className, containerClassName, tableClassName, rowClassName, rowTone, maxHeight, minHeight, sorting, pagination, loading = false, loadingRows = 5, visibleColumnKeys, resizableColumns = false, columnResizeMode = "pair", columnWidths, defaultColumnWidths, onColumnWidthsChange, renderColumnResizeHandle, tableLayout, centerEmptyState = false, emptyStateMinHeight = DEFAULT_CENTERED_EMPTY_STATE_MIN_HEIGHT, striped = false, rowExpansion, onRowClick, onScroll, style, ...props }) {
|
|
331
332
|
const visibleColumns = getVisibleColumns(columns, visibleColumnKeys);
|
|
333
|
+
const hasExpansionColumn = Boolean(rowExpansion);
|
|
332
334
|
const isGrowResizeMode = columnResizeMode === "grow";
|
|
333
335
|
const isColumnResizingEnabled = resizableColumns || visibleColumns.some((column) => column.resizable);
|
|
334
336
|
// Use auto layout by default so the browser can grow a column to contain its
|
|
@@ -339,7 +341,8 @@ function Table({ columns, rows, getRowKey, emptyState = (_jsx(EmptyState, { mess
|
|
|
339
341
|
const resolvedColumnWidths = columnWidths !== null && columnWidths !== void 0 ? columnWidths : uncontrolledColumnWidths;
|
|
340
342
|
const hasResolvedColumnWidths = hasColumnWidthOverrides(resolvedColumnWidths);
|
|
341
343
|
const growTableMinWidth = isGrowResizeMode
|
|
342
|
-
? getTableMinWidth(visibleColumns, resolvedColumnWidths)
|
|
344
|
+
? getTableMinWidth(visibleColumns, resolvedColumnWidths) +
|
|
345
|
+
(hasExpansionColumn ? TABLE_EXPANSION_COLUMN_WIDTH : 0)
|
|
343
346
|
: undefined;
|
|
344
347
|
const resolvedMinHeight = minHeight !== null && minHeight !== void 0 ? minHeight : (centerEmptyState ? DEFAULT_TABLE_MIN_HEIGHT : undefined);
|
|
345
348
|
const columnWidthsRef = React.useRef(resolvedColumnWidths);
|
|
@@ -349,6 +352,10 @@ function Table({ columns, rows, getRowKey, emptyState = (_jsx(EmptyState, { mess
|
|
|
349
352
|
left: false,
|
|
350
353
|
right: false,
|
|
351
354
|
});
|
|
355
|
+
const [uncontrolledExpandedRowKeys, setUncontrolledExpandedRowKeys] = React.useState(() => { var _a; return new Set((_a = rowExpansion === null || rowExpansion === void 0 ? void 0 : rowExpansion.defaultExpandedRowKeys) !== null && _a !== void 0 ? _a : []); });
|
|
356
|
+
const controlledExpandedRowKeys = rowExpansion === null || rowExpansion === void 0 ? void 0 : rowExpansion.expandedRowKeys;
|
|
357
|
+
const resolvedExpandedRowKeys = new Set(controlledExpandedRowKeys !== null && controlledExpandedRowKeys !== void 0 ? controlledExpandedRowKeys : uncontrolledExpandedRowKeys);
|
|
358
|
+
const expansionIdPrefix = React.useId().replace(/:/g, "");
|
|
352
359
|
const updateStickyScrollState = React.useCallback((element = tableContainerRef.current) => {
|
|
353
360
|
if (!element) {
|
|
354
361
|
return;
|
|
@@ -516,6 +523,20 @@ function Table({ columns, rows, getRowKey, emptyState = (_jsx(EmptyState, { mess
|
|
|
516
523
|
onScroll === null || onScroll === void 0 ? void 0 : onScroll(event);
|
|
517
524
|
updateStickyScrollState(event.currentTarget);
|
|
518
525
|
}, [onScroll, updateStickyScrollState]);
|
|
526
|
+
const toggleExpandedRow = React.useCallback((rowKey) => {
|
|
527
|
+
var _a;
|
|
528
|
+
const nextExpandedRowKeys = new Set(controlledExpandedRowKeys !== null && controlledExpandedRowKeys !== void 0 ? controlledExpandedRowKeys : uncontrolledExpandedRowKeys);
|
|
529
|
+
if (nextExpandedRowKeys.has(rowKey)) {
|
|
530
|
+
nextExpandedRowKeys.delete(rowKey);
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
nextExpandedRowKeys.add(rowKey);
|
|
534
|
+
}
|
|
535
|
+
if (controlledExpandedRowKeys === undefined) {
|
|
536
|
+
setUncontrolledExpandedRowKeys(nextExpandedRowKeys);
|
|
537
|
+
}
|
|
538
|
+
(_a = rowExpansion === null || rowExpansion === void 0 ? void 0 : rowExpansion.onExpandedRowKeysChange) === null || _a === void 0 ? void 0 : _a.call(rowExpansion, Array.from(nextExpandedRowKeys));
|
|
539
|
+
}, [controlledExpandedRowKeys, rowExpansion, uncontrolledExpandedRowKeys]);
|
|
519
540
|
const resolvedEmptyState = centerEmptyState ? (_jsx("div", { "data-slot": "table-empty-state", className: "flex w-full min-w-0 items-center justify-center whitespace-normal text-center [&>*]:mx-auto", style: { minHeight: emptyStateMinHeight }, children: emptyState })) : (emptyState);
|
|
520
541
|
const container = (_jsx(TableContainer, { ref: tableContainerRef, onScroll: handleTableContainerScroll, className: cn("w-full", loading && "pointer-events-none select-none", className, containerClassName), style: {
|
|
521
542
|
...style,
|
|
@@ -527,49 +548,69 @@ function Table({ columns, rows, getRowKey, emptyState = (_jsx(EmptyState, { mess
|
|
|
527
548
|
}, ...props, children: _jsxs(TableRoot, { className: cn(shouldUseFixedLayout && "table-fixed", isGrowResizeMode &&
|
|
528
549
|
(hasResolvedColumnWidths
|
|
529
550
|
? "w-[var(--table-min-width)]"
|
|
530
|
-
: "min-w-[var(--table-min-width)]"), tableClassName), children: [caption ? _jsx(TableCaption, { children: caption }) : null,
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
});
|
|
548
|
-
const resizeHandle = renderResizeHandle(column, columnIndex);
|
|
549
|
-
return (isSortable ? (_jsx(SortableTableHead, { field: sortField, currentSortField: sorting.field, currentSortDirection: sorting.direction, onSort: sorting.onSort, className: cn(stickyClassName(column.sticky, "head", getStickyShadowVisibility(column.sticky, stickyScrollState)), column.headerClassName), allowWrap: column.wrap, width: columnWidth, minWidth: getRenderedColumnMinWidth(column, isColumnResizingEnabled), maxWidth: getRenderedColumnMaxWidth(column, isColumnResizingEnabled), align: column.align, sortLabel: column.sortLabel, resizeHandle: resizeHandle, treatWidthAsMinWidth: !isColumnResizingEnabled, containOverflow: isColumnResizingEnabled, children: column.header }, column.key)) : (_jsxs(TableHead, { width: columnWidth, minWidth: getRenderedColumnMinWidth(column, isColumnResizingEnabled), maxWidth: getRenderedColumnMaxWidth(column, isColumnResizingEnabled), wrap: column.wrap, treatWidthAsMinWidth: !isColumnResizingEnabled, containOverflow: isColumnResizingEnabled, className: cn(resizeHandle && "relative", alignClassName(column.align), stickyClassName(column.sticky, "head", getStickyShadowVisibility(column.sticky, stickyScrollState)), column.headerClassName), children: [column.header, resizeHandle] }, column.key)));
|
|
550
|
-
}) }) }), _jsx(TableBody, { children: loading ? (_jsx(TableRowSkeleton, { rows: loadingRows, columns: visibleColumns.map((column) => { var _a; return (_a = column.skeleton) !== null && _a !== void 0 ? _a : getDefaultSkeleton(column); }) })) : rows.length ? (rows.map((row, rowIndex) => {
|
|
551
|
-
const resolvedTone = typeof rowTone === "function"
|
|
552
|
-
? rowTone(row, rowIndex)
|
|
553
|
-
: rowTone;
|
|
554
|
-
return (_jsx(TableRow, { onClick: onRowClick ? () => onRowClick(row, rowIndex) : undefined, className: cn(onRowClick &&
|
|
555
|
-
"cursor-pointer hover:bg-muted", striped &&
|
|
556
|
-
rowIndex % 2 === 1 &&
|
|
557
|
-
!resolvedTone &&
|
|
558
|
-
"bg-[hsl(var(--table-row-striped-background))]", tableRowToneClassName(resolvedTone), typeof rowClassName === "function"
|
|
559
|
-
? rowClassName(row, rowIndex)
|
|
560
|
-
: rowClassName), children: visibleColumns.map((column) => {
|
|
561
|
-
var _a, _b;
|
|
551
|
+
: "min-w-[var(--table-min-width)]"), tableClassName), children: [caption ? _jsx(TableCaption, { children: caption }) : null, _jsxs("colgroup", { children: [hasExpansionColumn ? (_jsx("col", { style: {
|
|
552
|
+
width: `${TABLE_EXPANSION_COLUMN_WIDTH}px`,
|
|
553
|
+
minWidth: `${TABLE_EXPANSION_COLUMN_WIDTH}px`,
|
|
554
|
+
maxWidth: `${TABLE_EXPANSION_COLUMN_WIDTH}px`,
|
|
555
|
+
} })) : null, visibleColumns.map((column) => (_jsx("col", { style: getTableColumnSizingStyle({
|
|
556
|
+
width: getRenderedColumnWidth({
|
|
557
|
+
column,
|
|
558
|
+
columnWidths: resolvedColumnWidths,
|
|
559
|
+
resizing: isColumnResizingEnabled,
|
|
560
|
+
}),
|
|
561
|
+
minWidth: getRenderedColumnMinWidth(column, isColumnResizingEnabled),
|
|
562
|
+
maxWidth: getRenderedColumnMaxWidth(column, isColumnResizingEnabled),
|
|
563
|
+
treatWidthAsMinWidth: !isColumnResizingEnabled,
|
|
564
|
+
}) }, column.key)))] }), _jsx(TableHeader, { children: _jsxs(TableRow, { children: [hasExpansionColumn ? (_jsx(TableHead, { "data-slot": "table-expansion-head", "aria-label": "Expand rows", className: "w-12 px-2" })) : null, visibleColumns.map((column, columnIndex) => {
|
|
565
|
+
var _a;
|
|
566
|
+
const sortField = (_a = column.sortKey) !== null && _a !== void 0 ? _a : column.key;
|
|
567
|
+
const isSortable = column.sortable && sorting;
|
|
562
568
|
const columnWidth = getRenderedColumnWidth({
|
|
563
569
|
column,
|
|
564
570
|
columnWidths: resolvedColumnWidths,
|
|
565
571
|
resizing: isColumnResizingEnabled,
|
|
566
572
|
});
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
+
const resizeHandle = renderResizeHandle(column, columnIndex);
|
|
574
|
+
return (isSortable ? (_jsx(SortableTableHead, { field: sortField, currentSortField: sorting.field, currentSortDirection: sorting.direction, onSort: sorting.onSort, className: cn(stickyClassName(column.sticky, "head", getStickyShadowVisibility(column.sticky, stickyScrollState)), column.headerClassName), allowWrap: column.wrap, width: columnWidth, minWidth: getRenderedColumnMinWidth(column, isColumnResizingEnabled), maxWidth: getRenderedColumnMaxWidth(column, isColumnResizingEnabled), align: column.align, sortLabel: column.sortLabel, resizeHandle: resizeHandle, treatWidthAsMinWidth: !isColumnResizingEnabled, containOverflow: isColumnResizingEnabled, children: column.header }, column.key)) : (_jsxs(TableHead, { width: columnWidth, minWidth: getRenderedColumnMinWidth(column, isColumnResizingEnabled), maxWidth: getRenderedColumnMaxWidth(column, isColumnResizingEnabled), wrap: column.wrap, treatWidthAsMinWidth: !isColumnResizingEnabled, containOverflow: isColumnResizingEnabled, className: cn(resizeHandle && "relative", alignClassName(column.align), stickyClassName(column.sticky, "head", getStickyShadowVisibility(column.sticky, stickyScrollState)), column.headerClassName), children: [column.header, resizeHandle] }, column.key)));
|
|
575
|
+
})] }) }), _jsx(TableBody, { children: loading ? (_jsx(TableRowSkeleton, { rows: loadingRows, columns: [
|
|
576
|
+
...(hasExpansionColumn
|
|
577
|
+
? [{ width: "1rem", height: "1rem" }]
|
|
578
|
+
: []),
|
|
579
|
+
...visibleColumns.map((column) => {
|
|
580
|
+
var _a;
|
|
581
|
+
return (_a = column.skeleton) !== null && _a !== void 0 ? _a : getDefaultSkeleton(column);
|
|
582
|
+
}),
|
|
583
|
+
] })) : rows.length ? (rows.map((row, rowIndex) => {
|
|
584
|
+
var _a, _b, _c, _d;
|
|
585
|
+
const rowKey = getRowKey(row, rowIndex);
|
|
586
|
+
const resolvedTone = typeof rowTone === "function"
|
|
587
|
+
? rowTone(row, rowIndex)
|
|
588
|
+
: rowTone;
|
|
589
|
+
const isRowExpandable = (_b = (_a = rowExpansion === null || rowExpansion === void 0 ? void 0 : rowExpansion.isRowExpandable) === null || _a === void 0 ? void 0 : _a.call(rowExpansion, row, rowIndex)) !== null && _b !== void 0 ? _b : hasExpansionColumn;
|
|
590
|
+
const isExpanded = isRowExpandable && resolvedExpandedRowKeys.has(rowKey);
|
|
591
|
+
const expandedContentId = `${expansionIdPrefix}-expanded-row-${rowIndex}`;
|
|
592
|
+
return (_jsxs(React.Fragment, { children: [_jsxs(TableRow, { "data-expanded": isExpanded ? "true" : undefined, onClick: onRowClick ? () => onRowClick(row, rowIndex) : undefined, className: cn(onRowClick && "cursor-pointer hover:bg-muted", striped &&
|
|
593
|
+
rowIndex % 2 === 1 &&
|
|
594
|
+
!resolvedTone &&
|
|
595
|
+
"bg-[hsl(var(--table-row-striped-background))]", tableRowToneClassName(resolvedTone), typeof rowClassName === "function"
|
|
596
|
+
? rowClassName(row, rowIndex)
|
|
597
|
+
: rowClassName), children: [hasExpansionColumn ? (_jsx(TableCell, { className: "w-12 px-2 text-center", children: isRowExpandable ? (_jsx("button", { type: "button", "aria-expanded": isExpanded, "aria-controls": expandedContentId, "aria-label": (_d = (_c = rowExpansion === null || rowExpansion === void 0 ? void 0 : rowExpansion.getToggleLabel) === null || _c === void 0 ? void 0 : _c.call(rowExpansion, row, rowIndex, isExpanded)) !== null && _d !== void 0 ? _d : `${isExpanded ? "Collapse" : "Expand"} row ${rowIndex + 1}`, onClick: (event) => {
|
|
598
|
+
event.stopPropagation();
|
|
599
|
+
toggleExpandedRow(rowKey);
|
|
600
|
+
}, className: "inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", children: _jsx(ChevronRight, { "aria-hidden": "true", className: cn("h-4 w-4 transition-transform duration-150", isExpanded && "rotate-90") }) })) : null })) : null, visibleColumns.map((column) => {
|
|
601
|
+
var _a, _b;
|
|
602
|
+
const columnWidth = getRenderedColumnWidth({
|
|
603
|
+
column,
|
|
604
|
+
columnWidths: resolvedColumnWidths,
|
|
605
|
+
resizing: isColumnResizingEnabled,
|
|
606
|
+
});
|
|
607
|
+
const value = (_b = (_a = column.cell) === null || _a === void 0 ? void 0 : _a.call(column, row, rowIndex)) !== null && _b !== void 0 ? _b : (column.accessorKey !== undefined
|
|
608
|
+
? row[column.accessorKey]
|
|
609
|
+
: null);
|
|
610
|
+
return (_jsx(TableCell, { width: columnWidth, minWidth: getRenderedColumnMinWidth(column, isColumnResizingEnabled), maxWidth: getRenderedColumnMaxWidth(column, isColumnResizingEnabled), wrap: column.wrap, treatWidthAsMinWidth: !isColumnResizingEnabled, containOverflow: isColumnResizingEnabled, className: cn(alignClassName(column.align), stickyClassName(column.sticky, "cell", getStickyShadowVisibility(column.sticky, stickyScrollState)), column.cellClassName), children: value }, column.key));
|
|
611
|
+
})] }), isExpanded ? (_jsx(TableRow, { id: expandedContentId, "data-slot": "table-expanded-row", className: "bg-[hsl(var(--table-row-striped-background))] hover:bg-[hsl(var(--table-row-striped-background))]", children: _jsx(TableCell, { colSpan: Math.max(visibleColumns.length +
|
|
612
|
+
(hasExpansionColumn ? 1 : 0), 1), className: "h-auto whitespace-normal p-4", children: rowExpansion === null || rowExpansion === void 0 ? void 0 : rowExpansion.renderExpandedContent(row, rowIndex) }) })) : null] }, rowKey));
|
|
613
|
+
})) : (_jsx(TableRow, { className: "cursor-default hover:bg-card", children: _jsx(TableCell, { colSpan: Math.max(visibleColumns.length + (hasExpansionColumn ? 1 : 0), 1), className: "p-6", children: resolvedEmptyState }) })) })] }) }));
|
|
573
614
|
if (!pagination) {
|
|
574
615
|
return (_jsxs("div", { className: "space-y-4", children: [toolbar, container] }));
|
|
575
616
|
}
|