@spark-ui/components 17.3.1 → 17.3.2
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/dropdown/index.js +1 -1
- package/dist/dropdown/index.js.map +1 -1
- package/dist/dropdown/index.mjs +10 -10
- package/dist/dropdown/index.mjs.map +1 -1
- package/dist/src/dropdown/DropdownItems.d.ts +3 -0
- package/dist/src/table/Table.d.ts +2 -45
- package/dist/src/table/TableBody.d.ts +8 -3
- package/dist/src/table/TableBulkBar.d.ts +9 -2
- package/dist/src/table/TableCell.d.ts +3 -4
- package/dist/src/table/TableColumn.d.ts +11 -5
- package/dist/src/table/TableHeader.d.ts +7 -4
- package/dist/src/table/TableRow.d.ts +8 -3
- package/dist/src/table/index.d.mts +1 -1
- package/dist/src/table/index.d.ts +1 -1
- package/dist/src/table/internal/ResizableTableContainer.d.ts +13 -0
- package/dist/src/table/{Table.styles.d.ts → internal/Table.styles.d.ts} +4 -1
- package/dist/src/table/internal/TableBodyCellRenderer.d.ts +10 -0
- package/dist/src/table/internal/TableBodyRowRenderer.d.ts +10 -0
- package/dist/src/table/internal/TableColumnHeader.d.ts +17 -0
- package/dist/src/table/internal/TableColumnResizer.d.ts +14 -0
- package/dist/src/table/{TableContext.d.ts → internal/TableContext.d.ts} +9 -2
- package/dist/src/table/internal/TableGrid.d.ts +12 -0
- package/dist/src/table/internal/TableHeaderRowRenderer.d.ts +15 -0
- package/dist/src/table/internal/TableHeaderSelectionCheckbox.d.ts +18 -0
- package/dist/src/table/internal/TableKeyboardModeContext.d.ts +2 -0
- package/dist/src/table/internal/TableRoot.d.ts +8 -0
- package/dist/src/table/internal/TableRootWrapper.d.ts +37 -0
- package/dist/src/table/internal/TableSelectionCheckbox.d.ts +18 -0
- package/dist/src/table/internal/table-keyboard.d.ts +26 -0
- package/dist/src/table/internal/table-utils.d.ts +8 -0
- package/dist/src/table/useTablePagination.d.ts +1 -1
- package/dist/src/table/useTableSort.d.ts +1 -1
- package/dist/table/index.js +1 -1
- package/dist/table/index.js.map +1 -1
- package/dist/table/index.mjs +694 -336
- package/dist/table/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/src/table/ResizableTableContainer.d.ts +0 -9
- package/dist/src/table/TableHeaderSelectionCheckbox.d.ts +0 -13
- package/dist/src/table/TableSelectionCheckbox.d.ts +0 -7
- package/dist/src/table/table-utils.d.ts +0 -2
|
@@ -1,45 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { ResizableTableContainerProps } from './ResizableTableContainer';
|
|
4
|
-
export interface TableProps extends Omit<AriaTableProps, 'className'>, Pick<ResizableTableContainerProps, 'onResizeStart' | 'onResize' | 'onResizeEnd'> {
|
|
5
|
-
className?: string;
|
|
6
|
-
onKeyDownCapture?: React.KeyboardEventHandler<Element>;
|
|
7
|
-
/** When true (default), columns can be resized. Pass onResizeStart, onResize, onResizeEnd to react to resize events. */
|
|
8
|
-
allowsResizing?: boolean;
|
|
9
|
-
/** Max height of the scroll container (number in px or CSS value). Applied so vertical and horizontal scrollbars share the same container. */
|
|
10
|
-
maxHeight?: number | string;
|
|
11
|
-
/** For BulkBar: total number of items (e.g. for "Select all X items"). */
|
|
12
|
-
totalCount?: number;
|
|
13
|
-
/** When true, BulkBar shows "Clear all" and "Select all" buttons. */
|
|
14
|
-
hasMultiplePages?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Called when user clicks "Clear all" in BulkBar.
|
|
17
|
-
* Useful with pagination selection models (e.g. `useTablePagination`) where clearing only the
|
|
18
|
-
* current page would be incorrect.
|
|
19
|
-
*/
|
|
20
|
-
onClearSelection?: () => void;
|
|
21
|
-
/** Called when user clicks "Select all" in BulkBar. */
|
|
22
|
-
onSelectAll?: () => void;
|
|
23
|
-
}
|
|
24
|
-
export interface TableRootWrapperProps extends TableProps {
|
|
25
|
-
children: ReactNode;
|
|
26
|
-
}
|
|
27
|
-
export declare function TableRootWrapper({ children, className, selectedKeys, onSelectionChange, totalCount, hasMultiplePages, onClearSelection: onClearSelectionProp, onSelectAll, allowsResizing, maxHeight, onResizeStart, onResize, onResizeEnd, onKeyDownCapture, sortDescriptor, onSortChange, ...restProps }: TableRootWrapperProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
-
export declare namespace TableRootWrapper {
|
|
29
|
-
var displayName: string;
|
|
30
|
-
}
|
|
31
|
-
export declare const TableRoot: {
|
|
32
|
-
({ className, onKeyDownCapture, ...props }: TableProps): import("react/jsx-runtime").JSX.Element;
|
|
33
|
-
displayName: string;
|
|
34
|
-
};
|
|
35
|
-
export interface TableGridProps {
|
|
36
|
-
/** Required for accessibility. */
|
|
37
|
-
'aria-label'?: string;
|
|
38
|
-
'aria-labelledby'?: string;
|
|
39
|
-
className?: string;
|
|
40
|
-
children?: ReactNode;
|
|
41
|
-
}
|
|
42
|
-
export declare function TableGrid({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className: gridClassName, children, }: TableGridProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
-
export declare namespace TableGrid {
|
|
44
|
-
var displayName: string;
|
|
45
|
-
}
|
|
1
|
+
export { TableRootWrapper, type TableProps, type TableRootWrapperProps, } from './internal/TableRootWrapper';
|
|
2
|
+
export { TableGrid, type TableGridProps } from './internal/TableGrid';
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { TableBodyProps as
|
|
2
|
-
|
|
1
|
+
import { TableBodyProps as StatelyTableBodyProps } from '@react-stately/table';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export interface TableBodyProps<T extends object = object> extends StatelyTableBodyProps<T> {
|
|
3
4
|
className?: string;
|
|
5
|
+
/** Spark-only: used to re-render body when external deps change (Storybook/demo convenience). */
|
|
6
|
+
dependencies?: unknown[];
|
|
7
|
+
/** Spark-only: empty state renderer (handled by Spark Table renderer). */
|
|
8
|
+
renderEmptyState?: () => ReactNode;
|
|
4
9
|
}
|
|
5
|
-
export declare function TableBody<T extends object>(
|
|
10
|
+
export declare function TableBody<T extends object>(props: TableBodyProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
6
11
|
export declare namespace TableBody {
|
|
7
12
|
var displayName: string;
|
|
8
13
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
2
2
|
import { ButtonProps } from '../button';
|
|
3
3
|
export interface TableBulkBarProps {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
className?: string;
|
|
6
|
+
/** `aria-label` for the toolbar (for i18n). Overrides `bulkBarAriaLabel` from `Table`. */
|
|
7
|
+
'aria-label'?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Additional props passed to the root element.
|
|
10
|
+
* Note: `role` is fixed to "toolbar".
|
|
11
|
+
*/
|
|
12
|
+
rootProps?: Omit<ComponentPropsWithoutRef<'div'>, 'children' | 'className' | 'role' | 'aria-label'>;
|
|
6
13
|
}
|
|
7
|
-
declare function TableBulkBarRoot({ children, className }: TableBulkBarProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
declare function TableBulkBarRoot({ children, className, rootProps, ...props }: TableBulkBarProps): import("react/jsx-runtime").JSX.Element;
|
|
8
15
|
declare namespace TableBulkBarRoot {
|
|
9
16
|
var displayName: string;
|
|
10
17
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { CellProps as
|
|
2
|
-
export interface CellProps extends
|
|
1
|
+
import { CellProps as StatelyCellProps } from '@react-stately/table';
|
|
2
|
+
export interface CellProps extends StatelyCellProps {
|
|
3
3
|
className?: string;
|
|
4
|
-
/** When true, cell uses same width + padding as the TableSelectionCheckbox header column. */
|
|
5
4
|
checkbox?: boolean;
|
|
6
5
|
}
|
|
7
|
-
export declare function Cell(
|
|
6
|
+
export declare function Cell(props: CellProps): import("react/jsx-runtime").JSX.Element;
|
|
8
7
|
export declare namespace Cell {
|
|
9
8
|
var displayName: string;
|
|
10
9
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Key } from '@react-types/shared';
|
|
2
|
+
import { ColumnProps as ReactTypesColumnProps } from '@react-types/table';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
export interface ColumnProps<T extends object = object> extends Omit<ReactTypesColumnProps<T>, 'title' | 'children'> {
|
|
5
|
+
/** Spark-only props. Stored on the column node and used by the renderer. */
|
|
3
6
|
className?: string;
|
|
4
|
-
|
|
7
|
+
/** Stable key for the column (Spark API). */
|
|
8
|
+
id?: Key;
|
|
9
|
+
/** Header label (Spark API). */
|
|
5
10
|
label: string;
|
|
6
|
-
/**
|
|
11
|
+
/** Optional header content (Spark API). */
|
|
12
|
+
children?: ReactNode;
|
|
7
13
|
allowsResizing?: boolean;
|
|
8
14
|
}
|
|
9
|
-
export declare function Column({
|
|
15
|
+
export declare function Column<T extends object>({ label, allowsResizing, ...props }: ColumnProps<T>): null;
|
|
10
16
|
export declare namespace Column {
|
|
11
17
|
var displayName: string;
|
|
12
18
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { TableHeaderProps as
|
|
2
|
-
export interface TableHeaderProps<T extends object = object> extends
|
|
1
|
+
import { TableHeaderProps as StatelyTableHeaderProps } from '@react-stately/table';
|
|
2
|
+
export interface TableHeaderProps<T extends object = object> extends StatelyTableHeaderProps<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Spark-only props. They are stored on the collection node and used by the renderer.
|
|
5
|
+
* (No DOM is rendered by `@react-stately/table` collection components.)
|
|
6
|
+
*/
|
|
3
7
|
className?: string;
|
|
4
|
-
/** When true (default), the header row is sticky with z-raised and top-0. */
|
|
5
8
|
sticky?: boolean;
|
|
6
9
|
}
|
|
7
|
-
export declare function TableHeader<T extends object>(
|
|
10
|
+
export declare function TableHeader<T extends object>(props: TableHeaderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
8
11
|
export declare namespace TableHeader {
|
|
9
12
|
var displayName: string;
|
|
10
13
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Key } from '@react-types/shared';
|
|
2
|
+
import { RowProps as ReactTypesRowProps } from '@react-types/table';
|
|
3
|
+
export interface RowProps<T extends object = object> extends ReactTypesRowProps<T> {
|
|
3
4
|
className?: string;
|
|
5
|
+
/** Stable key for the row (Spark API). */
|
|
6
|
+
id?: Key;
|
|
7
|
+
/** Called when the row is activated (e.g. Enter on a link row). */
|
|
8
|
+
onAction?: () => void;
|
|
4
9
|
}
|
|
5
|
-
export declare function Row<T extends object>(
|
|
10
|
+
export declare function Row<T extends object>(props: RowProps<T>): null;
|
|
6
11
|
export declare namespace Row {
|
|
7
12
|
var displayName: string;
|
|
8
13
|
}
|
|
@@ -20,7 +20,7 @@ export declare const TableWithSubcomponents: typeof TableRootWrapper & {
|
|
|
20
20
|
export { TableWithSubcomponents as Table };
|
|
21
21
|
export { useTableSort } from './useTableSort';
|
|
22
22
|
export { useTablePagination } from './useTablePagination';
|
|
23
|
-
export type { SortDescriptor } from 'react-
|
|
23
|
+
export type { SortDescriptor } from '@react-types/shared';
|
|
24
24
|
export type { UseTableSortOptions } from './useTableSort';
|
|
25
25
|
export type { UseTablePaginationOptions, UseTablePaginationResult } from './useTablePagination';
|
|
26
26
|
export { type TableGridProps, type TableProps, type TableRootWrapperProps } from './Table';
|
|
@@ -20,7 +20,7 @@ export declare const TableWithSubcomponents: typeof TableRootWrapper & {
|
|
|
20
20
|
export { TableWithSubcomponents as Table };
|
|
21
21
|
export { useTableSort } from './useTableSort';
|
|
22
22
|
export { useTablePagination } from './useTablePagination';
|
|
23
|
-
export type { SortDescriptor } from 'react-
|
|
23
|
+
export type { SortDescriptor } from '@react-types/shared';
|
|
24
24
|
export type { UseTableSortOptions } from './useTableSort';
|
|
25
25
|
export type { UseTablePaginationOptions, UseTablePaginationResult } from './useTablePagination';
|
|
26
26
|
export { type TableGridProps, type TableProps, type TableRootWrapperProps } from './Table';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Key } from '@react-types/shared';
|
|
2
|
+
import { ColumnSize } from '@react-types/table';
|
|
3
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
4
|
+
export interface ResizableTableContainerProps extends ComponentPropsWithoutRef<'div'> {
|
|
5
|
+
className?: string;
|
|
6
|
+
onResizeStart?: (widths: Map<Key, ColumnSize>) => void;
|
|
7
|
+
onResize?: (widths: Map<Key, ColumnSize>) => void;
|
|
8
|
+
onResizeEnd?: (widths: Map<Key, ColumnSize>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function ResizableTableContainer({ className, children, ...props }: ResizableTableContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare namespace ResizableTableContainer {
|
|
12
|
+
var displayName: string;
|
|
13
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { VariantProps } from 'class-variance-authority';
|
|
2
|
-
export declare const columnStyles: (props?: ({
|
|
2
|
+
export declare const columnStyles: (props?: ({
|
|
3
|
+
checkbox?: boolean | null | undefined;
|
|
4
|
+
resizable?: boolean | null | undefined;
|
|
5
|
+
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
3
6
|
export declare const columnHeaderContentStyles: (props?: ({} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
4
7
|
export declare const tableBodyStyles: (props?: ({} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
5
8
|
export declare const cellStyles: (props?: ({
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TableState } from '@react-stately/table';
|
|
2
|
+
import { GridNode } from '@react-types/grid';
|
|
3
|
+
export declare function TableBodyCellRenderer({ cell, state, resizeState, }: {
|
|
4
|
+
cell: GridNode<unknown>;
|
|
5
|
+
state: TableState<unknown>;
|
|
6
|
+
resizeState: any;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare namespace TableBodyCellRenderer {
|
|
9
|
+
var displayName: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TableState } from '@react-stately/table';
|
|
2
|
+
import { GridNode } from '@react-types/grid';
|
|
3
|
+
export declare function TableBodyRowRenderer({ item, state, resizeState, }: {
|
|
4
|
+
item: GridNode<unknown>;
|
|
5
|
+
state: TableState<unknown>;
|
|
6
|
+
resizeState: any;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare namespace TableBodyRowRenderer {
|
|
9
|
+
var displayName: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TableState } from '@react-stately/table';
|
|
2
|
+
import { GridNode } from '@react-types/grid';
|
|
3
|
+
export declare function TableColumnHeader({ column, state, resizeState, resizeCallbacks, isLastColumnInRow, }: {
|
|
4
|
+
column: GridNode<unknown>;
|
|
5
|
+
state: TableState<unknown>;
|
|
6
|
+
resizeState: any;
|
|
7
|
+
resizeCallbacks: {
|
|
8
|
+
onResizeStart?: (widths: any) => void;
|
|
9
|
+
onResize?: (widths: any) => void;
|
|
10
|
+
onResizeEnd?: (widths: any) => void;
|
|
11
|
+
};
|
|
12
|
+
/** Rightmost header cell in this row. No resizer — nothing to resize against. */
|
|
13
|
+
isLastColumnInRow?: boolean;
|
|
14
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare namespace TableColumnHeader {
|
|
16
|
+
var displayName: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GridNode } from '@react-types/grid';
|
|
2
|
+
export declare function TableColumnResizer({ column, ariaLabel, resizeState, resizeCallbacks, }: {
|
|
3
|
+
column: GridNode<unknown>;
|
|
4
|
+
ariaLabel?: string;
|
|
5
|
+
resizeState: any;
|
|
6
|
+
resizeCallbacks: {
|
|
7
|
+
onResizeStart?: (widths: any) => void;
|
|
8
|
+
onResize?: (widths: any) => void;
|
|
9
|
+
onResizeEnd?: (widths: any) => void;
|
|
10
|
+
};
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare namespace TableColumnResizer {
|
|
13
|
+
var displayName: string;
|
|
14
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { Selection, SortDescriptor } from 'react-
|
|
1
|
+
import { Selection, SortDescriptor } from '@react-types/shared';
|
|
2
|
+
import { GridNode } from '@react-types/grid';
|
|
2
3
|
import { ResizableTableContainerProps } from './ResizableTableContainer';
|
|
3
4
|
export interface TableResizableContextValue {
|
|
4
5
|
isResizable: boolean;
|
|
6
|
+
tableWidth: number;
|
|
5
7
|
}
|
|
6
8
|
export declare const TableResizableContext: import('react').Context<TableResizableContextValue>;
|
|
7
9
|
export declare function useTableResizableContext(): TableResizableContextValue;
|
|
8
10
|
/** Values provided by Table (root) and consumed by Table.Grid and Table.BulkBar. */
|
|
9
|
-
export interface TableContextValue
|
|
11
|
+
export interface TableContextValue {
|
|
12
|
+
onResizeStart?: ResizableTableContainerProps['onResizeStart'];
|
|
13
|
+
onResize?: ResizableTableContainerProps['onResize'];
|
|
14
|
+
onResizeEnd?: ResizableTableContainerProps['onResizeEnd'];
|
|
10
15
|
selectionMode?: 'none' | 'single' | 'multiple';
|
|
11
16
|
selectionBehavior?: 'toggle' | 'replace';
|
|
12
17
|
selectedKeys?: Selection;
|
|
@@ -17,6 +22,8 @@ export interface TableContextValue extends Pick<ResizableTableContainerProps, 'o
|
|
|
17
22
|
selectedCount: number;
|
|
18
23
|
onClearSelection: () => void;
|
|
19
24
|
allowsResizing?: boolean;
|
|
25
|
+
/** `aria-label` for column resizer control. */
|
|
26
|
+
resizeColumnAriaLabel?: string | ((column: GridNode<unknown>) => string);
|
|
20
27
|
maxHeight?: number | string;
|
|
21
28
|
onKeyDownCapture?: React.KeyboardEventHandler<Element>;
|
|
22
29
|
sortDescriptor?: SortDescriptor;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TableProps as AriaTableProps } from '@react-types/table';
|
|
2
|
+
export interface TableGridProps {
|
|
3
|
+
/** Required for accessibility. */
|
|
4
|
+
'aria-label'?: string;
|
|
5
|
+
'aria-labelledby'?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
children?: AriaTableProps<object>['children'];
|
|
8
|
+
}
|
|
9
|
+
export declare function TableGrid({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className: gridClassName, children, }: TableGridProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare namespace TableGrid {
|
|
11
|
+
var displayName: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TableState } from '@react-stately/table';
|
|
2
|
+
import { GridNode } from '@react-types/grid';
|
|
3
|
+
export declare function TableHeaderRowRenderer({ item, state, resizeState, resizeCallbacks, }: {
|
|
4
|
+
item: GridNode<unknown>;
|
|
5
|
+
state: TableState<unknown>;
|
|
6
|
+
resizeState: any;
|
|
7
|
+
resizeCallbacks: {
|
|
8
|
+
onResizeStart?: (widths: any) => void;
|
|
9
|
+
onResize?: (widths: any) => void;
|
|
10
|
+
onResizeEnd?: (widths: any) => void;
|
|
11
|
+
};
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare namespace TableHeaderRowRenderer {
|
|
14
|
+
var displayName: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TableState } from '@react-stately/table';
|
|
2
|
+
/**
|
|
3
|
+
* Header "select all" checkbox that bases its checked/indeterminate state only
|
|
4
|
+
* on the currently visible (rendered) rows. So when the user changes page in a
|
|
5
|
+
* paginated table, the header shows unchecked instead of indeterminate when no
|
|
6
|
+
* visible row is selected.
|
|
7
|
+
*
|
|
8
|
+
* Keyboard: the column header `<th>` uses React Aria `usePress` for collection
|
|
9
|
+
* selection; Space/Enter would bubble from the checkbox and toggle the wrong key.
|
|
10
|
+
* We stop propagation on those keys and explicitly toggle on Enter (Radix checkbox
|
|
11
|
+
* prevents default Enter on the button so it does not activate like Space).
|
|
12
|
+
*/
|
|
13
|
+
export declare function TableHeaderSelectionCheckbox({ state }: {
|
|
14
|
+
state: TableState<unknown>;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare namespace TableHeaderSelectionCheckbox {
|
|
17
|
+
var displayName: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TableProps as AriaTableProps } from '@react-types/table';
|
|
2
|
+
export declare function TableRoot({ className, children, ...props }: AriaTableProps<object> & {
|
|
3
|
+
className?: string;
|
|
4
|
+
children?: AriaTableProps<object>['children'];
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare namespace TableRoot {
|
|
7
|
+
var displayName: string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Key, SelectionBehavior } from '@react-types/shared';
|
|
2
|
+
import { GridNode } from '@react-types/grid';
|
|
3
|
+
import { ColumnSize, TableProps as AriaTableProps } from '@react-types/table';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
export interface TableProps extends Omit<AriaTableProps<object>, 'children' | 'className'> {
|
|
6
|
+
className?: string;
|
|
7
|
+
selectionBehavior?: SelectionBehavior;
|
|
8
|
+
onKeyDownCapture?: React.KeyboardEventHandler<Element>;
|
|
9
|
+
/** When true (default), columns can be resized. Pass onResizeStart, onResize, onResizeEnd to react to resize events. */
|
|
10
|
+
allowsResizing?: boolean;
|
|
11
|
+
/** `aria-label` for the column resize control (for i18n). */
|
|
12
|
+
resizeColumnAriaLabel?: string | ((column: GridNode<unknown>) => string);
|
|
13
|
+
onResizeStart?: (widths: Map<Key, ColumnSize>) => void;
|
|
14
|
+
onResize?: (widths: Map<Key, ColumnSize>) => void;
|
|
15
|
+
onResizeEnd?: (widths: Map<Key, ColumnSize>) => void;
|
|
16
|
+
/** Max height of the scroll container (number in px or CSS value). Applied so vertical and horizontal scrollbars share the same container. */
|
|
17
|
+
maxHeight?: number | string;
|
|
18
|
+
/** For BulkBar: total number of items (e.g. for "Select all X items"). */
|
|
19
|
+
totalCount?: number;
|
|
20
|
+
/** When true, BulkBar shows "Clear all" and "Select all" buttons. */
|
|
21
|
+
hasMultiplePages?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Called when user clicks "Clear all" in BulkBar.
|
|
24
|
+
* Useful with pagination selection models (e.g. `useTablePagination`) where clearing only the
|
|
25
|
+
* current page would be incorrect.
|
|
26
|
+
*/
|
|
27
|
+
onClearSelection?: () => void;
|
|
28
|
+
/** Called when user clicks "Select all" in BulkBar. */
|
|
29
|
+
onSelectAll?: () => void;
|
|
30
|
+
}
|
|
31
|
+
export interface TableRootWrapperProps extends TableProps {
|
|
32
|
+
children: ReactNode;
|
|
33
|
+
}
|
|
34
|
+
export declare function TableRootWrapper({ children, className, selectedKeys, onSelectionChange, totalCount, hasMultiplePages, onClearSelection: onClearSelectionProp, onSelectAll, allowsResizing, resizeColumnAriaLabel, maxHeight, onResizeStart, onResize, onResizeEnd, onKeyDownCapture, sortDescriptor, onSortChange, ...restProps }: TableRootWrapperProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare namespace TableRootWrapper {
|
|
36
|
+
var displayName: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AriaCheckboxProps } from '@react-types/checkbox';
|
|
2
|
+
export interface TableSelectionCheckboxProps {
|
|
3
|
+
checkboxProps: AriaCheckboxProps;
|
|
4
|
+
className?: string;
|
|
5
|
+
/**
|
|
6
|
+
* When true, marks inner controls as ignored by React Aria's focusable tree walker so Arrow keys
|
|
7
|
+
* move to adjacent cells instead of trapping focus inside the checkbox (grid navigation mode).
|
|
8
|
+
*/
|
|
9
|
+
suppressFocusWalker?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Adapter that renders Spark `Checkbox` from React Aria checkbox props.
|
|
13
|
+
* Used for row selection and "select all" in the table header.
|
|
14
|
+
*/
|
|
15
|
+
export declare function TableSelectionCheckbox({ checkboxProps, className, suppressFocusWalker, }: TableSelectionCheckboxProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare namespace TableSelectionCheckbox {
|
|
17
|
+
var displayName: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DOMAttributes, FocusableElement } from '@react-types/shared';
|
|
2
|
+
import { FocusEventHandler, KeyboardEventHandler, RefObject } from 'react';
|
|
3
|
+
type KeyboardMode = 'grid' | 'interaction';
|
|
4
|
+
/**
|
|
5
|
+
* Collapsible list widgets handle Arrow keys on the focused control (Downshift, native select).
|
|
6
|
+
* - Capture: stopping propagation on the grid would prevent the event from reaching them.
|
|
7
|
+
* - Bubble: useSelectableCollection's grid onKeyDown still runs (target is inside the table), so
|
|
8
|
+
* we must not forward vertical arrows to the collection handler in that case.
|
|
9
|
+
*/
|
|
10
|
+
export declare function targetIsListboxLikeArrowKeyHandler(target: EventTarget | null): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Open combobox / dropdown consumes Escape to close the list first (APG pattern).
|
|
13
|
+
* Grid uses onKeyDownCapture on the table element, which runs before the trigger's handlers,
|
|
14
|
+
* so we must not exit interaction mode until aria-expanded is false.
|
|
15
|
+
*/
|
|
16
|
+
export declare function targetIsOpenComboboxConsumingEscape(target: EventTarget | null): boolean;
|
|
17
|
+
export declare function useTableKeyboardModes<T extends Element>({ ref, gridProps, onKeyDownCapture: userOnKeyDownCapture, onFocusCapture: userOnFocusCapture, }: {
|
|
18
|
+
ref: RefObject<T | null>;
|
|
19
|
+
gridProps: DOMAttributes<FocusableElement> | Record<string, unknown>;
|
|
20
|
+
onKeyDownCapture?: KeyboardEventHandler<Element>;
|
|
21
|
+
onFocusCapture?: FocusEventHandler<Element>;
|
|
22
|
+
}): {
|
|
23
|
+
gridProps: Record<string, unknown>;
|
|
24
|
+
keyboardMode: KeyboardMode;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function isInteractiveElement(element: EventTarget | null): element is Element;
|
|
2
|
+
export declare function isKeyboardActivatableElement(element: EventTarget | null): element is Element;
|
|
3
|
+
export declare function isColumnResizerElement(element: EventTarget | null): element is Element;
|
|
4
|
+
/**
|
|
5
|
+
* Skip React Aria row press/selection when the pointer target is inside in-cell controls
|
|
6
|
+
* (or any "interactive" body cell — same heuristic as grid vs interaction keyboard mode).
|
|
7
|
+
*/
|
|
8
|
+
export declare function shouldSuppressRowSelectionFromPointerTarget(target: EventTarget | null): boolean;
|
package/dist/table/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);const e=require(`../icon-CRPcdgYp.js`),t=require(`../button-B-sMnDc_.js`),n=require(`../checkbox-DjwbAH09.js`);let r=require(`class-variance-authority`),i=require(`react`),a=require(`react/jsx-runtime`),o=require(`react-aria-components`),s=require(`@spark-ui/icons/ArrowUp`),c=require(`@spark-ui/icons/Sort`);var l=`button, [role="button"], [role="switch"], [role="checkbox"], [role="option"], input:not([type="hidden"]), select, textarea, [href]`,u=`[data-resizable-direction]`;function d(e){if(!e||!(e instanceof Element))return!1;let t=e;return t.matches(l)||t.closest(l)!==null}function f(e){return!e||!(e instanceof Element)?!1:e.closest(u)!==null}var p=(0,i.createContext)({isResizable:!1});function m(){return(0,i.useContext)(p)}var h=(0,i.createContext)({selectedCount:0,onClearSelection:()=>{}});function g(){return(0,i.useContext)(h)}function _({className:e,children:t,...n}){let s=(0,i.useRef)(null);return(0,i.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=t=>{t.key!==` `&&t.key!==`Enter`||d(t.target)&&e.contains(t.target)&&(f(t.target)||(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),t.target.click()))};return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)},[]),(0,a.jsx)(p.Provider,{value:{isResizable:!0},children:(0,a.jsx)(o.ResizableTableContainer,{ref:s,"data-spark-component":`resizable-table-container`,className:(0,r.cx)(`relative w-full overflow-auto`,e),...n,children:t})})}_.displayName=`ResizableTableContainer`;function v({children:e,className:t,selectedKeys:n,onSelectionChange:i,totalCount:o,hasMultiplePages:s,onClearSelection:c,onSelectAll:l,allowsResizing:u=!0,maxHeight:d,onResizeStart:f,onResize:p,onResizeEnd:m,onKeyDownCapture:g,sortDescriptor:_,onSortChange:v,...y}){let b=0;n===`all`?b=o??0:n instanceof Set?b=n.size:n&&(b=new Set(n).size);let x=c??(()=>i?.(new Set)),S={...y,selectedKeys:n,onSelectionChange:i,totalCount:o,hasMultiplePages:s,onSelectAll:l,selectedCount:b,onClearSelection:x,allowsResizing:u,maxHeight:d,onResizeStart:f,onResize:p,onResizeEnd:m,onKeyDownCapture:g,sortDescriptor:_,onSortChange:v,className:t};return(0,a.jsx)(h.Provider,{value:S,children:(0,a.jsx)(`div`,{className:(0,r.cx)(`gap-md flex flex-col`,t),children:e})})}v.displayName=`Table`;var y=({className:e,onKeyDownCapture:t,...n})=>{let s=(0,i.useRef)(null);return(0,i.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let t=t=>{t.key!==` `&&t.key!==`Enter`||d(t.target)&&e.contains(t.target)&&(f(t.target)||(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),t.target.click()))};return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)},[]),(0,a.jsx)(o.Table,{ref:s,"data-spark-component":`table`,className:(0,r.cx)(`default:w-full`,`border-separate border-spacing-y-0`,`bg-surface`,`outline-none`,`text-body-1`,`forced-color-adjust-none`,`data-focus-visible:u-outline-inset`,`has-[>[data-empty]]:h-full`,e),...t?{...n,onKeyDownCapture:t}:n})};y.displayName=`Table.Grid.Inner`;function b(e){return typeof e==`number`?`${e}px`:e}function x({"aria-label":e,"aria-labelledby":t,className:n,children:r}){let{allowsResizing:i=!0,maxHeight:o,onResizeStart:s,onResize:c,onResizeEnd:l,onKeyDownCapture:u,sortDescriptor:d,onSortChange:f,className:p,...m}=g(),h=o==null?void 0:{maxHeight:b(o)},v=n??p,x={...m,...e!=null&&{"aria-label":e},...t!=null&&{"aria-labelledby":t},sortDescriptor:d,onSortChange:f,onKeyDownCapture:u,className:v};return i?(0,a.jsx)(_,{className:v,style:h,onResizeStart:s,onResize:c,onResizeEnd:l,children:(0,a.jsx)(y,{...x,children:r})}):(0,a.jsx)(`div`,{className:`relative w-full overflow-auto`,style:h,children:(0,a.jsx)(y,{...x,children:r})})}x.displayName=`Table.Grid`;var S=(0,r.cva)([`h-sz-64 min-w-sz-64`,`relative group/column first:rounded-l-xl last:rounded-r-xl bg-neutral-container`,`px-lg py-sm text-left outline-none box-border`,`cursor-default`,`data-focus-visible:u-outline data-focus-visible:-outline-offset-2`],{variants:{},defaultVariants:{}});(0,r.cva)([`flex flex-1 justify-between items-center gap-md`,`font-inherit text-left text-inherit`,`whitespace-nowrap text-ellipsis`,`border-transparent`,`data-focus-visible:u-outline data-focus-visible:outline-offset-2`],{variants:{},defaultVariants:{}});var C=(0,r.cva)([`empty:italic empty:text-center empty:text-body-2 empty:py-lg`],{variants:{},defaultVariants:{}}),w=(0,r.cva)([`p-lg outline-none box-border default:overflow-hidden`,`border-b-sm border-outline [tr:last-child>&]:border-b-0`,`[-webkit-tap-highlight-color:transparent]`,`data-focus-visible:u-outline-inset data-focus-visible:outline-dashed`],{variants:{checkbox:{true:[`w-sz-64 py-sm px-0 align-middle`]}},defaultVariants:{checkbox:!1}});(0,r.cva)([`pointer-events-none`,`[&_td]:h-sz-16 [&_td]:p-0 [&_td]:border-0 [&_td]:border-b-0 [&_td]:bg-surface [&_td]:align-middle`],{variants:{},defaultVariants:{}});function T({className:e,renderEmptyState:t,...n}){let i=t==null?void 0:e=>(0,a.jsx)(`div`,{"data-spark-component":`table-empty`,className:`p-lg`,children:t(e)});return(0,a.jsx)(o.TableBody,{"data-spark-component":`table-body`,className:(0,r.cx)(C(),e),renderEmptyState:i,...n})}T.displayName=`Table.Body`;var E=(0,i.createContext)(null);function D(){let e=(0,i.useContext)(E);if(!e)throw Error(`Table.BulkBar subcomponents must be used within Table.BulkBar`);return e}function O({children:e,className:t}){let{selectedCount:n,totalCount:i,onClearSelection:o,onSelectAll:s,hasMultiplePages:c}=g(),l={selectedCount:n,totalCount:i,onClearSelection:o,onSelectAll:s,hasMultiplePages:c};return(0,a.jsx)(E.Provider,{value:l,children:(0,a.jsx)(`div`,{role:`toolbar`,"aria-label":`Table bulk actions`,"data-spark-component":`table-bulk-bar`,className:(0,r.cx)(`gap-lg min-h-sz-64 flex w-full flex-wrap items-center justify-between`,`rounded-lg`,`bg-support-container text-on-support-container p-lg`,t),children:e})})}function k({children:e}){return D(),(0,a.jsx)(`span`,{className:`text-body-1 font-bold`,children:e})}function A({className:e,children:n,...i}){let{selectedCount:o,onClearSelection:s,hasMultiplePages:c}=D();return c?(0,a.jsx)(t.t,{size:`sm`,design:`ghost`,intent:`support`,underline:!0,ariaDisabled:o===0,onClick:s,className:(0,r.cx)(`text-body-2`,e),...i,children:n}):null}function j({className:e,children:n,...i}){let{selectedCount:o,totalCount:s,onSelectAll:c,hasMultiplePages:l}=D();return l?(0,a.jsx)(t.t,{size:`sm`,design:`ghost`,intent:`support`,underline:!0,ariaDisabled:s==null||c==null||o>=s,onClick:c,className:(0,r.cx)(`text-body-2`,e),...i,children:n}):null}O.displayName=`Table.BulkBar`;var M=O;M.displayName=`Table.BulkBar`,k.displayName=`Table.BulkBarSelectedCount`,A.displayName=`Table.BulkBarClearButton`,j.displayName=`Table.BulkBarSelectAllButton`;function N({className:e,checkbox:t,onClick:n,onPointerDown:i,...s}){let c=e=>{d(e.target)&&e.stopPropagation()};return(0,a.jsx)(o.Cell,{"data-spark-component":`table-cell`,className:(0,r.cx)(w({checkbox:t}),e),onClick:e=>{c(e),n?.(e)},onPointerDown:e=>{c(e),i?.(e)},...s})}N.displayName=`Table.Cell`;function P({className:t,label:n,children:i,allowsResizing:l=!0,minWidth:u=120,...f}){let{isResizable:p}=m(),h=i;return(0,a.jsx)(o.Column,{"data-spark-component":`table-column`,className:(0,r.cx)(S(),t),minWidth:u,...f,children:(0,o.composeRenderProps)(h,(t,u)=>{let{allowsSorting:m,sortDirection:h}=u,g=e=>{d(e.target)&&e.stopPropagation()};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(o.Group,{role:`presentation`,tabIndex:-1,className:(0,r.cx)(`border-transparent`,`focus-visible:u-outline focus-visible:outline-offset-2`,`gap-sm box-border flex flex-1 items-center`),onClick:g,onPointerDown:g,children:[(0,a.jsxs)(`div`,{className:`gap-md flex min-w-0 shrink items-center`,children:[(0,a.jsx)(`p`,{className:`truncate`,children:n}),i&&(0,a.jsx)(`div`,{className:`inline-flex shrink-0 items-center`,children:typeof t==`function`?t({...u,defaultChildren:void 0}):t})]}),m&&(0,a.jsx)(`span`,{className:`size-sz-32 ml-auto inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full`,children:(0,a.jsx)(e.t,{size:`sm`,className:(0,r.cx)(h===`descending`&&`rotate-180`),children:h?(0,a.jsx)(s.ArrowUp,{}):(0,a.jsx)(c.Sort,{})})})]}),p&&l&&!f.width&&(0,a.jsx)(o.ColumnResizer,{className:(0,r.cx)(`z-raised absolute top-0 right-[-8px]`,`group-last/column:hidden`,`h-full w-[16px] touch-none`,`mx-0 cursor-col-resize`,`data-focus-visible:after:u-outline`,`data-resizing:after:bg-outline-high after:transition-transform after:duration-200 data-resizing:after:scale-125`,`after:h-sz-32 after:bg-outline after:absolute after:top-1/2 after:left-1/2 after:w-[2px] after:-translate-y-1/2`)})]})})})}P.displayName=`Table.Column`;var F=(0,i.forwardRef)(function(e,t){let[r,i]=(0,o.useContextProps)({...e,slot:`selection`},t,o.CheckboxContext),{isSelected:s,isIndeterminate:c,onChange:l,...u}=r;return(0,a.jsx)(`span`,{onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),className:`flex h-full min-h-full items-center justify-center`,children:(0,a.jsx)(n.n,{ref:i,checked:c===!0?`indeterminate`:!!s,onCheckedChange:l,...u})})});F.displayName=`Table.SelectionCheckbox`;function I(){let e=(0,i.useContext)(o.TableStateContext);if(!e)return(0,a.jsx)(F,{});let{collection:t,selectionManager:r}=e,s=r.selectedKeys,c=t,l=c.body,u=l==null?new Set(t.getKeys()):new Set([...c.getChildren(l.key)].map(e=>e.key)),d=s===`all`?u:s,f=[...u].filter(e=>d.has(e)).length,p=u.size;return(0,a.jsx)(`span`,{onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),className:`flex h-full min-h-full items-center justify-center`,children:(0,a.jsx)(n.n,{checked:f>0&&f<p?`indeterminate`:p>0&&f===p,onCheckedChange:()=>{r.toggleSelectAll()}})})}I.displayName=`Table.HeaderSelectionCheckbox`;function L({className:e,columns:t,children:n,sticky:i=!0,...s}){let{selectionBehavior:c,selectionMode:l,allowsDragging:u}=(0,o.useTableOptions)();return(0,a.jsxs)(o.TableHeader,{"data-spark-component":`table-header`,className:(0,r.cx)([i&&`z-raised sticky top-0`,`text-on-neutral-container text-body-1 font-semibold`,`after:pt-md after:block after:size-0`],e),columns:t,...s,children:[u&&(0,a.jsx)(o.Column,{width:20,minWidth:20,className:`w-sz-20 min-w-sz-20 box-border`}),c===`toggle`&&(0,a.jsx)(o.Column,{width:56,minWidth:56,className:(0,r.cx)(S()),children:l===`multiple`&&(0,a.jsx)(I,{})}),t==null?n:(0,a.jsx)(o.Collection,{items:t,children:n})]})}L.displayName=`Table.Header`;function R({id:e,columns:t,children:n,className:i,...s}){let{selectionBehavior:c,allowsDragging:l}=(0,o.useTableOptions)();return(0,a.jsxs)(o.Row,{id:e,"data-spark-component":`table-row`,className:(0,r.cx)(`group/row`,`h-sz-80`,`group/row text-on-surface relative cursor-default select-none`,`[-webkit-tap-highlight-color:transparent]`,`data-focus-visible:u-outline-inset outline-none data-focus-visible:outline-dashed`,`data-react-aria-pressable:hover:bg-surface-hovered data-react-aria-pressable:pressed:bg-surface-hovered`,`data-selected:bg-support-container data-selected:text-on-support-container`,`data-selected:hover:bg-support-container-hovered data-selected:data-pressed:bg-support-container-hovered`,`data-disabled:text-on-surface/dim-3`,`data-href:cursor-pointer`,i),columns:t,...s,children:[l&&(0,a.jsx)(N,{children:(0,a.jsx)(o.Button,{slot:`drag`,className:`w-sz-15 data-focus-visible:u-outline flex items-center justify-center text-center outline-none data-[focus-visible]:rounded-md`,children:`≡`})}),c===`toggle`&&(0,a.jsx)(N,{checkbox:!0,children:(0,a.jsx)(F,{})}),t==null?n:(0,a.jsx)(o.Collection,{items:t,children:n})]})}R.displayName=`Table.Row`;function z(e,t,n,r){let i=e[n],a=t[n];if(i===a)return 0;let o;return o=typeof i==`number`&&typeof a==`number`?i<a?-1:1:String(i).localeCompare(String(a)),r===`descending`?-o:o}function B(e,t={}){let{initialSort:n,compare:r}=t,[a,o]=(0,i.useState)(()=>n?{column:n.column,direction:n.direction}:{column:`id`,direction:`ascending`});return{sortDescriptor:a,onSortChange:o,setSortDescriptor:o,sortedItems:(0,i.useMemo)(()=>{let t=a.column;if(!t)return[...e];let n=r??z,i=a.direction??`ascending`;return[...e].sort((e,r)=>n(e,r,t,i))},[e,a.column,a.direction,r])}}function V(e,t){let{pageSize:n,initialPage:r=1,getId:a}=t,[o,s]=(0,i.useState)(r),[c,l]=(0,i.useState)(()=>new Set),u=e.length,d=Math.max(1,Math.ceil(u/n));(0,i.useEffect)(()=>{s(e=>e<1?1:e>d?d:e)},[d]);let f=o;f<1?f=1:f>d&&(f=d);let p=(0,i.useMemo)(()=>{let t=(f-1)*n,r=t+n;return e.slice(t,r)},[e,f,n]),m=(0,i.useMemo)(()=>{let t=a??(e=>{let t=e.id;if(t==null)throw Error("useTablePagination: item.id is undefined. Provide a `getId` option to extract a stable key.");return t});return new Set(e.map(e=>t(e)))},[a,e]),h=(0,i.useMemo)(()=>{let e=a??(e=>{let t=e.id;if(t==null)throw Error("useTablePagination: item.id is undefined. Provide a `getId` option to extract a stable key.");return t});return new Set(p.map(t=>e(t)))},[a,p]);return{page:f,setPage:s,pageItems:p,totalItems:u,totalPages:d,allKeys:m,selectedKeys:c,onSelectionChange:e=>{let t=e===`all`?new Set(h):new Set(e);l(e=>{let n=new Set(t);for(let t of e)h.has(t)||n.add(t);return n})},onPageChange:e=>{s(e.page)},clearSelection:()=>{l(()=>new Set)}}}var H=Object.assign(v,{Grid:x,Header:L,Column:P,Body:T,Row:R,Cell:N,BulkBar:M,BulkBarSelectedCount:k,BulkBarClearButton:A,BulkBarSelectAllButton:j});H.displayName=`Table`,L.displayName=`Table.Header`,P.displayName=`Table.Column`,T.displayName=`Table.Body`,R.displayName=`Table.Row`,N.displayName=`Table.Cell`,exports.Table=H,exports.TableWithSubcomponents=H,exports.useTablePagination=V,exports.useTableSort=B;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-C91j1N6u.js`),t=require(`../icon-CRPcdgYp.js`),n=require(`../button-B-sMnDc_.js`),r=require(`../checkbox-DjwbAH09.js`);let i=require(`class-variance-authority`),a=require(`react`);a=e.t(a);let o=require(`react/jsx-runtime`),s=require(`@react-aria/utils`),c=require(`@react-stately/table`),l=require(`react-aria`),u=require(`@react-aria/table`),d=require(`@spark-ui/icons/ArrowDown`),f=require(`@spark-ui/icons/ArrowUp`),p=require(`@spark-ui/icons/Sort`);var m=(0,a.createContext)({isResizable:!1,tableWidth:0});function h(){return(0,a.useContext)(m)}var g=(0,a.createContext)({selectedCount:0,onClearSelection:()=>{}});function _(){return(0,a.useContext)(g)}function v({children:e,className:t,selectedKeys:n,onSelectionChange:r,totalCount:a,hasMultiplePages:s,onClearSelection:c,onSelectAll:l,allowsResizing:u=!0,resizeColumnAriaLabel:d,maxHeight:f,onResizeStart:p,onResize:m,onResizeEnd:h,onKeyDownCapture:_,sortDescriptor:v,onSortChange:y,...b}){let x=0;n===`all`?x=a??0:n instanceof Set?x=n.size:n&&(x=new Set(n).size);let S=c??(()=>r?.(new Set)),C={...b,selectedKeys:n,onSelectionChange:r,totalCount:a,hasMultiplePages:s,onSelectAll:l,selectedCount:x,onClearSelection:S,allowsResizing:u,resizeColumnAriaLabel:d,maxHeight:f,onResizeStart:p,onResize:m,onResizeEnd:h,onKeyDownCapture:_,sortDescriptor:v,onSortChange:y,className:t};return(0,o.jsx)(g.Provider,{value:C,children:(0,o.jsx)(`div`,{className:(0,i.cx)(`gap-md flex flex-col`,t),children:e})})}v.displayName=`Table`;function y({className:e,children:t,...n}){let r=(0,a.useRef)(null),[c,l]=(0,a.useState)(0);return(0,a.useLayoutEffect)(()=>{let e=r.current;e&&l(e.clientWidth)},[]),(0,s.useResizeObserver)({ref:r,onResize:()=>{let e=r.current;e&&l(e.clientWidth)}}),(0,o.jsx)(m.Provider,{value:{isResizable:!0,tableWidth:c},children:(0,o.jsx)(`div`,{ref:r,"data-spark-component":`resizable-table-container`,className:(0,i.cx)(`relative w-full overflow-auto`,e),...n,children:t})})}y.displayName=`ResizableTableContainer`;var b=(0,i.cva)([`h-sz-64 min-w-sz-64`,`relative group/column first:rounded-l-xl last:rounded-r-xl bg-neutral-container`,`pl-lg pr-lg py-sm text-left outline-none box-border`,`cursor-default`,`data-focus-visible:u-outline data-focus-visible:-outline-offset-2`],{variants:{checkbox:{true:[`w-sz-64 min-w-sz-64 max-w-sz-64`,`px-0 align-middle`]},resizable:{true:[`pr-xl`]}},defaultVariants:{checkbox:!1,resizable:!1}}),x=(0,i.cva)([`flex flex-1 justify-between items-center gap-md`,`font-inherit text-left text-inherit`,`whitespace-nowrap text-ellipsis`,`border-transparent`,`data-focus-visible:u-outline data-focus-visible:outline-offset-2`],{variants:{},defaultVariants:{}});(0,i.cva)([`empty:italic empty:text-center empty:text-body-2 empty:py-lg`],{variants:{},defaultVariants:{}});var S=(0,i.cva)([`p-lg outline-none box-border default:overflow-hidden`,`border-b-sm border-outline [tr:last-child>&]:border-b-0`,`[-webkit-tap-highlight-color:transparent]`,`data-focus-visible:u-outline-inset data-focus-visible:outline-dashed`],{variants:{checkbox:{true:[`w-sz-64 py-sm px-0 align-middle`]}},defaultVariants:{checkbox:!1}}),C=(0,i.cva)([`pointer-events-none`,`[&_td]:h-sz-16 [&_td]:p-0 [&_td]:border-0 [&_td]:border-b-0 [&_td]:bg-surface [&_td]:align-middle`],{variants:{},defaultVariants:{}}),w=`[data-spark-component="table-cell"]`;function T(e){return!e||!(e instanceof Element)?!1:!!e.closest(`[role="combobox"],select,[data-spark-component="dropdown-trigger"],[data-spark-component="combobox-input"]`)}function E(e){if(!e||!(e instanceof Element))return!1;let t=e.closest(`[role="combobox"],[data-spark-component="dropdown-trigger"],[data-spark-component="combobox-input"]`);return t?t.getAttribute(`aria-expanded`)===`true`:!1}var ee=`a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]`;function D(e){return!e||!(e instanceof Element)?null:e.closest(w)}function O(e){return e.getAttribute(`data-table-cell-kind`)===`selection`}function k(e){return Array.from(e.querySelectorAll(ee)).filter(t=>!(t===e||t.hasAttribute(`disabled`)||t.getAttribute(`aria-disabled`)===`true`||t.getAttribute(`hidden`)!==null))}function A(e,t){for(let n of k(e)){let e=`data-prev-tabindex`;if(!t)n.hasAttribute(e)||n.setAttribute(e,n.getAttribute(`tabindex`)??``),n.setAttribute(`tabindex`,`-1`);else{let t=n.getAttribute(e);if(t===null)continue;n.removeAttribute(e),t===``?n.removeAttribute(`tabindex`):n.setAttribute(`tabindex`,t)}}}function j(e){let t=Array.from(e.querySelectorAll(w));for(let e of t)A(e,!1)}function te({ref:e,gridProps:t,onKeyDownCapture:n,onFocusCapture:r}){let[i,o]=(0,a.useState)(`grid`),s=(0,a.useRef)(`grid`),c=(0,a.useRef)(null),u=(0,a.useRef)(!1),d=(0,a.useMemo)(()=>{let{onKeyDown:a,...d}=t,f=e=>{c.current=e,s.current=`interaction`,o(`interaction`),A(e,!0)};return(0,l.mergeProps)(d,{onKeyDown:e=>{if(s.current===`interaction`&&(e.key===`ArrowLeft`||e.key===`ArrowRight`||e.key===`ArrowUp`||e.key===`ArrowDown`)){let e=c.current,t=document.activeElement;if(e&&t instanceof Node&&e.contains(t))return}s.current===`interaction`&&(e.key===`ArrowUp`||e.key===`ArrowDown`)&&T(e.target)&&D(e.target)===c.current||a?.(e)},onKeyDownCapture:e=>{if(n?.(e),s.current===`interaction`&&e.key===`Tab`){let t=D(e.target);t&&t===c.current&&e.stopPropagation();return}if(T(e.target)&&s.current===`interaction`&&(e.key===`ArrowLeft`||e.key===`ArrowRight`||e.key===`ArrowUp`||e.key===`ArrowDown`)){let t=D(e.target);if(t&&t===c.current)return}if(s.current===`interaction`&&(e.key===`ArrowLeft`||e.key===`ArrowRight`||e.key===`ArrowUp`||e.key===`ArrowDown`)){let t=D(e.target);if(t&&t===c.current){e.stopPropagation();return}}if(s.current===`grid`&&e.key===`ArrowRight`){let t=D(e.target);if(t){let n=t.closest(`tr`);if(n){let r=Array.from(n.querySelectorAll(w));if(r.length>0&&r[r.length-1]===t){e.preventDefault(),e.stopPropagation(),n.focus();return}}}}if(s.current===`grid`&&e.key===`Enter`){let t=D(e.target);if(!t||O(t))return;let n=k(t);if(n.length===0)return;e.preventDefault(),e.stopPropagation(),f(t),n[0]?.focus();return}if(s.current===`grid`&&e.key===`F2`){let t=D(e.target);if(!t||O(t))return;let n=k(t);if(n.length===0)return;e.preventDefault(),e.stopPropagation(),f(t),n[0]?.focus();return}if(s.current===`interaction`&&e.key===`Escape`){if(E(e.target))return;let t=c.current;if(!t)return;e.preventDefault(),e.stopPropagation(),s.current=`grid`,o(`grid`),t.focus()}if(s.current===`interaction`&&e.key===`F2`){let t=c.current;if(!t)return;e.preventDefault(),e.stopPropagation(),s.current=`grid`,o(`grid`),t.focus()}},onBlurCapture:t=>{if(s.current!==`interaction`)return;let n=e.current;if(!n)return;let r=t.relatedTarget;r instanceof Node&&n.contains(r)||(c.current=null,s.current=`grid`,o(`grid`))},onFocusCapture:t=>{r?.(t);let n=u.current;u.current=!1;let i=e.current,a=D(t.target);if(s.current===`interaction`&&c.current&&i){let e=!!(a&&a!==c.current),n=!a&&t.target instanceof Element&&i.contains(t.target)&&!c.current.contains(t.target);(e||n)&&(s.current=`grid`,o(`grid`),n&&(c.current=null))}if(!a)return;c.current=a;let l=t.target instanceof Element?t.target:null,d=a.matches(w),p=s.current===`grid`,m=!!(l&&l!==a&&a.contains(l)),h=k(a).length>0;p&&d&&m&&h&&!n&&queueMicrotask(()=>a.focus()),n&&p&&m&&d&&h&&!O(a)&&f(a)},onPointerDownCapture:e=>{let t=D(e.target);t?.matches(w)&&e.target instanceof Element&&e.target!==t&&t.contains(e.target)&&(u.current=!0)},"data-table-keyboard-mode":i})},[t,i,e,r,n]);return(0,a.useEffect)(()=>{s.current=i;let t=e.current;if(t){if(i===`grid`){j(t),c.current?.focus?.();return}j(t),c.current&&A(c.current,!0)}},[i,e]),{gridProps:d,keyboardMode:i}}var M=`button, [role="button"], [role="switch"], [role="checkbox"], [role="option"], input:not([type="hidden"]), select, textarea, [href], [data-spark-component="dropdown-trigger"], [data-spark-component="icon-button"], [data-spark-component="switch"], [data-spark-component="switch-input"], [data-spark-component="combobox-input"]`,ne=`a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]`;function re(e){if(!e||!(e instanceof Element))return!1;let t=e;return t.matches(M)||t.closest(M)!==null}function ie(e){return e?e instanceof Element?e:e instanceof Text?e.parentElement:null:null}function ae(e){for(let t of e.querySelectorAll(ne))if(t!==e&&!t.hasAttribute(`disabled`)&&t.getAttribute(`aria-disabled`)!==`true`&&t.getAttribute(`hidden`)===null)return!0;return!1}function oe(e){let t=ie(e);if(!t)return!1;if(re(t))return!0;let n=t.closest(`[data-spark-component="table-cell"]`);return!n||n.getAttribute(`data-table-cell-kind`)===`selection`?!1:ae(n)}var se=(0,a.createContext)(`grid`);function N({checkboxProps:e,className:t,suppressFocusWalker:n}){let{isSelected:i,isIndeterminate:a,isDisabled:s,onChange:c,...l}=e,u=a===!0?`indeterminate`:!!i;return(0,o.jsx)(`span`,{...n?{"data-react-aria-prevent-focus":!0}:void 0,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),className:t??`flex h-full min-h-full items-center justify-center`,children:(0,o.jsx)(r.n,{checked:u,disabled:s,onCheckedChange:c,...l})})}N.displayName=`Table.SelectionCheckbox`;function P({cell:e,state:t,resizeState:n}){let r=(0,a.useRef)(null),{gridCellProps:i}=(0,l.useTableCell)({node:e},t,r),{isFocusVisible:s,focusProps:c}=(0,l.useFocusRing)(),d=(0,a.useContext)(se),f=(0,a.useCallback)(e=>{d===`interaction`&&(e.key!==` `&&e.key!==`Enter`||e.stopPropagation())},[d]),{onKeyDownCapture:p,...m}=i,h=(0,a.useCallback)(e=>{[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`].includes(e.key)||p?.(e)},[p]),g=(0,u.useTableSelectionCheckbox)({key:e.parentKey??e.key},t),_=t.collection.columns[e.index??0]?.key??null,v=_?n?.columnWidths?.get?.(_):void 0;return e.props?.isSelectionCell?(0,o.jsx)(`td`,{...(0,l.mergeProps)(m,{onKeyDownCapture:h},c,{onKeyDown:f}),ref:r,"data-spark-component":`table-cell`,"data-table-cell-kind":`selection`,className:S({checkbox:!0}),"data-focus-visible":s||void 0,children:(0,o.jsx)(N,{suppressFocusWalker:d===`grid`,checkboxProps:g.checkboxProps})}):(0,o.jsx)(`td`,{...(0,l.mergeProps)(m,{onKeyDownCapture:h},c,{onKeyDown:f}),ref:r,"data-spark-component":`table-cell`,className:S(),"data-focus-visible":s||void 0,style:v?{width:v}:void 0,children:e.rendered})}P.displayName=`Table.BodyCellRenderer`;function F(e){if(e)return t=>{oe((0,s.getEventTarget)(t.nativeEvent))||e(t)}}function I({item:e,state:t,resizeState:n}){let r=(0,a.useRef)(null),{rowProps:s,isSelected:c}=(0,l.useTableRow)({node:e},t,r),{isFocusVisible:u,focusProps:d}=(0,l.useFocusRing)(),{onClick:f,onPointerDown:p,onMouseDown:m,onPointerUp:h,onPointerCancel:g,..._}=s,v=(0,i.cx)(`outline-none box-border data-focus-visible:u-outline-inset data-focus-visible:outline-dashed`,_.className,c&&`bg-support-container text-on-support-container`);return(0,o.jsx)(`tr`,{...(0,l.mergeProps)(_,d),onPointerDown:F(p),onMouseDown:F(m),onPointerUp:F(h),onPointerCancel:F(g),onClick:F(f),ref:r,"data-spark-component":`table-row`,"data-selected":c||void 0,"data-focus-visible":u||void 0,className:v,tabIndex:-1,children:[...e.childNodes].map(e=>(0,o.jsx)(P,{cell:e,state:t,resizeState:n},e.key))})}I.displayName=`Table.BodyRowRenderer`;function L({column:e,ariaLabel:t,resizeState:n,resizeCallbacks:r}){let s=(0,a.useRef)(null),{resizerProps:c,inputProps:l,isResizing:d}=(0,u.useTableColumnResize)({column:e,"aria-label":t??`Resize column`,onResizeStart:r.onResizeStart,onResize:r.onResize,onResizeEnd:r.onResizeEnd},n,s);return(0,o.jsx)(`div`,{role:`presentation`,className:(0,i.cx)(`cursor-col-resize absolute inset-y-lg right-0 flex w-lg items-center justify-center`,`after:block after:h-full after:w-[2px] after:bg-outline`,`has-[input:focus-visible]:after:u-outline has-[input:focus-visible]:after:outline-offset-2`),"data-resizable-direction":`both`,...c,children:(0,o.jsx)(`input`,{ref:s,disabled:!d,...l})})}L.displayName=`Table.ColumnResizer`;function R({state:e}){let{checkboxProps:t}=(0,u.useTableSelectAllCheckbox)(e),{collection:n,selectionManager:r}=e,i=r.selectedKeys,a=n,s=a.body,c=s==null?new Set(n.getKeys()):new Set([...a.getChildren(s.key)].map(e=>e.key)),l=i===`all`?c:i,d=[...c].filter(e=>l.has(e)).length,f=c.size,p=f>0&&d===f,m=d>0&&d<f,{isSelected:h,isIndeterminate:g,onChange:_,...v}=t,y=e=>{(e.key===` `||e.key===`Enter`)&&e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),t.isDisabled||_?.(!p))};return(0,o.jsx)(N,{checkboxProps:{...v,isSelected:p,isIndeterminate:m,onChange:_,onKeyDown:y}})}R.displayName=`Table.HeaderSelectionCheckbox`;function z({column:e,state:n,resizeState:r,resizeCallbacks:s,isLastColumnInRow:c=!1}){let u=(0,a.useRef)(null),{resizeColumnAriaLabel:m}=_(),{columnHeaderProps:h}=(0,l.useTableColumnHeader)({node:e},n,u),{isFocusVisible:g,focusProps:v}=(0,l.useFocusRing)(),y=e.props?.allowsResizing!==!1&&!c,S=r?.columnWidths?.get?.(e.key),C=!!(r&&y);if(e.props?.isSelectionCell)return(0,o.jsx)(`th`,{...h,ref:u,role:`columnheader`,className:b({checkbox:!0}),"data-spark-component":`table-column`,"data-table-selection-columnheader":!0,"data-focus-visible":g||void 0,children:(0,o.jsx)(R,{state:n})});let w=!!e.props?.allowsSorting,T=n.sortDescriptor?.column===e.key,E=n.sortDescriptor?.direction??`ascending`,ee=T?E===`descending`?(0,o.jsx)(d.ArrowDown,{}):(0,o.jsx)(f.ArrowUp,{}):(0,o.jsx)(p.Sort,{}),D=t=>{w&&(t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),t.stopPropagation(),n.sort?.(e.key)))};return(0,o.jsxs)(`th`,{...(0,l.mergeProps)(h,v),ref:u,role:`columnheader`,className:(0,i.cx)(b({resizable:C})),style:S?{width:S}:void 0,"data-spark-component":`table-column`,"data-focus-visible":g||void 0,onKeyDown:D,children:[(0,o.jsxs)(`div`,{className:x(),children:[(0,o.jsx)(`button`,{type:`button`,className:(0,i.cx)(`gap-md flex min-w-0 flex-1 items-center text-left`,`focus-visible:u-outline outline-none`,`bg-transparent p-0 border-0`),onKeyDown:D,children:(0,o.jsx)(`span`,{className:`min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,children:e.rendered})}),w?(0,o.jsx)(`span`,{"aria-hidden":`true`,className:(0,i.cx)(`shrink-0 opacity-dim-2 group-hover/column:opacity-100`,T&&`opacity-100`),children:(0,o.jsx)(t.t,{size:`sm`,children:ee})}):null]}),r&&y?(0,o.jsx)(L,{column:e,ariaLabel:typeof m==`function`?m(e):m,resizeState:r,resizeCallbacks:s}):null]})}z.displayName=`Table.ColumnHeader`;function B({item:e,state:t,resizeState:n,resizeCallbacks:r}){let i=(0,a.useRef)(null),{rowProps:s}=(0,l.useTableHeaderRow)({node:e},t,i),c=[...e.childNodes];return(0,o.jsx)(`tr`,{...s,ref:i,children:c.map((e,i)=>(0,o.jsx)(z,{column:e,state:t,resizeState:n,resizeCallbacks:r,isLastColumnInRow:i===c.length-1},e.key))})}B.displayName=`Table.HeaderRowRenderer`;function V({className:e,children:t,...n}){let r=(0,a.useRef)(null),u=h(),d=n.selectionMode===`multiple`,f=(0,c.useTableState)({...n,showSelectionCheckboxes:n.selectionMode===`multiple`,children:t}),p=(0,c.useTableColumnResizeState)({tableWidth:u.tableWidth},f),m=u.isResizable&&n.allowsResizing!==!1?p:null,{gridProps:g}=(0,l.useTable)({...n},f,r),_=f.collection.headerRows,v=[...f.collection.body.childNodes],y=f.collection.body.props?.renderEmptyState,b=f.collection.columns.length||1,x=v.length>0||!!y,{rowGroupProps:S}=(0,l.useTableRowGroup)(),{rowGroupProps:w}=(0,l.useTableRowGroup)(),{gridProps:T,keyboardMode:E}=te({ref:r,gridProps:g,onKeyDownCapture:n.onKeyDownCapture,onFocusCapture:n.onFocusCapture});return(0,o.jsx)(se.Provider,{value:E,children:(0,o.jsxs)(`table`,{...(0,l.mergeProps)(T,(0,s.filterDOMProps)(n,{global:!0})),ref:r,"data-spark-component":`table`,className:(0,i.cx)(`default:w-full`,d?`table-fixed`:void 0,`border-separate border-spacing-y-0`,`bg-surface`,`outline-none`,`text-body-1`,`forced-color-adjust-none`,`data-focus-visible:u-outline-inset`,`has-[>[data-empty]]:h-full`,e),children:[(0,o.jsx)(`thead`,{...S,"data-spark-component":`table-header`,children:_.map(e=>(0,o.jsx)(B,{item:e,state:f,resizeState:m,resizeCallbacks:{onResizeStart:n.onResizeStart,onResize:n.onResize,onResizeEnd:n.onResizeEnd}},e.key))}),(0,o.jsxs)(`tbody`,{...w,"data-spark-component":`table-body`,children:[x?(0,o.jsx)(`tr`,{"aria-hidden":`true`,className:C(),role:`presentation`,"data-spark-component":`table-body-spacer`,children:(0,o.jsx)(`td`,{colSpan:b,role:`presentation`})}):null,v.length===0&&y?(0,o.jsx)(`tr`,{"data-empty":!0,children:(0,o.jsx)(`td`,{colSpan:b,children:y({isEmpty:!0})})}):null,v.map(e=>(0,o.jsx)(I,{item:e,state:f,resizeState:m},e.key))]})]})})}V.displayName=`Table.Grid.Inner`;function ce(e){return typeof e==`number`?`${e}px`:e}function H({"aria-label":e,"aria-labelledby":t,className:n,children:r}){let{allowsResizing:i=!0,maxHeight:a,onResizeStart:s,onResize:c,onResizeEnd:l,onKeyDownCapture:u,sortDescriptor:d,onSortChange:f,className:p,...m}=_(),h=a==null?void 0:{maxHeight:ce(a)},g=n??p,v={...m,...e!=null&&{"aria-label":e},...t!=null&&{"aria-labelledby":t},sortDescriptor:d,onSortChange:f,onKeyDownCapture:u,className:g},b=V;return i?(0,o.jsx)(y,{className:g,style:h,onResizeStart:s,onResize:c,onResizeEnd:l,children:(0,o.jsx)(b,{...v,children:r})}):(0,o.jsx)(`div`,{className:`relative w-full overflow-auto`,style:h,children:(0,o.jsx)(b,{...v,children:r})})}H.displayName=`Table.Grid`;function U(e){return(0,o.jsx)(c.TableBody,{...e})}U.displayName=`Table.Body`,U.getCollectionNode=c.TableBody.getCollectionNode;var W=(0,a.createContext)(null);function G(){let e=(0,a.useContext)(W);if(!e)throw Error(`Table.BulkBar subcomponents must be used within Table.BulkBar`);return e}function K({children:e,className:t,rootProps:n,...r}){let{selectedCount:a,totalCount:s,onClearSelection:c,onSelectAll:l,hasMultiplePages:u}=_(),d={selectedCount:a,totalCount:s,onClearSelection:c,onSelectAll:l,hasMultiplePages:u};return(0,o.jsx)(W.Provider,{value:d,children:(0,o.jsx)(`div`,{role:`toolbar`,"aria-label":r[`aria-label`]??`Table bulk actions`,"data-spark-component":`table-bulk-bar`,className:(0,i.cx)(`gap-lg min-h-sz-64 flex w-full flex-wrap items-center justify-between`,`rounded-lg`,`bg-support-container text-on-support-container p-lg`,t),...n,children:e})})}function q({children:e}){return G(),(0,o.jsx)(`span`,{className:`text-body-1 font-bold`,children:e})}function J({className:e,children:t,...r}){let{selectedCount:a,onClearSelection:s,hasMultiplePages:c}=G();return c?(0,o.jsx)(n.t,{size:`sm`,design:`ghost`,intent:`support`,underline:!0,ariaDisabled:a===0,onClick:s,className:(0,i.cx)(`text-body-2`,e),...r,children:t}):null}function le({className:e,children:t,...r}){let{selectedCount:a,totalCount:s,onSelectAll:c,hasMultiplePages:l}=G();return l?(0,o.jsx)(n.t,{size:`sm`,design:`ghost`,intent:`support`,underline:!0,ariaDisabled:s==null||c==null||a>=s,onClick:c,className:(0,i.cx)(`text-body-2`,e),...r,children:t}):null}K.displayName=`Table.BulkBar`;var ue=K;ue.displayName=`Table.BulkBar`,q.displayName=`Table.BulkBarSelectedCount`,J.displayName=`Table.BulkBarClearButton`,le.displayName=`Table.BulkBarSelectAllButton`;function Y(e){return(0,o.jsx)(c.Cell,{...e})}Y.displayName=`Table.Cell`,Y.getCollectionNode=c.Cell.getCollectionNode;function X({label:e,allowsResizing:t=!0,...n}){return null}X.displayName=`Table.Column`,X.getCollectionNode=function*(e,t){let n=e.title??e.label??e.children??null,r=e.textValue||(typeof n==`string`?n:``)||e[`aria-label`],i=yield{type:`column`,key:e.id??null,hasChildNodes:!!e.childColumns||!!e.title&&a.default.Children.count(e.children)>0,rendered:n,textValue:r,props:{...e,title:e.title??e.label,allowsResizing:e.allowsResizing},*childNodes(){if(e.childColumns)for(let t of e.childColumns)yield{type:`column`,value:t};else if(e.title){let t=[];a.default.Children.forEach(e.children,e=>{t.push({type:`column`,element:e})}),yield*t}},shouldInvalidate(e){return o(e),!1}},o=e=>{for(let t of i)t.hasChildNodes||e.columns.push(t)};o(t)};function Z(e){return(0,o.jsx)(c.TableHeader,{...e})}Z.displayName=`Table.Header`,Z.getCollectionNode=c.TableHeader.getCollectionNode;function Q(e){return null}Q.displayName=`Table.Row`,Q.getCollectionNode=function*(e,t){let{children:n,textValue:r,UNSTABLE_childItems:i}=e;yield{type:`item`,key:e.id??null,props:e,textValue:r,"aria-label":e[`aria-label`],hasChildNodes:!0,*childNodes(){if(t.showDragButtons&&(yield{type:`cell`,key:`header-drag`,props:{isDragButtonCell:!0}}),t.showSelectionCheckboxes&&t.selectionMode!==`none`&&(yield{type:`cell`,key:`header`,props:{isSelectionCell:!0}}),typeof n==`function`){for(let e of t.columns)yield{type:`cell`,element:n(e.key),key:e.key};if(i)for(let e of i)yield{type:`item`,value:e}}else{let e=[],r=[],i=0;if(a.default.Children.forEach(n,n=>{if(n)if(n.type===Q){if(e.length<t.columns.length)throw Error(`All of a Row's child Cells must be positioned before any child Rows.`);r.push({type:`item`,element:n})}else e.push({type:`cell`,element:n}),i+=n.props?.colSpan??1}),i!==t.columns.length)throw Error(`Cell count must match column count. Found ${i} cells and ${t.columns.length} columns.`);yield*e,yield*r}},shouldInvalidate(e){return e.columns.length!==t.columns.length||e.columns.some((e,n)=>e.key!==t.columns[n].key)||e.showSelectionCheckboxes!==t.showSelectionCheckboxes||e.showDragButtons!==t.showDragButtons||e.selectionMode!==t.selectionMode}}};function de(e,t,n,r){let i=e[n],a=t[n];if(i===a)return 0;let o;return o=typeof i==`number`&&typeof a==`number`?i<a?-1:1:String(i).localeCompare(String(a)),r===`descending`?-o:o}function fe(e,t={}){let{initialSort:n,compare:r}=t,[i,o]=(0,a.useState)(()=>n?{column:n.column,direction:n.direction}:{column:`id`,direction:`ascending`});return{sortDescriptor:i,onSortChange:o,setSortDescriptor:o,sortedItems:(0,a.useMemo)(()=>{let t=i.column;if(!t)return[...e];let n=r??de,a=i.direction??`ascending`;return[...e].sort((e,r)=>n(e,r,t,a))},[e,i.column,i.direction,r])}}function pe(e,t){let{pageSize:n,initialPage:r=1,getId:i}=t,[o,s]=(0,a.useState)(r),[c,l]=(0,a.useState)(()=>new Set),u=e.length,d=Math.max(1,Math.ceil(u/n));(0,a.useEffect)(()=>{s(e=>e<1?1:e>d?d:e)},[d]);let f=o;f<1?f=1:f>d&&(f=d);let p=(0,a.useMemo)(()=>{let t=(f-1)*n,r=t+n;return e.slice(t,r)},[e,f,n]),m=(0,a.useMemo)(()=>{let t=i??(e=>{let t=e.id;if(t==null)throw Error("useTablePagination: item.id is undefined. Provide a `getId` option to extract a stable key.");return t});return new Set(e.map(e=>t(e)))},[i,e]),h=(0,a.useMemo)(()=>{let e=i??(e=>{let t=e.id;if(t==null)throw Error("useTablePagination: item.id is undefined. Provide a `getId` option to extract a stable key.");return t});return new Set(p.map(t=>e(t)))},[i,p]);return{page:f,setPage:s,pageItems:p,totalItems:u,totalPages:d,allKeys:m,selectedKeys:c,onSelectionChange:e=>{let t=e===`all`?new Set(h):new Set(e);l(e=>{let n=new Set(t);for(let t of e)h.has(t)||n.add(t);return n})},onPageChange:e=>{s(e.page)},clearSelection:()=>{l(()=>new Set)}}}var $=Object.assign(v,{Grid:H,Header:Z,Column:X,Body:U,Row:Q,Cell:Y,BulkBar:ue,BulkBarSelectedCount:q,BulkBarClearButton:J,BulkBarSelectAllButton:le});$.displayName=`Table`,Z.displayName=`Table.Header`,X.displayName=`Table.Column`,U.displayName=`Table.Body`,Q.displayName=`Table.Row`,Y.displayName=`Table.Cell`,exports.Table=$,exports.TableWithSubcomponents=$,exports.useTablePagination=pe,exports.useTableSort=fe;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|