@brotskyllc/react-data-table 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -2
  3. package/THIRD_PARTY_NOTICES.md +27 -0
  4. package/dist/ColumnResizeHandle.d.ts +9 -0
  5. package/dist/ColumnResizeHandle.js +49 -0
  6. package/dist/DataTableDraggableRows.d.ts +21 -0
  7. package/dist/DataTableDraggableRows.js +29 -0
  8. package/dist/DataTableRows.d.ts +22 -0
  9. package/dist/DataTableRows.js +62 -0
  10. package/dist/DataTableSkeletonRows.d.ts +8 -0
  11. package/dist/DataTableSkeletonRows.js +9 -0
  12. package/dist/DataTableTableContent.d.ts +28 -0
  13. package/dist/DataTableTableContent.js +46 -0
  14. package/dist/TableCell.d.ts +7 -0
  15. package/dist/TableCell.js +20 -0
  16. package/dist/TableHeader.d.ts +16 -0
  17. package/dist/TableHeader.js +42 -0
  18. package/dist/TableRow.d.ts +26 -0
  19. package/dist/TableRow.js +31 -0
  20. package/dist/cn.d.ts +2 -0
  21. package/dist/cn.js +3 -0
  22. package/dist/columnResizeTypes.d.ts +18 -0
  23. package/dist/columnResizeTypes.js +1 -0
  24. package/dist/columnTypes.d.ts +25 -0
  25. package/dist/columnTypes.js +1 -0
  26. package/dist/columnWidthStorage.d.ts +13 -0
  27. package/dist/columnWidthStorage.js +53 -0
  28. package/dist/compat.d.ts +17 -0
  29. package/dist/compat.js +19 -0
  30. package/dist/getColumnWidthStyle.d.ts +1 -0
  31. package/dist/getColumnWidthStyle.js +7 -0
  32. package/dist/getTableHeaderFlexClassName.d.ts +2 -0
  33. package/dist/getTableHeaderFlexClassName.js +6 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.js +4 -0
  36. package/dist/isRowClickSelectTarget.d.ts +1 -0
  37. package/dist/isRowClickSelectTarget.js +34 -0
  38. package/dist/rowIds.d.ts +2 -0
  39. package/dist/rowIds.js +2 -0
  40. package/dist/rowPickerOpenState.d.ts +11 -0
  41. package/dist/rowPickerOpenState.js +41 -0
  42. package/dist/selectionTypes.d.ts +10 -0
  43. package/dist/selectionTypes.js +1 -0
  44. package/dist/sortOrder.d.ts +5 -0
  45. package/dist/sortOrder.js +1 -0
  46. package/dist/sortRowsByColumn.d.ts +9 -0
  47. package/dist/sortRowsByColumn.js +40 -0
  48. package/dist/stripImportantWidthClasses.d.ts +1 -0
  49. package/dist/stripImportantWidthClasses.js +9 -0
  50. package/dist/types.d.ts +47 -0
  51. package/dist/types.js +1 -0
  52. package/dist/ui/skeleton.d.ts +2 -0
  53. package/dist/ui/skeleton.js +6 -0
  54. package/dist/ui/table-scroll-region.d.ts +11 -0
  55. package/dist/ui/table-scroll-region.js +30 -0
  56. package/dist/ui/table.d.ts +51 -0
  57. package/dist/ui/table.js +20 -0
  58. package/dist/ui/tableScrollRegion.d.ts +15 -0
  59. package/dist/ui/tableScrollRegion.js +10 -0
  60. package/dist/ui/tooltip.d.ts +12 -0
  61. package/dist/ui/tooltip.js +10 -0
  62. package/dist/utils.d.ts +1 -0
  63. package/dist/utils.js +5 -0
  64. package/package.json +65 -4
  65. package/src/ColumnResizeHandle.tsx +102 -0
  66. package/src/DataTableDraggableRows.tsx +132 -0
  67. package/src/DataTableRows.tsx +239 -0
  68. package/src/DataTableSkeletonRows.tsx +46 -0
  69. package/src/DataTableTableContent.tsx +160 -0
  70. package/src/TableCell.tsx +39 -0
  71. package/src/TableHeader.tsx +205 -0
  72. package/src/TableRow.tsx +151 -0
  73. package/src/cn.ts +3 -0
  74. package/src/columnResizeTypes.ts +26 -0
  75. package/src/columnTypes.ts +39 -0
  76. package/src/columnWidthStorage.ts +94 -0
  77. package/src/compat.ts +19 -0
  78. package/src/getColumnWidthStyle.ts +11 -0
  79. package/src/getTableHeaderFlexClassName.ts +14 -0
  80. package/src/index.ts +13 -0
  81. package/src/isRowClickSelectTarget.ts +39 -0
  82. package/src/rowIds.ts +11 -0
  83. package/src/rowPickerOpenState.tsx +98 -0
  84. package/src/selectionTypes.ts +16 -0
  85. package/src/sortOrder.ts +2 -0
  86. package/src/sortRowsByColumn.ts +72 -0
  87. package/src/stripImportantWidthClasses.ts +16 -0
  88. package/src/types.ts +51 -0
  89. package/src/ui/skeleton.tsx +15 -0
  90. package/src/ui/table-scroll-region.tsx +68 -0
  91. package/src/ui/table.tsx +147 -0
  92. package/src/ui/tableScrollRegion.ts +33 -0
  93. package/src/ui/tooltip.tsx +36 -0
  94. package/src/utils.ts +5 -0
