ionbase-ui 0.75.0 → 0.81.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/dist/components/Card.d.ts +61 -0
- package/dist/components/Card.d.ts.map +1 -0
- package/dist/components/Card.js +37 -0
- package/dist/components/Card.js.map +1 -0
- package/dist/components/CommandPalette.d.ts +76 -0
- package/dist/components/CommandPalette.d.ts.map +1 -0
- package/dist/components/CommandPalette.js +194 -0
- package/dist/components/CommandPalette.js.map +1 -0
- package/dist/components/DateField.d.ts +14 -0
- package/dist/components/DateField.d.ts.map +1 -1
- package/dist/components/DateField.js +1 -1
- package/dist/components/DateField.js.map +1 -1
- package/dist/components/Kbd.d.ts +45 -0
- package/dist/components/Kbd.d.ts.map +1 -0
- package/dist/components/Kbd.js +45 -0
- package/dist/components/Kbd.js.map +1 -0
- package/dist/components/NavItem.d.ts +7 -0
- package/dist/components/NavItem.d.ts.map +1 -1
- package/dist/components/NavItem.js +3 -1
- package/dist/components/NavItem.js.map +1 -1
- package/dist/components/Table.d.ts +18 -0
- package/dist/components/Table.d.ts.map +1 -1
- package/dist/components/Table.js +14 -3
- package/dist/components/Table.js.map +1 -1
- package/dist/components/TagGroup.d.ts +51 -0
- package/dist/components/TagGroup.d.ts.map +1 -0
- package/dist/components/TagGroup.js +84 -0
- package/dist/components/TagGroup.js.map +1 -0
- package/dist/components/TimeField.d.ts +72 -0
- package/dist/components/TimeField.d.ts.map +1 -0
- package/dist/components/TimeField.js +102 -0
- package/dist/components/TimeField.js.map +1 -0
- package/dist/components/index.d.ts +14 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +6 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/iso-time.d.ts +23 -0
- package/dist/components/iso-time.d.ts.map +1 -0
- package/dist/components/iso-time.js +34 -0
- package/dist/components/iso-time.js.map +1 -0
- package/dist/components/shortcut.d.ts +19 -0
- package/dist/components/shortcut.d.ts.map +1 -0
- package/dist/components/shortcut.js +122 -0
- package/dist/components/shortcut.js.map +1 -0
- package/dist/components/use-table-sort.d.ts +38 -0
- package/dist/components/use-table-sort.d.ts.map +1 -0
- package/dist/components/use-table-sort.js +33 -0
- package/dist/components/use-table-sort.js.map +1 -0
- package/dist/figma-descriptions.json +103 -68
- package/dist/figma-map.json +353 -4
- package/dist/meta/Card.json +153 -0
- package/dist/meta/Checkbox.json +2 -2
- package/dist/meta/CommandPalette.json +178 -0
- package/dist/meta/DatePicker.json +2 -2
- package/dist/meta/Kbd.json +97 -0
- package/dist/meta/NavItem.json +17 -3
- package/dist/meta/Radio.json +2 -2
- package/dist/meta/RadioGroup.json +2 -2
- package/dist/meta/Table.json +4 -1
- package/dist/meta/TableBody.json +3 -0
- package/dist/meta/TableCell.json +49 -5
- package/dist/meta/TableHead.json +3 -0
- package/dist/meta/TableRow.json +3 -0
- package/dist/meta/Tag.json +54 -0
- package/dist/meta/TagGroup.json +211 -0
- package/dist/meta/TimeField.json +224 -0
- package/dist/meta/Toggle.json +2 -2
- package/dist/meta/components.json +1027 -39
- package/dist/meta/contrast.json +1307 -0
- package/dist/meta/index.json +86 -12
- package/dist/meta/patterns/DataTable.json +27 -3
- package/dist/meta/patterns/PageShell.json +15 -2
- package/dist/meta/patterns/index.json +7 -3
- package/dist/styles/agent-activity.css +4 -2
- package/dist/styles/approval-gate.css +4 -3
- package/dist/styles/card.css +75 -0
- package/dist/styles/citation.css +4 -2
- package/dist/styles/command-palette.css +250 -0
- package/dist/styles/confidence-indicator.css +2 -2
- package/dist/styles/index.css +5 -0
- package/dist/styles/kbd.css +47 -0
- package/dist/styles/nav-item.css +37 -2
- package/dist/styles/streaming-text.css +3 -2
- package/dist/styles/table.css +51 -0
- package/dist/styles/tag-group.css +172 -0
- package/dist/styles/time-field.css +31 -0
- package/llms.txt +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The time boundary — `iso-date.ts`'s sibling, for the same reasons.
|
|
3
|
+
*
|
|
4
|
+
* The public value is a wall-clock time as `HH:MM` (or `HH:MM:SS`), 24-hour,
|
|
5
|
+
* with no date and no timezone. What the user SEES is their own locale's
|
|
6
|
+
* format — "2:30 PM" for one reader, "14:30" for another — and the value
|
|
7
|
+
* comes back as `14:30` either way. react-aria's `Time` object never appears
|
|
8
|
+
* in a consumer's import list.
|
|
9
|
+
*
|
|
10
|
+
* NOT A `Date`, NOT A TIMESTAMP
|
|
11
|
+
*
|
|
12
|
+
* "Run every day at 09:00" means nine o'clock wherever the schedule lives.
|
|
13
|
+
* A `Date` would pin it to one instant, and it would drift an hour twice a
|
|
14
|
+
* year. Pair the time with a timezone field where the product needs one; the
|
|
15
|
+
* time itself stays a wall-clock reading.
|
|
16
|
+
*/
|
|
17
|
+
import { Time } from '@internationalized/date';
|
|
18
|
+
const ISO_TIME = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$/;
|
|
19
|
+
export function toTime(value, prop) {
|
|
20
|
+
if (value === undefined || value === null)
|
|
21
|
+
return value;
|
|
22
|
+
const m = ISO_TIME.exec(value);
|
|
23
|
+
if (!m) {
|
|
24
|
+
throw new Error(`TimeField: \`${prop}\` must be "HH:MM" or "HH:MM:SS" in 24-hour time, got "${value}".`);
|
|
25
|
+
}
|
|
26
|
+
return new Time(Number(m[1]), Number(m[2]), m[3] ? Number(m[3]) : 0);
|
|
27
|
+
}
|
|
28
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
29
|
+
/** `Time` out to `HH:MM`, or `HH:MM:SS` when the field shows seconds. */
|
|
30
|
+
export function toIsoTime(time, withSeconds) {
|
|
31
|
+
const hm = `${pad(time.hour)}:${pad(time.minute)}`;
|
|
32
|
+
return withSeconds ? `${hm}:${pad(time.second)}` : hm;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=iso-time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iso-time.js","sourceRoot":"","sources":["../../src/components/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ctrl' | 'alt' | 'shift' | 'meta';
|
|
2
|
+
export interface ParsedShortcut {
|
|
3
|
+
modifiers: Set<Modifier>;
|
|
4
|
+
key: string;
|
|
5
|
+
}
|
|
6
|
+
/** `mod+Shift+P` → `{ modifiers: {mod, shift}, key: 'p' }`. Throws on a shortcut with no key. */
|
|
7
|
+
export declare function parseShortcut(shortcut: string): ParsedShortcut;
|
|
8
|
+
export interface ShortcutKey {
|
|
9
|
+
/** What is printed on the key: `⌘`, `Ctrl`, `K`. */
|
|
10
|
+
symbol: string;
|
|
11
|
+
/** What a screen reader should say: `Command`, `Control`, `K`. */
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
/** The keys to draw, in the platform's conventional order. */
|
|
15
|
+
export declare function shortcutKeys(shortcut: string, isMac: boolean): ShortcutKey[];
|
|
16
|
+
/** Whether a keydown is this shortcut — modifiers exact, so `mod+k` is not `mod+shift+k`. */
|
|
17
|
+
export declare function matchesShortcut(event: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'altKey' | 'shiftKey'>, shortcut: ParsedShortcut, isMac: boolean): boolean;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=shortcut.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcut.d.ts","sourceRoot":"","sources":["../../src/components/shortcut.ts"],"names":[],"mappings":"AAWA,KAAK,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAkB1D,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAsB9D;AAqDD,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,WAAW,EAAE,CAkB5E;AAED,6FAA6F;AAC7F,wBAAgB,eAAe,CAC7B,KAAK,EAAE,IAAI,CACT,aAAa,EACb,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,UAAU,CACtD,EACD,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,OAAO,GACb,OAAO,CAUT"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const MODIFIERS = ['mod', 'ctrl', 'alt', 'shift', 'meta'];
|
|
2
|
+
const ALIASES = {
|
|
3
|
+
cmd: 'meta',
|
|
4
|
+
command: 'meta',
|
|
5
|
+
option: 'alt',
|
|
6
|
+
opt: 'alt',
|
|
7
|
+
control: 'ctrl',
|
|
8
|
+
esc: 'escape',
|
|
9
|
+
return: 'enter',
|
|
10
|
+
del: 'delete',
|
|
11
|
+
up: 'arrowup',
|
|
12
|
+
down: 'arrowdown',
|
|
13
|
+
left: 'arrowleft',
|
|
14
|
+
right: 'arrowright',
|
|
15
|
+
};
|
|
16
|
+
/** `mod+Shift+P` → `{ modifiers: {mod, shift}, key: 'p' }`. Throws on a shortcut with no key. */
|
|
17
|
+
export function parseShortcut(shortcut) {
|
|
18
|
+
const parts = shortcut
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.split('+')
|
|
21
|
+
.map((p) => p.trim())
|
|
22
|
+
.map((p) => ALIASES[p] ?? p);
|
|
23
|
+
// `mod++` is mod and the plus key: an empty part after the split is `+`.
|
|
24
|
+
const key = shortcut.endsWith('++') ? '+' : parts.pop();
|
|
25
|
+
const modifiers = new Set();
|
|
26
|
+
for (const p of parts) {
|
|
27
|
+
if (!p)
|
|
28
|
+
continue;
|
|
29
|
+
if (!MODIFIERS.includes(p)) {
|
|
30
|
+
throw new Error(`Shortcut "${shortcut}": "${p}" is not a modifier. Use mod, ctrl, alt, shift or meta, joined with "+".`);
|
|
31
|
+
}
|
|
32
|
+
modifiers.add(p);
|
|
33
|
+
}
|
|
34
|
+
if (!key || MODIFIERS.includes(key)) {
|
|
35
|
+
throw new Error(`Shortcut "${shortcut}" has no key, only modifiers.`);
|
|
36
|
+
}
|
|
37
|
+
return { modifiers, key };
|
|
38
|
+
}
|
|
39
|
+
const MAC_SYMBOL = {
|
|
40
|
+
mod: '⌘',
|
|
41
|
+
meta: '⌘',
|
|
42
|
+
ctrl: '⌃',
|
|
43
|
+
alt: '⌥',
|
|
44
|
+
shift: '⇧',
|
|
45
|
+
};
|
|
46
|
+
const MAC_NAME = {
|
|
47
|
+
mod: 'Command',
|
|
48
|
+
meta: 'Command',
|
|
49
|
+
ctrl: 'Control',
|
|
50
|
+
alt: 'Option',
|
|
51
|
+
shift: 'Shift',
|
|
52
|
+
};
|
|
53
|
+
const OTHER_SYMBOL = {
|
|
54
|
+
mod: 'Ctrl',
|
|
55
|
+
ctrl: 'Ctrl',
|
|
56
|
+
meta: 'Win',
|
|
57
|
+
alt: 'Alt',
|
|
58
|
+
shift: 'Shift',
|
|
59
|
+
};
|
|
60
|
+
const OTHER_NAME = {
|
|
61
|
+
mod: 'Control',
|
|
62
|
+
ctrl: 'Control',
|
|
63
|
+
meta: 'Windows',
|
|
64
|
+
alt: 'Alt',
|
|
65
|
+
shift: 'Shift',
|
|
66
|
+
};
|
|
67
|
+
const KEY_SYMBOL = {
|
|
68
|
+
enter: ['↵', 'Enter'],
|
|
69
|
+
escape: ['Esc', 'Escape'],
|
|
70
|
+
backspace: ['⌫', 'Backspace'],
|
|
71
|
+
delete: ['Del', 'Delete'],
|
|
72
|
+
tab: ['Tab', 'Tab'],
|
|
73
|
+
space: ['Space', 'Space'],
|
|
74
|
+
arrowup: ['↑', 'Up arrow'],
|
|
75
|
+
arrowdown: ['↓', 'Down arrow'],
|
|
76
|
+
arrowleft: ['←', 'Left arrow'],
|
|
77
|
+
arrowright: ['→', 'Right arrow'],
|
|
78
|
+
};
|
|
79
|
+
/** macOS order: Control, Option, Shift, Command. Everywhere else: Ctrl, Alt, Shift. */
|
|
80
|
+
const ORDER = ['ctrl', 'alt', 'shift', 'mod', 'meta'];
|
|
81
|
+
const OTHER_ORDER = [
|
|
82
|
+
'mod',
|
|
83
|
+
'ctrl',
|
|
84
|
+
'meta',
|
|
85
|
+
'alt',
|
|
86
|
+
'shift',
|
|
87
|
+
];
|
|
88
|
+
/** The keys to draw, in the platform's conventional order. */
|
|
89
|
+
export function shortcutKeys(shortcut, isMac) {
|
|
90
|
+
const { modifiers, key } = parseShortcut(shortcut);
|
|
91
|
+
const order = isMac ? ORDER : OTHER_ORDER;
|
|
92
|
+
const keys = order
|
|
93
|
+
.filter((m) => modifiers.has(m))
|
|
94
|
+
// `mod` and `meta` are the same key on a Mac; draw it once.
|
|
95
|
+
.filter((m) => !(isMac && m === 'meta' && modifiers.has('mod')))
|
|
96
|
+
.map((m) => ({
|
|
97
|
+
symbol: (isMac ? MAC_SYMBOL : OTHER_SYMBOL)[m],
|
|
98
|
+
name: (isMac ? MAC_NAME : OTHER_NAME)[m],
|
|
99
|
+
}));
|
|
100
|
+
const named = KEY_SYMBOL[key];
|
|
101
|
+
keys.push(named
|
|
102
|
+
? { symbol: named[0], name: named[1] }
|
|
103
|
+
: { symbol: key.toUpperCase(), name: key.toUpperCase() });
|
|
104
|
+
return keys;
|
|
105
|
+
}
|
|
106
|
+
/** Whether a keydown is this shortcut — modifiers exact, so `mod+k` is not `mod+shift+k`. */
|
|
107
|
+
export function matchesShortcut(event, shortcut, isMac) {
|
|
108
|
+
const { modifiers, key } = shortcut;
|
|
109
|
+
const wantMeta = modifiers.has('meta') || (isMac && modifiers.has('mod'));
|
|
110
|
+
const wantCtrl = modifiers.has('ctrl') || (!isMac && modifiers.has('mod'));
|
|
111
|
+
if (event.metaKey !== wantMeta)
|
|
112
|
+
return false;
|
|
113
|
+
if (event.ctrlKey !== wantCtrl)
|
|
114
|
+
return false;
|
|
115
|
+
if (event.altKey !== modifiers.has('alt'))
|
|
116
|
+
return false;
|
|
117
|
+
if (event.shiftKey !== modifiers.has('shift'))
|
|
118
|
+
return false;
|
|
119
|
+
const pressed = event.key.toLowerCase();
|
|
120
|
+
return pressed === key || (key === 'space' && pressed === ' ');
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=shortcut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcut.js","sourceRoot":"","sources":["../../src/components/shortcut.ts"],"names":[],"mappings":"AAaA,MAAM,SAAS,GAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAC/E,MAAM,OAAO,GAA2B;IACtC,GAAG,EAAE,MAAM;IACX,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,KAAK;IACb,GAAG,EAAE,KAAK;IACV,OAAO,EAAE,MAAM;IACf,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,OAAO;IACf,GAAG,EAAE,QAAQ;IACb,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,YAAY;CACpB,CAAC;AAOF,iGAAiG;AACjG,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,KAAK,GAAG,QAAQ;SACnB,WAAW,EAAE;SACb,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,yEAAyE;IACzE,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IACxD,MAAM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K,CAAC,QAAQ,KAAK,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5D,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;IACxC,OAAO,OAAO,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,OAAO,IAAI,OAAO,KAAK,GAAG,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TableSortDirection } from './Table.js';
|
|
2
|
+
/** Which column the rows are sorted by, and which way. */
|
|
3
|
+
export interface TableSort<Column extends string = string> {
|
|
4
|
+
column: Column;
|
|
5
|
+
direction: Exclude<TableSortDirection, 'none'>;
|
|
6
|
+
}
|
|
7
|
+
export interface TableSortProps {
|
|
8
|
+
sortDirection: TableSortDirection;
|
|
9
|
+
onSort: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface UseTableSortResult<Column extends string> {
|
|
12
|
+
/** The current sort; `null` until a column is chosen when no `initial` is given. */
|
|
13
|
+
sort: TableSort<Column> | null;
|
|
14
|
+
/** Set the sort directly — from a URL, a saved view, a reset. */
|
|
15
|
+
setSort: (sort: TableSort<Column> | null) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Spread onto a header `TableCell`. `firstDirection` is where a column
|
|
18
|
+
* starts when it is chosen: `descending` for dates and amounts, where the
|
|
19
|
+
* newest or largest is what people look for first.
|
|
20
|
+
*/
|
|
21
|
+
sortProps: (column: Column, options?: {
|
|
22
|
+
firstDirection?: TableSort['direction'];
|
|
23
|
+
}) => TableSortProps;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The state of a sortable table: which column, which way, and the props that
|
|
27
|
+
* wire each header to it.
|
|
28
|
+
*
|
|
29
|
+
* Choosing a new column sorts it in its `firstDirection` (ascending unless
|
|
30
|
+
* given); choosing the current column again reverses it. There is no third
|
|
31
|
+
* "unsorted" click: a table that silently returns to server order on the
|
|
32
|
+
* third press loses the reader's place for no reason they can see.
|
|
33
|
+
*
|
|
34
|
+
* It does not sort rows. The rows may be one page of thousands on a server,
|
|
35
|
+
* so ordering them is the caller's — with `sort` as the input.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useTableSort<Column extends string>(initial?: TableSort<Column> | null): UseTableSortResult<Column>;
|
|
38
|
+
//# sourceMappingURL=use-table-sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-table-sort.d.ts","sourceRoot":"","sources":["../../src/components/use-table-sort.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,0DAA0D;AAC1D,MAAM,WAAW,SAAS,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB,CAAC,MAAM,SAAS,MAAM;IACvD,oFAAoF;IACpF,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAC/B,iEAAiE;IACjE,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IAClD;;;;OAIG;IACH,SAAS,EAAE,CACT,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,CAAA;KAAE,KAClD,cAAc,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,MAAM,EAChD,OAAO,GAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAW,GACvC,kBAAkB,CAAC,MAAM,CAAC,CA6B5B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* The state of a sortable table: which column, which way, and the props that
|
|
5
|
+
* wire each header to it.
|
|
6
|
+
*
|
|
7
|
+
* Choosing a new column sorts it in its `firstDirection` (ascending unless
|
|
8
|
+
* given); choosing the current column again reverses it. There is no third
|
|
9
|
+
* "unsorted" click: a table that silently returns to server order on the
|
|
10
|
+
* third press loses the reader's place for no reason they can see.
|
|
11
|
+
*
|
|
12
|
+
* It does not sort rows. The rows may be one page of thousands on a server,
|
|
13
|
+
* so ordering them is the caller's — with `sort` as the input.
|
|
14
|
+
*/
|
|
15
|
+
export function useTableSort(initial = null) {
|
|
16
|
+
const [sort, setSort] = useState(initial);
|
|
17
|
+
const sortProps = useCallback((column, options) => ({
|
|
18
|
+
sortDirection: sort?.column === column ? sort.direction : 'none',
|
|
19
|
+
onSort: () => setSort((current) => current?.column === column
|
|
20
|
+
? {
|
|
21
|
+
column,
|
|
22
|
+
direction: current.direction === 'ascending'
|
|
23
|
+
? 'descending'
|
|
24
|
+
: 'ascending',
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
column,
|
|
28
|
+
direction: options?.firstDirection ?? 'ascending',
|
|
29
|
+
}),
|
|
30
|
+
}), [sort]);
|
|
31
|
+
return { sort, setSort, sortProps };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=use-table-sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-table-sort.js","sourceRoot":"","sources":["../../src/components/use-table-sort.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA8B9C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAoC,IAAI;IAExC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAA2B,OAAO,CAAC,CAAC;IAEpE,MAAM,SAAS,GAAG,WAAW,CAC3B,CACE,MAAc,EACd,OAAqD,EACrC,EAAE,CAAC,CAAC;QACpB,aAAa,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM;QAChE,MAAM,EAAE,GAAG,EAAE,CACX,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAClB,OAAO,EAAE,MAAM,KAAK,MAAM;YACxB,CAAC,CAAC;gBACE,MAAM;gBACN,SAAS,EACP,OAAO,CAAC,SAAS,KAAK,WAAW;oBAC/B,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,WAAW;aAClB;YACH,CAAC,CAAC;gBACE,MAAM;gBACN,SAAS,EAAE,OAAO,EAAE,cAAc,IAAI,WAAW;aAClD,CACN;KACJ,CAAC,EACF,CAAC,IAAI,CAAC,CACP,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACtC,CAAC"}
|