@cognitap/radiant 0.0.53 → 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.
- package/CHANGELOG.md +11 -0
- package/dist/library/Select.d.ts +9 -11
- package/dist/library/Select.d.ts.map +1 -1
- package/dist/library/Select.js +9 -13
- package/dist/library/Select.js.map +1 -1
- package/dist/library/Slider.d.ts +2 -2
- package/dist/library/Slider.d.ts.map +1 -1
- package/dist/library/Tabs.d.ts +8 -8
- package/dist/library/Tabs.d.ts.map +1 -1
- package/dist/library/Tabs.js +6 -6
- package/dist/library/Tabs.js.map +1 -1
- package/dist/library/index.d.ts +3 -3
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js.map +1 -1
- package/dist/library/presentation.d.ts +1 -0
- package/dist/library/presentation.d.ts.map +1 -1
- package/dist/library/styles.css +1 -1
- package/package.json +1 -1
- package/src/Select.tsx +32 -17
- package/src/Slider.tsx +2 -2
- package/src/Tabs.tsx +12 -13
- package/src/index.ts +3 -1
- package/src/presentation.ts +1 -0
package/package.json
CHANGED
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
|
-
|
|
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
|
-
|
|
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-
|
|
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?:
|
|
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-
|
|
41
|
-
'data-
|
|
42
|
-
'data-
|
|
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-
|
|
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?:
|
|
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:
|
|
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-
|
|
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/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,
|
package/src/presentation.ts
CHANGED
|
@@ -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 }
|