@cognitap/radiant 0.0.7 → 0.0.9
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 +9 -1
- package/README.md +2 -2
- package/dist/library/Dialog.js +1 -1
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/Select.d.ts +87 -0
- package/dist/library/Select.d.ts.map +1 -0
- package/dist/library/Select.js +454 -0
- package/dist/library/Select.js.map +1 -0
- package/dist/library/Textarea.d.ts +15 -0
- package/dist/library/Textarea.d.ts.map +1 -0
- package/dist/library/Textarea.js +54 -0
- package/dist/library/Textarea.js.map +1 -0
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +45 -3
- package/dist/library/cn.js.map +1 -1
- package/dist/library/examples/glass.d.ts.map +1 -1
- package/dist/library/examples/glass.js +5 -0
- package/dist/library/examples/glass.js.map +1 -1
- package/dist/library/index.d.ts +4 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/internal/select.d.ts +37 -0
- package/dist/library/internal/select.d.ts.map +1 -0
- package/dist/library/internal/select.js +42 -0
- package/dist/library/internal/select.js.map +1 -0
- package/dist/library/motion/host.d.ts +2 -1
- package/dist/library/motion/host.d.ts.map +1 -1
- package/dist/library/motion/host.js.map +1 -1
- package/dist/library/motion/popup.d.ts +5 -0
- package/dist/library/motion/popup.d.ts.map +1 -0
- package/dist/library/motion/popup.js +60 -0
- package/dist/library/motion/popup.js.map +1 -0
- package/dist/library/motion/react.d.ts.map +1 -1
- package/dist/library/motion/react.js +3 -1
- package/dist/library/motion/react.js.map +1 -1
- package/dist/library/react/useControllableState.d.ts +1 -0
- package/dist/library/react/useControllableState.d.ts.map +1 -1
- package/dist/library/react/useControllableState.js +8 -1
- package/dist/library/react/useControllableState.js.map +1 -1
- package/dist/library/selectStyles.d.ts +4 -0
- package/dist/library/selectStyles.d.ts.map +1 -0
- package/dist/library/selectStyles.js +32 -0
- package/dist/library/selectStyles.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +47 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +47 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +17 -5
- package/docs/motion.md +4 -4
- package/docs/theming.md +2 -2
- package/package.json +6 -8
- package/src/Dialog.tsx +1 -1
- package/src/Select.tsx +781 -0
- package/src/Textarea.tsx +92 -0
- package/src/cn.ts +45 -3
- package/src/examples/glass.ts +5 -0
- package/src/index.ts +29 -0
- package/src/internal/select.ts +80 -0
- package/src/motion/host.ts +2 -1
- package/src/motion/popup.ts +55 -0
- package/src/motion/react.ts +3 -1
- package/src/react/useControllableState.ts +7 -1
- package/src/selectStyles.ts +34 -0
- package/src/themes/components.ts +47 -0
package/src/Textarea.tsx
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from 'react'
|
|
4
|
+
import { cva } from 'class-variance-authority'
|
|
5
|
+
import { cn } from './cn.js'
|
|
6
|
+
import { controlBorderClass, controlMetrics } from './controlStyles.js'
|
|
7
|
+
import { useNativeOwner, type ValueOwner } from './react/useNativeOwner.js'
|
|
8
|
+
import type { ThemeStyle } from './themes/defineTheme.js'
|
|
9
|
+
import type { ControlSize } from './presentation.js'
|
|
10
|
+
import { useFieldControl } from './Field.js'
|
|
11
|
+
|
|
12
|
+
const textareaVariants = cva([
|
|
13
|
+
controlBorderClass,
|
|
14
|
+
'box-border w-full min-w-0',
|
|
15
|
+
'min-h-[var(--rad-textarea-min-height,var(--_rad-control-height))]',
|
|
16
|
+
'resize-y overflow-auto',
|
|
17
|
+
'py-[var(--rad-textarea-padding-block,calc((var(--_rad-control-height)_-_1lh)/2_-_var(--rad-textarea-border-width,var(--rad-control-border-width,1px))))]',
|
|
18
|
+
'px-[var(--rad-textarea-padding,var(--_rad-control-padding))]',
|
|
19
|
+
'font-[family-name:var(--rad-textarea-font-family,var(--rad-typography-roles-ui-body-family,system-ui,sans-serif))] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)]',
|
|
20
|
+
'text-[length:var(--rad-textarea-font-size,var(--_rad-control-font-size))]',
|
|
21
|
+
'leading-[var(--rad-typography-roles-ui-body-line-height,1.5)]',
|
|
22
|
+
'font-[number:var(--rad-textarea-font-weight,var(--rad-typography-roles-ui-body-weight,400))]',
|
|
23
|
+
'[color:var(--rad-textarea-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))]',
|
|
24
|
+
'bg-[var(--rad-textarea-background,var(--rad-color-surface,oklch(1_0_0)))]',
|
|
25
|
+
'[border-width:var(--rad-textarea-border-width,var(--rad-control-border-width,1px))]',
|
|
26
|
+
'[border-style:var(--rad-textarea-border-style,var(--rad-control-border-style,solid))]',
|
|
27
|
+
'[border-color:var(--rad-textarea-border-color,var(--_rad-control-border))]',
|
|
28
|
+
'rounded-[var(--rad-textarea-radius,var(--rad-control-radius,0.5rem))]',
|
|
29
|
+
'[corner-shape:var(--rad-textarea-corner-shape,var(--rad-control-corner-shape,round))]',
|
|
30
|
+
'[box-shadow:var(--rad-textarea-shadow,none)]',
|
|
31
|
+
'placeholder:[color:var(--rad-textarea-placeholder,var(--rad-color-placeholder,oklch(0.5_0.01_286)))]',
|
|
32
|
+
'focus-visible:outline-solid',
|
|
33
|
+
'focus-visible:[outline-color:var(--rad-textarea-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))]',
|
|
34
|
+
'focus-visible:[outline-width:var(--rad-textarea-focus-width,var(--rad-focus-width,2px))]',
|
|
35
|
+
'focus-visible:[outline-offset:var(--rad-textarea-focus-offset,var(--rad-focus-offset,2px))]',
|
|
36
|
+
'focus-visible:[outline-style:var(--rad-textarea-focus-style,var(--rad-focus-style,solid))]',
|
|
37
|
+
'data-invalid:[border-color:var(--rad-textarea-invalid-border,var(--rad-color-invalid,oklch(0.56_0.19_25)))]',
|
|
38
|
+
'disabled:cursor-not-allowed',
|
|
39
|
+
'disabled:[background:var(--rad-textarea-disabled-background,var(--rad-color-disabled-background,oklch(0.96_0.005_286)))]',
|
|
40
|
+
'forced-colors:border-[CanvasText] forced-colors:text-[CanvasText]',
|
|
41
|
+
'forced-colors:disabled:bg-[Canvas] forced-colors:disabled:text-[GrayText]'
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
export type TextareaProps = Omit<
|
|
45
|
+
ComponentProps<'textarea'>,
|
|
46
|
+
'value' | 'defaultValue' | 'style' | 'children'
|
|
47
|
+
> &
|
|
48
|
+
ValueOwner<Exclude<ComponentProps<'textarea'>['value'], undefined>> & {
|
|
49
|
+
/** Set initial text with defaultValue. */
|
|
50
|
+
children?: never
|
|
51
|
+
/** Shared visual metrics. Native rows and cols keep their browser meanings. */
|
|
52
|
+
controlSize?: ControlSize
|
|
53
|
+
/** Applied to the native textarea, including caller-owned motion styles. */
|
|
54
|
+
style?: ThemeStyle
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Native editing, selection, events and ref; Field supplies owned form relationships. */
|
|
58
|
+
export function Textarea({
|
|
59
|
+
className,
|
|
60
|
+
controlSize = 'medium',
|
|
61
|
+
rows = 3,
|
|
62
|
+
id,
|
|
63
|
+
disabled,
|
|
64
|
+
required,
|
|
65
|
+
'aria-describedby': ariaDescribedBy,
|
|
66
|
+
'aria-invalid': ariaInvalid,
|
|
67
|
+
'aria-required': ariaRequired,
|
|
68
|
+
...props
|
|
69
|
+
}: TextareaProps) {
|
|
70
|
+
useNativeOwner('Textarea', props.value, props.defaultValue)
|
|
71
|
+
if (props.value === null)
|
|
72
|
+
throw new TypeError('Textarea value cannot be null. Use an empty string.')
|
|
73
|
+
const control = useFieldControl({
|
|
74
|
+
id,
|
|
75
|
+
disabled,
|
|
76
|
+
required,
|
|
77
|
+
'aria-invalid': ariaInvalid,
|
|
78
|
+
'aria-required': ariaRequired,
|
|
79
|
+
'aria-describedby': ariaDescribedBy
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<textarea
|
|
84
|
+
{...props}
|
|
85
|
+
{...control}
|
|
86
|
+
className={cn(textareaVariants(), controlMetrics({ controlSize }), className)}
|
|
87
|
+
data-control-size={controlSize}
|
|
88
|
+
data-slot="textarea"
|
|
89
|
+
rows={rows}
|
|
90
|
+
/>
|
|
91
|
+
)
|
|
92
|
+
}
|
package/src/cn.ts
CHANGED
|
@@ -9,9 +9,51 @@ const roleClasses = (prefix: string, leaf: string) =>
|
|
|
9
9
|
export const cn: CnFunction = createCn({
|
|
10
10
|
extend: {
|
|
11
11
|
classGroups: {
|
|
12
|
-
'font-family':
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
'font-family': [
|
|
13
|
+
...roleClasses('font', 'family'),
|
|
14
|
+
'font-(--rad-select-font-family)',
|
|
15
|
+
'font-(--rad-textarea-font-family)'
|
|
16
|
+
],
|
|
17
|
+
'font-weight': [
|
|
18
|
+
...roleClasses('font', 'weight'),
|
|
19
|
+
'font-(--rad-select-font-weight)',
|
|
20
|
+
'font-(--rad-textarea-font-weight)'
|
|
21
|
+
],
|
|
22
|
+
'font-size': [
|
|
23
|
+
...roleClasses('text', 'size'),
|
|
24
|
+
...roleClasses('text', 'fluid-size'),
|
|
25
|
+
'text-(--rad-select-font-size)',
|
|
26
|
+
'text-(--rad-textarea-font-size)'
|
|
27
|
+
],
|
|
28
|
+
h: ['h-(--rad-select-height)'],
|
|
29
|
+
'min-h': ['min-h-(--rad-textarea-min-height)'],
|
|
30
|
+
py: ['py-(--rad-textarea-padding-block)'],
|
|
31
|
+
px: ['px-(--rad-select-padding)', 'px-(--rad-textarea-padding)'],
|
|
32
|
+
p: ['p-(--rad-select-content-padding)'],
|
|
33
|
+
rounded: [
|
|
34
|
+
'rounded-(--rad-select-radius)',
|
|
35
|
+
'rounded-(--rad-textarea-radius)',
|
|
36
|
+
'rounded-(--rad-select-content-radius)',
|
|
37
|
+
'rounded-(--rad-select-item-radius)'
|
|
38
|
+
],
|
|
39
|
+
'border-w': ['border-(--rad-select-border-width)', 'border-(--rad-textarea-border-width)'],
|
|
40
|
+
'border-style': [
|
|
41
|
+
'border-(--rad-select-border-style)',
|
|
42
|
+
'border-(--rad-textarea-border-style)'
|
|
43
|
+
],
|
|
44
|
+
shadow: [
|
|
45
|
+
'shadow-(--rad-select-shadow)',
|
|
46
|
+
'shadow-(--rad-select-content-shadow)',
|
|
47
|
+
'shadow-(--rad-textarea-shadow)'
|
|
48
|
+
],
|
|
49
|
+
'corner-shape': [
|
|
50
|
+
'[corner-shape:var(--rad-select-corner-shape)]',
|
|
51
|
+
'[corner-shape:var(--rad-textarea-corner-shape)]'
|
|
52
|
+
],
|
|
53
|
+
'outline-w': ['outline-(--rad-textarea-focus-width)'],
|
|
54
|
+
'outline-offset': ['outline-offset-(--rad-textarea-focus-offset)'],
|
|
55
|
+
'outline-style': ['outline-(--rad-textarea-focus-style)'],
|
|
56
|
+
'backdrop-filter': ['[backdrop-filter:var(--rad-select-content-backdrop-filter)]'],
|
|
15
57
|
leading: roleClasses('leading', 'line-height'),
|
|
16
58
|
tracking: roleClasses('tracking', 'letter-spacing'),
|
|
17
59
|
'max-inline-size': roleClasses('max-inline', 'measure'),
|
package/src/examples/glass.ts
CHANGED
|
@@ -87,6 +87,10 @@ export const glassDefinition: ThemeDefinition = {
|
|
|
87
87
|
state: { disabledOpacity: 0.5 }
|
|
88
88
|
},
|
|
89
89
|
components: {
|
|
90
|
+
select: {
|
|
91
|
+
contentBackground: 'rgb(255 255 255 / 0.92)',
|
|
92
|
+
contentBackdropFilter: 'blur(18px) saturate(190%)'
|
|
93
|
+
},
|
|
90
94
|
dialog: { backdropFilter: 'blur(18px) saturate(190%)' },
|
|
91
95
|
button: {
|
|
92
96
|
fontWeight: 700,
|
|
@@ -102,6 +106,7 @@ export const glassDefinition: ThemeDefinition = {
|
|
|
102
106
|
},
|
|
103
107
|
modes: {
|
|
104
108
|
dark: {
|
|
109
|
+
components: { select: { contentBackground: 'rgb(27 25 48 / 0.94)' } },
|
|
105
110
|
tokens: {
|
|
106
111
|
color: {
|
|
107
112
|
surface: 'rgb(27 25 48 / 0.9)',
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,35 @@ export { Field, useField } from './Field.js'
|
|
|
5
5
|
export type { FieldControlProps, FieldLayout, FieldProps, FieldState } from './Field.js'
|
|
6
6
|
export { Input } from './Input.js'
|
|
7
7
|
export type { InputProps } from './Input.js'
|
|
8
|
+
export { Textarea } from './Textarea.js'
|
|
9
|
+
export type { TextareaProps } from './Textarea.js'
|
|
10
|
+
export {
|
|
11
|
+
Select,
|
|
12
|
+
SelectTrigger,
|
|
13
|
+
SelectValue,
|
|
14
|
+
SelectIcon,
|
|
15
|
+
SelectPortal,
|
|
16
|
+
SelectContent,
|
|
17
|
+
SelectViewport,
|
|
18
|
+
SelectItem,
|
|
19
|
+
SelectItemText,
|
|
20
|
+
SelectItemIndicator,
|
|
21
|
+
SelectGroup,
|
|
22
|
+
useSelect
|
|
23
|
+
} from './Select.js'
|
|
24
|
+
export type {
|
|
25
|
+
SelectProps,
|
|
26
|
+
SelectOption,
|
|
27
|
+
SelectState,
|
|
28
|
+
SelectTriggerProps,
|
|
29
|
+
SelectValueProps,
|
|
30
|
+
SelectIconProps,
|
|
31
|
+
SelectContentProps,
|
|
32
|
+
SelectViewportProps,
|
|
33
|
+
SelectItemProps,
|
|
34
|
+
SelectItemTextProps,
|
|
35
|
+
SelectGroupProps
|
|
36
|
+
} from './Select.js'
|
|
8
37
|
export { Checkbox } from './Checkbox.js'
|
|
9
38
|
export type { CheckboxProps } from './Checkbox.js'
|
|
10
39
|
export { Radio, RadioGroup } from './RadioGroup.js'
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type SelectEntry = { value: string; textValue: string; disabled?: boolean }
|
|
2
|
+
|
|
3
|
+
/** Native-like text matching, including repeated-letter cycling. */
|
|
4
|
+
export function matchSelectText(
|
|
5
|
+
items: readonly SelectEntry[],
|
|
6
|
+
text: string,
|
|
7
|
+
current: string | null
|
|
8
|
+
) {
|
|
9
|
+
const search = text.toLocaleLowerCase()
|
|
10
|
+
const repeated = search.length > 1 && [...search].every(letter => letter === search[0])
|
|
11
|
+
const query = repeated ? search[0] : search
|
|
12
|
+
const index = items.findIndex(item => item.value === current)
|
|
13
|
+
const ordered = [...items.slice(index + 1), ...items.slice(0, index + 1)]
|
|
14
|
+
if (query.length > 1 && index >= 0) ordered.unshift(items[index])
|
|
15
|
+
return ordered.find(
|
|
16
|
+
item => !item.disabled && item.textValue.toLocaleLowerCase().startsWith(query)
|
|
17
|
+
)?.value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function moveSelectFocus(
|
|
21
|
+
items: readonly SelectEntry[],
|
|
22
|
+
current: string | null,
|
|
23
|
+
key: string
|
|
24
|
+
) {
|
|
25
|
+
const enabled = items.filter(item => !item.disabled)
|
|
26
|
+
if (key === 'Home') return enabled[0]?.value
|
|
27
|
+
if (key === 'End') return enabled.at(-1)?.value
|
|
28
|
+
const index = enabled.findIndex(item => item.value === current)
|
|
29
|
+
return enabled[Math.max(0, Math.min(enabled.length - 1, index + (key === 'ArrowUp' ? -1 : 1)))]
|
|
30
|
+
?.value
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function positionSelect(input: {
|
|
34
|
+
trigger: {
|
|
35
|
+
top: number
|
|
36
|
+
bottom: number
|
|
37
|
+
left: number
|
|
38
|
+
right: number
|
|
39
|
+
height: number
|
|
40
|
+
width: number
|
|
41
|
+
}
|
|
42
|
+
width: number
|
|
43
|
+
height: number
|
|
44
|
+
selectedOffset: number
|
|
45
|
+
viewport: { top: number; left: number; width: number; height: number }
|
|
46
|
+
padding: number
|
|
47
|
+
offset: number
|
|
48
|
+
aligned: boolean
|
|
49
|
+
rtl: boolean
|
|
50
|
+
}) {
|
|
51
|
+
const { trigger, viewport, padding } = input
|
|
52
|
+
const width = Math.min(
|
|
53
|
+
Math.max(input.width, trigger.width),
|
|
54
|
+
Math.max(0, viewport.width - 2 * padding)
|
|
55
|
+
)
|
|
56
|
+
const height = Math.min(input.height, Math.max(0, viewport.height - 2 * padding))
|
|
57
|
+
let top = input.aligned
|
|
58
|
+
? trigger.top + trigger.height / 2 - input.selectedOffset
|
|
59
|
+
: trigger.bottom + input.offset
|
|
60
|
+
if (
|
|
61
|
+
!input.aligned &&
|
|
62
|
+
top + height > viewport.top + viewport.height - padding &&
|
|
63
|
+
trigger.top - input.offset - height >= viewport.top + padding
|
|
64
|
+
)
|
|
65
|
+
top = trigger.top - input.offset - height
|
|
66
|
+
top = Math.max(
|
|
67
|
+
viewport.top + padding,
|
|
68
|
+
Math.min(top, viewport.top + viewport.height - height - padding)
|
|
69
|
+
)
|
|
70
|
+
const preferredLeft = input.rtl ? trigger.right - width : trigger.left
|
|
71
|
+
return {
|
|
72
|
+
top,
|
|
73
|
+
left: Math.max(
|
|
74
|
+
viewport.left + padding,
|
|
75
|
+
Math.min(preferredLeft, viewport.left + viewport.width - width - padding)
|
|
76
|
+
),
|
|
77
|
+
width,
|
|
78
|
+
maxHeight: height
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/motion/host.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface MotionHostRuntime {
|
|
|
14
14
|
press(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
15
15
|
disclosure?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
16
16
|
dialog?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
17
|
+
popup?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
17
18
|
}
|
|
18
19
|
export const MotionHostContext = createContext<MotionHostRuntime | null>(null)
|
|
19
20
|
/** Engine-free bridge: only the opt-in provider supplies implementation. */
|
|
@@ -58,7 +59,7 @@ export function usePressHost<Node extends HTMLElement>(
|
|
|
58
59
|
|
|
59
60
|
/** Shared lifecycle for native presentation adapters; no engine enters the root path. */
|
|
60
61
|
export function useTransitionHost<Node extends HTMLElement>(
|
|
61
|
-
kind: 'disclosure' | 'dialog',
|
|
62
|
+
kind: 'disclosure' | 'dialog' | 'popup',
|
|
62
63
|
ref: Ref<Node> | undefined,
|
|
63
64
|
disabled: boolean
|
|
64
65
|
) {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createSpring } from './runtime.js'
|
|
2
|
+
import { resolveMotion, type MotionProfile } from './config.js'
|
|
3
|
+
import type { MotionHostBinding } from './host.js'
|
|
4
|
+
|
|
5
|
+
/** Enter presentation only. Closing, focus and top-layer removal are immediate. */
|
|
6
|
+
export function bindPopupMotion(node: HTMLElement, initial: MotionProfile): MotionHostBinding {
|
|
7
|
+
let profile = initial
|
|
8
|
+
let open = false
|
|
9
|
+
const win = node.ownerDocument.defaultView!
|
|
10
|
+
const query = win.matchMedia('(prefers-reduced-motion: reduce)')
|
|
11
|
+
const spring = createSpring(0, {
|
|
12
|
+
...resolveMotion(profile, 'dialog', query.matches),
|
|
13
|
+
reducedValue: 0
|
|
14
|
+
})
|
|
15
|
+
const previous = node.style.getPropertyValue('--_rad-select-enter')
|
|
16
|
+
let owned = previous
|
|
17
|
+
const render = (value: number) => {
|
|
18
|
+
owned = String(Math.max(0, Math.min(1, value)))
|
|
19
|
+
node.style.setProperty('--_rad-select-enter', owned)
|
|
20
|
+
}
|
|
21
|
+
const off = spring.subscribe(render)
|
|
22
|
+
render(spring.get())
|
|
23
|
+
const sync = () => {
|
|
24
|
+
const next = node.dataset.state === 'open'
|
|
25
|
+
const resolved = resolveMotion(profile, 'dialog', query.matches)
|
|
26
|
+
spring.configure({ ...resolved, reducedValue: next ? 1 : 0 })
|
|
27
|
+
if (next !== open) {
|
|
28
|
+
open = next
|
|
29
|
+
if (next) {
|
|
30
|
+
spring.jump(0)
|
|
31
|
+
spring.to(1)
|
|
32
|
+
} else spring.jump(0)
|
|
33
|
+
} else if (!resolved.enabled) spring.jump(next ? 1 : 0)
|
|
34
|
+
}
|
|
35
|
+
const observer = new win.MutationObserver(sync)
|
|
36
|
+
observer.observe(node, { attributes: true, attributeFilter: ['data-state'] })
|
|
37
|
+
query.addEventListener('change', sync)
|
|
38
|
+
sync()
|
|
39
|
+
return {
|
|
40
|
+
update(next) {
|
|
41
|
+
profile = next
|
|
42
|
+
sync()
|
|
43
|
+
},
|
|
44
|
+
destroy() {
|
|
45
|
+
observer.disconnect()
|
|
46
|
+
query.removeEventListener('change', sync)
|
|
47
|
+
off()
|
|
48
|
+
spring.destroy()
|
|
49
|
+
if (node.style.getPropertyValue('--_rad-select-enter') === owned) {
|
|
50
|
+
if (previous) node.style.setProperty('--_rad-select-enter', previous)
|
|
51
|
+
else node.style.removeProperty('--_rad-select-enter')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/motion/react.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { createElement, type ReactNode } from 'react'
|
|
|
12
12
|
import { MotionHostContext } from './host.js'
|
|
13
13
|
import { bindDisclosureMotion, bindDialogMotion } from './transitions.js'
|
|
14
14
|
import { bindPressMotion } from './press.js'
|
|
15
|
+
import { bindPopupMotion } from './popup.js'
|
|
15
16
|
import { MotionProfileContext } from './context.js'
|
|
16
17
|
import { resolveMotion, type MotionInteraction } from './config.js'
|
|
17
18
|
import { createSpringDrag, type SpringDragController, type SpringDragOptions } from './drag.js'
|
|
@@ -134,7 +135,8 @@ export function useSpringStyle(
|
|
|
134
135
|
const hostRuntime = {
|
|
135
136
|
press: bindPressMotion,
|
|
136
137
|
disclosure: bindDisclosureMotion,
|
|
137
|
-
dialog: bindDialogMotion
|
|
138
|
+
dialog: bindDialogMotion,
|
|
139
|
+
popup: bindPopupMotion
|
|
138
140
|
}
|
|
139
141
|
/** Opt into native Radiant spring interactions without adding a DOM wrapper. */
|
|
140
142
|
export function MotionProvider({ children }: { children?: ReactNode }) {
|
|
@@ -33,6 +33,7 @@ export function useControllableState<Value>({
|
|
|
33
33
|
throw new TypeError(`${name} accepts a controlled value or a default, not both.`)
|
|
34
34
|
}
|
|
35
35
|
const current = value !== undefined ? value : uncontrolled
|
|
36
|
+
const initial = useRef(uncontrolled)
|
|
36
37
|
const accepted = useRef(current)
|
|
37
38
|
const request = (update: Value | ((current: Value) => Value)) => {
|
|
38
39
|
const previous = controlled ? current : accepted.current
|
|
@@ -46,5 +47,10 @@ export function useControllableState<Value>({
|
|
|
46
47
|
}
|
|
47
48
|
onChange?.(next)
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
const reset = () => {
|
|
51
|
+
if (controlled) return
|
|
52
|
+
accepted.current = initial.current
|
|
53
|
+
setUncontrolled(initial.current)
|
|
54
|
+
}
|
|
55
|
+
return { value: current, request, controlled, reset }
|
|
50
56
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { controlBorderClass } from './controlStyles.js'
|
|
2
|
+
|
|
3
|
+
export const selectTriggerClass = [
|
|
4
|
+
controlBorderClass,
|
|
5
|
+
'box-border flex w-full min-w-0 items-center justify-between gap-2 text-start',
|
|
6
|
+
'[&>span:first-child]:w-full [&>span:first-child]:min-w-0 [&>span:first-child]:justify-between',
|
|
7
|
+
'h-[var(--rad-select-height,var(--_rad-control-height))] px-[var(--rad-select-padding,var(--_rad-control-padding))]',
|
|
8
|
+
'font-[family-name:var(--rad-select-font-family,var(--rad-typography-roles-ui-body-family,system-ui,sans-serif))] text-[length:var(--rad-select-font-size,var(--_rad-control-font-size))] font-[number:var(--rad-select-font-weight,var(--rad-typography-roles-ui-body-weight,400))] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)]',
|
|
9
|
+
'[color:var(--rad-select-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))] bg-[var(--rad-select-background,var(--rad-color-surface,white))]',
|
|
10
|
+
'[border-width:var(--rad-select-border-width,var(--rad-control-border-width,1px))] [border-style:var(--rad-select-border-style,var(--rad-control-border-style,solid))] [border-color:var(--rad-select-border-color,var(--_rad-control-border))]',
|
|
11
|
+
'rounded-[var(--rad-select-radius,var(--rad-control-radius,0.5rem))] [corner-shape:var(--rad-select-corner-shape,var(--rad-control-corner-shape,round))] [box-shadow:var(--rad-select-shadow,none)]',
|
|
12
|
+
'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-select-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-focus-width,2px)] focus-visible:[outline-offset:var(--rad-focus-offset,2px)]',
|
|
13
|
+
'data-invalid:[border-color:var(--rad-color-invalid)] disabled:cursor-not-allowed disabled:bg-[var(--rad-color-disabled-background)]',
|
|
14
|
+
'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText] forced-colors:disabled:text-[GrayText]'
|
|
15
|
+
].join(' ')
|
|
16
|
+
|
|
17
|
+
export const selectContentClass = [
|
|
18
|
+
'fixed right-auto bottom-auto m-0 box-border min-w-0 overflow-hidden overscroll-contain',
|
|
19
|
+
'left-[var(--_rad-select-left,0px)] top-[var(--_rad-select-top,0px)] w-[var(--_rad-select-width,auto)] max-h-[var(--_rad-select-max-height,calc(100dvh-1rem))]',
|
|
20
|
+
'p-[var(--rad-select-content-padding,0.25rem)] rounded-[var(--rad-select-content-radius,var(--rad-surface-radius,0.75rem))]',
|
|
21
|
+
'[border-width:var(--rad-select-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-select-border-style,var(--rad-surface-border-style,solid))] [border-color:var(--rad-select-border-color,var(--rad-color-border))]',
|
|
22
|
+
'bg-[var(--rad-select-content-background,var(--rad-color-surface,white))] [color:var(--rad-select-color,var(--rad-color-foreground))] [box-shadow:var(--rad-select-content-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))]',
|
|
23
|
+
'[backdrop-filter:var(--rad-select-content-backdrop-filter,none)]',
|
|
24
|
+
'font-[family-name:var(--rad-select-font-family,var(--rad-typography-roles-ui-body-family,system-ui,sans-serif))] text-[length:var(--rad-select-font-size,var(--_rad-control-font-size))] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] font-[number:var(--rad-select-font-weight,var(--rad-typography-roles-ui-body-weight,400))]',
|
|
25
|
+
'outline-none forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]'
|
|
26
|
+
].join(' ')
|
|
27
|
+
|
|
28
|
+
export const selectItemClass = [
|
|
29
|
+
'relative flex min-w-0 cursor-default select-none items-center gap-2 break-words rounded-[var(--rad-select-item-radius,var(--rad-control-radius,0.5rem))]',
|
|
30
|
+
'min-h-[var(--_rad-control-height,2.5rem)] px-[var(--_rad-control-padding,1rem)] py-2 outline-none',
|
|
31
|
+
'focus:[background:var(--rad-select-item-background,var(--rad-color-accent))] focus:[color:var(--rad-select-item-color,var(--rad-color-accent-foreground))]',
|
|
32
|
+
'data-disabled:opacity-[var(--rad-state-disabled-opacity,0.5)] data-disabled:cursor-not-allowed',
|
|
33
|
+
'forced-colors:focus:bg-[Highlight] forced-colors:focus:text-[HighlightText] forced-colors:data-disabled:text-[GrayText] forced-colors:data-disabled:opacity-100'
|
|
34
|
+
].join(' ')
|
package/src/themes/components.ts
CHANGED
|
@@ -95,6 +95,53 @@ export const componentRegistry = {
|
|
|
95
95
|
focusOffset: 'css',
|
|
96
96
|
focusStyle: 'css'
|
|
97
97
|
},
|
|
98
|
+
textarea: {
|
|
99
|
+
minHeight: 'css',
|
|
100
|
+
paddingBlock: 'css',
|
|
101
|
+
padding: 'css',
|
|
102
|
+
fontFamily: 'css',
|
|
103
|
+
fontSize: 'css',
|
|
104
|
+
fontWeight: 'weight',
|
|
105
|
+
color: 'css',
|
|
106
|
+
background: 'css',
|
|
107
|
+
borderWidth: 'css',
|
|
108
|
+
borderStyle: 'css',
|
|
109
|
+
borderColor: 'css',
|
|
110
|
+
radius: 'css',
|
|
111
|
+
cornerShape: 'css',
|
|
112
|
+
shadow: 'css',
|
|
113
|
+
placeholder: 'css',
|
|
114
|
+
invalidBorder: 'css',
|
|
115
|
+
disabledBackground: 'css',
|
|
116
|
+
focusColor: 'css',
|
|
117
|
+
focusWidth: 'css',
|
|
118
|
+
focusOffset: 'css',
|
|
119
|
+
focusStyle: 'css'
|
|
120
|
+
},
|
|
121
|
+
select: {
|
|
122
|
+
height: 'css',
|
|
123
|
+
padding: 'css',
|
|
124
|
+
fontFamily: 'css',
|
|
125
|
+
fontSize: 'css',
|
|
126
|
+
fontWeight: 'weight',
|
|
127
|
+
color: 'css',
|
|
128
|
+
background: 'css',
|
|
129
|
+
borderWidth: 'css',
|
|
130
|
+
borderStyle: 'css',
|
|
131
|
+
borderColor: 'css',
|
|
132
|
+
radius: 'css',
|
|
133
|
+
cornerShape: 'css',
|
|
134
|
+
shadow: 'css',
|
|
135
|
+
focusColor: 'css',
|
|
136
|
+
contentPadding: 'css',
|
|
137
|
+
contentRadius: 'css',
|
|
138
|
+
contentBackground: 'css',
|
|
139
|
+
contentBackdropFilter: 'css',
|
|
140
|
+
contentShadow: 'css',
|
|
141
|
+
itemRadius: 'css',
|
|
142
|
+
itemBackground: 'css',
|
|
143
|
+
itemColor: 'css'
|
|
144
|
+
},
|
|
98
145
|
checkbox: {
|
|
99
146
|
size: 'css',
|
|
100
147
|
radius: 'css',
|