@prairielearn/ui 1.1.2 → 1.3.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.
- package/CHANGELOG.md +20 -0
- package/dist/components/CategoricalColumnFilter.d.ts.map +1 -1
- package/dist/components/CategoricalColumnFilter.js +13 -5
- package/dist/components/CategoricalColumnFilter.js.map +1 -1
- package/dist/components/ColumnManager.d.ts +2 -1
- package/dist/components/ColumnManager.d.ts.map +1 -1
- package/dist/components/ColumnManager.js +13 -28
- package/dist/components/ColumnManager.js.map +1 -1
- package/dist/components/MultiSelectColumnFilter.d.ts +25 -0
- package/dist/components/MultiSelectColumnFilter.d.ts.map +1 -0
- package/dist/components/MultiSelectColumnFilter.js +41 -0
- package/dist/components/MultiSelectColumnFilter.js.map +1 -0
- package/dist/components/NumericInputColumnFilter.d.ts +42 -0
- package/dist/components/NumericInputColumnFilter.d.ts.map +1 -0
- package/dist/components/NumericInputColumnFilter.js +79 -0
- package/dist/components/NumericInputColumnFilter.js.map +1 -0
- package/dist/components/TanstackTable.css +49 -0
- package/dist/components/TanstackTable.d.ts +8 -1
- package/dist/components/TanstackTable.d.ts.map +1 -1
- package/dist/components/TanstackTable.js +78 -46
- package/dist/components/TanstackTable.js.map +1 -1
- package/dist/components/TanstackTableDownloadButton.d.ts.map +1 -1
- package/dist/components/TanstackTableDownloadButton.js +3 -1
- package/dist/components/TanstackTableDownloadButton.js.map +1 -1
- package/dist/components/useShiftClickCheckbox.d.ts +26 -0
- package/dist/components/useShiftClickCheckbox.d.ts.map +1 -0
- package/dist/components/useShiftClickCheckbox.js +59 -0
- package/dist/components/useShiftClickCheckbox.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/components/CategoricalColumnFilter.tsx +57 -27
- package/src/components/ColumnManager.tsx +32 -57
- package/src/components/MultiSelectColumnFilter.tsx +103 -0
- package/src/components/NumericInputColumnFilter.test.ts +102 -0
- package/src/components/NumericInputColumnFilter.tsx +153 -0
- package/src/components/TanstackTable.css +49 -0
- package/src/components/TanstackTable.tsx +193 -116
- package/src/components/TanstackTableDownloadButton.tsx +27 -1
- package/src/components/useShiftClickCheckbox.tsx +67 -0
- package/src/index.ts +12 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Row, Table } from '@tanstack/react-table';
|
|
2
|
+
import { type MouseEvent, useCallback, useState } from 'preact/compat';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A hook that provides shift-click range selection functionality for table checkboxes.
|
|
6
|
+
* Use this hook in the parent component and pass the returned props to individual checkboxes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const { lastClickedRowIndex, createCheckboxProps } = useShiftClickCheckbox();
|
|
11
|
+
*
|
|
12
|
+
* // In your column definition:
|
|
13
|
+
* cell: ({ row, table }) => {
|
|
14
|
+
* return <input type="checkbox" {...createCheckboxProps(row, table)} />;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function useShiftClickCheckbox<TData>() {
|
|
19
|
+
const [lastClickedRowIndex, setLastClickedRowIndex] = useState<number | null>(null);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates props for a checkbox that supports shift-click range selection.
|
|
23
|
+
* @param row - The TanStack Table row
|
|
24
|
+
* @param table - The TanStack Table instance
|
|
25
|
+
* @returns Props to spread on the checkbox input element
|
|
26
|
+
*/
|
|
27
|
+
const createCheckboxProps = useCallback(
|
|
28
|
+
(row: Row<TData>, table: Table<TData>) => {
|
|
29
|
+
const handleClick = (e: MouseEvent<HTMLInputElement>) => {
|
|
30
|
+
if (e.shiftKey && lastClickedRowIndex !== null) {
|
|
31
|
+
// Shift-click: select range
|
|
32
|
+
const currentIndex = row.index;
|
|
33
|
+
const start = Math.min(lastClickedRowIndex, currentIndex);
|
|
34
|
+
const end = Math.max(lastClickedRowIndex, currentIndex);
|
|
35
|
+
|
|
36
|
+
// Get all rows in the range
|
|
37
|
+
const rows = table.getRowModel().rows;
|
|
38
|
+
const shouldSelect = !row.getIsSelected();
|
|
39
|
+
|
|
40
|
+
// Select or deselect all rows in the range
|
|
41
|
+
for (let i = start; i <= end; i++) {
|
|
42
|
+
if (rows[i]?.getCanSelect()) {
|
|
43
|
+
rows[i].toggleSelected(shouldSelect);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
// Normal click: toggle this row
|
|
48
|
+
row.getToggleSelectedHandler()(e);
|
|
49
|
+
}
|
|
50
|
+
setLastClickedRowIndex(row.index);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
checked: row.getIsSelected(),
|
|
55
|
+
disabled: !row.getCanSelect(),
|
|
56
|
+
onClick: handleClick,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
[lastClickedRowIndex],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
lastClickedRowIndex,
|
|
64
|
+
setLastClickedRowIndex,
|
|
65
|
+
createCheckboxProps,
|
|
66
|
+
};
|
|
67
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
TanstackTable,
|
|
3
|
+
TanstackTableCard,
|
|
4
|
+
TanstackTableEmptyState,
|
|
5
|
+
} from './components/TanstackTable.js';
|
|
2
6
|
export { ColumnManager } from './components/ColumnManager.js';
|
|
3
7
|
export { TanstackTableDownloadButton } from './components/TanstackTableDownloadButton.js';
|
|
4
8
|
export { CategoricalColumnFilter } from './components/CategoricalColumnFilter.js';
|
|
9
|
+
export { MultiSelectColumnFilter } from './components/MultiSelectColumnFilter.js';
|
|
10
|
+
export {
|
|
11
|
+
NumericInputColumnFilter,
|
|
12
|
+
parseNumericFilter,
|
|
13
|
+
numericColumnFilterFn,
|
|
14
|
+
} from './components/NumericInputColumnFilter.js';
|
|
15
|
+
export { useShiftClickCheckbox } from './components/useShiftClickCheckbox.js';
|