@cognitap/radiant 0.0.52 → 0.0.54

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 (61) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/library/Autocomplete.d.ts.map +1 -1
  3. package/dist/library/Autocomplete.js +1 -1
  4. package/dist/library/Autocomplete.js.map +1 -1
  5. package/dist/library/Combobox.d.ts +44 -1
  6. package/dist/library/Combobox.d.ts.map +1 -1
  7. package/dist/library/Combobox.js +59 -21
  8. package/dist/library/Combobox.js.map +1 -1
  9. package/dist/library/Command.d.ts +49 -0
  10. package/dist/library/Command.d.ts.map +1 -0
  11. package/dist/library/Command.js +110 -0
  12. package/dist/library/Command.js.map +1 -0
  13. package/dist/library/Dialog.d.ts +2 -2
  14. package/dist/library/Dialog.d.ts.map +1 -1
  15. package/dist/library/Dialog.js.map +1 -1
  16. package/dist/library/Field.d.ts +4 -0
  17. package/dist/library/Field.d.ts.map +1 -1
  18. package/dist/library/Field.js +4 -0
  19. package/dist/library/Field.js.map +1 -1
  20. package/dist/library/Select.d.ts +9 -11
  21. package/dist/library/Select.d.ts.map +1 -1
  22. package/dist/library/Select.js +9 -13
  23. package/dist/library/Select.js.map +1 -1
  24. package/dist/library/Slider.d.ts +2 -2
  25. package/dist/library/Slider.d.ts.map +1 -1
  26. package/dist/library/Tabs.d.ts +8 -8
  27. package/dist/library/Tabs.d.ts.map +1 -1
  28. package/dist/library/Tabs.js +6 -6
  29. package/dist/library/Tabs.js.map +1 -1
  30. package/dist/library/cn.d.ts.map +1 -1
  31. package/dist/library/cn.js +1 -0
  32. package/dist/library/cn.js.map +1 -1
  33. package/dist/library/index.d.ts +4 -3
  34. package/dist/library/index.d.ts.map +1 -1
  35. package/dist/library/index.js +1 -0
  36. package/dist/library/index.js.map +1 -1
  37. package/dist/library/presentation.d.ts +1 -0
  38. package/dist/library/presentation.d.ts.map +1 -1
  39. package/dist/library/react/useNativeOwner.d.ts +9 -0
  40. package/dist/library/react/useNativeOwner.d.ts.map +1 -1
  41. package/dist/library/react/useNativeOwner.js.map +1 -1
  42. package/dist/library/styles.css +1 -1
  43. package/dist/library/themes/components.d.ts +3 -0
  44. package/dist/library/themes/components.d.ts.map +1 -1
  45. package/dist/library/themes/components.js +1 -0
  46. package/dist/library/themes/components.js.map +1 -1
  47. package/docs/architecture.md +43 -44
  48. package/package.json +1 -1
  49. package/src/Autocomplete.tsx +1 -0
  50. package/src/Combobox.tsx +113 -31
  51. package/src/Command.tsx +317 -0
  52. package/src/Dialog.tsx +4 -2
  53. package/src/Field.tsx +5 -0
  54. package/src/Select.tsx +32 -17
  55. package/src/Slider.tsx +2 -2
  56. package/src/Tabs.tsx +12 -13
  57. package/src/cn.ts +1 -0
  58. package/src/index.ts +26 -1
  59. package/src/presentation.ts +1 -0
  60. package/src/react/useNativeOwner.ts +4 -0
  61. package/src/themes/components.ts +1 -0
