@pk-design/react-tailwind 1.5.0 → 1.5.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.
@@ -1,5 +1,5 @@
1
1
  import type { DataTableProps } from './DataTable.types';
2
- export declare function DataTable<T extends Record<string, any> = Record<string, any>>({ items, columns, sorting, onSort, loading, pagination, setPagination, emptyMessage, containerClass, wrapperClass, tableClass, headClass, footerRow, rowKey, onRowClick, rowClass, density, striped, layout, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
2
+ export declare function DataTable<T extends Record<string, any> = Record<string, any>>({ items, columns, sorting, onSort, loading, pagination, setPagination, emptyMessage, containerClass, wrapperClass, tableClass, headClass, footerRow, rowKey, onRowClick, rowClass, density, striped, layout, selectable, selectedRowKeys, defaultSelectedRowKeys, onSelectionChange, isRowSelectable, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
3
3
  export declare namespace DataTable {
4
4
  var displayName: string;
5
5
  }
@@ -112,4 +112,20 @@ export interface DataTableProps<T = any> {
112
112
  tableClass?: string;
113
113
  /** Optional classes applied to the `<thead>` element */
114
114
  headClass?: string;
115
+ /**
116
+ * Renders a leading checkbox column so rows can be selected.
117
+ * @default false
118
+ */
119
+ selectable?: boolean;
120
+ /** Controlled selected row keys — pair with `onSelectionChange`. */
121
+ selectedRowKeys?: Array<string | number>;
122
+ /** Initially selected row keys (uncontrolled). */
123
+ defaultSelectedRowKeys?: Array<string | number>;
124
+ /** Called with the new selected row keys and their matching items whenever selection changes. */
125
+ onSelectionChange?: (selectedRowKeys: Array<string | number>, selectedItems: T[]) => void;
126
+ /**
127
+ * Marks specific rows as ineligible for selection — their checkbox is
128
+ * disabled and they're excluded from "select all".
129
+ */
130
+ isRowSelectable?: (item: T) => boolean;
115
131
  }
@@ -10,3 +10,24 @@ export declare const nextSortDirection: (prev: Sorting | undefined, type?: "stri
10
10
  * Toggles sort direction, removing key when reset.
11
11
  */
12
12
  export declare const updateSortQuery: (sortQuery: SortQuery, name: string, type?: DataValueType) => SortQuery;
13
+ /** Options for {@link useRowSelection}. */
14
+ export interface UseRowSelectionOptions<T> {
15
+ items: T[];
16
+ getKey: (item: T, idx: number) => string | number;
17
+ selectedRowKeys?: Array<string | number>;
18
+ defaultSelectedRowKeys?: Array<string | number>;
19
+ onSelectionChange?: (selectedRowKeys: Array<string | number>, selectedItems: T[]) => void;
20
+ isRowSelectable?: (item: T) => boolean;
21
+ }
22
+ /**
23
+ * Shared row-selection state/behaviour used by DataTable and VirtualizedDataTable.
24
+ * Supports controlled (`selectedRowKeys`) and uncontrolled (`defaultSelectedRowKeys`) usage.
25
+ */
26
+ export declare const useRowSelection: <T>({ items, getKey, selectedRowKeys, defaultSelectedRowKeys, onSelectionChange, isRowSelectable, }: UseRowSelectionOptions<T>) => {
27
+ selectedKeys: (string | number)[];
28
+ isSelected: (key: string | number) => boolean;
29
+ toggleRow: (key: string | number) => void;
30
+ toggleAll: () => void;
31
+ allSelected: boolean;
32
+ someSelected: boolean;
33
+ };
@@ -1,2 +1,2 @@
1
1
  import type { VirtualizedDataTableProps } from './VirtualizedDataTable.types';
2
- export declare function VirtualizedDataTable<T extends Record<string, any> = Record<string, any>>({ items, columns, sorting, onSort, loading, emptyMessage, containerClass, wrapperClass, onRowClick, rowClass, density, striped, rowHeight, maxHeight, overscanCount, }: VirtualizedDataTableProps<T>): import("react/jsx-runtime").JSX.Element;
2
+ export declare function VirtualizedDataTable<T extends Record<string, any> = Record<string, any>>({ items, columns, sorting, onSort, loading, emptyMessage, containerClass, wrapperClass, onRowClick, rowClass, density, striped, rowHeight, maxHeight, overscanCount, rowKey, selectable, selectedRowKeys, defaultSelectedRowKeys, onSelectionChange, isRowSelectable, }: VirtualizedDataTableProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  import type { DataTableColumn, DataTableDensity, DataTableProps } from '../DataTable';
2
2
  /**
3
3
  * Props shared with DataTable but not applicable to virtualized tables are omitted:
4
- * pagination, setPagination, layout, footerRow, rowKey, tableClass, headClass.
4
+ * pagination, setPagination, layout, footerRow, tableClass, headClass.
5
5
  */
6
- type VirtualizedBase<T = any> = Omit<DataTableProps<T>, 'pagination' | 'setPagination' | 'layout' | 'footerRow' | 'rowKey' | 'tableClass' | 'headClass'>;
6
+ type VirtualizedBase<T = any> = Omit<DataTableProps<T>, 'pagination' | 'setPagination' | 'layout' | 'footerRow' | 'tableClass' | 'headClass'>;
7
7
  /**
8
8
  * Props for VirtualizedDataTable.
9
9
  * @template T Shape of each data row
@@ -38,5 +38,10 @@ export type VirtualizedRowProps = {
38
38
  rowClass?: string | ((item: any, index: number) => string);
39
39
  density?: DataTableDensity;
40
40
  striped?: boolean;
41
+ selectable?: boolean;
42
+ getKey?: (item: any, index: number) => string | number;
43
+ isSelected?: (key: string | number) => boolean;
44
+ toggleRow?: (key: string | number) => void;
45
+ isRowSelectable?: (item: any) => boolean;
41
46
  };
42
47
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pk-design/react-tailwind",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "main": "dist/react-tailwind.cjs.js",
5
5
  "module": "dist/react-tailwind.es.js",
6
6
  "types": "dist/types/index.d.ts",