@prunellejs/ui 0.8.0 → 0.10.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 +7 -7
  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 +85 -20
  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 +24 -4
  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/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}`}
package/src/Toaster.tsx CHANGED
@@ -2,14 +2,15 @@
2
2
  // Live-region Toast stack driven by the reactive `toast` store.
3
3
 
4
4
  import { effect } from 'prunelle'
5
- import { dismiss } from './labels/toaster'
5
+ import { toasterLabels } from './labels/toaster'
6
6
  import { pauseToasts, resumeToasts, toast } from './toast'
7
7
 
8
8
  export interface ToasterProps {
9
9
  dismissLabel?: string | undefined
10
10
  }
11
11
 
12
- export function Toaster({ dismissLabel = dismiss }: ToasterProps = {}) {
12
+ export function Toaster(props: ToasterProps = {}) {
13
+ const labels = toasterLabels()
13
14
  let hovered = false
14
15
  let focused = false
15
16
  // Where focus was before it entered the toaster, given back when the last toast closes.
@@ -93,7 +94,7 @@ export function Toaster({ dismissLabel = dismiss }: ToasterProps = {}) {
93
94
  <button
94
95
  data-part="close"
95
96
  type="button"
96
- aria-label={dismissLabel}
97
+ aria-label={props.dismissLabel ?? labels.dismiss}
97
98
  onClick={e => close(e.currentTarget.closest<HTMLElement>('[data-ui="toast"]')!)}
98
99
  >
99
100
  ✕
@@ -1,3 +1,7 @@
1
- export const close = 'Close'
2
- export const dialog = 'Dialog'
3
- export const drawer = 'Drawer'
1
+ import type { DialogLabels } from './en/dialog'
2
+ import { LABELS } from './en/dialog'
3
+
4
+ export type { DialogLabels }
5
+ export function dialogLabels(): DialogLabels {
6
+ return LABELS
7
+ }
@@ -0,0 +1,11 @@
1
+ export interface DialogLabels {
2
+ readonly close: string
3
+ readonly dialog: string
4
+ readonly drawer: string
5
+ }
6
+
7
+ export const LABELS: DialogLabels = {
8
+ close: 'Close',
9
+ dialog: 'Dialog',
10
+ drawer: 'Drawer',
11
+ }
@@ -0,0 +1,21 @@
1
+ export interface PaletteLabels {
2
+ readonly placeholder: string
3
+ readonly input: string
4
+ readonly palette: string
5
+ readonly trigger: string
6
+ readonly empty: string
7
+ readonly noResults: string
8
+ readonly result: string
9
+ readonly results: string
10
+ }
11
+
12
+ export const LABELS: PaletteLabels = {
13
+ placeholder: 'Type a command or search...',
14
+ input: 'Search commands',
15
+ palette: 'Command palette',
16
+ trigger: 'Search (⌘K)',
17
+ empty: 'No matching commands.',
18
+ noResults: 'No results',
19
+ result: 'result',
20
+ results: 'results',
21
+ }
@@ -0,0 +1,7 @@
1
+ export interface SelectLabels {
2
+ readonly placeholder: string
3
+ }
4
+
5
+ export const LABELS: SelectLabels = {
6
+ placeholder: 'Select…',
7
+ }
@@ -0,0 +1,31 @@
1
+ export interface TableLabels {
2
+ readonly placeholder: string
3
+ readonly search: string
4
+ readonly selectColumn: string
5
+ readonly selectRow: string
6
+ readonly selectAll: string
7
+ readonly ascending: string
8
+ readonly descending: string
9
+ readonly rows: string
10
+ readonly selected: string
11
+ readonly page: string
12
+ readonly prev: string
13
+ readonly next: string
14
+ readonly empty: string
15
+ }
16
+
17
+ export const LABELS: TableLabels = {
18
+ placeholder: 'Filter rows...',
19
+ search: 'Search',
20
+ selectColumn: 'Select',
21
+ selectRow: 'Select row',
22
+ selectAll: 'Select all rows',
23
+ ascending: 'ascending',
24
+ descending: 'descending',
25
+ rows: 'rows',
26
+ selected: 'selected',
27
+ page: 'Page',
28
+ prev: 'Prev',
29
+ next: 'Next',
30
+ empty: 'No matching rows.',
31
+ }
@@ -0,0 +1,7 @@
1
+ export interface ToasterLabels {
2
+ readonly dismiss: string
3
+ }
4
+
5
+ export const LABELS: ToasterLabels = {
6
+ dismiss: 'Dismiss',
7
+ }
@@ -1,3 +1,7 @@
1
- export const close = 'Fermer'
2
- export const dialog = 'Boîte de dialogue'
3
- export const drawer = 'Panneau'
1
+ import type { DialogLabels } from '../en/dialog'
2
+
3
+ export const LABELS: DialogLabels = {
4
+ close: 'Fermer',
5
+ dialog: 'Boîte de dialogue',
6
+ drawer: 'Panneau',
7
+ }
@@ -1,8 +1,12 @@
1
- export const placeholder = 'Tapez une commande ou cherchez…'
2
- export const input = 'Rechercher une commande'
3
- export const palette = 'Palette de commandes'
4
- export const trigger = 'Rechercher (⌘K)'
5
- export const empty = 'Aucune commande ne correspond.'
6
- export const noResults = 'Aucun résultat'
7
- export const result = 'résultat'
8
- export const results = 'résultats'
1
+ import type { PaletteLabels } from '../en/palette'
2
+
3
+ export const LABELS: PaletteLabels = {
4
+ placeholder: 'Tapez une commande ou cherchez…',
5
+ input: 'Rechercher une commande',
6
+ palette: 'Palette de commandes',
7
+ trigger: 'Rechercher (⌘K)',
8
+ empty: 'Aucune commande ne correspond.',
9
+ noResults: 'Aucun résultat',
10
+ result: 'résultat',
11
+ results: 'résultats',
12
+ }
@@ -1 +1,5 @@
1
- export const placeholder = 'Choisir…'
1
+ import type { SelectLabels } from '../en/select'
2
+
3
+ export const LABELS: SelectLabels = {
4
+ placeholder: 'Choisir…',
5
+ }
@@ -1,13 +1,17 @@
1
- export const placeholder = 'Filtrer les lignes…'
2
- export const search = 'Rechercher'
3
- export const selectColumn = 'Sélection'
4
- export const selectRow = 'Sélectionner la ligne'
5
- export const selectAll = 'Sélectionner toutes les lignes'
6
- export const ascending = 'croissant'
7
- export const descending = 'décroissant'
8
- export const rows = 'lignes'
9
- export const selected = 'sélectionnées'
10
- export const page = 'Page'
11
- export const prev = 'Précédente'
12
- export const next = 'Suivante'
13
- export const empty = 'Aucune ligne ne correspond.'
1
+ import type { TableLabels } from '../en/table'
2
+
3
+ export const LABELS: TableLabels = {
4
+ placeholder: 'Filtrer les lignes…',
5
+ search: 'Rechercher',
6
+ selectColumn: 'Sélection',
7
+ selectRow: 'Sélectionner la ligne',
8
+ selectAll: 'Sélectionner toutes les lignes',
9
+ ascending: 'croissant',
10
+ descending: 'décroissant',
11
+ rows: 'lignes',
12
+ selected: 'sélectionnées',
13
+ page: 'Page',
14
+ prev: 'Précédente',
15
+ next: 'Suivante',
16
+ empty: 'Aucune ligne ne correspond.',
17
+ }
@@ -1 +1,5 @@
1
- export const dismiss = 'Fermer'
1
+ import type { ToasterLabels } from '../en/toaster'
2
+
3
+ export const LABELS: ToasterLabels = {
4
+ dismiss: 'Fermer',
5
+ }
@@ -1,8 +1,7 @@
1
- export const placeholder = 'Type a command or search...'
2
- export const input = 'Search commands'
3
- export const palette = 'Command palette'
4
- export const trigger = 'Search (⌘K)'
5
- export const empty = 'No matching commands.'
6
- export const noResults = 'No results'
7
- export const result = 'result'
8
- export const results = 'results'
1
+ import type { PaletteLabels } from './en/palette'
2
+ import { LABELS } from './en/palette'
3
+
4
+ export type { PaletteLabels }
5
+ export function paletteLabels(): PaletteLabels {
6
+ return LABELS
7
+ }
@@ -1 +1,7 @@
1
- export const placeholder = 'Select…'
1
+ import type { SelectLabels } from './en/select'
2
+ import { LABELS } from './en/select'
3
+
4
+ export type { SelectLabels }
5
+ export function selectLabels(): SelectLabels {
6
+ return LABELS
7
+ }
@@ -1,13 +1,7 @@
1
- export const placeholder = 'Filter rows...'
2
- export const search = 'Search'
3
- export const selectColumn = 'Select'
4
- export const selectRow = 'Select row'
5
- export const selectAll = 'Select all rows'
6
- export const ascending = 'ascending'
7
- export const descending = 'descending'
8
- export const rows = 'rows'
9
- export const selected = 'selected'
10
- export const page = 'Page'
11
- export const prev = 'Prev'
12
- export const next = 'Next'
13
- export const empty = 'No matching rows.'
1
+ import type { TableLabels } from './en/table'
2
+ import { LABELS } from './en/table'
3
+
4
+ export type { TableLabels }
5
+ export function tableLabels(): TableLabels {
6
+ return LABELS
7
+ }
@@ -1 +1,7 @@
1
- export const dismiss = 'Dismiss'
1
+ import type { ToasterLabels } from './en/toaster'
2
+ import { LABELS } from './en/toaster'
3
+
4
+ export type { ToasterLabels }
5
+ export function toasterLabels(): ToasterLabels {
6
+ return LABELS
7
+ }
package/src/locale.ts ADDED
@@ -0,0 +1,15 @@
1
+ // Per-request SSR and browser locale check for multi-locale apps (bundled only when @prunellejs/i18n is active).
2
+
3
+ const FRENCH_RE = /^fr(?:-|$)/i
4
+ const BRIDGE_KEY = Symbol.for('pru.server.context.bridge')
5
+
6
+ interface LocaleBridge {
7
+ requestLocale?: () => string | undefined
8
+ }
9
+
10
+ export function isFrenchLocale(fallback = ''): boolean {
11
+ if (typeof document !== 'undefined')
12
+ return FRENCH_RE.test(document.documentElement.lang || fallback)
13
+ const bridge = (globalThis as Record<symbol, LocaleBridge | undefined>)[BRIDGE_KEY]
14
+ return FRENCH_RE.test(bridge?.requestLocale?.() ?? fallback)
15
+ }
@@ -19,18 +19,20 @@ export const FALLBACK_JS = 'const C=!("command"in HTMLButtonElement.prototype),B
19
19
  + '(e.clientX<r.left||e.clientX>r.right||e.clientY<r.top||e.clientY>r.bottom)&&t.close()}})'
20
20
 
21
21
  /** The fallback's file under the asset prefix, named by its content so a browser keeps it for good. */
22
- export const FALLBACK_FILE = `kui-fallback-${new Bun.CryptoHasher('sha256').update(FALLBACK_JS).digest('hex').slice(0, 8)}.js`
22
+ export const FALLBACK_FILE = `pru-fallback-${new Bun.CryptoHasher('sha256').update(FALLBACK_JS).digest('hex').slice(0, 8)}.js`
23
23
 
24
24
  /** Inline on a page with a `commandfor` button or a popup: imports the fallback only where a feature is missing, so other browsers fetch nothing. */
25
- export const FALLBACK_GUARD = 'if(!("command"in HTMLButtonElement.prototype&&"closedBy"in HTMLDialogElement.prototype&&CSS.supports("position-area:block-end")))import(document.querySelector("script[data-kui-fallback]").dataset.kuiFallback)'
25
+ export const FALLBACK_GUARD = 'if(!("command"in HTMLButtonElement.prototype&&"closedBy"in HTMLDialogElement.prototype&&CSS.supports("position-area:block-end")))import(document.querySelector("script[data-pru-fallback]").dataset.pruFallback)'
26
26
 
27
27
  const NEEDS_FALLBACK_RE = /<button\b[^>]*\scommandfor=|\sdata-ui="(?:menu|select|popover)"/
28
28
 
29
29
  /** `html` with the guard before `</head>` when a button in it carries `commandfor` or it holds a Menu, Select or Popover, pointing at the fallback under `assetPrefix`. */
30
30
  export function withPlatformFallback(html: string, assetPrefix: string): string {
31
- if (!NEEDS_FALLBACK_RE.test(html) || html.includes('data-kui-fallback'))
31
+ if (!NEEDS_FALLBACK_RE.test(html) || html.includes('data-pru-fallback'))
32
32
  return html
33
- const tag = `<script type="module" data-kui-fallback="${assetPrefix.replace(/\/$/, '')}/${FALLBACK_FILE}">${FALLBACK_GUARD}</script>`
34
33
  const head = html.indexOf('</head>')
35
- return head === -1 ? `${tag}${html}` : `${html.slice(0, head)}${tag}${html.slice(head)}`
34
+ if (head === -1)
35
+ return html
36
+ const tag = `<script type="module" data-pru-fallback="${assetPrefix.replace(/\/$/, '')}/${FALLBACK_FILE}">${FALLBACK_GUARD}</script>`
37
+ return `${html.slice(0, head)}${tag}${html.slice(head)}`
36
38
  }
package/src/plugin.ts CHANGED
@@ -7,7 +7,7 @@ import type { GrammarName, UiComponentPart } from './styles/split'
7
7
  import { createHash } from 'node:crypto'
8
8
  import { mkdirSync, writeFileSync } from 'node:fs'
9
9
  import { dirname, join, resolve } from 'node:path'
10
- import { definePlugin, minifyCss, UI_KUI_LAYER_SERVICE } from 'prunelle/config'
10
+ import { definePlugin, minifyCss, UI_LAYER_SERVICE } from 'prunelle/config'
11
11
  import { FALLBACK_FILE, FALLBACK_GUARD, FALLBACK_JS, withPlatformFallback } from './platform-fallback'
12
12
  import { createUiPartScanner } from './styles/scan'
13
13
  import {
@@ -128,20 +128,38 @@ function emitGrammarStyles(ctx: BuildPluginContext, grammar: GrammarName): void
128
128
  }
129
129
 
130
130
  const LABELS_DIR = join(import.meta.dir, 'labels')
131
- const LABELS_FILTER = new RegExp(`^${LABELS_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\\\/](\\w+)\\.ts$`)
131
+ const LABELS_FILTER = new RegExp(`^${LABELS_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\\\/](dialog|palette|select|table|toaster)\\.ts$`)
132
132
  const FRENCH_RE = /^fr(?:-|$)/i
133
133
 
134
- // A French app loads labels/fr/<name>.ts wherever ui imports labels/<name>.ts, so each island ships its own labels in one language.
135
- function frenchLabels(lang: string | undefined): BunPlugin[] {
134
+ // Single-locale apps ship only their language (0 B overhead for EN); multi-locale (@prunellejs/i18n) apps pick per request / <html lang>.
135
+ function labelsPlugin(lang: string | undefined, multiLocale: boolean | undefined): BunPlugin[] {
136
+ if (multiLocale) {
137
+ const fallback = JSON.stringify(lang ?? '')
138
+ return [{
139
+ name: 'prunelle-ui-labels',
140
+ setup(build) {
141
+ build.onLoad({ filter: LABELS_FILTER }, (args) => {
142
+ const name = LABELS_FILTER.exec(args.path)![1]!
143
+ return {
144
+ contents: `import { LABELS as en } from './en/${name}'\nimport { LABELS as fr } from './fr/${name}'\nimport { isFrenchLocale } from '../locale'\nexport function ${name}Labels() { return isFrenchLocale(${fallback}) ? fr : en }\n`,
145
+ loader: 'ts',
146
+ }
147
+ })
148
+ },
149
+ }]
150
+ }
136
151
  if (lang === undefined || !FRENCH_RE.test(lang))
137
152
  return []
138
153
  return [{
139
154
  name: 'prunelle-ui-labels',
140
155
  setup(build) {
141
- build.onLoad({ filter: LABELS_FILTER }, async args => ({
142
- contents: await Bun.file(join(LABELS_DIR, 'fr', `${LABELS_FILTER.exec(args.path)![1]}.ts`)).text(),
143
- loader: 'ts',
144
- }))
156
+ build.onLoad({ filter: LABELS_FILTER }, (args) => {
157
+ const name = LABELS_FILTER.exec(args.path)![1]!
158
+ return {
159
+ contents: `import { LABELS } from './fr/${name}'\nexport function ${name}Labels() { return LABELS }\n`,
160
+ loader: 'ts',
161
+ }
162
+ })
145
163
  },
146
164
  }]
147
165
  }
@@ -153,11 +171,12 @@ export function ui(options: UiPluginOptions = {}): PrunellePlugin {
153
171
  return definePlugin({
154
172
  name: '@prunellejs/ui',
155
173
  inlineScripts: [FALLBACK_GUARD],
156
- bunPlugins: ({ lang }) => frenchLabels(lang),
174
+ bunPlugins: ({ lang, multiLocale }) => labelsPlugin(lang, multiLocale),
157
175
  build(ctx) {
176
+ assetPrefix = ctx.assetPrefix
158
177
  ctx.emitAsset(FALLBACK_FILE, FALLBACK_JS)
159
178
  if (grammar !== false) {
160
- ctx.provide?.(UI_KUI_LAYER_SERVICE, true)
179
+ ctx.provide?.(UI_LAYER_SERVICE, true)
161
180
  emitGrammarStyles(ctx, grammar)
162
181
  }
163
182
  if (emit !== undefined) {
@@ -3,6 +3,7 @@
3
3
 
4
4
  import type { PrunelleChild } from 'prunelle'
5
5
  import type { ButtonVariant, SpaceValue, Tone, TrackValue } from './static'
6
+ import { layoutStyle, restProps } from './static'
6
7
 
7
8
  const SPACE_TOKENS = new Set<string>(['none', '2xs', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'])
8
9
  const TRACK_TOKENS = new Set<string>(['xs', 'sm', 'md', 'lg', 'xl'])
@@ -15,14 +16,16 @@ export function Badge(props: BoxProps & { tone?: Tone | undefined }) {
15
16
  }
16
17
 
17
18
  export function Grid(props: BoxProps & { min?: TrackValue | undefined, gap?: SpaceValue | undefined }) {
18
- const rest = restProps(props, ['min', 'gap', 'class'])
19
+ const rest = restProps(props, ['min', 'gap', 'class', 'style'])
19
20
  return (
20
21
  <div
21
22
  data-layout="grid"
22
23
  data-min={isTrackToken(props.min) ? props.min : undefined}
23
- data-min-value={props.min && !isTrackToken(props.min) ? props.min : undefined}
24
24
  data-gap={isSpaceToken(props.gap) ? props.gap : undefined}
25
- data-gap-value={props.gap && !isSpaceToken(props.gap) ? props.gap : undefined}
25
+ style={layoutStyle({
26
+ '--ui-min': isTrackToken(props.min) ? undefined : props.min,
27
+ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap,
28
+ }, props.style)}
26
29
  class={props.class}
27
30
  {...rest}
28
31
  >
@@ -32,14 +35,16 @@ export function Grid(props: BoxProps & { min?: TrackValue | undefined, gap?: Spa
32
35
  }
33
36
 
34
37
  export function Sidebar(props: BoxProps & { side?: TrackValue | undefined, gap?: SpaceValue | undefined }) {
35
- const rest = restProps(props, ['side', 'gap', 'class'])
38
+ const rest = restProps(props, ['side', 'gap', 'class', 'style'])
36
39
  return (
37
40
  <div
38
41
  data-layout="sidebar"
39
42
  data-side={isTrackToken(props.side) ? props.side : undefined}
40
- data-side-value={props.side && !isTrackToken(props.side) ? props.side : undefined}
41
43
  data-gap={isSpaceToken(props.gap) ? props.gap : undefined}
42
- data-gap-value={props.gap && !isSpaceToken(props.gap) ? props.gap : undefined}
44
+ style={layoutStyle({
45
+ '--ui-side': isTrackToken(props.side) ? undefined : props.side,
46
+ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap,
47
+ }, props.style)}
43
48
  class={props.class}
44
49
  {...rest}
45
50
  >
@@ -49,12 +54,12 @@ export function Sidebar(props: BoxProps & { side?: TrackValue | undefined, gap?:
49
54
  }
50
55
 
51
56
  export function Split(props: BoxProps & { gap?: SpaceValue | undefined }) {
52
- const rest = restProps(props, ['gap', 'class'])
57
+ const rest = restProps(props, ['gap', 'class', 'style'])
53
58
  return (
54
59
  <div
55
60
  data-layout="split"
56
61
  data-gap={isSpaceToken(props.gap) ? props.gap : undefined}
57
- data-gap-value={props.gap && !isSpaceToken(props.gap) ? props.gap : undefined}
62
+ style={layoutStyle({ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap }, props.style)}
58
63
  class={props.class}
59
64
  {...rest}
60
65
  >
@@ -69,15 +74,6 @@ interface BoxProps {
69
74
  [attr: string]: unknown
70
75
  }
71
76
 
72
- function restProps(props: Record<string, unknown>, skip: readonly string[]): Record<string, unknown> {
73
- const out: Record<string, unknown> = {}
74
- for (const k of Object.keys(props)) {
75
- if (k !== 'children' && !skip.includes(k))
76
- out[k] = props[k]
77
- }
78
- return out
79
- }
80
-
81
77
  export function Card(props: BoxProps) {
82
78
  const rest = restProps(props, ['class'])
83
79
  return <section data-ui="card" class={props.class} {...rest}>{props.children}</section>
@@ -122,23 +118,23 @@ export interface PopoverProps {
122
118
  children?: PrunelleChild | undefined
123
119
  }
124
120
 
125
- export function Popover({ id, triggerLabel, triggerVariant = 'outline', children }: PopoverProps) {
121
+ export function Popover(props: PopoverProps) {
126
122
  return (
127
123
  <>
128
124
  <button
129
125
  data-ui="button"
130
- data-variant={triggerVariant}
126
+ data-variant={props.triggerVariant ?? 'outline'}
131
127
  type="button"
132
- popovertarget={id}
128
+ popovertarget={props.id}
133
129
  >
134
- {triggerLabel}
130
+ {props.triggerLabel}
135
131
  </button>
136
132
  <div
137
- id={id}
133
+ id={props.id}
138
134
  data-ui="popover"
139
135
  popover="auto"
140
136
  >
141
- {children}
137
+ {props.children}
142
138
  </div>
143
139
  </>
144
140
  )
@@ -158,21 +154,23 @@ export interface CheckControlProps {
158
154
  [attr: string]: unknown
159
155
  }
160
156
 
161
- export function Checkbox({ id, name, value, label, checked, disabled, class: cls, ...rest }: CheckControlProps) {
157
+ export function Checkbox(props: CheckControlProps) {
158
+ const rest = restProps(props, ['id', 'name', 'value', 'label', 'checked', 'disabled', 'class'])
162
159
  return (
163
- <label data-ui="checkbox" data-disabled={disabled ? 'true' : undefined} class={cls}>
164
- <input id={id} type="checkbox" name={name} value={value} checked={checked} disabled={disabled} {...rest} />
165
- <span data-part="label">{label}</span>
160
+ <label data-ui="checkbox" data-disabled={props.disabled ? 'true' : undefined} class={props.class}>
161
+ <input id={props.id} type="checkbox" name={props.name} value={props.value} checked={props.checked} disabled={props.disabled} {...rest} />
162
+ <span data-part="label">{props.label}</span>
166
163
  </label>
167
164
  )
168
165
  }
169
166
 
170
- export function Switch({ id, name, value, label, checked, disabled, class: cls, ...rest }: CheckControlProps) {
167
+ export function Switch(props: CheckControlProps) {
168
+ const rest = restProps(props, ['id', 'name', 'value', 'label', 'checked', 'disabled', 'class'])
171
169
  return (
172
- <label data-ui="switch" data-disabled={disabled ? 'true' : undefined} class={cls}>
173
- <input id={id} type="checkbox" role="switch" name={name} value={value} checked={checked} disabled={disabled} {...rest} />
170
+ <label data-ui="switch" data-disabled={props.disabled ? 'true' : undefined} class={props.class}>
171
+ <input id={props.id} type="checkbox" role="switch" name={props.name} value={props.value} checked={props.checked} disabled={props.disabled} {...rest} />
174
172
  <span data-part="track" aria-hidden="true" />
175
- <span data-part="label">{label}</span>
173
+ <span data-part="label">{props.label}</span>
176
174
  </label>
177
175
  )
178
176
  }
@@ -192,18 +190,18 @@ export interface RadioGroupProps {
192
190
  class?: string | undefined
193
191
  }
194
192
 
195
- export function RadioGroup({ name, legend, options, defaultValue, class: cls }: RadioGroupProps) {
193
+ export function RadioGroup(props: RadioGroupProps) {
196
194
  return (
197
- <fieldset data-ui="radio-group" class={cls}>
198
- {legend && <legend data-part="legend">{legend}</legend>}
195
+ <fieldset data-ui="radio-group" class={props.class}>
196
+ {props.legend && <legend data-part="legend">{props.legend}</legend>}
199
197
  <div data-part="options">
200
- {options.map(opt => (
198
+ {props.options.map(opt => (
201
199
  <label key={opt.value} data-part="option" data-disabled={opt.disabled ? 'true' : undefined}>
202
200
  <input
203
201
  type="radio"
204
- name={name}
202
+ name={props.name}
205
203
  value={opt.value}
206
- checked={defaultValue === opt.value ? true : undefined}
204
+ checked={props.defaultValue === opt.value ? true : undefined}
207
205
  disabled={opt.disabled}
208
206
  />
209
207
  <span data-part="label">{opt.label}</span>
@@ -227,12 +225,13 @@ export interface ProgressProps {
227
225
  // The share done, rounded to the 5% step a grammar styles: a style attribute would break a CSP without 'unsafe-inline'.
228
226
  const progressStep = (value: number, max: number): string => String(Math.round(Math.min(Math.max(value / max, 0), 1) * 20) * 5)
229
227
 
230
- export function Progress({ label, value, max = 100, class: cls, ...rest }: ProgressProps) {
228
+ export function Progress(props: ProgressProps) {
229
+ const rest = restProps(props, ['label', 'value', 'max', 'class'])
231
230
  return (
232
- <span data-ui="progress" data-value={value === undefined ? undefined : progressStep(value, max)} class={cls} {...rest}>
231
+ <span data-ui="progress" data-value={props.value === undefined ? undefined : progressStep(props.value, props.max ?? 100)} class={props.class} {...rest}>
233
232
  <span data-part="eye" aria-hidden="true" />
234
- <progress value={value} max={value === undefined ? undefined : max} aria-label={label} />
235
- <span data-part="label" aria-hidden="true">{label}</span>
233
+ <progress value={props.value} max={props.value === undefined ? undefined : (props.max ?? 100)} aria-label={props.label} />
234
+ <span data-part="label" aria-hidden="true">{props.label}</span>
236
235
  </span>
237
236
  )
238
237
  }