@@ -0,0 +1,25 @@
1
+ export type NestedKeyOf<T> = T extends object ? {
2
+ [K in keyof T]: K extends string ? T[K] extends object ? K | `${K}.${NestedKeyOf<T[K]>}` : K : never;
3
+ }[keyof T] : never;
4
+ export type ExportCellValue = string | number | boolean | null | undefined;
5
+ export type SortCellValue = string | number | boolean | null | undefined;
6
+ export interface TableColumn<T> {
7
+ key: NestedKeyOf<T> | string;
8
+ header: string;
9
+ headerTooltip?: string;
10
+ /** Dynamic nested cell values preserve the host column renderer contract. */
11
+ render?: (value: any, row: T) => React.ReactNode;
12
+ sortable?: boolean;
13
+ sortValue?: (row: T) => SortCellValue;
14
+ width?: string | number;
15
+ resizable?: boolean;
16
+ className?: string;
17
+ /** Additional header-only classes (for sticky headers or theme overrides). */
18
+ headerClassName?: string;
19
+ /** Accessible sort-button name; defaults to the visible header. */
20
+ sortAriaLabel?: string;
21
+ skeletonClassName?: string;
22
+ /** Metadata consumed by host exporters; this package never exports data. */
23
+ exportValue?: (value: any, row: T) => ExportCellValue;
24
+ excludeFromExport?: boolean;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ export declare const COLUMN_WIDTH_STORAGE_KEY_PREFIX = "datatable-column-widths:v1";
2
+ export declare const MIN_COLUMN_WIDTH_PX = 64;
3
+ export declare const MAX_COLUMN_WIDTH_PX = 960;
4
+ export declare const DEFAULT_COLUMN_WIDTH_PX = 160;
5
+ export declare const UTILITY_COLUMN_WIDTH_PX = 64;
6
+ export type PersistedColumnWidths = Record<string, number>;
7
+ export declare const createColumnWidths: () => PersistedColumnWidths;
8
+ export declare const buildColumnWidthStorageKey: (tableId: string) => string;
9
+ export declare const clampColumnWidth: (width: number) => number;
10
+ export declare const clampColumnWidthAround: (width: number, baselineWidth: number) => number;
11
+ export declare const resizeColumnWidth: (startWidth: number, deltaX: number) => number;
12
+ export declare const parsePersistedColumnWidths: (rawValue: string | null) => PersistedColumnWidths | null;
13
+ export declare const readColumnWidth: (widths: PersistedColumnWidths, columnKey: string) => number | undefined;
@@ -0,0 +1,53 @@
1
+ export const COLUMN_WIDTH_STORAGE_KEY_PREFIX = "datatable-column-widths:v1";
2
+ export const MIN_COLUMN_WIDTH_PX = 64;
3
+ export const MAX_COLUMN_WIDTH_PX = 960;
4
+ export const DEFAULT_COLUMN_WIDTH_PX = 160;
5
+ export const UTILITY_COLUMN_WIDTH_PX = 64;
6
+ export const createColumnWidths = () => Object.create(null);
7
+ export const buildColumnWidthStorageKey = (tableId) => `${COLUMN_WIDTH_STORAGE_KEY_PREFIX}:${tableId}`;
8
+ export const clampColumnWidth = (width) => {
9
+ if (!Number.isFinite(width)) {
10
+ return MIN_COLUMN_WIDTH_PX;
11
+ }
12
+ return Math.min(MAX_COLUMN_WIDTH_PX, Math.max(MIN_COLUMN_WIDTH_PX, Math.round(width)));
13
+ };
14
+ export const clampColumnWidthAround = (width, baselineWidth) => {
15
+ if (!(Number.isFinite(baselineWidth) && Number.isFinite(width))) {
16
+ return clampColumnWidth(width);
17
+ }
18
+ const baseline = Math.round(baselineWidth);
19
+ return Math.min(Math.max(MAX_COLUMN_WIDTH_PX, baseline), Math.max(Math.min(MIN_COLUMN_WIDTH_PX, baseline), Math.round(width)));
20
+ };
21
+ export const resizeColumnWidth = (startWidth, deltaX) => clampColumnWidthAround(startWidth + deltaX, startWidth);
22
+ export const parsePersistedColumnWidths = (rawValue) => {
23
+ if (rawValue === null) {
24
+ return null;
25
+ }
26
+ let parsed;
27
+ try {
28
+ parsed = JSON.parse(rawValue);
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
34
+ return null;
35
+ }
36
+ const widths = createColumnWidths();
37
+ for (const [columnKey, width] of Object.entries(parsed)) {
38
+ if (typeof width !== "number" || !Number.isFinite(width) || width <= 0) {
39
+ continue;
40
+ }
41
+ widths[columnKey] = Math.round(width);
42
+ }
43
+ return widths;
44
+ };
45
+ export const readColumnWidth = (widths, columnKey) => {
46
+ if (!Object.hasOwn(widths, columnKey)) {
47
+ return undefined;
48
+ }
49
+ const width = widths[columnKey];
50
+ return typeof width === "number" && Number.isFinite(width)
51
+ ? width
52
+ : undefined;
53
+ };
@@ -0,0 +1,17 @@
1
+ export * from "./DataTableRows.js";
2
+ export * from "./DataTableDraggableRows.js";
3
+ export * from "./DataTableSkeletonRows.js";
4
+ export * from "./TableHeader.js";
5
+ export * from "./TableRow.js";
6
+ export * from "./TableCell.js";
7
+ export * from "./ColumnResizeHandle.js";
8
+ export * from "./rowIds.js";
9
+ export * from "./isRowClickSelectTarget.js";
10
+ export * from "./stripImportantWidthClasses.js";
11
+ export * from "./getColumnWidthStyle.js";
12
+ export * from "./getTableHeaderFlexClassName.js";
13
+ export * from "./columnWidthStorage.js";
14
+ export * from "./columnTypes.js";
15
+ export * from "./selectionTypes.js";
16
+ export * from "./sortRowsByColumn.js";
17
+ export * from "./utils.js";
package/dist/compat.js ADDED
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ // Compatibility exports for apps migrating existing table modules.
3
+ export * from "./DataTableRows.js";
4
+ export * from "./DataTableDraggableRows.js";
5
+ export * from "./DataTableSkeletonRows.js";
6
+ export * from "./TableHeader.js";
7
+ export * from "./TableRow.js";
8
+ export * from "./TableCell.js";
9
+ export * from "./ColumnResizeHandle.js";
10
+ export * from "./rowIds.js";
11
+ export * from "./isRowClickSelectTarget.js";
12
+ export * from "./stripImportantWidthClasses.js";
13
+ export * from "./getColumnWidthStyle.js";
14
+ export * from "./getTableHeaderFlexClassName.js";
15
+ export * from "./columnWidthStorage.js";
16
+ export * from "./columnTypes.js";
17
+ export * from "./selectionTypes.js";
18
+ export * from "./sortRowsByColumn.js";
19
+ export * from "./utils.js";
@@ -0,0 +1 @@
1
+ export declare const getColumnWidthStyle: (width: string | number | undefined) => React.CSSProperties | undefined;
@@ -0,0 +1,7 @@
1
+ export const getColumnWidthStyle = (width) => {
2
+ if (width === undefined) {
3
+ return undefined;
4
+ }
5
+ const cssWidth = typeof width === "number" ? `${width}px` : width;
6
+ return { width: cssWidth, minWidth: cssWidth, maxWidth: cssWidth };
7
+ };
@@ -0,0 +1,2 @@
1
+ export declare const isTableColumnRightAligned: (columnClassName?: string) => boolean;
2
+ export declare const getTableHeaderFlexClassName: (columnClassName?: string) => string;
@@ -0,0 +1,6 @@
1
+ import { cn } from "./cn.js";
2
+ export const isTableColumnRightAligned = (columnClassName) => (columnClassName?.split(/\s+/) ?? []).includes("text-right");
3
+ export const getTableHeaderFlexClassName = (columnClassName) => {
4
+ const classes = columnClassName?.split(/\s+/) ?? [];
5
+ return cn("flex items-center gap-1", classes.includes("text-right") && "justify-end", classes.includes("text-center") && "justify-center");
6
+ };
@@ -0,0 +1,6 @@
1
+ export { DataTableTableContent, DataTableTableContent as DataTableCore, } from "./DataTableTableContent.js";
2
+ export type { DataTableTableContentProps, DataTableTableContentProps as DataTableCoreProps, } from "./DataTableTableContent.js";
3
+ export type * from "./types.js";
4
+ export type { ColumnResizeApi } from "./columnResizeTypes.js";
5
+ export * from "./rowPickerOpenState.js";
6
+ export { sortRowsByColumn } from "./sortRowsByColumn.js";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+ export { DataTableTableContent, DataTableTableContent as DataTableCore, } from "./DataTableTableContent.js";
3
+ export * from "./rowPickerOpenState.js";
4
+ export { sortRowsByColumn } from "./sortRowsByColumn.js";
@@ -0,0 +1 @@
1
+ export declare const isRowClickSelectTarget: (target: EventTarget | null) => boolean;
@@ -0,0 +1,34 @@
1
+ const INTERACTIVE_SELECTOR = [
2
+ "a[href]",
3
+ "button",
4
+ "input",
5
+ "select",
6
+ "textarea",
7
+ "label",
8
+ "summary",
9
+ "audio[controls]",
10
+ "video[controls]",
11
+ "[contenteditable='true']",
12
+ "[role='button']",
13
+ "[role='checkbox']",
14
+ "[role='combobox']",
15
+ "[role='link']",
16
+ "[role='menuitem']",
17
+ "[role='option']",
18
+ "[role='radio']",
19
+ "[role='switch']",
20
+ "[role='tab']",
21
+ ].join(",");
22
+ export const isRowClickSelectTarget = (target) => {
23
+ if (!(target instanceof Element)) {
24
+ return false;
25
+ }
26
+ if (target.closest(INTERACTIVE_SELECTOR)) {
27
+ return false;
28
+ }
29
+ const selection = typeof window === "undefined" ? null : window.getSelection?.();
30
+ if (selection && !selection.isCollapsed && selection.toString().length > 0) {
31
+ return false;
32
+ }
33
+ return true;
34
+ };
@@ -0,0 +1,2 @@
1
+ export declare const getRowId: <T>(row: T, index: number) => string;
2
+ export declare const getExpandedContentRowId: (tableInstanceId: string, rowId: string) => string;
package/dist/rowIds.js ADDED
@@ -0,0 +1,2 @@
1
+ export const getRowId = (row, index) => row.id || `row-${index}`;
2
+ export const getExpandedContentRowId = (tableInstanceId, rowId) => `${tableInstanceId}-expanded-content-${rowId}`.replace(/[^a-zA-Z0-9_-]/g, "-");
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from "react";
2
+ export declare const RowPickerOpenStateProvider: ({ children, }: {
3
+ children: ReactNode;
4
+ }) => import("react").JSX.Element;
5
+ export declare const DataTableRowIdProvider: ({ rowId, children, }: {
6
+ rowId: string;
7
+ children: ReactNode;
8
+ }) => import("react").JSX.Element;
9
+ export declare const useDataTableRowPickerOpen: (kind: string, hostRef?: {
10
+ readonly current: HTMLElement | null;
11
+ }) => readonly [boolean, (next: boolean) => void];
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useCallback, useContext, useMemo, useState, } from "react";
4
+ const RowPickerOpenStateContext = createContext(null);
5
+ const DataTableRowIdContext = createContext(null);
6
+ export const RowPickerOpenStateProvider = ({ children, }) => {
7
+ const [openPickerId, setOpenPickerId] = useState(null);
8
+ const setPickerOpen = useCallback((pickerId, open) => {
9
+ setOpenPickerId((current) => {
10
+ if (open) {
11
+ return pickerId;
12
+ }
13
+ return current === pickerId ? null : current;
14
+ });
15
+ }, []);
16
+ const value = useMemo(() => ({ openPickerId, setPickerOpen }), [openPickerId, setPickerOpen]);
17
+ return (_jsx(RowPickerOpenStateContext.Provider, { value: value, children: children }));
18
+ };
19
+ export const DataTableRowIdProvider = ({ rowId, children, }) => (_jsx(DataTableRowIdContext.Provider, { value: rowId, children: children }));
20
+ const isHostDisconnected = (hostRef) => Boolean(hostRef?.current && !hostRef.current.isConnected);
21
+ export const useDataTableRowPickerOpen = (kind, hostRef) => {
22
+ const rowId = useContext(DataTableRowIdContext);
23
+ const tableState = useContext(RowPickerOpenStateContext);
24
+ const [localOpen, setLocalOpen] = useState(false);
25
+ const pickerId = rowId ? `${kind}:${rowId}` : null;
26
+ const persist = pickerId !== null && tableState !== null;
27
+ const open = persist && pickerId && tableState
28
+ ? tableState.openPickerId === pickerId
29
+ : localOpen;
30
+ const setOpen = useCallback((next) => {
31
+ if (persist && pickerId && tableState) {
32
+ if (!next && isHostDisconnected(hostRef)) {
33
+ return;
34
+ }
35
+ tableState.setPickerOpen(pickerId, next);
36
+ return;
37
+ }
38
+ setLocalOpen(next);
39
+ }, [hostRef, persist, pickerId, tableState]);
40
+ return [open, setOpen];
41
+ };
@@ -0,0 +1,10 @@
1
+ export type DataTableSelectionOptions<T> = {
2
+ selectedIds: string[];
3
+ onSelectionChange: (selectedIds: string[]) => void;
4
+ isRowSelectable?: (row: T) => boolean;
5
+ selectOnRowClick?: boolean;
6
+ selectAllAriaLabel?: string;
7
+ selectAllTestId?: string;
8
+ getRowCheckboxAriaLabel?: (row: T) => string;
9
+ getRowCheckboxTestId?: (row: T) => string | undefined;
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare const SortOrder: {
2
+ readonly Asc: "asc";
3
+ readonly Desc: "desc";
4
+ };
5
+ export type SortOrder = (typeof SortOrder)[keyof typeof SortOrder];
@@ -0,0 +1 @@
1
+ export const SortOrder = { Asc: "asc", Desc: "desc" };
@@ -0,0 +1,9 @@
1
+ import { SortOrder } from "./sortOrder.js";
2
+ import type { TableColumn } from "./types.js";
3
+ interface SortRowsByColumnParams<T> {
4
+ rows: T[];
5
+ column: TableColumn<T> | undefined;
6
+ order: SortOrder | null;
7
+ }
8
+ export declare const sortRowsByColumn: <T>({ rows, column, order, }: SortRowsByColumnParams<T>) => T[];
9
+ export {};
@@ -0,0 +1,40 @@
1
+ import { SortOrder } from "./sortOrder.js";
2
+ import { getNestedValue } from "./utils.js";
3
+ const readSortValue = (row, column) => {
4
+ const value = column.sortValue
5
+ ? column.sortValue(row)
6
+ : getNestedValue(row, String(column.key));
7
+ if (typeof value === "boolean")
8
+ return value ? 1 : 0;
9
+ if (typeof value === "string" || typeof value === "number")
10
+ return value;
11
+ return null;
12
+ };
13
+ const isEmptySortValue = (value) => value === null || value === undefined || value === "";
14
+ const compareSortValues = (left, right) => {
15
+ if (typeof left === "number" && typeof right === "number") {
16
+ return left - right;
17
+ }
18
+ return String(left).localeCompare(String(right), undefined, {
19
+ sensitivity: "accent",
20
+ });
21
+ };
22
+ export const sortRowsByColumn = ({ rows, column, order, }) => {
23
+ if (!column?.sortable || !order) {
24
+ return rows;
25
+ }
26
+ const direction = order === SortOrder.Desc ? -1 : 1;
27
+ return [...rows].sort((leftRow, rightRow) => {
28
+ const left = readSortValue(leftRow, column);
29
+ const right = readSortValue(rightRow, column);
30
+ const leftEmpty = isEmptySortValue(left);
31
+ const rightEmpty = isEmptySortValue(right);
32
+ if (leftEmpty || rightEmpty) {
33
+ if (leftEmpty && rightEmpty)
34
+ return 0;
35
+ return leftEmpty ? 1 : -1;
36
+ }
37
+ return (direction *
38
+ compareSortValues(left, right));
39
+ });
40
+ };
@@ -0,0 +1 @@
1
+ export declare const stripImportantWidthClasses: (className: string | undefined) => string | undefined;
@@ -0,0 +1,9 @@
1
+ export const stripImportantWidthClasses = (className) => {
2
+ if (!className) {
3
+ return className;
4
+ }
5
+ const kept = className
6
+ .split(/\s+/)
7
+ .filter((token) => token !== "" && !/^(?:[\w-]+:)*!(?:w|min-w|max-w)-/.test(token));
8
+ return kept.length > 0 ? kept.join(" ") : undefined;
9
+ };
@@ -0,0 +1,47 @@
1
+ import type * as React from "react";
2
+ import type { DropResult } from "@hello-pangea/dnd";
3
+ import type { TableColumn } from "./columnTypes.js";
4
+ import type { DataTableSelectionOptions } from "./selectionTypes.js";
5
+ export type { TableColumn, SortCellValue, ExportCellValue, NestedKeyOf, } from "./columnTypes.js";
6
+ export type { DataTableSelectionOptions } from "./selectionTypes.js";
7
+ export type ExpandableRowsOptions<T> = {
8
+ renderExpandedContent: (row: T) => React.ReactNode;
9
+ isRowExpandable?: (row: T) => boolean;
10
+ expandedRowClassName?: string;
11
+ getToggleAriaLabel?: (row: T, isExpanded: boolean) => string;
12
+ getToggleDataTestId?: (row: T) => string | undefined;
13
+ expandedRowIds?: Set<string>;
14
+ onToggleExpandedRowId?: (rowId: string) => void;
15
+ };
16
+ export interface DataTableProps<T> {
17
+ columns: TableColumn<T>[];
18
+ data: T[];
19
+ sort?: {
20
+ field: string | null;
21
+ order: "asc" | "desc" | null;
22
+ };
23
+ selection?: DataTableSelectionOptions<T>;
24
+ draggable?: {
25
+ enabled: boolean;
26
+ onDragEnd: (result: DropResult) => void;
27
+ dragHandleClassName?: string;
28
+ getRowDragHandleLabel?: (row: T) => string;
29
+ };
30
+ expandableRows?: ExpandableRowsOptions<T>;
31
+ tableClassName?: string;
32
+ scrollAreaLabel?: string;
33
+ rowClassName?: (row: T) => string;
34
+ getRowDataTestId?: (row: T) => string | undefined;
35
+ onRowClick?: (row: T) => void;
36
+ onRowMouseEnter?: (row: T) => void;
37
+ onRowMouseLeave?: () => void;
38
+ footer?: {
39
+ cells: {
40
+ key: string;
41
+ content: React.ReactNode;
42
+ className?: string;
43
+ }[];
44
+ className?: string;
45
+ };
46
+ emptyState?: React.ReactNode;
47
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): import("react").JSX.Element;
2
+ export { Skeleton };
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "../cn.js";
3
+ function Skeleton({ className, ...props }) {
4
+ return (_jsx("div", { className: cn("animate-pulse rounded-md bg-muted", className), ...props }));
5
+ }
6
+ export { Skeleton };
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from "react";
2
+ interface TableScrollRegionProps {
3
+ label?: string;
4
+ className?: string;
5
+ children: ReactNode;
6
+ }
7
+ export declare const TableScrollRegion: {
8
+ ({ label, className, children, }: TableScrollRegionProps): import("react").JSX.Element;
9
+ displayName: string;
10
+ };
11
+ export {};
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { cn } from "../cn.js";
5
+ import { isHorizontallyScrollable, resolveTableScrollRegionAttributes, } from "./tableScrollRegion.js";
6
+ export const TableScrollRegion = ({ label, className, children, }) => {
7
+ const scrollRef = useRef(null);
8
+ const [isScrollable, setIsScrollable] = useState(false);
9
+ useEffect(() => {
10
+ const node = scrollRef.current;
11
+ if (!node) {
12
+ return;
13
+ }
14
+ const measure = () => {
15
+ setIsScrollable(isHorizontallyScrollable(node));
16
+ };
17
+ measure();
18
+ if (typeof ResizeObserver === "undefined") {
19
+ return;
20
+ }
21
+ const observer = new ResizeObserver(measure);
22
+ observer.observe(node);
23
+ for (const child of Array.from(node.children)) {
24
+ observer.observe(child);
25
+ }
26
+ return () => observer.disconnect();
27
+ }, []);
28
+ return (_jsx("div", { ref: scrollRef, className: cn("relative w-full overflow-auto", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset", className), "data-testid": "table-scroll-region", "data-scrollable": isScrollable ? "true" : "false", ...resolveTableScrollRegionAttributes({ label, isScrollable }), children: children }));
29
+ };
30
+ TableScrollRegion.displayName = "TableScrollRegion";
@@ -0,0 +1,51 @@
1
+ import type * as React from "react";
2
+ declare const Table: {
3
+ ({ ref, className, scrollAreaLabel, ...props }: React.HTMLAttributes<HTMLTableElement> & {
4
+ ref?: React.Ref<HTMLTableElement>;
5
+ scrollAreaLabel?: string;
6
+ }): React.JSX.Element;
7
+ displayName: string;
8
+ };
9
+ declare const TableHeader: {
10
+ ({ ref, className, ...props }: React.HTMLAttributes<HTMLTableSectionElement> & {
11
+ ref?: React.Ref<HTMLTableSectionElement>;
12
+ }): React.JSX.Element;
13
+ displayName: string;
14
+ };
15
+ declare const TableBody: {
16
+ ({ ref, className, ...props }: React.HTMLAttributes<HTMLTableSectionElement> & {
17
+ ref?: React.Ref<HTMLTableSectionElement>;
18
+ }): React.JSX.Element;
19
+ displayName: string;
20
+ };
21
+ declare const TableFooter: {
22
+ ({ ref, className, ...props }: React.HTMLAttributes<HTMLTableSectionElement> & {
23
+ ref?: React.Ref<HTMLTableSectionElement>;
24
+ }): React.JSX.Element;
25
+ displayName: string;
26
+ };
27
+ declare const TableRow: {
28
+ ({ ref, className, ...props }: React.HTMLAttributes<HTMLTableRowElement> & {
29
+ ref?: React.Ref<HTMLTableRowElement>;
30
+ }): React.JSX.Element;
31
+ displayName: string;
32
+ };
33
+ declare const TableHead: {
34
+ ({ ref, className, scope, ...props }: React.ThHTMLAttributes<HTMLTableCellElement> & {
35
+ ref?: React.Ref<HTMLTableCellElement>;
36
+ }): React.JSX.Element;
37
+ displayName: string;
38
+ };
39
+ declare const TableCell: {
40
+ ({ ref, className, ...props }: React.TdHTMLAttributes<HTMLTableCellElement> & {
41
+ ref?: React.Ref<HTMLTableCellElement>;
42
+ }): React.JSX.Element;
43
+ displayName: string;
44
+ };
45
+ declare const TableCaption: {
46
+ ({ ref, className, ...props }: React.HTMLAttributes<HTMLTableCaptionElement> & {
47
+ ref?: React.Ref<HTMLTableCaptionElement>;
48
+ }): React.JSX.Element;
49
+ displayName: string;
50
+ };
51
+ export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, };
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "../cn.js";
3
+ import { TableScrollRegion } from "./table-scroll-region.js";
4
+ const Table = ({ ref, className, scrollAreaLabel, ...props }) => (_jsx(TableScrollRegion, { label: scrollAreaLabel, children: _jsx("table", { ref: ref, className: cn("w-full caption-bottom text-sm", className), ...props }) }));
5
+ Table.displayName = "Table";
6
+ const TableHeader = ({ ref, className, ...props }) => (_jsx("thead", { ref: ref, className: cn("[&_tr]:border-b", className), ...props }));
7
+ TableHeader.displayName = "TableHeader";
8
+ const TableBody = ({ ref, className, ...props }) => (_jsx("tbody", { ref: ref, className: cn("[&_tr:last-child]:border-0", className), ...props }));
9
+ TableBody.displayName = "TableBody";
10
+ const TableFooter = ({ ref, className, ...props }) => (_jsx("tfoot", { ref: ref, className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className), ...props }));
11
+ TableFooter.displayName = "TableFooter";
12
+ const TableRow = ({ ref, className, ...props }) => (_jsx("tr", { ref: ref, className: cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className), ...props }));
13
+ TableRow.displayName = "TableRow";
14
+ const TableHead = ({ ref, className, scope = "col", ...props }) => (_jsx("th", { ref: ref, scope: scope, className: cn("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", className), ...props }));
15
+ TableHead.displayName = "TableHead";
16
+ const TableCell = ({ ref, className, ...props }) => (_jsx("td", { ref: ref, className: cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className), ...props }));
17
+ TableCell.displayName = "TableCell";
18
+ const TableCaption = ({ ref, className, ...props }) => (_jsx("caption", { ref: ref, className: cn("mt-4 text-sm text-muted-foreground", className), ...props }));
19
+ TableCaption.displayName = "TableCaption";
20
+ export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, };
@@ -0,0 +1,15 @@
1
+ export declare const HORIZONTAL_OVERFLOW_TOLERANCE_PX = 1;
2
+ export interface HorizontalOverflowBox {
3
+ scrollWidth: number;
4
+ clientWidth: number;
5
+ }
6
+ export declare const isHorizontallyScrollable: (box: HorizontalOverflowBox | null | undefined) => boolean;
7
+ export interface TableScrollRegionAttributes {
8
+ role?: "region";
9
+ "aria-label"?: string;
10
+ tabIndex?: number;
11
+ }
12
+ export declare const resolveTableScrollRegionAttributes: ({ label, isScrollable, }: {
13
+ label?: string;
14
+ isScrollable: boolean;
15
+ }) => TableScrollRegionAttributes;
@@ -0,0 +1,10 @@
1
+ export const HORIZONTAL_OVERFLOW_TOLERANCE_PX = 1;
2
+ export const isHorizontallyScrollable = (box) => box
3
+ ? box.scrollWidth - box.clientWidth > HORIZONTAL_OVERFLOW_TOLERANCE_PX
4
+ : false;
5
+ export const resolveTableScrollRegionAttributes = ({ label, isScrollable, }) => {
6
+ if (label) {
7
+ return { role: "region", "aria-label": label, tabIndex: 0 };
8
+ }
9
+ return isScrollable ? { tabIndex: 0 } : {};
10
+ };
@@ -0,0 +1,12 @@
1
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
2
+ import * as React from "react";
3
+ declare const TooltipProvider: React.FC<TooltipPrimitive.TooltipProviderProps>;
4
+ declare const Tooltip: React.FC<TooltipPrimitive.TooltipProps>;
5
+ declare const TooltipTrigger: React.ForwardRefExoticComponent<TooltipPrimitive.TooltipTriggerProps & React.RefAttributes<HTMLButtonElement>>;
6
+ declare const TooltipContent: {
7
+ ({ ref, className, sideOffset, ...props }: React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content> & {
8
+ ref?: React.Ref<React.ElementRef<typeof TooltipPrimitive.Content>>;
9
+ }): React.JSX.Element;
10
+ displayName: string | undefined;
11
+ };
12
+ export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
4
+ import { cn } from "../cn.js";
5
+ const TooltipProvider = TooltipPrimitive.Provider;
6
+ const Tooltip = TooltipPrimitive.Root;
7
+ const TooltipTrigger = TooltipPrimitive.Trigger;
8
+ const TooltipContent = ({ ref, className, sideOffset = 4, ...props }) => (_jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn("z-[100] overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props }) }));
9
+ TooltipContent.displayName = TooltipPrimitive.Content.displayName;
10
+ export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
@@ -0,0 +1 @@
1
+ export declare const getNestedValue: (obj: any, path: string) => any;
package/dist/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ export const getNestedValue = (obj, path) => {
2
+ return path
3
+ .split(".")
4
+ .reduce((acc, part) => (acc ? acc[part] : undefined), obj);
5
+ };