@prunellejs/ui 0.7.7 → 0.9.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 +5 -5
- package/package.json +3 -3
- package/src/CommandPalette.tsx +27 -29
- package/src/DataTable.tsx +64 -68
- package/src/Dialog.tsx +5 -4
- package/src/Menu.tsx +3 -5
- package/src/Select.tsx +52 -13
- package/src/Tabs.tsx +8 -9
- package/src/Toaster.tsx +4 -3
- package/src/labels/dialog.ts +7 -3
- package/src/labels/en/dialog.ts +11 -0
- package/src/labels/en/palette.ts +21 -0
- package/src/labels/en/select.ts +7 -0
- package/src/labels/en/table.ts +31 -0
- package/src/labels/en/toaster.ts +7 -0
- package/src/labels/fr/dialog.ts +7 -3
- package/src/labels/fr/palette.ts +12 -8
- package/src/labels/fr/select.ts +5 -1
- package/src/labels/fr/table.ts +17 -13
- package/src/labels/fr/toaster.ts +5 -1
- package/src/labels/palette.ts +7 -8
- package/src/labels/select.ts +7 -1
- package/src/labels/table.ts +7 -13
- package/src/labels/toaster.ts +7 -1
- package/src/locale.ts +15 -0
- package/src/platform-fallback.ts +7 -5
- package/src/plugin.ts +29 -10
- package/src/primitives.tsx +40 -41
- package/src/static.tsx +56 -10
- package/src/styles/bare.css +1 -1
- package/src/styles/base.css +3 -3
- package/src/styles/components/accordion.css +1 -1
- package/src/styles/components/badge.css +1 -1
- package/src/styles/components/button.css +1 -1
- package/src/styles/components/card.css +1 -1
- package/src/styles/components/checkbox.css +1 -1
- package/src/styles/components/command.css +1 -1
- package/src/styles/components/consent.css +1 -1
- package/src/styles/components/datatable.css +1 -1
- package/src/styles/components/dialog.css +1 -1
- package/src/styles/components/drawer.css +1 -1
- package/src/styles/components/field.css +1 -1
- package/src/styles/components/layout.css +1 -8
- package/src/styles/components/menu.css +1 -1
- package/src/styles/components/notice.css +1 -1
- package/src/styles/components/popover.css +1 -1
- package/src/styles/components/progress.css +1 -1
- package/src/styles/components/radio-group.css +1 -1
- package/src/styles/components/select.css +2 -1
- package/src/styles/components/switch.css +1 -1
- package/src/styles/components/tabs.css +1 -1
- package/src/styles/components/toast.css +1 -1
- package/src/styles/grammars/console.css +1 -1
- package/src/styles/grammars/editorial.css +1 -1
- package/src/styles/grammars/orbit.css +1 -1
- package/src/styles/grammars/prunelle.css +1 -1
- package/src/styles/grammars/soft.css +1 -1
- package/src/styles/grammars/workshop.css +1 -1
- package/src/styles/scan.ts +1 -0
- package/src/styles/split.ts +10 -10
- package/src/styles/theme.css +1 -1
- package/src/styles/themed/accordion.css +1 -1
- package/src/styles/themed/badge.css +1 -1
- package/src/styles/themed/button.css +1 -1
- package/src/styles/themed/card.css +1 -1
- package/src/styles/themed/checkbox.css +1 -1
- package/src/styles/themed/command.css +1 -1
- package/src/styles/themed/consent.css +1 -1
- package/src/styles/themed/datatable.css +1 -1
- package/src/styles/themed/dialog.css +1 -1
- package/src/styles/themed/drawer.css +1 -1
- package/src/styles/themed/field.css +1 -1
- package/src/styles/themed/menu.css +1 -1
- package/src/styles/themed/notice.css +1 -1
- package/src/styles/themed/popover.css +1 -1
- package/src/styles/themed/radio-group.css +1 -1
- package/src/styles/themed/select.css +1 -1
- package/src/styles/themed/switch.css +1 -1
- package/src/styles/themed/tabs.css +1 -1
- package/src/styles/themed/toast.css +1 -1
- package/src/table-state.ts +11 -5
package/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @prunellejs/ui Reference
|
|
2
2
|
|
|
3
|
-
> Platform-first headless UI primitives and pure CSS `@layer
|
|
3
|
+
> Platform-first headless UI primitives and pure CSS `@layer pru-ui` Style Grammars (`0 KB` JS for static primitives; islands only for interactive widgets).
|
|
4
4
|
|
|
5
5
|
## Imports
|
|
6
6
|
|
|
@@ -25,15 +25,15 @@ 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
|
-
- Labels: built-in labels (Dialog's close button, Toaster's dismiss, Select's placeholder, CommandPalette and DataTable texts) follow `lang` from `prunelle.config.ts
|
|
28
|
+
- Labels: built-in labels (Dialog's close button, Toaster's dismiss, Select's placeholder, CommandPalette and DataTable texts) follow `lang` from `prunelle.config.ts` on single-locale apps (French for `'fr'` or `'fr-*'`, English otherwise, shipping only one language), and automatically follow the active request locale (`ctx.locals.locale` / `<html lang>`) when `@prunellejs/i18n` is active. Each label prop still overrides them.
|
|
29
29
|
- 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`).
|
|
30
30
|
|
|
31
31
|
## Tokenized Grammar Architecture & Per-Component CSS
|
|
32
32
|
|
|
33
|
-
- All styles live inside `@layer
|
|
33
|
+
- All styles live inside `@layer pru-ui`, layered as `base.css` (box-sizing, `.pru-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`).
|
|
34
34
|
- 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`.
|
|
35
35
|
- 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).
|
|
36
|
-
- prunelle's `<ConsentBanner
|
|
36
|
+
- prunelle's `<ConsentBanner>`, `<ConsentPreferences>`, and `<CookieTable>` are styled by the `consent` and `datatable` parts, shipped to the pages that import them: the banner sits fixed at the bottom of the viewport, Refuse all and Accept all at one width.
|
|
37
37
|
|
|
38
38
|
## Key Props & Types
|
|
39
39
|
|
|
@@ -48,7 +48,7 @@ export default defineConfig({
|
|
|
48
48
|
- `Dialog` / `Drawer`: `{ id?, title?, ariaLabel?, description?, triggerLabel?, triggerVariant?, closeLabel?, side?: 'right' | 'left' | 'bottom', children? }`; another button opens one with `commandfor={id} command="show-modal"`. `ControlledDialog` / `ControlledDrawer` take the same props plus `open: Signal<boolean>`, which the browser closing it sets back to `false`.
|
|
49
49
|
- `Tabs`: `{ id?, items: Array<{ id, label, content }>, defaultValue?, label? }` (the tablist is named only when `label` is given; each panel takes `tabindex="0"` so Tab reaches a panel of plain text).
|
|
50
50
|
- `Menu`: `{ id?, label, items: Array<{ id, label, href?, disabled?, onSelect? }>, variant?, onSelect? }`.
|
|
51
|
-
- `Select`: `{ id?, options: Array<{ value, label, disabled? }>, value?: Signal<string>, defaultValue?, name?, placeholder?, ariaLabel?, onChange? }`. With no `value` or `defaultValue` it shows `placeholder` and submits `""` until the user picks. Outside a `Field` or `<label for>` it needs `ariaLabel`, or `prunelle check` warns `rgaa/form-label`.
|
|
51
|
+
- `Select`: `{ id?, options: Array<{ value, label, disabled? }>, value?: Signal<string>, defaultValue?, name?, placeholder?, ariaLabel?, onChange? }`. With no `value` or `defaultValue` it shows `placeholder` and submits `""` until the user picks. The server renders a native `<select name>` (labelled by the `Field` or `ariaLabel`, with an empty `placeholder` option), so a form posts the choice with JS off; once the island mounts it becomes the hidden field and the combobox takes over (about 200 B gzipped on a page using `Select`). Outside a `Field` or `<label for>` it needs `ariaLabel`, or `prunelle check` warns `rgaa/form-label`.
|
|
52
52
|
- `CommandPalette`: `{ id?, items?: CommandItem[], source?: CommandSource, shortcutKey? ('k'; Ctrl or Cmd, named in `aria-keyshortcuts`, so the palette opens on it even when hydrated on `interaction`), 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).
|
|
53
53
|
- `DataTable`: `{ rows, columns: Array<{ key, label, sortable? }>, rowKey? ('id'; every row needs a unique key, or the table throws), locale? (sort order; `<html lang>`), onSelect?(keys) (the selected keys, each time they change), rowLabelKey? (first column: names each row's checkbox), pageSize? (10), searchable? (true), selectable? (false), ...labels }`. With `selectable`, the header checkbox selects or clears every row the filter shows. A sort is announced (`ascendingLabel`, `descendingLabel`), and so is the page. Sort is numeric and accent-aware (`Intl.Collator`), search and `CommandPalette` ignore case and accents, and the selection drops rows that leave `rows`. `createDataTable()` also has `setSelected(keys, on)` and `onSelect`.
|
|
54
54
|
- `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()`. A `danger`/`error` toast stays until dismissed and the others stay 4.5 to 15 s by text length, unless `durationMs` is given (`0` keeps it). Hovering or focusing the stack pauses every timer, which then resumes with the time it had left; Escape closes the focused toast, and focus moves to the next toast, else back where it was.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Platform-first headless UI primitives and pure CSS @layer
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Platform-first headless UI primitives and pure CSS @layer pru-ui Style Grammars for Prunelle",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"directory": "packages/ui"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"prunelle": "^0.
|
|
32
|
+
"prunelle": "^0.9.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/CommandPalette.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import type { Signal } from 'prunelle'
|
|
|
5
5
|
import { computed, effect, onMount, signal } from 'prunelle'
|
|
6
6
|
import { findFirstEnabledIndex, handleListKeyDown, isDialogBackdropClick, navigateSafeHref, nextUiId, syncDialogOpen } from './behaviors'
|
|
7
7
|
import { foldText } from './fold'
|
|
8
|
-
import
|
|
8
|
+
import { paletteLabels } from './labels/palette'
|
|
9
9
|
|
|
10
10
|
export interface CommandItem {
|
|
11
11
|
id: string
|
|
@@ -54,14 +54,15 @@ function filterStaticItems(items: CommandItem[], rawQuery: string): CommandItem[
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function createSourceLoader(
|
|
57
|
-
|
|
57
|
+
getSource: () => CommandSource | undefined,
|
|
58
58
|
sourceItems: Signal<CommandItem[]>,
|
|
59
59
|
onLoaded: () => void,
|
|
60
60
|
): (q: string) => void {
|
|
61
|
-
if (!source)
|
|
62
|
-
return () => {}
|
|
63
61
|
let seq = 0
|
|
64
62
|
return (q: string) => {
|
|
63
|
+
const source = getSource()
|
|
64
|
+
if (!source)
|
|
65
|
+
return
|
|
65
66
|
const id = ++seq
|
|
66
67
|
const out = typeof source === 'function' ? source(q) : source.search(q)
|
|
67
68
|
Promise.resolve(out).then(
|
|
@@ -83,7 +84,7 @@ function createSourceLoader(
|
|
|
83
84
|
function bindPaletteShortcut(shortcutKey: string, isOpen: Signal<boolean>): string {
|
|
84
85
|
onMount(() => {
|
|
85
86
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
86
|
-
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcutKey) {
|
|
87
|
+
if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey && e.key.toLowerCase() === shortcutKey) {
|
|
87
88
|
e.preventDefault()
|
|
88
89
|
isOpen.value = !isOpen.value
|
|
89
90
|
}
|
|
@@ -118,33 +119,28 @@ function selectCommandItem(item: CommandItem, isOpen: Signal<boolean>, onSelect?
|
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
export function CommandPalette(props: CommandPaletteProps) {
|
|
121
|
-
const
|
|
122
|
+
const labels = paletteLabels()
|
|
123
|
+
const baseId = props.id ?? nextUiId('pru-cmd')
|
|
122
124
|
const listId = `${baseId}-list`
|
|
123
125
|
const optionId = (idx: number) => `${baseId}-opt-${idx}`
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const triggerLabel = props.triggerLabel ?? PALETTE_LABELS.trigger
|
|
128
|
-
const emptyLabel = props.emptyLabel ?? PALETTE_LABELS.empty
|
|
129
|
-
const noResultsLabel = props.noResultsLabel ?? PALETTE_LABELS.noResults
|
|
130
|
-
const resultLabel = props.resultLabel ?? PALETTE_LABELS.result
|
|
131
|
-
const resultsLabel = props.resultsLabel ?? PALETTE_LABELS.results
|
|
132
|
-
const staticItems = props.items ?? []
|
|
126
|
+
const staticItems = () => props.items ?? []
|
|
127
|
+
const triggerText = () => props.triggerLabel ?? labels.trigger
|
|
128
|
+
const inputText = () => props.inputLabel ?? labels.input
|
|
133
129
|
|
|
134
130
|
const isOpen = props.open ?? signal(false)
|
|
135
131
|
const query = signal('')
|
|
136
132
|
const sourceItems = signal<CommandItem[]>([])
|
|
137
|
-
const activeIdx = signal(findFirstEnabledIndex(staticItems, isItemDisabled))
|
|
133
|
+
const activeIdx = signal(findFirstEnabledIndex(staticItems(), isItemDisabled))
|
|
138
134
|
let dialogEl: HTMLDialogElement | undefined
|
|
139
135
|
let inputEl: HTMLInputElement | undefined
|
|
140
136
|
|
|
141
137
|
const filtered = computed(() => {
|
|
142
|
-
const base = filterStaticItems(staticItems, query.value)
|
|
138
|
+
const base = filterStaticItems(staticItems(), query.value)
|
|
143
139
|
const remote = sourceItems.value
|
|
144
140
|
return remote.length ? (base.length ? [...base, ...remote] : remote) : base
|
|
145
141
|
})
|
|
146
142
|
|
|
147
|
-
const refreshSource = createSourceLoader(props.source, sourceItems, () => {
|
|
143
|
+
const refreshSource = createSourceLoader(() => props.source, sourceItems, () => {
|
|
148
144
|
activeIdx.value = findFirstEnabledIndex(filtered.value, isItemDisabled)
|
|
149
145
|
})
|
|
150
146
|
|
|
@@ -154,11 +150,13 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
154
150
|
return !isOpen.value || idx < 0 || idx >= list.length || list[idx]?.disabled ? undefined : optionId(idx)
|
|
155
151
|
}
|
|
156
152
|
|
|
157
|
-
const statusText = () => isOpen.value
|
|
153
|
+
const statusText = () => isOpen.value
|
|
154
|
+
? countLabel(filtered.value.length, props.noResultsLabel ?? labels.noResults, props.resultLabel ?? labels.result, props.resultsLabel ?? labels.results)
|
|
155
|
+
: ''
|
|
158
156
|
|
|
159
157
|
const onOpened = () => {
|
|
160
158
|
query.value = ''
|
|
161
|
-
activeIdx.value = findFirstEnabledIndex(staticItems, isItemDisabled)
|
|
159
|
+
activeIdx.value = findFirstEnabledIndex(staticItems(), isItemDisabled)
|
|
162
160
|
refreshSource('')
|
|
163
161
|
queueMicrotask(() => inputEl?.focus())
|
|
164
162
|
}
|
|
@@ -171,7 +169,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
171
169
|
|
|
172
170
|
return (
|
|
173
171
|
<div data-ui="command-root" data-state={isOpen.value ? 'open' : 'closed'}>
|
|
174
|
-
{
|
|
172
|
+
{triggerText() && (
|
|
175
173
|
<button
|
|
176
174
|
data-ui="button"
|
|
177
175
|
data-variant="outline"
|
|
@@ -182,14 +180,14 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
182
180
|
aria-expanded={isOpen.value ? 'true' : 'false'}
|
|
183
181
|
onClick={() => { isOpen.value = true }}
|
|
184
182
|
>
|
|
185
|
-
{
|
|
183
|
+
{triggerText()}
|
|
186
184
|
</button>
|
|
187
185
|
)}
|
|
188
186
|
<dialog
|
|
189
187
|
data-ui="command"
|
|
190
188
|
data-part="content"
|
|
191
|
-
aria-label={ariaLabel}
|
|
192
|
-
aria-keyshortcuts={
|
|
189
|
+
aria-label={props.ariaLabel ?? labels.palette}
|
|
190
|
+
aria-keyshortcuts={triggerText() ? undefined : keyShortcuts}
|
|
193
191
|
ref={(el) => {
|
|
194
192
|
dialogEl = el
|
|
195
193
|
syncDialogOpen(dialogEl, isOpen, isOpen.peek(), onOpened)
|
|
@@ -207,12 +205,12 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
207
205
|
data-part="input"
|
|
208
206
|
type="text"
|
|
209
207
|
role="combobox"
|
|
210
|
-
aria-label={
|
|
208
|
+
aria-label={inputText()}
|
|
211
209
|
aria-expanded={isOpen.value ? 'true' : 'false'}
|
|
212
210
|
aria-autocomplete="list"
|
|
213
211
|
aria-controls={filtered.value.length > 0 ? listId : undefined}
|
|
214
212
|
aria-activedescendant={activeOptionId()}
|
|
215
|
-
placeholder={placeholder}
|
|
213
|
+
placeholder={props.placeholder ?? labels.placeholder}
|
|
216
214
|
value={query.value}
|
|
217
215
|
onInput={(e) => {
|
|
218
216
|
const val = e.currentTarget.value
|
|
@@ -236,7 +234,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
236
234
|
</div>
|
|
237
235
|
{filtered.value.length > 0
|
|
238
236
|
? (
|
|
239
|
-
<div id={listId} data-part="list" role="listbox" aria-label={
|
|
237
|
+
<div id={listId} data-part="list" role="listbox" aria-label={inputText()}>
|
|
240
238
|
{filtered.value.map((item, idx) => (
|
|
241
239
|
<button
|
|
242
240
|
key={item.id}
|
|
@@ -263,9 +261,9 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
263
261
|
</div>
|
|
264
262
|
)
|
|
265
263
|
: (
|
|
266
|
-
<p data-part="empty">{emptyLabel}</p>
|
|
264
|
+
<p data-part="empty">{props.emptyLabel ?? labels.empty}</p>
|
|
267
265
|
)}
|
|
268
|
-
<div class="
|
|
266
|
+
<div class="pru-sr-only" role="status" aria-live="polite" aria-atomic="true">
|
|
269
267
|
{statusText()}
|
|
270
268
|
</div>
|
|
271
269
|
</div>
|
package/src/DataTable.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/** @jsxImportSource prunelle */
|
|
2
2
|
// Interactive DataTable island powered by headless `createDataTable()` signals (sort, filter, select, paginate).
|
|
3
3
|
|
|
4
|
+
import type { TableLabels } from './labels/table'
|
|
4
5
|
import type { DataTableState } from './table-state'
|
|
5
6
|
import { effect, signal } from 'prunelle'
|
|
6
|
-
import
|
|
7
|
+
import { tableLabels } from './labels/table'
|
|
7
8
|
import { createDataTable } from './table-state'
|
|
8
9
|
|
|
9
10
|
export interface DataTableColumn {
|
|
@@ -60,11 +61,11 @@ function checkedRows(rows: Row[], rowKey: string): Row[] {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
// When a pager button disables itself, focus moves to the other one instead of falling to <body>.
|
|
63
|
-
function Pager(
|
|
64
|
+
function Pager(props: { table: DataTableState<Row>, pageLabel: string, prevLabel: string, nextLabel: string }) {
|
|
64
65
|
const turn = (by: number, other: Element | null) => {
|
|
65
|
-
table.page.value += by
|
|
66
|
-
const page = table.page.peek()
|
|
67
|
-
const total = table.totalPages.peek()
|
|
66
|
+
props.table.page.value += by
|
|
67
|
+
const page = props.table.page.peek()
|
|
68
|
+
const total = props.table.totalPages.peek()
|
|
68
69
|
const atEnd = by < 0 ? page <= 1 : page >= total
|
|
69
70
|
const otherEnabled = by < 0 ? page < total : page > 1
|
|
70
71
|
if (atEnd && otherEnabled && other instanceof HTMLButtonElement) {
|
|
@@ -76,7 +77,7 @@ function Pager({ table, pageLabel, prevLabel, nextLabel }: { table: DataTableSta
|
|
|
76
77
|
return (
|
|
77
78
|
<div data-part="pagination" data-layout="split">
|
|
78
79
|
<span data-part="meta" role="status">
|
|
79
|
-
{`${pageLabel} ${table.page.value} / ${table.totalPages.value}`}
|
|
80
|
+
{`${props.pageLabel} ${props.table.page.value} / ${props.table.totalPages.value}`}
|
|
80
81
|
</span>
|
|
81
82
|
<div data-layout="cluster">
|
|
82
83
|
<button
|
|
@@ -84,59 +85,64 @@ function Pager({ table, pageLabel, prevLabel, nextLabel }: { table: DataTableSta
|
|
|
84
85
|
data-variant="outline"
|
|
85
86
|
data-size="sm"
|
|
86
87
|
type="button"
|
|
87
|
-
disabled={table.page.value <= 1}
|
|
88
|
+
disabled={props.table.page.value <= 1}
|
|
88
89
|
onClick={e => turn(-1, e.currentTarget.nextElementSibling)}
|
|
89
90
|
>
|
|
90
|
-
{prevLabel}
|
|
91
|
+
{props.prevLabel}
|
|
91
92
|
</button>
|
|
92
93
|
<button
|
|
93
94
|
data-ui="button"
|
|
94
95
|
data-variant="outline"
|
|
95
96
|
data-size="sm"
|
|
96
97
|
type="button"
|
|
97
|
-
disabled={table.page.value >= table.totalPages.value}
|
|
98
|
+
disabled={props.table.page.value >= props.table.totalPages.value}
|
|
98
99
|
onClick={e => turn(1, e.currentTarget.previousElementSibling)}
|
|
99
100
|
>
|
|
100
|
-
{nextLabel}
|
|
101
|
+
{props.nextLabel}
|
|
101
102
|
</button>
|
|
102
103
|
</div>
|
|
103
104
|
</div>
|
|
104
105
|
)
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
function TableToolbar(props: { table: DataTableState<Row>, dt: DataTableProps, labels: TableLabels }) {
|
|
109
|
+
return (
|
|
110
|
+
<div data-part="toolbar" data-layout="split">
|
|
111
|
+
<input
|
|
112
|
+
data-part="search"
|
|
113
|
+
type="search"
|
|
114
|
+
aria-label={props.dt.searchLabel ?? props.labels.search}
|
|
115
|
+
placeholder={props.dt.placeholder ?? props.labels.placeholder}
|
|
116
|
+
value={props.table.query.value}
|
|
117
|
+
onInput={(e) => {
|
|
118
|
+
props.table.query.value = e.currentTarget.value
|
|
119
|
+
props.table.page.value = 1
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
<span data-part="meta" role="status" aria-live="polite">
|
|
123
|
+
{`${props.table.filtered.value.length} ${props.dt.rowsLabel ?? props.labels.rows}${props.dt.selectable && props.table.selected.value.size > 0 ? ` · ${props.table.selected.value.size} ${props.dt.selectedLabel ?? props.labels.selected}` : ''}`}
|
|
124
|
+
</span>
|
|
125
|
+
</div>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
107
129
|
export function DataTable(props: DataTableProps) {
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const selectable = props.selectable ?? false
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const placeholder = props.placeholder ?? TABLE_LABELS.placeholder
|
|
114
|
-
const searchLabel = props.searchLabel ?? TABLE_LABELS.search
|
|
115
|
-
const selectColumnLabel = props.selectColumnLabel ?? TABLE_LABELS.selectColumn
|
|
116
|
-
const selectRowLabel = props.selectRowLabel ?? TABLE_LABELS.selectRow
|
|
117
|
-
const selectAllLabel = props.selectAllLabel ?? TABLE_LABELS.selectAll
|
|
118
|
-
const ascendingLabel = props.ascendingLabel ?? TABLE_LABELS.ascending
|
|
119
|
-
const descendingLabel = props.descendingLabel ?? TABLE_LABELS.descending
|
|
120
|
-
const rowsLabel = props.rowsLabel ?? TABLE_LABELS.rows
|
|
121
|
-
const selectedLabel = props.selectedLabel ?? TABLE_LABELS.selected
|
|
122
|
-
const pageLabel = props.pageLabel ?? TABLE_LABELS.page
|
|
123
|
-
const prevLabel = props.prevLabel ?? TABLE_LABELS.prev
|
|
124
|
-
const nextLabel = props.nextLabel ?? TABLE_LABELS.next
|
|
125
|
-
const emptyLabel = props.emptyLabel ?? TABLE_LABELS.empty
|
|
126
|
-
const columns = props.columns
|
|
127
|
-
const keyOf = (r: Row) => String(r[rowKey] ?? '')
|
|
128
|
-
const labelKey = props.rowLabelKey ?? columns[0]?.key ?? rowKey
|
|
130
|
+
const labels = tableLabels()
|
|
131
|
+
const rowKey = () => props.rowKey ?? 'id'
|
|
132
|
+
const selectable = () => props.selectable ?? false
|
|
133
|
+
const keyOf = (r: Row) => String(r[rowKey()] ?? '')
|
|
134
|
+
const labelKey = () => props.rowLabelKey ?? props.columns[0]?.key ?? rowKey()
|
|
129
135
|
const sortOf = (k: string) => (table.sortBy.value === k ? table.sortDir.value : undefined)
|
|
130
136
|
// What a sort just changed, for screen readers: aria-sort alone changes silently.
|
|
131
137
|
const said = signal('')
|
|
132
138
|
|
|
133
139
|
const table = createDataTable({
|
|
134
|
-
rows: () => checkedRows(props.rows, rowKey),
|
|
140
|
+
rows: () => checkedRows(props.rows, rowKey()),
|
|
135
141
|
getKey: keyOf,
|
|
136
|
-
locale
|
|
137
|
-
onSelect: props.onSelect,
|
|
138
|
-
pageSize
|
|
139
|
-
searchText: r => columns.map(c => String(r[c.key] ?? '')).join(' '),
|
|
142
|
+
get locale() { return props.locale },
|
|
143
|
+
onSelect: keys => props.onSelect?.(keys),
|
|
144
|
+
get pageSize() { return props.pageSize ?? 10 },
|
|
145
|
+
searchText: r => props.columns.map(c => String(r[c.key] ?? '')).join(' '),
|
|
140
146
|
})
|
|
141
147
|
// The header checkbox covers the rows the filter shows.
|
|
142
148
|
const shownKeys = () => table.filtered.value.map(keyOf)
|
|
@@ -145,36 +151,19 @@ export function DataTable(props: DataTableProps) {
|
|
|
145
151
|
|
|
146
152
|
return (
|
|
147
153
|
<div data-ui="datatable">
|
|
148
|
-
{searchable &&
|
|
149
|
-
<div data-part="toolbar" data-layout="split">
|
|
150
|
-
<input
|
|
151
|
-
data-part="search"
|
|
152
|
-
type="search"
|
|
153
|
-
aria-label={searchLabel}
|
|
154
|
-
placeholder={placeholder}
|
|
155
|
-
value={table.query.value}
|
|
156
|
-
onInput={(e) => {
|
|
157
|
-
table.query.value = e.currentTarget.value
|
|
158
|
-
table.page.value = 1
|
|
159
|
-
}}
|
|
160
|
-
/>
|
|
161
|
-
<span data-part="meta" role="status" aria-live="polite">
|
|
162
|
-
{`${table.filtered.value.length} ${rowsLabel}${selectable && table.selected.value.size > 0 ? ` · ${table.selected.value.size} ${selectedLabel}` : ''}`}
|
|
163
|
-
</span>
|
|
164
|
-
</div>
|
|
165
|
-
)}
|
|
154
|
+
{(props.searchable ?? true) && <TableToolbar table={table} dt={props} labels={labels} />}
|
|
166
155
|
|
|
167
156
|
<div data-part="scroll">
|
|
168
|
-
<table data-ui="table" aria-label={caption ? undefined : ariaLabel}>
|
|
169
|
-
{caption && <caption data-part="caption">{caption}</caption>}
|
|
157
|
+
<table data-ui="table" aria-label={props.caption ? undefined : props.ariaLabel}>
|
|
158
|
+
{props.caption && <caption data-part="caption">{props.caption}</caption>}
|
|
170
159
|
<thead>
|
|
171
160
|
<tr>
|
|
172
|
-
{selectable && (
|
|
161
|
+
{selectable() && (
|
|
173
162
|
<th scope="col" data-part="select-col">
|
|
174
|
-
<span class="
|
|
163
|
+
<span class="pru-sr-only">{props.selectColumnLabel ?? labels.selectColumn}</span>
|
|
175
164
|
<input
|
|
176
165
|
type="checkbox"
|
|
177
|
-
aria-label={selectAllLabel}
|
|
166
|
+
aria-label={props.selectAllLabel ?? labels.selectAll}
|
|
178
167
|
disabled={table.filtered.value.length === 0}
|
|
179
168
|
checked={allShownSelected()}
|
|
180
169
|
ref={(el: HTMLInputElement) => effect(() => { el.indeterminate = someShownSelected() && !allShownSelected() })}
|
|
@@ -182,7 +171,7 @@ export function DataTable(props: DataTableProps) {
|
|
|
182
171
|
/>
|
|
183
172
|
</th>
|
|
184
173
|
)}
|
|
185
|
-
{columns.map(col => (
|
|
174
|
+
{props.columns.map(col => (
|
|
186
175
|
<th
|
|
187
176
|
key={col.key}
|
|
188
177
|
scope="col"
|
|
@@ -196,7 +185,7 @@ export function DataTable(props: DataTableProps) {
|
|
|
196
185
|
data-active={sortOf(col.key) ? 'true' : undefined}
|
|
197
186
|
onClick={() => {
|
|
198
187
|
table.toggleSort(col.key)
|
|
199
|
-
said.value = `${col.label}, ${table.sortDir.peek() === 'asc' ? ascendingLabel : descendingLabel}`
|
|
188
|
+
said.value = `${col.label}, ${table.sortDir.peek() === 'asc' ? (props.ascendingLabel ?? labels.ascending) : (props.descendingLabel ?? labels.descending)}`
|
|
200
189
|
}}
|
|
201
190
|
>
|
|
202
191
|
{col.label}
|
|
@@ -212,24 +201,24 @@ export function DataTable(props: DataTableProps) {
|
|
|
212
201
|
{table.visible.value.length === 0
|
|
213
202
|
? (
|
|
214
203
|
<tr data-part="empty">
|
|
215
|
-
<td colspan={Math.max(1, columns.length + (selectable ? 1 : 0))}>
|
|
216
|
-
{emptyLabel}
|
|
204
|
+
<td colspan={Math.max(1, props.columns.length + (selectable() ? 1 : 0))}>
|
|
205
|
+
{props.emptyLabel ?? labels.empty}
|
|
217
206
|
</td>
|
|
218
207
|
</tr>
|
|
219
208
|
)
|
|
220
209
|
: table.visible.value.map(row => (
|
|
221
210
|
<tr key={keyOf(row)} data-selected={table.isSelected(keyOf(row)) ? 'true' : undefined}>
|
|
222
|
-
{selectable && (
|
|
211
|
+
{selectable() && (
|
|
223
212
|
<td data-part="select-col">
|
|
224
213
|
<input
|
|
225
214
|
type="checkbox"
|
|
226
215
|
checked={table.isSelected(keyOf(row))}
|
|
227
|
-
aria-label={`${selectRowLabel} ${String(row[labelKey] ?? keyOf(row))}`}
|
|
216
|
+
aria-label={`${props.selectRowLabel ?? labels.selectRow} ${String(row[labelKey()] ?? keyOf(row))}`}
|
|
228
217
|
onChange={() => table.toggleSelect(keyOf(row))}
|
|
229
218
|
/>
|
|
230
219
|
</td>
|
|
231
220
|
)}
|
|
232
|
-
{columns.map(col => (
|
|
221
|
+
{props.columns.map(col => (
|
|
233
222
|
<td key={col.key}>{String(row[col.key] ?? '')}</td>
|
|
234
223
|
))}
|
|
235
224
|
</tr>
|
|
@@ -238,8 +227,15 @@ export function DataTable(props: DataTableProps) {
|
|
|
238
227
|
</table>
|
|
239
228
|
</div>
|
|
240
229
|
|
|
241
|
-
{table.totalPages.value > 1 &&
|
|
242
|
-
|
|
230
|
+
{table.totalPages.value > 1 && (
|
|
231
|
+
<Pager
|
|
232
|
+
table={table}
|
|
233
|
+
pageLabel={props.pageLabel ?? labels.page}
|
|
234
|
+
prevLabel={props.prevLabel ?? labels.prev}
|
|
235
|
+
nextLabel={props.nextLabel ?? labels.next}
|
|
236
|
+
/>
|
|
237
|
+
)}
|
|
238
|
+
<span data-part="announce" class="pru-sr-only" role="status">{said.value}</span>
|
|
243
239
|
</div>
|
|
244
240
|
)
|
|
245
241
|
}
|
package/src/Dialog.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import type { PrunelleChild, Signal } from 'prunelle'
|
|
|
6
6
|
import type { ButtonVariant } from './static'
|
|
7
7
|
import { effect } from 'prunelle'
|
|
8
8
|
import { nextUiId, syncDialogOpen } from './behaviors'
|
|
9
|
-
import
|
|
9
|
+
import { dialogLabels } from './labels/dialog'
|
|
10
10
|
|
|
11
11
|
export interface DialogProps {
|
|
12
12
|
id?: string | undefined
|
|
@@ -44,11 +44,12 @@ interface DialogIds {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function dialogIds(props: Shared, kind: Kind): DialogIds {
|
|
47
|
-
const baseId = props.id ?? nextUiId(`
|
|
47
|
+
const baseId = props.id ?? nextUiId(`pru-${kind}`)
|
|
48
48
|
return { baseId, titleId: `${baseId}-title`, descId: `${baseId}-desc` }
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function dialogAttrs(props: Shared, kind: Kind, ids: DialogIds) {
|
|
52
|
+
const labels = dialogLabels()
|
|
52
53
|
return {
|
|
53
54
|
'id': ids.baseId,
|
|
54
55
|
'closedby': 'any' as const,
|
|
@@ -56,7 +57,7 @@ function dialogAttrs(props: Shared, kind: Kind, ids: DialogIds) {
|
|
|
56
57
|
'data-side': kind === 'drawer' ? (props.side ?? 'right') : undefined,
|
|
57
58
|
'data-part': 'content',
|
|
58
59
|
'aria-labelledby': props.title ? ids.titleId : undefined,
|
|
59
|
-
'aria-label': !props.title ? (props.ariaLabel ?? (kind === 'drawer' ?
|
|
60
|
+
'aria-label': !props.title ? (props.ariaLabel ?? (kind === 'drawer' ? labels.drawer : labels.dialog)) : undefined,
|
|
60
61
|
'aria-describedby': props.description ? ids.descId : undefined,
|
|
61
62
|
}
|
|
62
63
|
}
|
|
@@ -70,7 +71,7 @@ function closeButtonAttrs(dialog: Shared, ids: DialogIds) {
|
|
|
70
71
|
'type': 'button' as const,
|
|
71
72
|
'commandfor': ids.baseId,
|
|
72
73
|
'command': 'close' as const,
|
|
73
|
-
'aria-label': dialog.closeLabel ??
|
|
74
|
+
'aria-label': dialog.closeLabel ?? dialogLabels().close,
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
package/src/Menu.tsx
CHANGED
|
@@ -21,12 +21,10 @@ export interface MenuProps {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function Menu(props: MenuProps) {
|
|
24
|
-
const baseId = props.id ?? nextUiId('
|
|
24
|
+
const baseId = props.id ?? nextUiId('pru-menu')
|
|
25
25
|
const triggerId = `${baseId}-trigger`
|
|
26
26
|
const menuId = `${baseId}-menu`
|
|
27
27
|
const itemId = (idx: number) => `${baseId}-item-${idx}`
|
|
28
|
-
const variant = props.variant ?? 'outline'
|
|
29
|
-
const label = props.label
|
|
30
28
|
|
|
31
29
|
const activate = (item: MenuItemDef, navigateHref: boolean) => {
|
|
32
30
|
if (item.disabled)
|
|
@@ -56,7 +54,7 @@ export function Menu(props: MenuProps) {
|
|
|
56
54
|
<button
|
|
57
55
|
id={triggerId}
|
|
58
56
|
data-ui="button"
|
|
59
|
-
data-variant={variant}
|
|
57
|
+
data-variant={props.variant ?? 'outline'}
|
|
60
58
|
data-part="trigger"
|
|
61
59
|
type="button"
|
|
62
60
|
aria-haspopup="menu"
|
|
@@ -65,7 +63,7 @@ export function Menu(props: MenuProps) {
|
|
|
65
63
|
onClick={e => popup.toggle(e)}
|
|
66
64
|
onKeyDown={e => popup.onTriggerKeyDown(e)}
|
|
67
65
|
>
|
|
68
|
-
{label}
|
|
66
|
+
{props.label}
|
|
69
67
|
</button>
|
|
70
68
|
{popup.open.value && (
|
|
71
69
|
<div
|
package/src/Select.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** @jsxImportSource prunelle */
|
|
2
|
-
// Accessible custom Select (listbox) primitive with aria-activedescendant navigation
|
|
2
|
+
// Accessible custom Select (listbox) primitive with aria-activedescendant navigation. It renders a native <select> first, so a form posts the choice without JS, and keeps it as the hidden field once mounted.
|
|
3
3
|
|
|
4
4
|
import type { Signal } from 'prunelle'
|
|
5
5
|
import { onMount, signal } from 'prunelle'
|
|
6
6
|
import { createListPopup, nextUiId, useFieldContext } from './behaviors'
|
|
7
|
-
import
|
|
7
|
+
import { selectLabels } from './labels/select'
|
|
8
8
|
|
|
9
9
|
export interface SelectOption {
|
|
10
10
|
value: string
|
|
@@ -25,16 +25,18 @@ export interface SelectProps {
|
|
|
25
25
|
|
|
26
26
|
export function Select(props: SelectProps) {
|
|
27
27
|
const field = useFieldContext()
|
|
28
|
-
const
|
|
28
|
+
const labels = selectLabels()
|
|
29
|
+
const baseId = props.id ?? field?.id ?? nextUiId('pru-select')
|
|
29
30
|
const triggerId = signal(props.id ?? field?.id ?? `${baseId}-trigger`)
|
|
31
|
+
const describedBy = signal(field?.describedBy)
|
|
32
|
+
const invalid = signal(field?.invalid ?? false)
|
|
33
|
+
const required = signal(field?.required ?? false)
|
|
30
34
|
const listboxId = `${baseId}-listbox`
|
|
31
35
|
const optionId = (idx: number) => `${baseId}-opt-${idx}`
|
|
32
|
-
const
|
|
33
|
-
const placeholder = props.placeholder ?? SELECT_LABELS.placeholder
|
|
34
|
-
const ariaLabel = props.ariaLabel
|
|
36
|
+
const placeholder = () => props.placeholder ?? labels.placeholder
|
|
35
37
|
|
|
36
38
|
const selected = props.value ?? signal(props.defaultValue ?? '')
|
|
37
|
-
const currentLabel = () => props.options.find(o => o.value === selected.value)?.label ?? placeholder
|
|
39
|
+
const currentLabel = () => props.options.find(o => o.value === selected.value)?.label ?? placeholder()
|
|
38
40
|
|
|
39
41
|
const pick = (opt: SelectOption) => {
|
|
40
42
|
if (opt.disabled)
|
|
@@ -60,7 +62,29 @@ export function Select(props: SelectProps) {
|
|
|
60
62
|
if (labelFor)
|
|
61
63
|
triggerId.value = labelFor
|
|
62
64
|
}
|
|
63
|
-
|
|
65
|
+
// Until the island mounts, the native <select> is the control, so a page with JS off or still loading posts the user's choice.
|
|
66
|
+
const enhanced = signal(false)
|
|
67
|
+
let nativeEl: HTMLSelectElement | undefined
|
|
68
|
+
onMount(() => {
|
|
69
|
+
syncFieldLabel(rootEl)
|
|
70
|
+
if (nativeEl) {
|
|
71
|
+
if (nativeEl.value !== selected.value)
|
|
72
|
+
selected.value = nativeEl.value // a choice made before the island mounted
|
|
73
|
+
if (!field) {
|
|
74
|
+
const desc = nativeEl.getAttribute('aria-describedby')
|
|
75
|
+
if (desc)
|
|
76
|
+
describedBy.value = desc
|
|
77
|
+
if (nativeEl.getAttribute('aria-invalid') === 'true')
|
|
78
|
+
invalid.value = true
|
|
79
|
+
if (nativeEl.hasAttribute('required') || nativeEl.getAttribute('aria-required') === 'true')
|
|
80
|
+
required.value = true
|
|
81
|
+
}
|
|
82
|
+
// The select turns into a hidden form field: a hidden `required` control would block the submit without a message.
|
|
83
|
+
nativeEl.removeAttribute('required')
|
|
84
|
+
}
|
|
85
|
+
enhanced.value = true
|
|
86
|
+
})
|
|
87
|
+
const hasEmptyOption = () => props.options.some(o => o.value === '')
|
|
64
88
|
|
|
65
89
|
return (
|
|
66
90
|
<div
|
|
@@ -72,13 +96,16 @@ export function Select(props: SelectProps) {
|
|
|
72
96
|
syncFieldLabel(el)
|
|
73
97
|
}}
|
|
74
98
|
>
|
|
75
|
-
{name && <input type="hidden" name={name} value={selected.value} />}
|
|
76
99
|
<button
|
|
77
|
-
id={triggerId.value}
|
|
100
|
+
id={enhanced.value ? triggerId.value : undefined}
|
|
101
|
+
hidden={!enhanced.value}
|
|
78
102
|
data-part="trigger"
|
|
79
103
|
type="button"
|
|
80
104
|
role="combobox"
|
|
81
|
-
aria-label={ariaLabel}
|
|
105
|
+
aria-label={props.ariaLabel}
|
|
106
|
+
aria-describedby={describedBy.value}
|
|
107
|
+
aria-invalid={invalid.value ? 'true' : undefined}
|
|
108
|
+
aria-required={required.value ? 'true' : undefined}
|
|
82
109
|
aria-haspopup="listbox"
|
|
83
110
|
aria-expanded={popup.open.value ? 'true' : 'false'}
|
|
84
111
|
aria-controls={popup.open.value ? listboxId : undefined}
|
|
@@ -94,8 +121,8 @@ export function Select(props: SelectProps) {
|
|
|
94
121
|
id={listboxId}
|
|
95
122
|
data-part="listbox"
|
|
96
123
|
role="listbox"
|
|
97
|
-
aria-label={ariaLabel}
|
|
98
|
-
aria-labelledby={ariaLabel ? undefined : triggerId.value}
|
|
124
|
+
aria-label={props.ariaLabel}
|
|
125
|
+
aria-labelledby={props.ariaLabel ? undefined : triggerId.value}
|
|
99
126
|
popover="auto"
|
|
100
127
|
ref={popup.mountPopup}
|
|
101
128
|
>
|
|
@@ -120,6 +147,18 @@ export function Select(props: SelectProps) {
|
|
|
120
147
|
))}
|
|
121
148
|
</div>
|
|
122
149
|
)}
|
|
150
|
+
<select
|
|
151
|
+
id={enhanced.value ? undefined : triggerId.value}
|
|
152
|
+
hidden={enhanced.value}
|
|
153
|
+
name={props.name}
|
|
154
|
+
aria-label={props.ariaLabel}
|
|
155
|
+
ref={(el) => { nativeEl = el }}
|
|
156
|
+
>
|
|
157
|
+
{!hasEmptyOption() && <option value="" selected={selected.value === ''}>{placeholder()}</option>}
|
|
158
|
+
{props.options.map(opt => (
|
|
159
|
+
<option key={opt.value} value={opt.value} disabled={opt.disabled} selected={selected.value === opt.value}>{opt.label}</option>
|
|
160
|
+
))}
|
|
161
|
+
</select>
|
|
123
162
|
</div>
|
|
124
163
|
)
|
|
125
164
|
}
|