@prunellejs/ui 0.7.4 → 0.8.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 +2 -2
- package/package.json +2 -2
- package/src/CommandPalette.tsx +22 -9
- package/src/Select.tsx +27 -4
- package/src/styles/components/command.css +14 -2
- package/src/styles/components/select.css +1 -0
- package/src/styles/grammars/orbit.css +1 -1
- package/src/styles/grammars/soft.css +1 -1
- package/src/styles/themed/command.css +1 -0
package/llms.txt
CHANGED
|
@@ -48,8 +48,8 @@ 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`.
|
|
52
|
-
- `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).
|
|
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
|
+
- `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.
|
|
55
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.8.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/CommandPalette.tsx
CHANGED
|
@@ -79,7 +79,8 @@ function createSourceLoader(
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
// Returns the shortcut as `aria-keyshortcuts` names it: on the trigger (the dialog without one) for screen readers, and so an `interaction` island hydrates on the shortcut itself.
|
|
83
|
+
function bindPaletteShortcut(shortcutKey: string, isOpen: Signal<boolean>): string {
|
|
83
84
|
onMount(() => {
|
|
84
85
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
85
86
|
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcutKey) {
|
|
@@ -90,6 +91,20 @@ function bindPaletteShortcut(shortcutKey: string, isOpen: Signal<boolean>): void
|
|
|
90
91
|
window.addEventListener('keydown', onKeyDown)
|
|
91
92
|
return () => window.removeEventListener('keydown', onKeyDown)
|
|
92
93
|
})
|
|
94
|
+
const key = shortcutKey.toUpperCase()
|
|
95
|
+
return `Control+${key} Meta+${key}`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function keepActiveInView(isOpen: Signal<boolean>, activeIdx: Signal<number>, option: (idx: number) => Element | null | undefined): void {
|
|
99
|
+
effect(() => {
|
|
100
|
+
const idx = activeIdx.value
|
|
101
|
+
if (isOpen.value && idx >= 0)
|
|
102
|
+
option(idx)?.scrollIntoView({ block: 'nearest' })
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function countLabel(n: number, none: string, one: string, many: string): string {
|
|
107
|
+
return n === 0 ? none : n === 1 ? `1 ${one}` : `${n} ${many}`
|
|
93
108
|
}
|
|
94
109
|
|
|
95
110
|
function selectCommandItem(item: CommandItem, isOpen: Signal<boolean>, onSelect?: (id: string) => void): void {
|
|
@@ -139,12 +154,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
139
154
|
return !isOpen.value || idx < 0 || idx >= list.length || list[idx]?.disabled ? undefined : optionId(idx)
|
|
140
155
|
}
|
|
141
156
|
|
|
142
|
-
const statusText = () =>
|
|
143
|
-
if (!isOpen.value)
|
|
144
|
-
return ''
|
|
145
|
-
const n = filtered.value.length
|
|
146
|
-
return n === 0 ? noResultsLabel : n === 1 ? `1 ${resultLabel}` : `${n} ${resultsLabel}`
|
|
147
|
-
}
|
|
157
|
+
const statusText = () => isOpen.value ? countLabel(filtered.value.length, noResultsLabel, resultLabel, resultsLabel) : ''
|
|
148
158
|
|
|
149
159
|
const onOpened = () => {
|
|
150
160
|
query.value = ''
|
|
@@ -153,8 +163,9 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
153
163
|
queueMicrotask(() => inputEl?.focus())
|
|
154
164
|
}
|
|
155
165
|
|
|
156
|
-
bindPaletteShortcut((props.shortcutKey ?? 'k').toLowerCase(), isOpen)
|
|
166
|
+
const keyShortcuts = bindPaletteShortcut((props.shortcutKey ?? 'k').toLowerCase(), isOpen)
|
|
157
167
|
effect(() => { syncDialogOpen(dialogEl, isOpen, isOpen.value, onOpened) })
|
|
168
|
+
keepActiveInView(isOpen, activeIdx, idx => dialogEl?.ownerDocument.getElementById(optionId(idx)))
|
|
158
169
|
|
|
159
170
|
const runItem = (item: CommandItem) => selectCommandItem(item, isOpen, props.onSelect)
|
|
160
171
|
|
|
@@ -167,6 +178,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
167
178
|
data-part="trigger"
|
|
168
179
|
type="button"
|
|
169
180
|
aria-haspopup="dialog"
|
|
181
|
+
aria-keyshortcuts={keyShortcuts}
|
|
170
182
|
aria-expanded={isOpen.value ? 'true' : 'false'}
|
|
171
183
|
onClick={() => { isOpen.value = true }}
|
|
172
184
|
>
|
|
@@ -177,6 +189,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
177
189
|
data-ui="command"
|
|
178
190
|
data-part="content"
|
|
179
191
|
aria-label={ariaLabel}
|
|
192
|
+
aria-keyshortcuts={triggerLabel ? undefined : keyShortcuts}
|
|
180
193
|
ref={(el) => {
|
|
181
194
|
dialogEl = el
|
|
182
195
|
syncDialogOpen(dialogEl, isOpen, isOpen.peek(), onOpened)
|
|
@@ -192,7 +205,7 @@ export function CommandPalette(props: CommandPaletteProps) {
|
|
|
192
205
|
<input
|
|
193
206
|
ref={(el) => { inputEl = el }}
|
|
194
207
|
data-part="input"
|
|
195
|
-
type="
|
|
208
|
+
type="text"
|
|
196
209
|
role="combobox"
|
|
197
210
|
aria-label={inputLabel}
|
|
198
211
|
aria-expanded={isOpen.value ? 'true' : 'false'}
|
package/src/Select.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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'
|
|
@@ -60,7 +60,18 @@ export function Select(props: SelectProps) {
|
|
|
60
60
|
if (labelFor)
|
|
61
61
|
triggerId.value = labelFor
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
// Until the island mounts, the native <select> is the control, so a page with JS off or still loading posts the user's choice.
|
|
64
|
+
const enhanced = signal(false)
|
|
65
|
+
let nativeEl: HTMLSelectElement | undefined
|
|
66
|
+
onMount(() => {
|
|
67
|
+
syncFieldLabel(rootEl)
|
|
68
|
+
if (nativeEl && nativeEl.value !== selected.value)
|
|
69
|
+
selected.value = nativeEl.value // a choice made before the island mounted
|
|
70
|
+
// The select turns into a hidden form field: a hidden `required` control would block the submit without a message.
|
|
71
|
+
nativeEl?.removeAttribute('required')
|
|
72
|
+
enhanced.value = true
|
|
73
|
+
})
|
|
74
|
+
const hasEmptyOption = props.options.some(o => o.value === '')
|
|
64
75
|
|
|
65
76
|
return (
|
|
66
77
|
<div
|
|
@@ -72,9 +83,9 @@ export function Select(props: SelectProps) {
|
|
|
72
83
|
syncFieldLabel(el)
|
|
73
84
|
}}
|
|
74
85
|
>
|
|
75
|
-
{name && <input type="hidden" name={name} value={selected.value} />}
|
|
76
86
|
<button
|
|
77
|
-
id={triggerId.value}
|
|
87
|
+
id={enhanced.value ? triggerId.value : undefined}
|
|
88
|
+
hidden={!enhanced.value}
|
|
78
89
|
data-part="trigger"
|
|
79
90
|
type="button"
|
|
80
91
|
role="combobox"
|
|
@@ -120,6 +131,18 @@ export function Select(props: SelectProps) {
|
|
|
120
131
|
))}
|
|
121
132
|
</div>
|
|
122
133
|
)}
|
|
134
|
+
<select
|
|
135
|
+
id={enhanced.value ? undefined : triggerId.value}
|
|
136
|
+
hidden={enhanced.value}
|
|
137
|
+
name={name}
|
|
138
|
+
aria-label={ariaLabel}
|
|
139
|
+
ref={(el) => { nativeEl = el }}
|
|
140
|
+
>
|
|
141
|
+
{!hasEmptyOption && <option value="" selected={selected.value === ''}>{placeholder}</option>}
|
|
142
|
+
{props.options.map(opt => (
|
|
143
|
+
<option key={opt.value} value={opt.value} disabled={opt.disabled} selected={selected.value === opt.value}>{opt.label}</option>
|
|
144
|
+
))}
|
|
145
|
+
</select>
|
|
123
146
|
</div>
|
|
124
147
|
)
|
|
125
148
|
}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
@layer kui {
|
|
2
2
|
html:has(dialog[data-ui]:modal) { overflow: hidden; }
|
|
3
|
+
/* The palette ends 1rem above the viewport's bottom; the input stays put and only the results scroll. */
|
|
3
4
|
dialog[data-ui="command"] {
|
|
4
5
|
padding: 0;
|
|
5
6
|
margin: auto;
|
|
6
7
|
max-inline-size: min(32rem, calc(100vw - 2rem));
|
|
7
|
-
max-block-size: calc(100dvh -
|
|
8
|
-
overflow:
|
|
8
|
+
max-block-size: calc(100dvh - min(14vh, 6rem) - 1rem);
|
|
9
|
+
overflow: hidden;
|
|
9
10
|
inline-size: min(34rem, calc(100vw - 2rem));
|
|
10
11
|
margin-block-start: min(14vh, 6rem);
|
|
11
12
|
}
|
|
13
|
+
dialog[data-ui="command"][open],
|
|
14
|
+
dialog[data-ui="command"] [data-part="panel"] {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
min-block-size: 0;
|
|
18
|
+
}
|
|
19
|
+
dialog[data-ui="command"] [data-part="list"] {
|
|
20
|
+
min-block-size: 0;
|
|
21
|
+
overflow-y: auto;
|
|
22
|
+
overscroll-behavior: contain;
|
|
23
|
+
}
|
|
12
24
|
dialog[data-ui="command"]::backdrop { background: rgb(0 0 0 / 0.45); }
|
|
13
25
|
dialog[data-ui="command"] [data-part="input"] {
|
|
14
26
|
width: 100%;
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
--ui-btn-sm-pad: 0.36rem 0.65rem;
|
|
119
119
|
--ui-btn-lg-fs: 0.92rem;
|
|
120
120
|
--ui-btn-lg-pad: 0.68rem 1.2rem;
|
|
121
|
-
&:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-surface-strong); border-color: color-mix(in srgb, var(--ui-accent) 55%, var(--ui-line-strong)); }
|
|
121
|
+
&:hover:not(:disabled, [aria-disabled="true"], [data-tone]) { background: var(--ui-surface-strong); border-color: color-mix(in srgb, var(--ui-accent) 55%, var(--ui-line-strong)); }
|
|
122
122
|
&[data-variant="ghost"] { color: var(--ui-subtext); &:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-surface); color: var(--ui-ink); border-color: var(--ui-line); } }
|
|
123
123
|
&[data-tone="accent"] { font-weight: 600; &:hover:not(:disabled, [aria-disabled="true"]) { filter: brightness(1.06); } }
|
|
124
124
|
&[data-tone="danger"] { background: color-mix(in srgb, var(--ui-danger) 12%, var(--ui-surface)); border-color: color-mix(in srgb, var(--ui-danger) 55%, transparent); color: var(--ui-danger); &:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-danger); border-color: var(--ui-danger); color: var(--ui-on-accent); } }
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
--ui-btn-r: var(--ui-pill);
|
|
30
30
|
--ui-btn-bd: 0;
|
|
31
31
|
--ui-btn-bg: var(--ui-surface-2);
|
|
32
|
-
&:hover:not(:disabled, [aria-disabled="true"]) { background: color-mix(in srgb, var(--ui-ink) 12%, var(--ui-surface-2)); }
|
|
32
|
+
&:hover:not(:disabled, [aria-disabled="true"], [data-tone]) { background: color-mix(in srgb, var(--ui-ink) 12%, var(--ui-surface-2)); }
|
|
33
33
|
&:active:not(:disabled, [aria-disabled="true"]) { transform: scale(0.98); }
|
|
34
34
|
&[data-tone="accent"]:hover:not(:disabled, [aria-disabled="true"]), &[data-tone="danger"]:hover:not(:disabled, [aria-disabled="true"]) { filter: brightness(1.06); }
|
|
35
35
|
&[data-variant="outline"] { box-shadow: inset 0 0 0 1.5px var(--ui-line-strong); }
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
font: var(--ui-cmd-mf, 500 0.88rem/1.3 var(--ui-font-body));
|
|
28
28
|
&[data-highlighted="true"] { background: var(--ui-cmd-hbg, var(--ui-surface)); color: var(--ui-cmd-hfg, inherit); box-shadow: var(--ui-cmd-hind, inset 2px 0 0 var(--ui-accent)); }
|
|
29
29
|
}
|
|
30
|
+
& [data-part="item-description"] { font-size: 0.74rem; color: var(--ui-muted); }
|
|
30
31
|
& [data-part="kbd"] { font-size: 0.74rem; color: var(--ui-muted); border: 1px solid var(--ui-line); border-radius: var(--ui-radius-inner, 0); padding: 0.1rem 0.35rem; }
|
|
31
32
|
& [data-part="empty"] { padding: 0.9rem 1rem; margin: 0; color: var(--ui-muted); }
|
|
32
33
|
}
|