@prunellejs/ui 0.1.1 → 0.6.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/llms.txt +9 -3
- package/package.json +2 -2
- package/src/CommandPalette.tsx +120 -67
- package/src/DataTable.tsx +27 -17
- package/src/Dialog.tsx +29 -13
- package/src/Menu.tsx +10 -8
- package/src/Select.tsx +16 -6
- package/src/Toaster.tsx +112 -2
- package/src/behaviors.ts +108 -6
- package/src/index.ts +1 -1
- package/src/plugin.ts +96 -32
- package/src/styles/bare.css +21 -312
- package/src/styles/base.css +55 -0
- package/src/styles/components/accordion.css +10 -0
- package/src/styles/components/badge.css +6 -0
- package/src/styles/components/button.css +11 -0
- package/src/styles/components/card.css +5 -0
- package/src/styles/components/checkbox.css +11 -0
- package/src/styles/components/command.css +25 -0
- package/src/styles/components/datatable.css +9 -0
- package/src/styles/components/dialog.css +16 -0
- package/src/styles/components/drawer.css +29 -0
- package/src/styles/components/field.css +8 -0
- package/src/styles/components/layout.css +69 -0
- package/src/styles/components/menu.css +21 -0
- package/src/styles/components/notice.css +5 -0
- package/src/styles/components/popover.css +8 -0
- package/src/styles/components/progress.css +14 -0
- package/src/styles/components/radio-group.css +11 -0
- package/src/styles/components/select.css +25 -0
- package/src/styles/components/switch.css +42 -0
- package/src/styles/components/tabs.css +4 -0
- package/src/styles/components/toast.css +28 -0
- package/src/styles/grammars/console.css +113 -256
- package/src/styles/grammars/editorial.css +99 -270
- package/src/styles/grammars/orbit.css +118 -388
- package/src/styles/grammars/prunelle.css +157 -360
- package/src/styles/grammars/soft.css +103 -237
- package/src/styles/grammars/workshop.css +104 -246
- package/src/styles/scan.ts +137 -0
- package/src/styles/split.ts +381 -0
- package/src/styles/theme.css +21 -0
- package/src/styles/themed/accordion.css +20 -0
- package/src/styles/themed/badge.css +20 -0
- package/src/styles/themed/button.css +21 -0
- package/src/styles/themed/card.css +23 -0
- package/src/styles/themed/checkbox.css +4 -0
- package/src/styles/themed/command.css +33 -0
- package/src/styles/themed/datatable.css +28 -0
- package/src/styles/themed/dialog.css +13 -0
- package/src/styles/themed/drawer.css +13 -0
- package/src/styles/themed/field.css +22 -0
- package/src/styles/themed/menu.css +21 -0
- package/src/styles/themed/notice.css +17 -0
- package/src/styles/themed/popover.css +11 -0
- package/src/styles/themed/radio-group.css +12 -0
- package/src/styles/themed/select.css +32 -0
- package/src/styles/themed/switch.css +18 -0
- package/src/styles/themed/tabs.css +17 -0
- package/src/styles/themed/toast.css +18 -0
package/llms.txt
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
- Static & native-platform primitives (`0 KB` JS): `Button`, `Card`, `CardHeader`, `CardBody`, `CardFooter`, `Badge`, `Notice`, `Field`, `FieldContext`, `useFieldContext`, `Checkbox`, `Switch`, `RadioGroup`, `Progress`, `Accordion`, `AccordionItem`, `Popover`, `Dialog`, `Drawer` (opened by `commandfor`/`command` buttons and closed by Esc or a backdrop click, with no JS; `ui()` adds a fallback that only a browser without invoker commands, `closedby` or anchor positioning loads)
|
|
10
10
|
- Interactive island primitives: `ControlledDialog`, `ControlledDrawer`, `Tabs`, `Menu`, `Select`, `CommandPalette`, `DataTable`, `Toaster`
|
|
11
11
|
- Headless signal behaviors & helpers: `createDialog`, `createTabs`, `createDataTable`, `toast`, `handleListKeyDown`, `findFirstEnabledIndex`, `findLastEnabledIndex`, `findNextEnabledIndex`, `isDialogBackdropClick`, `syncDialogOpen`, `nextUiId`
|
|
12
|
-
- `@prunellejs/ui/plugin`: `ui(options?)`, `GRAMMAR_NAMES`, `grammarCssPath`, `renderGrammarCss`, `ejectGrammar`
|
|
12
|
+
- `@prunellejs/ui/plugin`: `ui(options?)`, `GRAMMAR_NAMES`, `UI_COMPONENT_PARTS`, `UI_EXPORT_TO_PARTS`, `grammarCssPath`, `renderGrammarCss`, `renderGrammarBaseCss`, `renderGrammarPartsCss`, `ejectGrammar`
|
|
13
13
|
- CSS subpaths: `@prunellejs/ui/bare.css`, `@prunellejs/ui/grammars/{editorial,workshop,console,soft,orbit,prunelle}.css`
|
|
14
14
|
|
|
15
15
|
## Plugin Setup (`prunelle.config.ts`)
|
|
@@ -25,7 +25,13 @@ export default defineConfig({
|
|
|
25
25
|
|
|
26
26
|
- `grammar`: `'editorial'` (default) | `'workshop'` | `'console'` | `'soft'` | `'orbit'` | `'prunelle'` (prunelle's own: eye radios, switches and progress; titles in Fraunces, which the app loads) | `'bare'` | `false` (skip injecting CSS when importing your own).
|
|
27
27
|
- `emitGrammars`: `boolean | GrammarName[] | { dir?: string, grammars?: GrammarName[] }` — emits standalone CSS files to `/<dir>/<name>.css` (default `grammars/<name>.css`) for runtime theme switching.
|
|
28
|
-
- CLI: `prunelle ui-eject <grammar> [dest]` copies a self-contained CSS grammar (with `
|
|
28
|
+
- CLI: `prunelle ui-eject <grammar> [dest]` copies a self-contained CSS grammar (with `base.css` and component sheets inlined) into your app (default `editorial` → `src/styles/ui.css`).
|
|
29
|
+
|
|
30
|
+
## Tokenized Grammar Architecture & Per-Component CSS
|
|
31
|
+
|
|
32
|
+
- All styles live inside `@layer kui`, layered as `base.css` (box-sizing, `.kui-sr-only`, single `:focus-visible` indicator, reduced motion, `[hidden]`) → per-component structural sheets (`components/<part>.css`) → shared tokenized sheets (`themed/<part>.css`) → thin grammar token files (`grammars/<name>.css`).
|
|
33
|
+
- Focus visibility (RGAA 10.7) is defined once in `base.css` via `--ui-focus-color` (falling back to `--ui-accent`); grammars never suppress focus outlines with `outline: none`.
|
|
34
|
+
- Per-component assembly: `renderGrammarBaseCss(grammar)` returns the base floor + grammar tokens; `renderGrammarPartsCss(grammar, parts)` returns only the requested `UiComponentPart` stylesheets in deterministic cascade order; `UI_EXPORT_TO_PARTS` maps every component export to its required parts (including transitive dependencies).
|
|
29
35
|
|
|
30
36
|
## Key Props & Types
|
|
31
37
|
|
|
@@ -41,7 +47,7 @@ export default defineConfig({
|
|
|
41
47
|
- `Tabs`: `{ id?, items: Array<{ id, label, content }>, defaultValue?, label? }`.
|
|
42
48
|
- `Menu`: `{ id?, label, items: Array<{ id, label, href?, disabled?, onSelect? }>, variant?, onSelect? }`.
|
|
43
49
|
- `Select`: `{ id?, options: Array<{ value, label, disabled? }>, value?: Signal<string>, defaultValue?, name?, placeholder?, ariaLabel?, onChange? }`.
|
|
44
|
-
- `CommandPalette`: `{ id?, items
|
|
50
|
+
- `CommandPalette`: `{ id?, items?: CommandItem[], source?: CommandSource, shortcutKey? ('k'), open?: Signal<boolean>, onSelect?, ...labels }` (`source` is a lazy search function or `{ search(query) }`, e.g. `createSearchSource()` from `@prunellejs/search/client`, invoked only once opened).
|
|
45
51
|
- `DataTable`: `{ rows, columns: Array<{ key, label, sortable? }>, rowKey? ('id'), pageSize? (10), searchable? (true), selectable? (false), ...labels }`.
|
|
46
52
|
- `Toaster` + `toast`: mount `<Toaster dismissLabel? />` once in `_layout.tsx`; call `toast.show|info|success|warning|danger|error(title, description?, durationMs?)`, `toast.dismiss(id)`, `toast.clear()`.
|
|
47
53
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Platform-first headless UI primitives and pure CSS @layer kui Style Grammars for Prunelle",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"directory": "packages/ui"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"prunelle": "^0.
|
|
32
|
+
"prunelle": "^0.6.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/CommandPalette.tsx
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import type { Signal } from 'prunelle'
|
|
5
5
|
import { computed, effect, onMount, signal } from 'prunelle'
|
|
6
|
-
import { findFirstEnabledIndex, handleListKeyDown, isDialogBackdropClick, nextUiId, syncDialogOpen } from './behaviors'
|
|
6
|
+
import { findFirstEnabledIndex, handleListKeyDown, isDialogBackdropClick, navigateSafeHref, nextUiId, syncDialogOpen } from './behaviors'
|
|
7
7
|
|
|
8
8
|
export interface CommandItem {
|
|
9
9
|
id: string
|
|
10
10
|
label: string
|
|
11
|
+
description?: string | undefined
|
|
11
12
|
group?: string | undefined
|
|
12
13
|
shortcut?: string | undefined
|
|
13
14
|
href?: string | undefined
|
|
@@ -15,9 +16,15 @@ export interface CommandItem {
|
|
|
15
16
|
onSelect?: (() => void) | undefined
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
export type CommandSource =
|
|
20
|
+
| ((query: string) => CommandItem[] | Promise<CommandItem[]>)
|
|
21
|
+
| { search: (query: string) => CommandItem[] | Promise<CommandItem[]> }
|
|
22
|
+
|
|
18
23
|
export interface CommandPaletteProps {
|
|
19
24
|
id?: string | undefined
|
|
20
|
-
items
|
|
25
|
+
items?: CommandItem[] | undefined
|
|
26
|
+
/** Dynamic or lazy search source (invoked only once the palette opens, e.g. `createSearchSource()` from `@prunellejs/search/client`). */
|
|
27
|
+
source?: CommandSource | undefined
|
|
21
28
|
placeholder?: string | undefined
|
|
22
29
|
inputLabel?: string | undefined
|
|
23
30
|
ariaLabel?: string | undefined
|
|
@@ -33,6 +40,66 @@ export interface CommandPaletteProps {
|
|
|
33
40
|
|
|
34
41
|
const isItemDisabled = (it: CommandItem) => Boolean(it.disabled)
|
|
35
42
|
|
|
43
|
+
function filterStaticItems(items: CommandItem[], rawQuery: string): CommandItem[] {
|
|
44
|
+
const q = rawQuery.trim().toLowerCase()
|
|
45
|
+
if (!q)
|
|
46
|
+
return items
|
|
47
|
+
return items.filter(it =>
|
|
48
|
+
it.label.toLowerCase().includes(q)
|
|
49
|
+
|| (it.group?.toLowerCase().includes(q) ?? false)
|
|
50
|
+
|| (it.description?.toLowerCase().includes(q) ?? false),
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function createSourceLoader(
|
|
55
|
+
source: CommandSource | undefined,
|
|
56
|
+
sourceItems: Signal<CommandItem[]>,
|
|
57
|
+
onLoaded: () => void,
|
|
58
|
+
): (q: string) => void {
|
|
59
|
+
if (!source)
|
|
60
|
+
return () => {}
|
|
61
|
+
let seq = 0
|
|
62
|
+
return (q: string) => {
|
|
63
|
+
const id = ++seq
|
|
64
|
+
const out = typeof source === 'function' ? source(q) : source.search(q)
|
|
65
|
+
Promise.resolve(out).then(
|
|
66
|
+
(results) => {
|
|
67
|
+
if (id === seq) {
|
|
68
|
+
sourceItems.value = results
|
|
69
|
+
onLoaded()
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
() => {
|
|
73
|
+
if (id === seq)
|
|
74
|
+
sourceItems.value = []
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function bindPaletteShortcut(shortcutKey: string, isOpen: Signal<boolean>): void {
|
|
81
|
+
onMount(() => {
|
|
82
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
83
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcutKey) {
|
|
84
|
+
e.preventDefault()
|
|
85
|
+
isOpen.value = !isOpen.value
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
window.addEventListener('keydown', onKeyDown)
|
|
89
|
+
return () => window.removeEventListener('keydown', onKeyDown)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function selectCommandItem(item: CommandItem, isOpen: Signal<boolean>, onSelect?: (id: string) => void): void {
|
|
94
|
+
if (item.disabled)
|
|
95
|
+
return
|
|
96
|
+
isOpen.value = false
|
|
97
|
+
item.onSelect?.()
|
|
98
|
+
onSelect?.(item.id)
|
|
99
|
+
if (item.href)
|
|
100
|
+
navigateSafeHref(item.href)
|
|
101
|
+
}
|
|
102
|
+
|
|
36
103
|
export function CommandPalette(props: CommandPaletteProps) {
|
|
37
104
|
const baseId = props.id ?? nextUiId('kui-cmd')
|
|
38
105
|
const listId = `${baseId}-list`
|
|
@@ -45,22 +112,23 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
45
112
|
const noResultsLabel = props.noResultsLabel ?? 'No results'
|
|
46
113
|
const resultLabel = props.resultLabel ?? 'result'
|
|
47
114
|
const resultsLabel = props.resultsLabel ?? 'results'
|
|
48
|
-
const
|
|
115
|
+
const staticItems = props.items ?? []
|
|
49
116
|
|
|
50
117
|
const isOpen = props.open ?? signal(false)
|
|
51
118
|
const query = signal('')
|
|
52
|
-
const
|
|
119
|
+
const sourceItems = signal<CommandItem[]>([])
|
|
120
|
+
const activeIdx = signal(findFirstEnabledIndex(staticItems, isItemDisabled))
|
|
53
121
|
let dialogEl: HTMLDialogElement | undefined
|
|
54
122
|
let inputEl: HTMLInputElement | undefined
|
|
55
123
|
|
|
56
124
|
const filtered = computed(() => {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
)
|
|
125
|
+
const base = filterStaticItems(staticItems, query.value)
|
|
126
|
+
const remote = sourceItems.value
|
|
127
|
+
return remote.length ? (base.length ? [...base, ...remote] : remote) : base
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const refreshSource = createSourceLoader(props.source, sourceItems, () => {
|
|
131
|
+
activeIdx.value = findFirstEnabledIndex(filtered.value, isItemDisabled)
|
|
64
132
|
})
|
|
65
133
|
|
|
66
134
|
const activeOptionId = () => {
|
|
@@ -73,41 +141,20 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
73
141
|
if (!isOpen.value)
|
|
74
142
|
return ''
|
|
75
143
|
const n = filtered.value.length
|
|
76
|
-
|
|
77
|
-
return noResultsLabel
|
|
78
|
-
return n === 1 ? `1 ${resultLabel}` : `${n} ${resultsLabel}`
|
|
144
|
+
return n === 0 ? noResultsLabel : n === 1 ? `1 ${resultLabel}` : `${n} ${resultsLabel}`
|
|
79
145
|
}
|
|
80
146
|
|
|
81
147
|
const onOpened = () => {
|
|
82
148
|
query.value = ''
|
|
83
|
-
activeIdx.value = findFirstEnabledIndex(
|
|
149
|
+
activeIdx.value = findFirstEnabledIndex(staticItems, isItemDisabled)
|
|
150
|
+
refreshSource('')
|
|
84
151
|
queueMicrotask(() => inputEl?.focus())
|
|
85
152
|
}
|
|
86
153
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcutKey) {
|
|
90
|
-
e.preventDefault()
|
|
91
|
-
isOpen.value = !isOpen.value
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
window.addEventListener('keydown', onKeyDown)
|
|
95
|
-
return () => window.removeEventListener('keydown', onKeyDown)
|
|
96
|
-
})
|
|
154
|
+
bindPaletteShortcut((props.shortcutKey ?? 'k').toLowerCase(), isOpen)
|
|
155
|
+
effect(() => { syncDialogOpen(dialogEl, isOpen, isOpen.value, onOpened) })
|
|
97
156
|
|
|
98
|
-
|
|
99
|
-
syncDialogOpen(dialogEl, isOpen, isOpen.value, onOpened)
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const runItem = (item: CommandItem) => {
|
|
103
|
-
if (item.disabled)
|
|
104
|
-
return
|
|
105
|
-
isOpen.value = false
|
|
106
|
-
item.onSelect?.()
|
|
107
|
-
props.onSelect?.(item.id)
|
|
108
|
-
if (item.href)
|
|
109
|
-
window.location.assign(item.href)
|
|
110
|
-
}
|
|
157
|
+
const runItem = (item: CommandItem) => selectCommandItem(item, isOpen, props.onSelect)
|
|
111
158
|
|
|
112
159
|
return (
|
|
113
160
|
<div data-ui="command-root" data-state={isOpen.value ? 'open' : 'closed'}>
|
|
@@ -148,13 +195,15 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
148
195
|
aria-label={inputLabel}
|
|
149
196
|
aria-expanded={isOpen.value ? 'true' : 'false'}
|
|
150
197
|
aria-autocomplete="list"
|
|
151
|
-
aria-controls={listId}
|
|
198
|
+
aria-controls={filtered.value.length > 0 ? listId : undefined}
|
|
152
199
|
aria-activedescendant={activeOptionId()}
|
|
153
200
|
placeholder={placeholder}
|
|
154
201
|
value={query.value}
|
|
155
202
|
onInput={(e) => {
|
|
156
|
-
|
|
203
|
+
const val = e.currentTarget.value
|
|
204
|
+
query.value = val
|
|
157
205
|
activeIdx.value = findFirstEnabledIndex(filtered.value, isItemDisabled)
|
|
206
|
+
refreshSource(val)
|
|
158
207
|
}}
|
|
159
208
|
onKeyDown={(e) => {
|
|
160
209
|
handleListKeyDown(e, {
|
|
@@ -170,33 +219,37 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
170
219
|
}}
|
|
171
220
|
/>
|
|
172
221
|
</div>
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
222
|
+
{filtered.value.length > 0
|
|
223
|
+
? (
|
|
224
|
+
<div id={listId} data-part="list" role="listbox" aria-label={inputLabel}>
|
|
225
|
+
{filtered.value.map((item, idx) => (
|
|
226
|
+
<button
|
|
227
|
+
key={item.id}
|
|
228
|
+
id={optionId(idx)}
|
|
229
|
+
type="button"
|
|
230
|
+
role="option"
|
|
231
|
+
tabindex={-1}
|
|
232
|
+
disabled={item.disabled}
|
|
233
|
+
aria-disabled={item.disabled ? 'true' : undefined}
|
|
234
|
+
data-part="item"
|
|
235
|
+
data-highlighted={activeIdx.value === idx ? 'true' : undefined}
|
|
236
|
+
aria-selected={activeIdx.value === idx ? 'true' : 'false'}
|
|
237
|
+
onMouseEnter={() => {
|
|
238
|
+
if (!item.disabled)
|
|
239
|
+
activeIdx.value = idx
|
|
240
|
+
}}
|
|
241
|
+
onClick={() => runItem(item)}
|
|
242
|
+
>
|
|
243
|
+
<span data-part="item-label">{item.label}</span>
|
|
244
|
+
{item.description && <span data-part="item-description">{item.description}</span>}
|
|
245
|
+
{item.shortcut && <kbd data-part="kbd">{item.shortcut}</kbd>}
|
|
246
|
+
</button>
|
|
247
|
+
))}
|
|
248
|
+
</div>
|
|
249
|
+
)
|
|
250
|
+
: (
|
|
251
|
+
<p data-part="empty">{emptyLabel}</p>
|
|
252
|
+
)}
|
|
200
253
|
<div class="kui-sr-only" role="status" aria-live="polite" aria-atomic="true">
|
|
201
254
|
{statusText()}
|
|
202
255
|
</div>
|
package/src/DataTable.tsx
CHANGED
|
@@ -27,6 +27,7 @@ export interface DataTableProps {
|
|
|
27
27
|
pageLabel?: string | undefined
|
|
28
28
|
prevLabel?: string | undefined
|
|
29
29
|
nextLabel?: string | undefined
|
|
30
|
+
emptyLabel?: string | undefined
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export function DataTable(props: DataTableProps) {
|
|
@@ -44,6 +45,7 @@ export function DataTable(props: DataTableProps) {
|
|
|
44
45
|
const pageLabel = props.pageLabel ?? 'Page'
|
|
45
46
|
const prevLabel = props.prevLabel ?? 'Prev'
|
|
46
47
|
const nextLabel = props.nextLabel ?? 'Next'
|
|
48
|
+
const emptyLabel = props.emptyLabel ?? 'No matching rows.'
|
|
47
49
|
const columns = props.columns
|
|
48
50
|
const keyOf = (r: Record<string, string | number>) => String(r[rowKey] ?? '')
|
|
49
51
|
const sortOf = (k: string) => (table.sortBy.value === k ? table.sortDir.value : undefined)
|
|
@@ -70,7 +72,7 @@ export function DataTable(props: DataTableProps) {
|
|
|
70
72
|
table.page.value = 1
|
|
71
73
|
}}
|
|
72
74
|
/>
|
|
73
|
-
<span data-part="meta">
|
|
75
|
+
<span data-part="meta" role="status" aria-live="polite">
|
|
74
76
|
{`${table.filtered.value.length} ${rowsLabel}${selectable && table.selected.value.size > 0 ? ` · ${table.selected.value.size} ${selectedLabel}` : ''}`}
|
|
75
77
|
</span>
|
|
76
78
|
</div>
|
|
@@ -110,23 +112,31 @@ export function DataTable(props: DataTableProps) {
|
|
|
110
112
|
</tr>
|
|
111
113
|
</thead>
|
|
112
114
|
<tbody>
|
|
113
|
-
{table.visible.value.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
{table.visible.value.length === 0
|
|
116
|
+
? (
|
|
117
|
+
<tr data-part="empty">
|
|
118
|
+
<td colspan={Math.max(1, columns.length + (selectable ? 1 : 0))}>
|
|
119
|
+
{emptyLabel}
|
|
120
|
+
</td>
|
|
121
|
+
</tr>
|
|
122
|
+
)
|
|
123
|
+
: table.visible.value.map(row => (
|
|
124
|
+
<tr key={keyOf(row)} data-selected={table.isSelected(keyOf(row)) ? 'true' : undefined}>
|
|
125
|
+
{selectable && (
|
|
126
|
+
<td data-part="select-col">
|
|
127
|
+
<input
|
|
128
|
+
type="checkbox"
|
|
129
|
+
checked={table.isSelected(keyOf(row))}
|
|
130
|
+
aria-label={`${selectRowLabel} ${keyOf(row)}`}
|
|
131
|
+
onChange={() => table.toggleSelect(keyOf(row))}
|
|
132
|
+
/>
|
|
133
|
+
</td>
|
|
134
|
+
)}
|
|
135
|
+
{columns.map(col => (
|
|
136
|
+
<td key={col.key}>{String(row[col.key] ?? '')}</td>
|
|
137
|
+
))}
|
|
138
|
+
</tr>
|
|
127
139
|
))}
|
|
128
|
-
</tr>
|
|
129
|
-
))}
|
|
130
140
|
</tbody>
|
|
131
141
|
</table>
|
|
132
142
|
</div>
|
package/src/Dialog.tsx
CHANGED
|
@@ -60,6 +60,19 @@ function dialogAttrs(props: Shared, kind: Kind, ids: DialogIds) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
function closeButtonAttrs(dialog: Shared, ids: DialogIds) {
|
|
64
|
+
return {
|
|
65
|
+
'data-ui': 'button',
|
|
66
|
+
'data-variant': 'ghost',
|
|
67
|
+
'data-size': 'sm',
|
|
68
|
+
'data-part': 'close',
|
|
69
|
+
'type': 'button' as const,
|
|
70
|
+
'commandfor': ids.baseId,
|
|
71
|
+
'command': 'close' as const,
|
|
72
|
+
'aria-label': dialog.closeLabel ?? 'Close',
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
63
76
|
// Takes `props` without spreading so lazy `get children()` getters evaluate strictly inside `<div data-part="body">`.
|
|
64
77
|
function DialogPanel(props: { dialog: Shared, ids: DialogIds }) {
|
|
65
78
|
const { dialog, ids } = props
|
|
@@ -67,18 +80,21 @@ function DialogPanel(props: { dialog: Shared, ids: DialogIds }) {
|
|
|
67
80
|
<div data-part="panel">
|
|
68
81
|
<header data-part="header" data-layout="split">
|
|
69
82
|
{dialog.title && <h2 id={ids.titleId} data-part="title">{dialog.title}</h2>}
|
|
70
|
-
<button
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
<button {...closeButtonAttrs(dialog, ids)}>✕</button>
|
|
84
|
+
</header>
|
|
85
|
+
{dialog.description && <p id={ids.descId} data-part="description">{dialog.description}</p>}
|
|
86
|
+
<div data-part="body">{dialog.children}</div>
|
|
87
|
+
</div>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function ControlledDialogPanel(props: { dialog: Shared, ids: DialogIds, onClose: () => void }) {
|
|
92
|
+
const { dialog, ids, onClose } = props
|
|
93
|
+
return (
|
|
94
|
+
<div data-part="panel">
|
|
95
|
+
<header data-part="header" data-layout="split">
|
|
96
|
+
{dialog.title && <h2 id={ids.titleId} data-part="title">{dialog.title}</h2>}
|
|
97
|
+
<button {...closeButtonAttrs(dialog, ids)} onClick={onClose}>✕</button>
|
|
82
98
|
</header>
|
|
83
99
|
{dialog.description && <p id={ids.descId} data-part="description">{dialog.description}</p>}
|
|
84
100
|
<div data-part="body">{dialog.children}</div>
|
|
@@ -142,7 +158,7 @@ function renderControlledDialog(props: ControlledDrawerProps, kind: Kind) {
|
|
|
142
158
|
}}
|
|
143
159
|
onClose={() => { isOpen.value = false }}
|
|
144
160
|
>
|
|
145
|
-
<
|
|
161
|
+
<ControlledDialogPanel dialog={props} ids={ids} onClose={() => { isOpen.value = false }} />
|
|
146
162
|
</dialog>
|
|
147
163
|
</div>
|
|
148
164
|
)
|
package/src/Menu.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Accessible dropdown Menu primitive with roving menuitem focus, link items, ArrowDown/Up trigger open, Escape/Tab close & click-outside dismiss.
|
|
3
3
|
|
|
4
4
|
import type { ButtonVariant } from './static'
|
|
5
|
-
import { createListPopup, nextUiId } from './behaviors'
|
|
5
|
+
import { createListPopup, navigateSafeHref, nextUiId, safeHref } from './behaviors'
|
|
6
6
|
|
|
7
7
|
export interface MenuItemDef {
|
|
8
8
|
id: string
|
|
@@ -33,9 +33,10 @@ export function Menu(props: MenuProps) {
|
|
|
33
33
|
return
|
|
34
34
|
item.onSelect?.()
|
|
35
35
|
props.onSelect?.(item.id)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const href = safeHref(item.href)
|
|
37
|
+
popup.close(href === undefined)
|
|
38
|
+
if (navigateHref && href !== undefined)
|
|
39
|
+
navigateSafeHref(href)
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const popup = createListPopup<MenuItemDef>({
|
|
@@ -75,8 +76,9 @@ export function Menu(props: MenuProps) {
|
|
|
75
76
|
popover="auto"
|
|
76
77
|
ref={popup.mountPopup}
|
|
77
78
|
>
|
|
78
|
-
{props.items.map((item, idx) =>
|
|
79
|
-
|
|
79
|
+
{props.items.map((item, idx) => {
|
|
80
|
+
const href = safeHref(item.href)
|
|
81
|
+
return href !== undefined && !item.disabled
|
|
80
82
|
? (
|
|
81
83
|
<a
|
|
82
84
|
key={item.id}
|
|
@@ -84,7 +86,7 @@ export function Menu(props: MenuProps) {
|
|
|
84
86
|
data-part="item"
|
|
85
87
|
data-highlighted={popup.highlighted.value === idx ? 'true' : undefined}
|
|
86
88
|
role="menuitem"
|
|
87
|
-
href={
|
|
89
|
+
href={href}
|
|
88
90
|
tabindex={-1}
|
|
89
91
|
onClick={() => activate(item, false)}
|
|
90
92
|
>
|
|
@@ -107,7 +109,7 @@ export function Menu(props: MenuProps) {
|
|
|
107
109
|
{item.label}
|
|
108
110
|
</button>
|
|
109
111
|
)
|
|
110
|
-
)
|
|
112
|
+
})}
|
|
111
113
|
</div>
|
|
112
114
|
)}
|
|
113
115
|
</div>
|
package/src/Select.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Accessible custom Select (listbox) primitive with aria-activedescendant navigation + hidden input for native <form> submission.
|
|
3
3
|
|
|
4
4
|
import type { Signal } from 'prunelle'
|
|
5
|
-
import { signal } from 'prunelle'
|
|
5
|
+
import { onMount, signal } from 'prunelle'
|
|
6
6
|
import { createListPopup, nextUiId, useFieldContext } from './behaviors'
|
|
7
7
|
|
|
8
8
|
export interface SelectOption {
|
|
@@ -25,7 +25,7 @@ export interface SelectProps {
|
|
|
25
25
|
export function Select(props: SelectProps) {
|
|
26
26
|
const field = useFieldContext()
|
|
27
27
|
const baseId = props.id ?? field?.id ?? nextUiId('kui-select')
|
|
28
|
-
|
|
28
|
+
const triggerId = signal(props.id ?? field?.id ?? `${baseId}-trigger`)
|
|
29
29
|
const listboxId = `${baseId}-listbox`
|
|
30
30
|
const optionId = (idx: number) => `${baseId}-opt-${idx}`
|
|
31
31
|
const name = props.name
|
|
@@ -51,19 +51,29 @@ export function Select(props: SelectProps) {
|
|
|
51
51
|
initialIndex: () => props.options.findIndex(o => o.value === selected.value && !o.disabled),
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
+
let rootEl: HTMLElement | undefined
|
|
55
|
+
const syncFieldLabel = (el: HTMLElement | undefined) => {
|
|
56
|
+
if (!el || props.id || field)
|
|
57
|
+
return
|
|
58
|
+
const labelFor = el.closest('[data-ui="field"]')?.querySelector('label')?.htmlFor
|
|
59
|
+
if (labelFor)
|
|
60
|
+
triggerId.value = labelFor
|
|
61
|
+
}
|
|
62
|
+
onMount(() => { syncFieldLabel(rootEl) })
|
|
63
|
+
|
|
54
64
|
return (
|
|
55
65
|
<div
|
|
56
66
|
data-ui="select"
|
|
57
67
|
data-state={popup.open.value ? 'open' : 'closed'}
|
|
58
68
|
ref={(el) => {
|
|
69
|
+
rootEl = el
|
|
59
70
|
popup.setRoot(el)
|
|
60
|
-
|
|
61
|
-
triggerId = el.closest('[data-ui="field"]')?.querySelector('label')?.htmlFor || triggerId
|
|
71
|
+
syncFieldLabel(el)
|
|
62
72
|
}}
|
|
63
73
|
>
|
|
64
74
|
{name && <input type="hidden" name={name} value={selected.value} />}
|
|
65
75
|
<button
|
|
66
|
-
id={triggerId}
|
|
76
|
+
id={triggerId.value}
|
|
67
77
|
data-part="trigger"
|
|
68
78
|
type="button"
|
|
69
79
|
role="combobox"
|
|
@@ -84,7 +94,7 @@ export function Select(props: SelectProps) {
|
|
|
84
94
|
data-part="listbox"
|
|
85
95
|
role="listbox"
|
|
86
96
|
aria-label={ariaLabel}
|
|
87
|
-
aria-labelledby={ariaLabel ? undefined : triggerId}
|
|
97
|
+
aria-labelledby={ariaLabel ? undefined : triggerId.value}
|
|
88
98
|
popover="auto"
|
|
89
99
|
ref={popup.mountPopup}
|
|
90
100
|
>
|