@@ -0,0 +1,317 @@
1
+ 'use client'
2
+ /* oxlint-disable jsx-a11y/prefer-tag-over-role -- Grouped results use the actual Combobox ARIA listbox. */
3
+ import { createContext, useContext } from 'react'
4
+ import type { ComponentProps, ReactNode } from 'react'
5
+ import {
6
+ DialogRoot,
7
+ DialogTrigger,
8
+ DialogContent,
9
+ DialogTitle,
10
+ DialogDescription,
11
+ DialogClose,
12
+ useDialog,
13
+ useDialogFamily,
14
+ type DialogProps,
15
+ type DialogRenderProps,
16
+ type DialogContentProps,
17
+ type DialogTriggerProps,
18
+ type DialogTitleProps,
19
+ type DialogDescriptionProps
20
+ } from './Dialog.js'
21
+ import {
22
+ ComboboxRoot,
23
+ ComboboxInput,
24
+ ComboboxInlineContent,
25
+ ComboboxItem,
26
+ useCommandParts,
27
+ type ComboboxOption,
28
+ type ComboboxInputProps,
29
+ type ComboboxItemProps
30
+ } from './Combobox.js'
31
+ import type { StateOwner } from './react/useNativeOwner.js'
32
+ import type { DistributiveOmit } from './internal/types.js'
33
+ import { requireAccessibleName, type AccessibleName } from './internal/accessibleName.js'
34
+ import { WithoutField } from './Field.js'
35
+ import { Kbd, KbdGroup } from './Kbd.js'
36
+ import { cn } from './cn.js'
37
+ import { useControllableState } from './react/useControllableState.js'
38
+ import type { ControlSize } from './presentation.js'
39
+ import type { ThemeStyle } from './themes/defineTheme.js'
40
+
41
+ export type CommandOption = ComboboxOption & { group?: string; shortcut?: readonly string[] }
42
+ export type CommandProps = DialogProps &
43
+ StateOwner<'query', string> & {
44
+ items: readonly CommandOption[]
45
+ onQueryChange?: (query: string) => void
46
+ /** Runs on explicit activation, then requests Dialog close. */
47
+ onAction: (value: string) => void
48
+ filter?: ((item: CommandOption, query: string) => boolean) | null
49
+ loading?: boolean
50
+ errorText?: ReactNode
51
+ loadingText?: string
52
+ emptyText?: string
53
+ controlSize?: ControlSize
54
+ }
55
+ export type CommandRenderProps = DialogRenderProps
56
+ export type CommandTriggerProps = DistributiveOmit<
57
+ DialogTriggerProps,
58
+ 'pressed' | 'defaultPressed' | 'onPressedChange'
59
+ >
60
+ export type CommandCloseProps = DialogTriggerProps
61
+ export type CommandContentProps = DialogContentProps
62
+ export type CommandTitleProps = DialogTitleProps
63
+ export type CommandDescriptionProps = DialogDescriptionProps
64
+ export type CommandInputProps = Omit<ComboboxInputProps, 'aria-label' | 'aria-labelledby'> &
65
+ (AccessibleName | { 'aria-label'?: undefined; 'aria-labelledby'?: undefined })
66
+ export type CommandListProps = Omit<ComponentProps<'div'>, 'style' | 'role' | 'id'> & {
67
+ style?: ThemeStyle
68
+ }
69
+ export type CommandItemProps = ComboboxItemProps
70
+ type Options = { items: readonly CommandOption[] }
71
+ const CommandContext = createContext<Options | null>(null)
72
+ function useCommandContext() {
73
+ const context = useContext(CommandContext)
74
+ const family = useDialogFamily()
75
+ if (!context || family !== 'command') throw new Error('Command parts must render inside Command.')
76
+ return context
77
+ }
78
+ /** Modal actions and editable query are independent; applications register their shortcuts. */
79
+ export function Command({
80
+ query,
81
+ defaultQuery,
82
+ onQueryChange,
83
+ items,
84
+ onAction,
85
+ filter,
86
+ loading,
87
+ errorText,
88
+ loadingText,
89
+ emptyText,
90
+ controlSize,
91
+ children,
92
+ ...dialog
93
+ }: CommandProps) {
94
+ const search = useControllableState({
95
+ name: 'Command query',
96
+ value: query,
97
+ defaultValue: defaultQuery,
98
+ initialValue: '',
99
+ onChange: onQueryChange
100
+ })
101
+ if (
102
+ typeof search.value !== 'string' ||
103
+ (defaultQuery !== undefined && typeof defaultQuery !== 'string')
104
+ )
105
+ throw new TypeError('Command queries must be strings.')
106
+ // Groups follow their first appearance. Keyboard and rendered order share this registry.
107
+ const groups = new Map<string | undefined, CommandOption[]>()
108
+ for (const item of items) {
109
+ if (item.group !== undefined && !item.group.trim())
110
+ throw new TypeError('Command groups need readable names.')
111
+ const group = groups.get(item.group) ?? []
112
+ group.push(item)
113
+ groups.set(item.group, group)
114
+ }
115
+ const ordered = [...groups.values()].flat()
116
+ return (
117
+ <DialogRoot
118
+ {...dialog}
119
+ family="command"
120
+ >
121
+ <CommandContext.Provider value={{ items: ordered }}>
122
+ <CommandResults
123
+ query={search.value}
124
+ onQueryChange={search.request}
125
+ items={ordered}
126
+ onAction={onAction}
127
+ filter={filter}
128
+ loading={loading}
129
+ errorText={errorText}
130
+ loadingText={loadingText}
131
+ emptyText={emptyText}
132
+ controlSize={controlSize}
133
+ >
134
+ {children}
135
+ </CommandResults>
136
+ </CommandContext.Provider>
137
+ </DialogRoot>
138
+ )
139
+ }
140
+ function CommandResults({
141
+ items,
142
+ onAction,
143
+ filter,
144
+ errorText,
145
+ children,
146
+ ...props
147
+ }: Pick<
148
+ CommandProps,
149
+ | 'items'
150
+ | 'query'
151
+ | 'onQueryChange'
152
+ | 'onAction'
153
+ | 'filter'
154
+ | 'loading'
155
+ | 'errorText'
156
+ | 'loadingText'
157
+ | 'emptyText'
158
+ | 'controlSize'
159
+ | 'children'
160
+ >) {
161
+ const dialog = useDialog()!
162
+ const registry = new Map(items.map(item => [item.value, item]))
163
+ return (
164
+ <WithoutField>
165
+ <ComboboxRoot
166
+ {...props}
167
+ items={items}
168
+ value={null}
169
+ error={errorText}
170
+ open={dialog.open}
171
+ filter={
172
+ filter === null
173
+ ? null
174
+ : filter
175
+ ? (item, text) => filter(registry.get(item.value)!, text)
176
+ : undefined
177
+ }
178
+ command={{
179
+ onCommit(value) {
180
+ onAction(value)
181
+ dialog.setOpen(false)
182
+ }
183
+ }}
184
+ >
185
+ {children ?? false}
186
+ </ComboboxRoot>
187
+ </WithoutField>
188
+ )
189
+ }
190
+ export function CommandTrigger(props: CommandTriggerProps) {
191
+ useCommandContext()
192
+ return (
193
+ <DialogTrigger
194
+ {...props}
195
+ pressed={undefined}
196
+ defaultPressed={undefined}
197
+ onPressedChange={undefined}
198
+ />
199
+ )
200
+ }
201
+ export function CommandClose(props: CommandCloseProps) {
202
+ useCommandContext()
203
+ return <DialogClose {...props} />
204
+ }
205
+ export function CommandContent({ className, ...props }: CommandContentProps) {
206
+ useCommandContext()
207
+ return (
208
+ <DialogContent
209
+ {...props}
210
+ className={cn('open:flex open:flex-col', className)}
211
+ />
212
+ )
213
+ }
214
+ export function CommandTitle(props: CommandTitleProps) {
215
+ useCommandContext()
216
+ return <DialogTitle {...props} />
217
+ }
218
+ export function CommandDescription(props: CommandDescriptionProps) {
219
+ useCommandContext()
220
+ return <DialogDescription {...props} />
221
+ }
222
+ export function CommandInput({ className, ...props }: CommandInputProps) {
223
+ useCommandContext()
224
+ useCommandParts()
225
+ const name = {
226
+ 'aria-label': props['aria-labelledby']
227
+ ? props['aria-label']
228
+ : (props['aria-label'] ?? 'Search commands'),
229
+ 'aria-labelledby': props['aria-labelledby']
230
+ }
231
+ requireAccessibleName('CommandInput', name)
232
+ return (
233
+ <ComboboxInput
234
+ {...props}
235
+ {...name}
236
+ className={cn('shrink-0 pe-[var(--_rad-control-padding,1rem)]', className)}
237
+ />
238
+ )
239
+ }
240
+ export function CommandList({ children, className, ...props }: CommandListProps) {
241
+ const { items } = useCommandContext()
242
+ const box = useCommandParts()
243
+ const visible = new Set(box.visible.map(item => item.value))
244
+ const groups = new Map<string | undefined, CommandOption[]>()
245
+ for (const item of items)
246
+ if (visible.has(item.value)) {
247
+ const group = groups.get(item.group) ?? []
248
+ group.push(item)
249
+ groups.set(item.group, group)
250
+ }
251
+ return (
252
+ <ComboboxInlineContent
253
+ {...props}
254
+ className={cn(
255
+ 'min-h-[var(--_rad-control-height,2.5rem)] max-h-[min(50dvh,var(--rad-command-results-max-height,24rem))]',
256
+ className
257
+ )}
258
+ >
259
+ {children ??
260
+ [...groups].map(([group, options]) =>
261
+ group === undefined ? (
262
+ options.map(item => (
263
+ <CommandItem
264
+ key={item.value}
265
+ value={item.value}
266
+ />
267
+ ))
268
+ ) : (
269
+ <div
270
+ key={group}
271
+ role="group"
272
+ aria-label={group}
273
+ data-slot="command-group"
274
+ >
275
+ <p
276
+ aria-hidden="true"
277
+ className="m-0 px-3 py-2 text-sm font-semibold"
278
+ data-slot="command-group-label"
279
+ >
280
+ {group}
281
+ </p>
282
+ {options.map(item => (
283
+ <CommandItem
284
+ key={item.value}
285
+ value={item.value}
286
+ />
287
+ ))}
288
+ </div>
289
+ )
290
+ )}
291
+ </ComboboxInlineContent>
292
+ )
293
+ }
294
+ export function CommandItem({ children, value, ...props }: CommandItemProps) {
295
+ const { items } = useCommandContext()
296
+ useCommandParts()
297
+ const item = items.find(item => item.value === value)
298
+ return (
299
+ <ComboboxItem
300
+ {...props}
301
+ value={value}
302
+ >
303
+ {children ?? (
304
+ <>
305
+ <span className="min-w-0 flex-1">{item?.label}</span>
306
+ {item?.shortcut?.length ? (
307
+ <KbdGroup className="shrink-0">
308
+ {item.shortcut.map((label, index) => (
309
+ <Kbd key={index}>{label}</Kbd>
310
+ ))}
311
+ </KbdGroup>
312
+ ) : null}
313
+ </>
314
+ )}
315
+ </ComboboxItem>
316
+ )
317
+ }
package/src/Dialog.tsx CHANGED
@@ -108,7 +108,9 @@ export type DialogDescriptionProps = Omit<ComponentProps<'p'>, 'style'> & { styl
108
108
  export type DialogCloseProps = DialogTriggerProps
109
109
 
110
110
  const DialogContext = createContext<DialogState | null>(null)
111
- const DialogFamilyContext = createContext<'dialog' | 'alert-dialog' | 'drawer'>('dialog')
111
+ const DialogFamilyContext = createContext<'dialog' | 'alert-dialog' | 'drawer' | 'command'>(
112
+ 'dialog'
113
+ )
112
114
 
113
115
  /** Private composition seam for specialized Dialog families; not exported from the package. */
114
116
  export function useDialogFamily() {
@@ -144,7 +146,7 @@ export function DialogRoot({
144
146
  closeOnEscape = true,
145
147
  children,
146
148
  family = 'dialog'
147
- }: DialogProps & { family?: 'dialog' | 'alert-dialog' | 'drawer' }) {
149
+ }: DialogProps & { family?: 'dialog' | 'alert-dialog' | 'drawer' | 'command' }) {
148
150
  const contentId = useId()
149
151
  const titleId = useId()
150
152
  const descriptionId = useId()
package/src/Field.tsx CHANGED
@@ -109,6 +109,11 @@ export type FieldProps = FieldControl | FieldGroup
109
109
 
110
110
  const FieldContext = createContext<FieldState | null>(null)
111
111
 
112
+ /** Private boundary for non-form composites nested inside a Field. */
113
+ export function WithoutField({ children }: { children?: ReactNode }) {
114
+ return <FieldContext.Provider value={null}>{children}</FieldContext.Provider>
115
+ }
116
+
112
117
  /** Nearest Field metadata, or null. Groups have no single target: controlProps is null. */
113
118
  export function useField(): FieldState | null {
114
119
  return useContext(FieldContext)
package/src/Select.tsx CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  } from 'react'
14
14
  import type { ComponentProps, ReactNode, RefObject } from 'react'
15
15
  import { createPortal } from 'react-dom'
16
- import { Button, type ButtonProps } from './Button.js'
16
+ import { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'
17
17
  import { useField, useFieldControl } from './Field.js'
18
18
  import type { DistributiveOmit } from './internal/types.js'
19
19
  import { cn } from './cn.js'
@@ -22,7 +22,7 @@ import { matchSelectText, moveSelectFocus, positionSelect } from './internal/sel
22
22
  import { useComposedRefs } from './react/useComposedRefs.js'
23
23
  import { useControllableState } from './react/useControllableState.js'
24
24
  import { useTransitionHost } from './motion/host.js'
25
- import type { ValueOwner } from './react/useNativeOwner.js'
25
+ import type { StateOwner, ValueOwner } from './react/useNativeOwner.js'
26
26
  import type { ControlSize } from './presentation.js'
27
27
  import type { ThemeStyle } from './themes/defineTheme.js'
28
28
  import { selectContentClass, selectItemClass, selectTriggerClass } from './selectStyles.js'
@@ -32,7 +32,7 @@ export type SelectOption = { value: string; disabled?: boolean } & (
32
32
  | { label: ReactNode; textValue: string }
33
33
  )
34
34
  export type SelectProps = ValueOwner<string | null> &
35
- ({ open: boolean; defaultOpen?: never } | { open?: undefined; defaultOpen?: boolean }) & {
35
+ StateOwner<'open', boolean> & {
36
36
  /** One registry for native options, SSR value text and keyboard matching. Values must be unique. */
37
37
  items: readonly SelectOption[]
38
38
  onValueChange?: (value: string | null) => void
@@ -42,6 +42,9 @@ export type SelectProps = ValueOwner<string | null> &
42
42
  autoComplete?: string
43
43
  disabled?: boolean
44
44
  required?: boolean
45
+ /** Keep the value focusable and submitted, but block opening and changes. */
46
+ readOnly?: boolean
47
+ 'aria-invalid'?: ComponentProps<'button'>['aria-invalid']
45
48
  controlSize?: ControlSize
46
49
  children?: ReactNode
47
50
  }
@@ -58,6 +61,8 @@ type Context = SelectState & {
58
61
  entries: { value: string; textValue: string; disabled?: boolean }[]
59
62
  controlSize: ControlSize
60
63
  required: boolean
64
+ readOnly: boolean
65
+ invalid: SelectProps['aria-invalid']
61
66
  triggerId: string
62
67
  contentId: string
63
68
  labelId?: string
@@ -95,6 +100,8 @@ export function Select({
95
100
  autoComplete,
96
101
  disabled: disabledProp,
97
102
  required: requiredProp,
103
+ readOnly = false,
104
+ 'aria-invalid': invalid,
98
105
  controlSize = 'medium',
99
106
  children
100
107
  }: SelectProps) {
@@ -135,8 +142,8 @@ export function Select({
135
142
  const selected = items.find(item => item.value === selection.value)
136
143
  const nativeValue = selected?.value ?? ''
137
144
  const [initialNativeValue] = useState(nativeValue)
138
- const isOpen = expansion.value && !disabled
139
- const unavailable = () => disabled || !!trigger?.matches(':disabled')
145
+ const isOpen = expansion.value && !disabled && !readOnly
146
+ const unavailable = () => disabled || readOnly || !!trigger?.matches(':disabled')
140
147
  const setOpen = (next: boolean) => {
141
148
  if (next && unavailable()) return
142
149
  searchBuffer.current = { text: '', at: 0 }
@@ -206,14 +213,6 @@ export function Select({
206
213
  win.clearTimeout(resetTimer)
207
214
  }
208
215
  }, [form, trigger])
209
- useEffect(() => {
210
- if (
211
- !isOpen &&
212
- restoreFocus.current &&
213
- content.current?.contains(content.current.ownerDocument.activeElement)
214
- )
215
- trigger?.focus({ preventScroll: true })
216
- }, [isOpen, trigger])
217
216
  const context: Context = {
218
217
  value: selection.value,
219
218
  setValue: selection.request,
@@ -224,6 +223,8 @@ export function Select({
224
223
  entries,
225
224
  controlSize,
226
225
  required,
226
+ readOnly,
227
+ invalid,
227
228
  triggerId: field?.controlProps?.id ?? `${ids}-trigger`,
228
229
  contentId: `${ids}-content`,
229
230
  labelId: field?.layout === 'control' ? field.labelId : undefined,
@@ -259,7 +260,7 @@ export function Select({
259
260
  name={name}
260
261
  form={form}
261
262
  autoComplete={autoComplete}
262
- required={required}
263
+ required={required && !readOnly}
263
264
  disabled={disabled}
264
265
  aria-hidden="true"
265
266
  tabIndex={-1}
@@ -299,8 +300,18 @@ export function Select({
299
300
 
300
301
  export type SelectTriggerProps = DistributiveOmit<
301
302
  ButtonProps,
302
- 'variant' | 'tone' | 'type' | 'pending' | 'controlSize' | 'disabled'
303
+ | 'variant'
304
+ | 'tone'
305
+ | 'type'
306
+ | 'pending'
307
+ | 'controlSize'
308
+ | 'disabled'
309
+ | 'pressed'
310
+ | 'defaultPressed'
311
+ | 'onPressedChange'
312
+ | 'aria-pressed'
303
313
  >
314
+ export type SelectRenderProps = ButtonRenderProps
304
315
  export function SelectTrigger({
305
316
  className,
306
317
  onClick,
@@ -315,7 +326,7 @@ export function SelectTrigger({
315
326
  disabled: select.disabled,
316
327
  required: select.required,
317
328
  'aria-describedby': props['aria-describedby'],
318
- 'aria-invalid': props['aria-invalid']
329
+ 'aria-invalid': props['aria-invalid'] ?? select.invalid
319
330
  })
320
331
  const hostRef = useComposedRefs(select.setTrigger, ref)
321
332
  return (
@@ -326,6 +337,9 @@ export function SelectTrigger({
326
337
  variant="outline"
327
338
  tone="neutral"
328
339
  type="button"
340
+ pressed={undefined}
341
+ defaultPressed={undefined}
342
+ onPressedChange={undefined}
329
343
  controlSize={select.controlSize}
330
344
  className={cn(
331
345
  selectTriggerClass,
@@ -337,6 +351,7 @@ export function SelectTrigger({
337
351
  aria-controls={select.contentId}
338
352
  aria-expanded={select.open}
339
353
  aria-required={select.required || undefined}
354
+ aria-readonly={select.readOnly || undefined}
340
355
  data-slot="button select-trigger"
341
356
  data-state={select.open ? 'open' : 'closed'}
342
357
  data-placeholder={select.value === null ? '' : undefined}
@@ -697,7 +712,7 @@ export function SelectItem({
697
712
  data-slot="select-item"
698
713
  data-value={value}
699
714
  data-disabled={item.disabled ? '' : undefined}
700
- data-state={select.value === value ? 'checked' : 'unchecked'}
715
+ data-selected={select.value === value ? '' : undefined}
701
716
  className={cn(selectItemClass, className)}
702
717
  onClick={event => {
703
718
  onClick?.(event)
package/src/Slider.tsx CHANGED
@@ -6,7 +6,7 @@ import { useFieldControl } from './Field.js'
6
6
  import { controlBorderClass, controlMetrics } from './controlStyles.js'
7
7
  import { useNativeOwner, type ValueOwner } from './react/useNativeOwner.js'
8
8
  import type { ThemeStyle } from './themes/defineTheme.js'
9
- import type { ControlSize } from './presentation.js'
9
+ import type { ControlSize, Orientation } from './presentation.js'
10
10
 
11
11
  const sliderClass = [
12
12
  controlBorderClass,
@@ -80,7 +80,7 @@ export type SliderProps = Omit<
80
80
  | 'style'
81
81
  > &
82
82
  ValueOwner<number> & {
83
- orientation?: 'horizontal' | 'vertical'
83
+ orientation?: Orientation
84
84
  controlSize?: ControlSize
85
85
  /** Native input styles, including slider track/thumb theme variables. */
86
86
  style?: ThemeStyle
package/src/Tabs.tsx CHANGED
@@ -8,14 +8,15 @@ import {
8
8
  useRef,
9
9
  type ComponentProps
10
10
  } from 'react'
11
- import { Button, type ButtonProps } from './Button.js'
11
+ import { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'
12
12
  import { cn } from './cn.js'
13
13
  import { controlMetrics } from './controlStyles.js'
14
14
  import { composeAction } from './internal/events.js'
15
15
  import { joinIds } from './internal/ids.js'
16
16
  import { useComposedRefs } from './react/useComposedRefs.js'
17
17
  import { useControllableState } from './react/useControllableState.js'
18
- import type { ControlSize } from './presentation.js'
18
+ import type { ControlSize, Orientation } from './presentation.js'
19
+ import type { ValueOwner } from './react/useNativeOwner.js'
19
20
  import type { ThemeStyle } from './themes/defineTheme.js'
20
21
 
21
22
  const rootClass =
@@ -37,9 +38,9 @@ const triggerClass = [
37
38
  '[color:var(--rad-tabs-trigger-color,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))]',
38
39
  'bg-[var(--rad-tabs-trigger-background,transparent)]',
39
40
  'hover:bg-[var(--rad-tabs-trigger-hover-background,var(--rad-color-surface,oklch(1_0_0)))]',
40
- 'data-[state=active]:bg-[var(--rad-tabs-trigger-active-background,var(--rad-color-surface,oklch(1_0_0)))]',
41
- 'data-[state=active]:[color:var(--rad-tabs-trigger-active-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))]',
42
- 'data-[state=active]:[border-color:var(--rad-tabs-trigger-active-border,var(--rad-color-accent,oklch(0.21_0.006_286)))]',
41
+ 'data-selected:bg-[var(--rad-tabs-trigger-active-background,var(--rad-color-surface,oklch(1_0_0)))]',
42
+ 'data-selected:[color:var(--rad-tabs-trigger-active-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))]',
43
+ 'data-selected:[border-color:var(--rad-tabs-trigger-active-border,var(--rad-color-accent,oklch(0.21_0.006_286)))]',
43
44
  'focus-visible:outline-solid',
44
45
  'focus-visible:[outline-color:var(--rad-tabs-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))]',
45
46
  'focus-visible:[outline-width:var(--rad-tabs-focus-width,var(--rad-focus-width,2px))]',
@@ -48,20 +49,18 @@ const triggerClass = [
48
49
  'disabled:cursor-not-allowed disabled:opacity-[var(--rad-tabs-disabled-opacity,var(--rad-state-disabled-opacity,0.5))]',
49
50
  'disabled:bg-[var(--rad-tabs-trigger-background,transparent)]',
50
51
  'forced-colors:border-[ButtonText] forced-colors:text-[ButtonText]',
51
- 'forced-colors:data-[state=active]:border-[Highlight] forced-colors:data-[state=active]:text-[Highlight]',
52
+ 'forced-colors:data-selected:border-[Highlight] forced-colors:data-selected:text-[Highlight]',
52
53
  'forced-colors:disabled:text-[GrayText] forced-colors:disabled:border-[GrayText] forced-colors:disabled:opacity-100'
53
54
  ].join(' ')
54
55
  const contentClass =
55
56
  'min-w-0 rounded-[var(--rad-tabs-content-radius,var(--rad-control-radius,0.5rem))] p-[var(--rad-tabs-content-padding,1rem)] [color:var(--rad-tabs-content-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))] bg-[var(--rad-tabs-content-background,var(--rad-color-surface,oklch(1_0_0)))] font-[family-name:var(--rad-typography-roles-ui-body-family,system-ui,sans-serif)] text-[length:var(--rad-typography-roles-ui-body-size,0.875rem)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] focus-visible:outline-solid focus-visible:[outline-color:var(--rad-tabs-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] focus-visible:[outline-width:var(--rad-tabs-focus-width,var(--rad-focus-width,2px))] focus-visible:[outline-offset:var(--rad-tabs-focus-offset,var(--rad-focus-offset,2px))] focus-visible:[outline-style:var(--rad-tabs-focus-style,var(--rad-focus-style,solid))]'
56
57
 
57
- type SelectionOwner =
58
- | { value: string; defaultValue?: never }
59
- | { value?: undefined; defaultValue: string }
58
+ type SelectionOwner = ValueOwner<string> & ({ value: string } | { defaultValue: string })
60
59
 
61
60
  export type TabsProps = Omit<ComponentProps<'div'>, 'defaultValue' | 'onChange' | 'style'> &
62
61
  SelectionOwner & {
63
62
  onValueChange?: (value: string) => void
64
- orientation?: 'horizontal' | 'vertical'
63
+ orientation?: Orientation
65
64
  activationMode?: 'automatic' | 'manual'
66
65
  loop?: boolean
67
66
  disabled?: boolean
@@ -96,6 +95,7 @@ export type TabsTriggerProps = Omit<
96
95
  | 'defaultPressed'
97
96
  | 'onPressedChange'
98
97
  > & { value: string }
98
+ export type TabsRenderProps = ButtonRenderProps
99
99
  export type TabsContentProps = Omit<
100
100
  ComponentProps<'div'>,
101
101
  'id' | 'role' | 'aria-labelledby' | 'aria-hidden' | 'hidden' | 'inert' | 'style'
@@ -110,7 +110,7 @@ export type TabsState = {
110
110
  value: string
111
111
  setValue: (value: string) => void
112
112
  controlled: boolean
113
- orientation: 'horizontal' | 'vertical'
113
+ orientation: Orientation
114
114
  activationMode: 'automatic' | 'manual'
115
115
  loop: boolean
116
116
  disabled: boolean
@@ -344,7 +344,7 @@ export function TabsTrigger({
344
344
  aria-disabled={unavailable || undefined}
345
345
  tabIndex={selected && !unavailable ? 0 : -1}
346
346
  data-value={value}
347
- data-state={selected ? 'active' : 'inactive'}
347
+ data-selected={selected ? '' : undefined}
348
348
  data-disabled={unavailable ? '' : undefined}
349
349
  data-slot={joinIds('tabs-trigger', props['data-slot'])}
350
350
  data-orientation={tabs.orientation}
@@ -433,7 +433,6 @@ export function TabsContent({
433
433
  className={cn(contentClass, className)}
434
434
  style={{ ...style, display: selected ? style?.display : 'none' }}
435
435
  data-slot={joinIds('tabs-content', props['data-slot'])}
436
- data-state={selected ? 'active' : 'inactive'}
437
436
  data-value={value}
438
437
  data-orientation={tabs.orientation}
439
438
  >
package/src/cn.ts CHANGED
@@ -88,6 +88,7 @@ export const cn: CnFunction = createCn({
88
88
  'w-(--rad-slider-length)'
89
89
  ],
90
90
  'min-w': ['min-w-(--rad-pagination-item-min-width)'],
91
+ 'max-h': ['max-h-(--rad-command-results-max-height)'],
91
92
  'max-w': ['max-w-(--rad-tooltip-max-width)'],
92
93
  size: [
93
94
  'size-(--rad-avatar-size)',
package/src/index.ts CHANGED
@@ -102,6 +102,7 @@ export type {
102
102
  TabsListProps,
103
103
  TabsTriggerProps,
104
104
  TabsContentProps,
105
+ TabsRenderProps,
105
106
  TabsState
106
107
  } from './Tabs.js'
107
108
  export {
@@ -123,6 +124,7 @@ export type {
123
124
  SelectOption,
124
125
  SelectState,
125
126
  SelectTriggerProps,
127
+ SelectRenderProps,
126
128
  SelectValueProps,
127
129
  SelectIconProps,
128
130
  SelectContentProps,
@@ -233,7 +235,7 @@ export type { ThemeScopeProps } from './ThemeScope.js'
233
235
  export type { ButtonProps, ButtonRenderProps, ButtonVariant } from './Button.js'
234
236
  export { generateTypography, typographyPresets, typographyRoles } from './typography/index.js'
235
237
  export type * from './typography/types.js'
236
- export type { ControlSize, Tone } from './presentation.js'
238
+ export type { ControlSize, Orientation, Tone } from './presentation.js'
237
239
 
238
240
  export {
239
241
  defineThemeDocument,
@@ -613,3 +615,26 @@ export {
613
615
  type AutocompleteItemProps,
614
616
  type AutocompleteStatusProps
615
617
  } from './Autocomplete.js'
618
+
619
+ export {
620
+ Command,
621
+ CommandTrigger,
622
+ CommandClose,
623
+ CommandContent,
624
+ CommandTitle,
625
+ CommandDescription,
626
+ CommandInput,
627
+ CommandList,
628
+ CommandItem,
629
+ type CommandProps,
630
+ type CommandRenderProps,
631
+ type CommandOption,
632
+ type CommandTriggerProps,
633
+ type CommandCloseProps,
634
+ type CommandContentProps,
635
+ type CommandTitleProps,
636
+ type CommandDescriptionProps,
637
+ type CommandInputProps,
638
+ type CommandListProps,
639
+ type CommandItemProps
640
+ } from './Command.js'
@@ -7,6 +7,7 @@ type ActionPresentation = VariantProps<typeof actionVariants>
7
7
  export type ButtonVariant = NonNullable<ActionPresentation['variant']>
8
8
  export type Tone = NonNullable<ActionPresentation['tone']>
9
9
  export type ControlSize = 'small' | 'medium' | 'large'
10
+ export type Orientation = 'horizontal' | 'vertical'
10
11
 
11
12
  export type PartStyle = { className?: string; style?: ThemeStyle }
12
13
  export type ControlParts = { wrapper?: PartStyle; label?: PartStyle; indicator?: PartStyle }
@@ -2,6 +2,10 @@
2
2
 
3
3
  import { useState } from 'react'
4
4
 
5
+ export type StateOwner<Name extends string, Value> =
6
+ | ({ [Key in Name]: Value } & { [Key in `default${Capitalize<Name>}`]?: never })
7
+ | ({ [Key in Name]?: undefined } & { [Key in `default${Capitalize<Name>}`]?: Value })
8
+
5
9
  export type ValueOwner<Value> =
6
10
  | { value: Value; defaultValue?: never }
7
11
  | { value?: undefined; defaultValue?: Value }