@prunellejs/ui 0.8.0 → 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.
Files changed (81) hide show
  1. package/llms.txt +4 -4
  2. package/package.json +3 -3
  3. package/src/CommandPalette.tsx +27 -29
  4. package/src/DataTable.tsx +64 -68
  5. package/src/Dialog.tsx +5 -4
  6. package/src/Menu.tsx +3 -5
  7. package/src/Select.tsx +33 -17
  8. package/src/Tabs.tsx +8 -9
  9. package/src/Toaster.tsx +4 -3
  10. package/src/labels/dialog.ts +7 -3
  11. package/src/labels/en/dialog.ts +11 -0
  12. package/src/labels/en/palette.ts +21 -0
  13. package/src/labels/en/select.ts +7 -0
  14. package/src/labels/en/table.ts +31 -0
  15. package/src/labels/en/toaster.ts +7 -0
  16. package/src/labels/fr/dialog.ts +7 -3
  17. package/src/labels/fr/palette.ts +12 -8
  18. package/src/labels/fr/select.ts +5 -1
  19. package/src/labels/fr/table.ts +17 -13
  20. package/src/labels/fr/toaster.ts +5 -1
  21. package/src/labels/palette.ts +7 -8
  22. package/src/labels/select.ts +7 -1
  23. package/src/labels/table.ts +7 -13
  24. package/src/labels/toaster.ts +7 -1
  25. package/src/locale.ts +15 -0
  26. package/src/platform-fallback.ts +7 -5
  27. package/src/plugin.ts +29 -10
  28. package/src/primitives.tsx +40 -41
  29. package/src/static.tsx +56 -10
  30. package/src/styles/bare.css +1 -1
  31. package/src/styles/base.css +3 -3
  32. package/src/styles/components/accordion.css +1 -1
  33. package/src/styles/components/badge.css +1 -1
  34. package/src/styles/components/button.css +1 -1
  35. package/src/styles/components/card.css +1 -1
  36. package/src/styles/components/checkbox.css +1 -1
  37. package/src/styles/components/command.css +1 -1
  38. package/src/styles/components/consent.css +1 -1
  39. package/src/styles/components/datatable.css +1 -1
  40. package/src/styles/components/dialog.css +1 -1
  41. package/src/styles/components/drawer.css +1 -1
  42. package/src/styles/components/field.css +1 -1
  43. package/src/styles/components/layout.css +1 -8
  44. package/src/styles/components/menu.css +1 -1
  45. package/src/styles/components/notice.css +1 -1
  46. package/src/styles/components/popover.css +1 -1
  47. package/src/styles/components/progress.css +1 -1
  48. package/src/styles/components/radio-group.css +1 -1
  49. package/src/styles/components/select.css +1 -1
  50. package/src/styles/components/switch.css +1 -1
  51. package/src/styles/components/tabs.css +1 -1
  52. package/src/styles/components/toast.css +1 -1
  53. package/src/styles/grammars/console.css +1 -1
  54. package/src/styles/grammars/editorial.css +1 -1
  55. package/src/styles/grammars/orbit.css +1 -1
  56. package/src/styles/grammars/prunelle.css +1 -1
  57. package/src/styles/grammars/soft.css +1 -1
  58. package/src/styles/grammars/workshop.css +1 -1
  59. package/src/styles/scan.ts +1 -0
  60. package/src/styles/split.ts +10 -10
  61. package/src/styles/theme.css +1 -1
  62. package/src/styles/themed/accordion.css +1 -1
  63. package/src/styles/themed/badge.css +1 -1
  64. package/src/styles/themed/button.css +1 -1
  65. package/src/styles/themed/card.css +1 -1
  66. package/src/styles/themed/checkbox.css +1 -1
  67. package/src/styles/themed/command.css +1 -1
  68. package/src/styles/themed/consent.css +1 -1
  69. package/src/styles/themed/datatable.css +1 -1
  70. package/src/styles/themed/dialog.css +1 -1
  71. package/src/styles/themed/drawer.css +1 -1
  72. package/src/styles/themed/field.css +1 -1
  73. package/src/styles/themed/menu.css +1 -1
  74. package/src/styles/themed/notice.css +1 -1
  75. package/src/styles/themed/popover.css +1 -1
  76. package/src/styles/themed/radio-group.css +1 -1
  77. package/src/styles/themed/select.css +1 -1
  78. package/src/styles/themed/switch.css +1 -1
  79. package/src/styles/themed/tabs.css +1 -1
  80. package/src/styles/themed/toast.css +1 -1
  81. 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 kui` Style Grammars (`0 KB` JS for static primitives; islands only for interactive widgets).
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`: French for `'fr'` or `'fr-*'`, English otherwise. Each label prop overrides them; an app with several locales passes them for the locales other than `lang`.
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 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
+ - 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>` and `<ConsentPreferences>` are styled by the `consent` part, 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.
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prunellejs/ui",
3
- "version": "0.8.0",
4
- "description": "Platform-first headless UI primitives and pure CSS @layer kui Style Grammars for Prunelle",
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.8.0"
32
+ "prunelle": "^0.9.0"
33
33
  }
34
34
  }
@@ -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 * as PALETTE_LABELS from './labels/palette'
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
- source: CommandSource | undefined,
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 baseId = props.id ?? nextUiId('kui-cmd')
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 placeholder = props.placeholder ?? PALETTE_LABELS.placeholder
125
- const inputLabel = props.inputLabel ?? PALETTE_LABELS.input
126
- const ariaLabel = props.ariaLabel ?? PALETTE_LABELS.palette
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 ? countLabel(filtered.value.length, noResultsLabel, resultLabel, resultsLabel) : ''
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
- {triggerLabel && (
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
- {triggerLabel}
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={triggerLabel ? undefined : 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={inputLabel}
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={inputLabel}>
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="kui-sr-only" role="status" aria-live="polite" aria-atomic="true">
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 * as TABLE_LABELS from './labels/table'
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({ table, pageLabel, prevLabel, nextLabel }: { table: DataTableState<Row>, pageLabel: string, prevLabel: string, nextLabel: string }) {
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 rowKey = props.rowKey ?? 'id'
109
- const searchable = props.searchable ?? true
110
- const selectable = props.selectable ?? false
111
- const caption = props.caption
112
- const ariaLabel = props.ariaLabel
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: props.locale,
137
- onSelect: props.onSelect,
138
- pageSize: props.pageSize ?? 10,
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="kui-sr-only">{selectColumnLabel}</span>
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 && <Pager table={table} pageLabel={pageLabel} prevLabel={prevLabel} nextLabel={nextLabel} />}
242
- <span data-part="announce" class="kui-sr-only" role="status">{said.value}</span>
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 * as DIALOG_LABELS from './labels/dialog'
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(`kui-${kind}`)
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' ? DIALOG_LABELS.drawer : DIALOG_LABELS.dialog)) : undefined,
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 ?? DIALOG_LABELS.close,
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('kui-menu')
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
@@ -4,7 +4,7 @@
4
4
  import type { Signal } from 'prunelle'
5
5
  import { onMount, signal } from 'prunelle'
6
6
  import { createListPopup, nextUiId, useFieldContext } from './behaviors'
7
- import * as SELECT_LABELS from './labels/select'
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 baseId = props.id ?? field?.id ?? nextUiId('kui-select')
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 name = props.name
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)
@@ -65,13 +67,24 @@ export function Select(props: SelectProps) {
65
67
  let nativeEl: HTMLSelectElement | undefined
66
68
  onMount(() => {
67
69
  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')
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
+ }
72
85
  enhanced.value = true
73
86
  })
74
- const hasEmptyOption = props.options.some(o => o.value === '')
87
+ const hasEmptyOption = () => props.options.some(o => o.value === '')
75
88
 
76
89
  return (
77
90
  <div
@@ -89,7 +102,10 @@ export function Select(props: SelectProps) {
89
102
  data-part="trigger"
90
103
  type="button"
91
104
  role="combobox"
92
- 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}
93
109
  aria-haspopup="listbox"
94
110
  aria-expanded={popup.open.value ? 'true' : 'false'}
95
111
  aria-controls={popup.open.value ? listboxId : undefined}
@@ -105,8 +121,8 @@ export function Select(props: SelectProps) {
105
121
  id={listboxId}
106
122
  data-part="listbox"
107
123
  role="listbox"
108
- aria-label={ariaLabel}
109
- aria-labelledby={ariaLabel ? undefined : triggerId.value}
124
+ aria-label={props.ariaLabel}
125
+ aria-labelledby={props.ariaLabel ? undefined : triggerId.value}
110
126
  popover="auto"
111
127
  ref={popup.mountPopup}
112
128
  >
@@ -134,11 +150,11 @@ export function Select(props: SelectProps) {
134
150
  <select
135
151
  id={enhanced.value ? undefined : triggerId.value}
136
152
  hidden={enhanced.value}
137
- name={name}
138
- aria-label={ariaLabel}
153
+ name={props.name}
154
+ aria-label={props.ariaLabel}
139
155
  ref={(el) => { nativeEl = el }}
140
156
  >
141
- {!hasEmptyOption && <option value="" selected={selected.value === ''}>{placeholder}</option>}
157
+ {!hasEmptyOption() && <option value="" selected={selected.value === ''}>{placeholder()}</option>}
142
158
  {props.options.map(opt => (
143
159
  <option key={opt.value} value={opt.value} disabled={opt.disabled} selected={selected.value === opt.value}>{opt.label}</option>
144
160
  ))}
package/src/Tabs.tsx CHANGED
@@ -19,15 +19,14 @@ export interface TabsProps {
19
19
  class?: string | undefined
20
20
  }
21
21
 
22
- export function Tabs({ id, items, defaultValue, label, class: cls }: TabsProps) {
23
- const baseId = id ?? nextUiId('kui-tabs')
24
- const ids = items.map(i => i.id)
25
- const tabs = createTabs(defaultValue ?? items[0]?.id ?? '')
22
+ export function Tabs(props: TabsProps) {
23
+ const baseId = props.id ?? nextUiId('pru-tabs')
24
+ const tabs = createTabs(props.defaultValue ?? props.items[0]?.id ?? '')
26
25
 
27
26
  return (
28
- <div data-ui="tabs" class={cls}>
29
- <div data-part="list" role="tablist" aria-label={label}>
30
- {items.map(item => (
27
+ <div data-ui="tabs" class={props.class}>
28
+ <div data-part="list" role="tablist" aria-label={props.label}>
29
+ {props.items.map(item => (
31
30
  <button
32
31
  key={item.id}
33
32
  id={`${baseId}-tab-${item.id}`}
@@ -39,13 +38,13 @@ export function Tabs({ id, items, defaultValue, label, class: cls }: TabsProps)
39
38
  aria-controls={`${baseId}-panel-${item.id}`}
40
39
  tabIndex={tabs.isActive(item.id) ? 0 : -1}
41
40
  onClick={() => tabs.select(item.id)}
42
- onKeyDown={e => tabs.onKeyDown(e, ids)}
41
+ onKeyDown={e => tabs.onKeyDown(e, props.items.map(i => i.id))}
43
42
  >
44
43
  {item.label}
45
44
  </button>
46
45
  ))}
47
46
  </div>
48
- {items.map(item => (
47
+ {props.items.map(item => (
49
48
  <div
50
49
  key={item.id}
51
50
  id={`${baseId}-panel-${item.id}`}