@cognitap/radiant 0.0.1 → 0.0.3
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 +323 -15
- package/LICENSE +1 -1
- package/README.md +963 -220
- package/RELEASE_POLICY.md +23 -95
- package/dist/library/Accordion.d.ts +56 -0
- package/dist/library/Accordion.d.ts.map +1 -0
- package/dist/library/Accordion.js +89 -0
- package/dist/library/Accordion.js.map +1 -0
- package/dist/library/Button.d.ts +25 -3
- package/dist/library/Button.d.ts.map +1 -1
- package/dist/library/Button.js +31 -3
- package/dist/library/Button.js.map +1 -1
- package/dist/library/Card.d.ts +31 -0
- package/dist/library/Card.d.ts.map +1 -0
- package/dist/library/Card.js +69 -0
- package/dist/library/Card.js.map +1 -0
- package/dist/library/Checkbox.d.ts +13 -0
- package/dist/library/Checkbox.d.ts.map +1 -0
- package/dist/library/Checkbox.js +77 -0
- package/dist/library/Checkbox.js.map +1 -0
- package/dist/library/Collapsible.d.ts +32 -0
- package/dist/library/Collapsible.d.ts.map +1 -0
- package/dist/library/Collapsible.js +99 -0
- package/dist/library/Collapsible.js.map +1 -0
- package/dist/library/Dialog.d.ts +50 -0
- package/dist/library/Dialog.d.ts.map +1 -0
- package/dist/library/Dialog.js +215 -0
- package/dist/library/Dialog.js.map +1 -0
- package/dist/library/Field.d.ts +68 -0
- package/dist/library/Field.d.ts.map +1 -0
- package/dist/library/Field.js +114 -0
- package/dist/library/Field.js.map +1 -0
- package/dist/library/Input.d.ts +10 -0
- package/dist/library/Input.d.ts.map +1 -0
- package/dist/library/Input.js +51 -0
- package/dist/library/Input.js.map +1 -0
- package/dist/library/Link.d.ts +27 -0
- package/dist/library/Link.d.ts.map +1 -0
- package/dist/library/Link.js +50 -0
- package/dist/library/Link.js.map +1 -0
- package/dist/library/RadioGroup.d.ts +27 -0
- package/dist/library/RadioGroup.d.ts.map +1 -0
- package/dist/library/RadioGroup.js +103 -0
- package/dist/library/RadioGroup.js.map +1 -0
- package/dist/library/ThemeScope.d.ts +10 -0
- package/dist/library/ThemeScope.d.ts.map +1 -0
- package/dist/library/ThemeScope.js +41 -0
- package/dist/library/ThemeScope.js.map +1 -0
- package/dist/library/actionStyles.d.ts +11 -0
- package/dist/library/actionStyles.d.ts.map +1 -0
- package/dist/library/actionStyles.js +75 -0
- package/dist/library/actionStyles.js.map +1 -0
- package/dist/library/cn.d.ts +1 -2
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +1 -8
- package/dist/library/cn.js.map +1 -1
- package/dist/library/controlStyles.d.ts +5 -0
- package/dist/library/controlStyles.d.ts.map +1 -0
- package/dist/library/controlStyles.js +15 -0
- package/dist/library/controlStyles.js.map +1 -0
- package/dist/library/index.d.ts +24 -1
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +11 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/internal/events.d.ts +8 -0
- package/dist/library/internal/events.d.ts.map +1 -0
- package/dist/library/internal/events.js +13 -0
- package/dist/library/internal/events.js.map +1 -0
- package/dist/library/internal/ids.d.ts +3 -0
- package/dist/library/internal/ids.d.ts.map +1 -0
- package/dist/library/internal/ids.js +6 -0
- package/dist/library/internal/ids.js.map +1 -0
- package/dist/library/internal/selection.d.ts +5 -0
- package/dist/library/internal/selection.d.ts.map +1 -0
- package/dist/library/internal/selection.js +18 -0
- package/dist/library/internal/selection.js.map +1 -0
- package/dist/library/presentation.d.ts +18 -0
- package/dist/library/presentation.d.ts.map +1 -0
- package/dist/library/presentation.js +2 -0
- package/dist/library/presentation.js.map +1 -0
- package/dist/library/react/useComposedRefs.d.ts +4 -0
- package/dist/library/react/useComposedRefs.d.ts.map +1 -0
- package/dist/library/react/useComposedRefs.js +28 -0
- package/dist/library/react/useComposedRefs.js.map +1 -0
- package/dist/library/react/useControllableState.d.ts +16 -0
- package/dist/library/react/useControllableState.d.ts.map +1 -0
- package/dist/library/react/useControllableState.js +29 -0
- package/dist/library/react/useControllableState.js.map +1 -0
- package/dist/library/react/useNativeOwner.d.ts +17 -0
- package/dist/library/react/useNativeOwner.d.ts.map +1 -0
- package/dist/library/react/useNativeOwner.js +17 -0
- package/dist/library/react/useNativeOwner.js.map +1 -0
- package/dist/library/reset.css +1 -0
- package/dist/library/styles.css +2 -1
- package/dist/library/themes/components.d.ts +217 -0
- package/dist/library/themes/components.d.ts.map +1 -0
- package/dist/library/themes/components.js +229 -0
- package/dist/library/themes/components.js.map +1 -0
- package/dist/library/themes/default.d.ts +2 -0
- package/dist/library/themes/default.d.ts.map +1 -0
- package/dist/library/themes/default.js +4 -0
- package/dist/library/themes/default.js.map +1 -0
- package/dist/library/themes/defineTheme.d.ts +33 -0
- package/dist/library/themes/defineTheme.d.ts.map +1 -0
- package/dist/library/themes/defineTheme.js +98 -0
- package/dist/library/themes/defineTheme.js.map +1 -0
- package/dist/library/themes/expressive.d.ts +2 -0
- package/dist/library/themes/expressive.d.ts.map +1 -0
- package/dist/library/themes/expressive.js +132 -0
- package/dist/library/themes/expressive.js.map +1 -0
- package/dist/library/themes/glass.d.ts +2 -0
- package/dist/library/themes/glass.d.ts.map +1 -0
- package/dist/library/themes/glass.js +132 -0
- package/dist/library/themes/glass.js.map +1 -0
- package/dist/library/themes/index.d.ts +14 -0
- package/dist/library/themes/index.d.ts.map +1 -0
- package/dist/library/themes/index.js +21 -0
- package/dist/library/themes/index.js.map +1 -0
- package/dist/library/themes/jelly.d.ts +2 -0
- package/dist/library/themes/jelly.d.ts.map +1 -0
- package/dist/library/themes/jelly.js +130 -0
- package/dist/library/themes/jelly.js.map +1 -0
- package/dist/library/themes/preset-values.d.ts +4 -0
- package/dist/library/themes/preset-values.d.ts.map +1 -0
- package/dist/library/themes/preset-values.js +5 -0
- package/dist/library/themes/preset-values.js.map +1 -0
- package/dist/library/themes/radiant.d.ts +2 -0
- package/dist/library/themes/radiant.d.ts.map +1 -0
- package/dist/library/themes/radiant.js +129 -0
- package/dist/library/themes/radiant.js.map +1 -0
- package/dist/library/themes/sharp-3d.d.ts +2 -0
- package/dist/library/themes/sharp-3d.d.ts.map +1 -0
- package/dist/library/themes/sharp-3d.js +142 -0
- package/dist/library/themes/sharp-3d.js.map +1 -0
- package/dist/library/themes/soft-squircle.d.ts +2 -0
- package/dist/library/themes/soft-squircle.d.ts.map +1 -0
- package/dist/library/themes/soft-squircle.js +131 -0
- package/dist/library/themes/soft-squircle.js.map +1 -0
- package/dist/library/themes/ticket.d.ts +2 -0
- package/dist/library/themes/ticket.d.ts.map +1 -0
- package/dist/library/themes/ticket.js +141 -0
- package/dist/library/themes/ticket.js.map +1 -0
- package/dist/library/themes/tokens.d.ts +100 -0
- package/dist/library/themes/tokens.d.ts.map +1 -0
- package/dist/library/themes/tokens.js +171 -0
- package/dist/library/themes/tokens.js.map +1 -0
- package/dist/library/themes/types.d.ts +2 -0
- package/dist/library/themes/types.d.ts.map +1 -0
- package/dist/library/themes/types.js +2 -0
- package/dist/library/themes/types.js.map +1 -0
- package/docs/accessibility.md +189 -0
- package/docs/system.md +218 -0
- package/docs/theming.md +392 -0
- package/package.json +28 -11
- package/src/Accordion.tsx +235 -0
- package/src/Button.tsx +95 -15
- package/src/Card.tsx +143 -0
- package/src/Checkbox.tsx +189 -0
- package/src/Collapsible.tsx +193 -0
- package/src/Dialog.tsx +333 -0
- package/src/Field.tsx +293 -0
- package/src/Input.tsx +82 -0
- package/src/Link.tsx +95 -0
- package/src/RadioGroup.tsx +255 -0
- package/src/ThemeScope.tsx +64 -0
- package/src/actionStyles.ts +90 -0
- package/src/cn.ts +1 -10
- package/src/controlStyles.ts +19 -0
- package/src/index.ts +93 -1
- package/src/internal/events.ts +17 -0
- package/src/internal/ids.ts +5 -0
- package/src/internal/selection.ts +20 -0
- package/src/presentation.ts +12 -0
- package/src/react/useComposedRefs.ts +32 -0
- package/src/react/useControllableState.ts +50 -0
- package/src/react/useNativeOwner.ts +33 -0
- package/src/styles.css +2 -14
- package/src/themes/baseline.css +116 -0
- package/src/themes/components.ts +249 -0
- package/src/themes/default.ts +4 -0
- package/src/themes/defineTheme.ts +145 -0
- package/src/themes/expressive.ts +132 -0
- package/src/themes/glass.ts +135 -0
- package/src/themes/index.ts +33 -0
- package/src/themes/jelly.ts +130 -0
- package/src/themes/preset-values.ts +5 -0
- package/src/themes/radiant.ts +129 -0
- package/src/themes/sharp-3d.ts +142 -0
- package/src/themes/soft-squircle.ts +131 -0
- package/src/themes/ticket.ts +141 -0
- package/src/themes/tokens.ts +262 -0
- package/src/themes/types.ts +10 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useRef, useState } from 'react'
|
|
4
|
+
import type { ChangeEvent, ComponentProps, ReactNode } from 'react'
|
|
5
|
+
import { cva } from 'class-variance-authority'
|
|
6
|
+
import { cn } from './cn.js'
|
|
7
|
+
import { joinIds } from './internal/ids.js'
|
|
8
|
+
import { useComposedRefs } from './react/useComposedRefs.js'
|
|
9
|
+
import { useNativeOwner, type ValueOwner, type CheckedOwner } from './react/useNativeOwner.js'
|
|
10
|
+
import { controlBorderClass, controlMetrics } from './controlStyles.js'
|
|
11
|
+
import { Field, useFieldControl } from './Field.js'
|
|
12
|
+
import type { FieldProps } from './Field.js'
|
|
13
|
+
import type { ThemeStyle } from './themes/defineTheme.js'
|
|
14
|
+
import type { ControlSize, ControlParts, PartStyle } from './presentation.js'
|
|
15
|
+
|
|
16
|
+
const radioVariants = cva([
|
|
17
|
+
controlBorderClass,
|
|
18
|
+
'peer col-start-1 row-start-1 m-0 box-border appearance-none',
|
|
19
|
+
'size-[var(--rad-radio-size,var(--_rad-control-indicator-size))]',
|
|
20
|
+
'rounded-[var(--rad-radio-radius,999px)]',
|
|
21
|
+
'[corner-shape:var(--rad-radio-corner-shape,unset)]',
|
|
22
|
+
'[border-width:var(--rad-radio-border-width,var(--rad-control-border-width,1px))]',
|
|
23
|
+
'[border-style:var(--rad-radio-border-style,var(--rad-control-border-style,solid))]',
|
|
24
|
+
'[border-color:var(--rad-radio-border-color,var(--_rad-control-border))]',
|
|
25
|
+
'bg-[var(--rad-radio-background,var(--rad-color-surface,oklch(1_0_0)))]',
|
|
26
|
+
'checked:bg-[var(--rad-radio-checked-background,var(--rad-color-accent,oklch(0.21_0.006_286)))]',
|
|
27
|
+
'checked:[border-color:var(--rad-radio-checked-border,var(--rad-radio-checked-background,var(--rad-color-accent,oklch(0.21_0.006_286))))]',
|
|
28
|
+
'data-invalid:[border-color:var(--rad-radio-invalid-border,var(--rad-color-invalid,oklch(0.56_0.19_25)))]',
|
|
29
|
+
'in-data-invalid:[border-color:var(--rad-radio-invalid-border,var(--rad-color-invalid,oklch(0.56_0.19_25)))]',
|
|
30
|
+
'focus-visible:outline-solid',
|
|
31
|
+
'focus-visible:[outline-color:var(--rad-radio-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))]',
|
|
32
|
+
'focus-visible:[outline-width:var(--rad-radio-focus-width,var(--rad-focus-width,2px))]',
|
|
33
|
+
'focus-visible:[outline-offset:var(--rad-radio-focus-offset,var(--rad-focus-offset,2px))]',
|
|
34
|
+
'focus-visible:[outline-style:var(--rad-radio-focus-style,var(--rad-focus-style,solid))]',
|
|
35
|
+
'disabled:cursor-not-allowed',
|
|
36
|
+
'disabled:[border-color:var(--rad-radio-disabled-border,var(--rad-color-disabled-border,oklch(0.88_0.005_286)))]',
|
|
37
|
+
'disabled:checked:bg-[var(--rad-radio-disabled-background,var(--rad-color-disabled-background,oklch(0.96_0.005_286)))]',
|
|
38
|
+
'forced-colors:border-[CanvasText]',
|
|
39
|
+
'forced-colors:checked:bg-[Highlight]',
|
|
40
|
+
'forced-colors:disabled:border-[GrayText] forced-colors:disabled:bg-[Canvas]'
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
const dotClass =
|
|
44
|
+
'pointer-events-none absolute inset-[30%] rounded-[var(--rad-radio-radius,999px)] bg-[var(--rad-radio-mark,var(--rad-color-accent-foreground,oklch(0.985_0_0)))] peer-disabled:bg-[var(--rad-radio-mark,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))] opacity-0 peer-checked:opacity-100 forced-colors:bg-[HighlightText] forced-colors:peer-disabled:bg-[GrayText]'
|
|
45
|
+
|
|
46
|
+
const rowClass =
|
|
47
|
+
'[font-family:var(--rad-typography-family,system-ui,sans-serif)] [letter-spacing:var(--rad-typography-letter-spacing,-0.011em)] [font-weight:var(--rad-typography-body-weight,400)] inline-flex min-h-6 cursor-pointer items-center gap-[var(--rad-radio-label-gap,var(--rad-spacing-label-gap,0.5rem))] select-none has-disabled:cursor-not-allowed'
|
|
48
|
+
|
|
49
|
+
const labelClass =
|
|
50
|
+
'leading-snug [color:var(--rad-radio-label-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))] [font-size:var(--rad-radio-label-size,var(--_rad-control-font-size))]'
|
|
51
|
+
|
|
52
|
+
const optionsClass =
|
|
53
|
+
'grid justify-items-start gap-[var(--rad-radio-group-gap,var(--rad-spacing-group-gap,0.75rem))]'
|
|
54
|
+
|
|
55
|
+
type RadioGroupContextValue = {
|
|
56
|
+
name: string
|
|
57
|
+
value?: string | null
|
|
58
|
+
defaultValue?: string | null
|
|
59
|
+
controlled: boolean
|
|
60
|
+
required?: boolean
|
|
61
|
+
controlSize: ControlSize
|
|
62
|
+
onChange?: (event: ChangeEvent<HTMLInputElement>) => void
|
|
63
|
+
onValueChange?: (value: string) => void
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const RadioGroupContext = createContext<RadioGroupContextValue | null>(null)
|
|
67
|
+
|
|
68
|
+
export type RadioGroupProps = Omit<
|
|
69
|
+
Extract<FieldProps, { layout: 'group' }>,
|
|
70
|
+
'layout' | 'children' | 'onChange' | 'defaultValue' | 'parts'
|
|
71
|
+
> &
|
|
72
|
+
ValueOwner<string | null> & {
|
|
73
|
+
name: string
|
|
74
|
+
controlSize?: ControlSize
|
|
75
|
+
parts?: NonNullable<FieldProps['parts']> & { options?: PartStyle }
|
|
76
|
+
onChange?: (event: ChangeEvent<HTMLInputElement>) => void
|
|
77
|
+
onValueChange?: (value: string) => void
|
|
78
|
+
children?: ReactNode
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type RadioProps = Omit<
|
|
82
|
+
ComponentProps<'input'>,
|
|
83
|
+
'type' | 'value' | 'checked' | 'defaultChecked' | 'style'
|
|
84
|
+
> &
|
|
85
|
+
CheckedOwner & {
|
|
86
|
+
label?: ReactNode
|
|
87
|
+
value: string
|
|
88
|
+
controlSize?: ControlSize
|
|
89
|
+
style?: ThemeStyle
|
|
90
|
+
parts?: ControlParts
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function hasContent(value: ReactNode) {
|
|
94
|
+
return value != null && value !== false && value !== ''
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function RadioGroup({
|
|
98
|
+
name,
|
|
99
|
+
value,
|
|
100
|
+
defaultValue,
|
|
101
|
+
onValueChange,
|
|
102
|
+
onChange,
|
|
103
|
+
children,
|
|
104
|
+
required,
|
|
105
|
+
controlSize = 'medium',
|
|
106
|
+
parts,
|
|
107
|
+
...fieldProps
|
|
108
|
+
}: RadioGroupProps) {
|
|
109
|
+
const controlled = useNativeOwner('RadioGroup', value, defaultValue)
|
|
110
|
+
const [initialDefault] = useState(defaultValue)
|
|
111
|
+
const { options: optionsPart, ...fieldParts } = parts ?? {}
|
|
112
|
+
return (
|
|
113
|
+
<Field
|
|
114
|
+
{...fieldProps}
|
|
115
|
+
data-slot={joinIds('radio-group', fieldProps['data-slot'])}
|
|
116
|
+
parts={fieldParts}
|
|
117
|
+
data-control-size={controlSize}
|
|
118
|
+
layout="group"
|
|
119
|
+
required={required}
|
|
120
|
+
>
|
|
121
|
+
<RadioGroupContext.Provider
|
|
122
|
+
value={{
|
|
123
|
+
name,
|
|
124
|
+
value,
|
|
125
|
+
defaultValue: initialDefault,
|
|
126
|
+
controlled,
|
|
127
|
+
required,
|
|
128
|
+
controlSize,
|
|
129
|
+
onChange,
|
|
130
|
+
onValueChange
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<div
|
|
134
|
+
className={cn(optionsClass, optionsPart?.className)}
|
|
135
|
+
style={optionsPart?.style}
|
|
136
|
+
data-slot="radio-group-options"
|
|
137
|
+
>
|
|
138
|
+
{children}
|
|
139
|
+
</div>
|
|
140
|
+
</RadioGroupContext.Provider>
|
|
141
|
+
</Field>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function Radio({
|
|
146
|
+
className,
|
|
147
|
+
controlSize: controlSizeProp,
|
|
148
|
+
parts,
|
|
149
|
+
label,
|
|
150
|
+
value,
|
|
151
|
+
name,
|
|
152
|
+
id,
|
|
153
|
+
disabled,
|
|
154
|
+
required,
|
|
155
|
+
checked,
|
|
156
|
+
defaultChecked,
|
|
157
|
+
onChange,
|
|
158
|
+
ref,
|
|
159
|
+
'aria-describedby': ariaDescribedBy,
|
|
160
|
+
'aria-invalid': ariaInvalid,
|
|
161
|
+
'aria-required': ariaRequired,
|
|
162
|
+
...props
|
|
163
|
+
}: RadioProps) {
|
|
164
|
+
const group = useContext(RadioGroupContext)
|
|
165
|
+
const labelled = hasContent(label)
|
|
166
|
+
const standaloneControlled = useNativeOwner('Radio', checked, defaultChecked, !group)
|
|
167
|
+
if (
|
|
168
|
+
group &&
|
|
169
|
+
((name !== undefined && name !== group.name) ||
|
|
170
|
+
checked !== undefined ||
|
|
171
|
+
defaultChecked !== undefined)
|
|
172
|
+
) {
|
|
173
|
+
throw new TypeError(
|
|
174
|
+
'RadioGroup owns name and selection. Remove conflicting name, checked and defaultChecked from Radio.'
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
const controlSize = controlSizeProp ?? group?.controlSize ?? 'medium'
|
|
178
|
+
const { 'aria-required': _ariaRequired, ...control } = useFieldControl({
|
|
179
|
+
id,
|
|
180
|
+
disabled,
|
|
181
|
+
required,
|
|
182
|
+
'aria-invalid': ariaInvalid,
|
|
183
|
+
'aria-required': ariaRequired,
|
|
184
|
+
'aria-describedby': ariaDescribedBy
|
|
185
|
+
})
|
|
186
|
+
const controlled = group ? group.controlled : standaloneControlled
|
|
187
|
+
const selected = group ? group.value === value : checked
|
|
188
|
+
const nodeRef = useRef<HTMLInputElement>(null)
|
|
189
|
+
const initialise = useCallback(
|
|
190
|
+
(node: HTMLInputElement | null) => {
|
|
191
|
+
nodeRef.current = node
|
|
192
|
+
if (node && controlled) node.defaultChecked = node.checked
|
|
193
|
+
},
|
|
194
|
+
[controlled]
|
|
195
|
+
)
|
|
196
|
+
const hostRef = useComposedRefs(initialise, ref)
|
|
197
|
+
useLayoutEffect(() => {
|
|
198
|
+
// Controlled resets preserve the current selection, rather than the first value.
|
|
199
|
+
if (nodeRef.current && controlled) nodeRef.current.defaultChecked = !!selected
|
|
200
|
+
}, [controlled, selected])
|
|
201
|
+
const controlNode = (
|
|
202
|
+
<span
|
|
203
|
+
className={cn('relative inline-grid shrink-0', !labelled && parts?.wrapper?.className)}
|
|
204
|
+
style={!labelled ? parts?.wrapper?.style : undefined}
|
|
205
|
+
data-slot={!labelled ? 'radio-wrapper' : undefined}
|
|
206
|
+
>
|
|
207
|
+
<input
|
|
208
|
+
{...props}
|
|
209
|
+
{...control}
|
|
210
|
+
onChange={event => {
|
|
211
|
+
onChange?.(event)
|
|
212
|
+
group?.onChange?.(event)
|
|
213
|
+
if (event.currentTarget.checked) group?.onValueChange?.(event.currentTarget.value)
|
|
214
|
+
}}
|
|
215
|
+
ref={hostRef}
|
|
216
|
+
checked={controlled ? selected : undefined}
|
|
217
|
+
className={cn(radioVariants(), controlMetrics({ controlSize }), className)}
|
|
218
|
+
data-control-size={controlSize}
|
|
219
|
+
data-slot="radio"
|
|
220
|
+
defaultChecked={
|
|
221
|
+
controlled ? undefined : group ? group.defaultValue === value : defaultChecked
|
|
222
|
+
}
|
|
223
|
+
name={group?.name ?? name}
|
|
224
|
+
required={group?.required || control.required}
|
|
225
|
+
type="radio"
|
|
226
|
+
value={value}
|
|
227
|
+
/>
|
|
228
|
+
<span
|
|
229
|
+
aria-hidden="true"
|
|
230
|
+
className={cn(dotClass, parts?.indicator?.className)}
|
|
231
|
+
style={parts?.indicator?.style}
|
|
232
|
+
data-slot="radio-indicator"
|
|
233
|
+
/>
|
|
234
|
+
</span>
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
if (!labelled) return controlNode
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<label
|
|
241
|
+
className={cn(rowClass, parts?.wrapper?.className)}
|
|
242
|
+
style={parts?.wrapper?.style}
|
|
243
|
+
data-slot="radio-wrapper"
|
|
244
|
+
>
|
|
245
|
+
{controlNode}
|
|
246
|
+
<span
|
|
247
|
+
className={cn(labelClass, controlMetrics({ controlSize }), parts?.label?.className)}
|
|
248
|
+
style={parts?.label?.style}
|
|
249
|
+
data-slot="radio-label"
|
|
250
|
+
>
|
|
251
|
+
{label}
|
|
252
|
+
</span>
|
|
253
|
+
</label>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext } from 'react'
|
|
4
|
+
import type { ComponentProps } from 'react'
|
|
5
|
+
import { cn } from './cn.js'
|
|
6
|
+
import { defaultTheme } from './themes/default.js'
|
|
7
|
+
import { modeStyle } from './themes/tokens.js'
|
|
8
|
+
import type { Theme, ThemeMode, ThemeStyle } from './themes/defineTheme.js'
|
|
9
|
+
|
|
10
|
+
type ScopeState = { theme: Theme; overrides: ThemeStyle }
|
|
11
|
+
const ThemeContext = createContext<ScopeState | null>(null)
|
|
12
|
+
const variables = new Set(Object.keys(defaultTheme.modes.light))
|
|
13
|
+
const scopeClass =
|
|
14
|
+
'[background:var(--rad-surface-canvas)] [color:var(--rad-color-foreground)] [font-family:var(--rad-typography-family)] [font-size:var(--rad-typography-body-size)] [font-weight:var(--rad-typography-body-weight)] [letter-spacing:var(--rad-typography-letter-spacing)]'
|
|
15
|
+
|
|
16
|
+
export type ThemeScopeProps = Omit<ComponentProps<'div'>, 'style'> & {
|
|
17
|
+
theme?: Theme
|
|
18
|
+
mode?: ThemeMode
|
|
19
|
+
style?: ThemeStyle
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Optional subtree configuration. The stylesheet supplies a provider-free baseline. */
|
|
23
|
+
export function ThemeScope({ theme, mode, style, className, children, ...props }: ThemeScopeProps) {
|
|
24
|
+
const parent = useContext(ThemeContext)
|
|
25
|
+
if (mode !== undefined && mode !== 'light' && mode !== 'dark' && mode !== 'system') {
|
|
26
|
+
throw new TypeError('Theme mode must be light, dark or system.')
|
|
27
|
+
}
|
|
28
|
+
if (theme !== undefined && (!theme.id || !theme.modes?.light || !theme.modes?.dark)) {
|
|
29
|
+
throw new TypeError('ThemeScope needs a theme created with defineTheme.')
|
|
30
|
+
}
|
|
31
|
+
const selected = theme ?? parent?.theme ?? defaultTheme
|
|
32
|
+
const establishesScope = theme !== undefined || mode !== undefined
|
|
33
|
+
// A named theme deliberately clears ancestor exceptions. A mode-only scope
|
|
34
|
+
// preserves explicit inline token exceptions while resolving the same theme.
|
|
35
|
+
const overrides: ThemeStyle = theme === undefined ? { ...parent?.overrides } : {}
|
|
36
|
+
for (const [key, value] of Object.entries(style ?? {})) {
|
|
37
|
+
if (variables.has(key) && value !== undefined) overrides[key as `--${string}`] = value
|
|
38
|
+
}
|
|
39
|
+
const resolved: ThemeStyle = establishesScope
|
|
40
|
+
? { ...modeStyle(selected.modes.light, selected.modes.dark), ...overrides }
|
|
41
|
+
: {}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<ThemeContext.Provider value={{ theme: selected, overrides }}>
|
|
45
|
+
<div
|
|
46
|
+
{...props}
|
|
47
|
+
data-rad-theme={theme?.id}
|
|
48
|
+
data-rad-mode={mode}
|
|
49
|
+
className={cn(scopeClass, className)}
|
|
50
|
+
style={{
|
|
51
|
+
...resolved,
|
|
52
|
+
...(mode === undefined
|
|
53
|
+
? parent === null
|
|
54
|
+
? { colorScheme: 'light dark' }
|
|
55
|
+
: {}
|
|
56
|
+
: { colorScheme: mode === 'system' ? 'light dark' : mode }),
|
|
57
|
+
...style
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{children}
|
|
61
|
+
</div>
|
|
62
|
+
</ThemeContext.Provider>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { cva } from 'class-variance-authority'
|
|
2
|
+
|
|
3
|
+
// Palette and readable ink are shared by action-shaped and text links. Ink is
|
|
4
|
+
// mixed toward the scope foreground so pale warning/accent fills stay readable
|
|
5
|
+
// on an unfilled surface in either mode. Neutral preserves the quiet palette.
|
|
6
|
+
const tones = {
|
|
7
|
+
accent:
|
|
8
|
+
'[--_action-color:var(--rad-color-accent,oklch(0.21_0.006_286))] [--_action-on-color:var(--rad-color-accent-foreground,oklch(0.985_0_0))] [--_action-ink:color-mix(in_oklab,var(--_action-color)_25%,var(--rad-color-foreground,oklch(0.21_0.006_286)))] [--_action-soft:color-mix(in_oklab,var(--_action-color)_12%,var(--rad-color-surface,white))] [--_action-edge:color-mix(in_oklab,var(--_action-ink)_45%,var(--rad-color-border,oklch(0.885_0.005_286)))] [--_action-solid-state:white]',
|
|
9
|
+
neutral:
|
|
10
|
+
'[--_action-color:var(--rad-color-neutral,oklch(0.955_0.004_286))] [--_action-on-color:var(--rad-color-neutral-foreground,oklch(0.21_0.006_286))] [--_action-ink:var(--rad-color-neutral-foreground,oklch(0.21_0.006_286))] [--_action-soft:var(--rad-color-neutral,oklch(0.955_0.004_286))] [--_action-edge:var(--rad-color-border,oklch(0.885_0.005_286))] [--_action-solid-state:var(--_action-on-color)]',
|
|
11
|
+
warning:
|
|
12
|
+
'[--_action-color:var(--rad-color-warning,oklch(0.8_0.14_78))] [--_action-on-color:var(--rad-color-warning-foreground,oklch(0.3_0.07_55))] [--_action-ink:color-mix(in_oklab,var(--_action-color)_25%,var(--rad-color-foreground,oklch(0.21_0.006_286)))] [--_action-soft:color-mix(in_oklab,var(--_action-color)_12%,var(--rad-color-surface,white))] [--_action-edge:color-mix(in_oklab,var(--_action-ink)_45%,var(--rad-color-border,oklch(0.885_0.005_286)))] [--_action-solid-state:black]',
|
|
13
|
+
danger:
|
|
14
|
+
'[--_action-color:var(--rad-color-danger,oklch(0.56_0.19_25))] [--_action-on-color:var(--rad-color-danger-foreground,oklch(0.99_0_0))] [--_action-ink:color-mix(in_oklab,var(--_action-color)_25%,var(--rad-color-foreground,oklch(0.21_0.006_286)))] [--_action-soft:color-mix(in_oklab,var(--_action-color)_12%,var(--rad-color-surface,white))] [--_action-edge:color-mix(in_oklab,var(--_action-ink)_45%,var(--rad-color-border,oklch(0.885_0.005_286)))] [--_action-solid-state:black]'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const actionTone = cva('', {
|
|
18
|
+
variants: { tone: tones },
|
|
19
|
+
defaultVariants: { tone: 'accent' }
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export const actionVariants = cva(
|
|
23
|
+
[
|
|
24
|
+
'relative box-border inline-flex shrink-0 select-none items-center justify-center [border-style:var(--rad-button-border-style,var(--rad-control-border-style,solid))] [border-width:var(--rad-button-border-width,var(--rad-control-border-width,1px))] [border-color:var(--rad-button-border-color,var(--_btn-edge))] text-center [font-family:var(--rad-button-font-family,var(--rad-typography-family,system-ui,sans-serif))] [text-transform:var(--rad-button-text-transform,none)] antialiased',
|
|
25
|
+
'[font-weight:var(--rad-button-font-weight,var(--rad-typography-label-weight,550))] [letter-spacing:var(--rad-button-letter-spacing,var(--rad-typography-letter-spacing,-0.011em))] [font-size:var(--_btn-fs)]',
|
|
26
|
+
'min-h-(--_btn-h) px-(--_btn-px) bg-(--_btn-bg) text-(--_btn-fg) no-underline',
|
|
27
|
+
'bg-[linear-gradient(to_bottom,rgb(255_255_255/var(--_btn-sheen)),rgb(255_255_255/0))]',
|
|
28
|
+
'[--_btn-corner:var(--rad-button-corner-shape,var(--rad-control-corner-shape,round))] rounded-(--_btn-radius) [corner-shape:var(--_btn-corner)]',
|
|
29
|
+
'[--_btn-radius:var(--rad-button-radius,var(--rad-control-radius,0.5rem))] [--_btn-radius-pressed:var(--rad-button-radius-pressed,var(--_btn-radius))]',
|
|
30
|
+
'[--_btn-glow:var(--rad-button-glow,0%)] shadow-(--_btn-shadow) inset-shadow-[0_1px_0_0_rgb(255_255_255/var(--_btn-highlight))] [backdrop-filter:var(--rad-button-backdrop,none)]',
|
|
31
|
+
'[--_btn-rd:var(--rad-button-release-duration,var(--rad-motion-release-duration,160ms))] [--_btn-re:var(--rad-button-release-ease,var(--rad-motion-release-ease,cubic-bezier(0.2,0.8,0.2,1)))]',
|
|
32
|
+
'[--_btn-pd:var(--rad-button-press-duration,var(--rad-motion-press-duration,80ms))] [--_btn-pe:var(--rad-button-press-ease,var(--rad-motion-press-ease,cubic-bezier(0.3,0,0,1)))]',
|
|
33
|
+
'[--_btn-cd:var(--rad-button-color-duration,var(--rad-motion-color-duration,150ms))]',
|
|
34
|
+
'cursor-pointer transition-[scale,translate,border-radius,corner-shape,box-shadow,background-color,color]',
|
|
35
|
+
'duration-[var(--_btn-rd),var(--_btn-rd),var(--_btn-rd),var(--_btn-rd),var(--_btn-cd),var(--_btn-cd),var(--_btn-cd)]',
|
|
36
|
+
'ease-[var(--_btn-re),var(--_btn-re),var(--_btn-re),var(--_btn-re),ease-out,ease-out,ease-out]',
|
|
37
|
+
'active:duration-[var(--_btn-pd),var(--_btn-pd),var(--_btn-pd),var(--_btn-pd),var(--_btn-pd),var(--_btn-pd),var(--_btn-pd)]',
|
|
38
|
+
'active:ease-[var(--_btn-pe),var(--_btn-pe),var(--_btn-pe),var(--_btn-pe),var(--_btn-pe),var(--_btn-pe),var(--_btn-pe)]',
|
|
39
|
+
'hover:bg-[color-mix(in_oklch,var(--_btn-bg),var(--rad-button-state-color,var(--_btn-hover-state))_var(--rad-button-hover-layer,5%))]',
|
|
40
|
+
'not-disabled:not-aria-busy:motion-safe:hover:translate-y-[var(--rad-button-hover-lift,0px)]',
|
|
41
|
+
'active:bg-[color-mix(in_oklch,var(--_btn-bg),var(--rad-button-state-color,var(--_btn-press-state))_var(--rad-button-press-layer,8%))]',
|
|
42
|
+
'disabled:bg-(--_btn-bg) aria-busy:bg-(--_btn-bg)',
|
|
43
|
+
'not-disabled:not-aria-busy:motion-safe:active:scale-[var(--rad-button-press-scale,0.97)] not-disabled:not-aria-busy:motion-safe:active:translate-y-[var(--rad-button-press-shift,0px)] not-disabled:not-aria-busy:motion-safe:active:translate-x-[var(--rad-button-press-shift-x,0px)]',
|
|
44
|
+
'not-disabled:not-aria-busy:active:rounded-(--_btn-radius-pressed) not-disabled:not-aria-busy:active:[corner-shape:var(--rad-button-corner-shape-pressed,var(--_btn-corner))]',
|
|
45
|
+
'not-disabled:not-aria-busy:active:[--_btn-highlight:0] not-disabled:not-aria-busy:active:[--_btn-sheen:0] not-disabled:not-aria-busy:active:shadow-[var(--rad-button-shadow-pressed,var(--_btn-shadow-pressed))]',
|
|
46
|
+
'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-button-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] focus-visible:[outline-width:var(--rad-button-focus-width,var(--rad-focus-width,2px))] focus-visible:[outline-offset:var(--rad-button-focus-offset,var(--rad-focus-offset,2px))] focus-visible:[outline-style:var(--rad-button-focus-style,var(--rad-focus-style,solid))]',
|
|
47
|
+
'in-[[data-slot~=field][data-disabled]]:[--_rad-disabled-opacity:1]',
|
|
48
|
+
'disabled:cursor-not-allowed disabled:opacity-[var(--_rad-disabled-opacity,var(--rad-button-disabled-opacity,var(--rad-state-disabled-opacity,0.5)))]',
|
|
49
|
+
'aria-busy:cursor-progress',
|
|
50
|
+
'motion-reduce:transition-[background-color,color]',
|
|
51
|
+
'forced-colors:border-[ButtonText] forced-colors:disabled:border-[GrayText] forced-colors:disabled:text-[GrayText] forced-colors:disabled:opacity-100'
|
|
52
|
+
],
|
|
53
|
+
{
|
|
54
|
+
variants: {
|
|
55
|
+
variant: {
|
|
56
|
+
solid:
|
|
57
|
+
'[--_btn-bg:var(--_action-color)] [--_btn-edge:color-mix(in_oklch,var(--_btn-bg),black_16%)] [--_btn-fg:var(--_action-on-color)] [--_btn-hover-state:var(--_action-solid-state)] [--_btn-press-state:black] [--_btn-sheen:var(--rad-button-sheen,0)] [--_btn-highlight:var(--rad-button-highlight,0)] [--_btn-shadow:var(--rad-button-shadow,0_1px_2px_0_rgb(0_0_0/0.06)),0_10px_26px_-10px_color-mix(in_oklch,var(--_btn-bg)_var(--_btn-glow),transparent)] [--_btn-shadow-pressed:var(--rad-button-shadow-pressed,0_1px_2px_0_rgb(0_0_0/0.06))]',
|
|
58
|
+
soft: '[--_btn-bg:var(--_action-soft)] [--_btn-edge:var(--_action-edge)] [--_btn-fg:var(--_action-ink)] [--_btn-hover-state:var(--_btn-fg)] [--_btn-press-state:var(--_btn-fg)] [--_btn-sheen:var(--rad-button-sheen,0)] [--_btn-highlight:var(--rad-button-highlight,0)] [--_btn-shadow:var(--rad-button-shadow,0_1px_2px_0_rgb(0_0_0/0.06))] [--_btn-shadow-pressed:var(--rad-button-shadow-pressed,0_1px_2px_0_rgb(0_0_0/0.06))]',
|
|
59
|
+
outline:
|
|
60
|
+
'[--_btn-bg:var(--rad-color-surface,oklch(1_0_0))] [--_btn-edge:var(--_action-edge)] [--_btn-fg:var(--_action-ink)] [--_btn-hover-state:var(--_btn-fg)] [--_btn-press-state:var(--_btn-fg)] [--_btn-sheen:var(--rad-button-sheen,0)] [--_btn-highlight:var(--rad-button-highlight,0)] [--_btn-shadow:var(--rad-button-shadow,0_1px_2px_0_rgb(0_0_0/0.06))] [--_btn-shadow-pressed:var(--rad-button-shadow-pressed,0_1px_2px_0_rgb(0_0_0/0.06))]',
|
|
61
|
+
ghost:
|
|
62
|
+
'[--_btn-bg:transparent] [--_btn-edge:transparent] [--_btn-fg:var(--_action-ink)] [--_btn-hover-state:var(--_btn-fg)] [--_btn-press-state:var(--_btn-fg)] [--_btn-sheen:var(--rad-button-sheen,0)] [--_btn-highlight:var(--rad-button-highlight,0)] [--_btn-shadow:var(--rad-button-ghost-shadow,0_0_#0000)] [--_btn-shadow-pressed:var(--rad-button-ghost-shadow-pressed,0_0_#0000)]'
|
|
63
|
+
},
|
|
64
|
+
tone: tones,
|
|
65
|
+
controlSize: {
|
|
66
|
+
small:
|
|
67
|
+
'[--_btn-h:var(--rad-button-height-small,var(--rad-control-small-height,2rem))] [--_btn-px:var(--rad-button-padding-small,var(--rad-control-small-padding-inline,0.75rem))] [--_btn-fs:var(--rad-button-font-size-small,var(--rad-control-small-font-size,0.8125rem))] [&_svg]:size-3.5',
|
|
68
|
+
medium:
|
|
69
|
+
'[--_btn-h:var(--rad-button-height,var(--rad-control-medium-height,2.5rem))] [--_btn-px:var(--rad-button-padding,var(--rad-control-medium-padding-inline,1rem))] [--_btn-fs:var(--rad-button-font-size,var(--rad-control-medium-font-size,0.875rem))] [&_svg]:size-4',
|
|
70
|
+
large:
|
|
71
|
+
'[--_btn-h:var(--rad-button-height-large,var(--rad-control-large-height,3rem))] [--_btn-px:var(--rad-button-padding-large,var(--rad-control-large-padding-inline,1.375rem))] [--_btn-fs:var(--rad-button-font-size-large,var(--rad-control-large-font-size,0.9375rem))] [&_svg]:size-[1.125rem]'
|
|
72
|
+
},
|
|
73
|
+
iconOnly: {
|
|
74
|
+
true: 'size-(--_btn-h) px-0',
|
|
75
|
+
false: ''
|
|
76
|
+
},
|
|
77
|
+
fullWidth: {
|
|
78
|
+
true: 'w-full',
|
|
79
|
+
false: ''
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
defaultVariants: {
|
|
83
|
+
variant: 'solid',
|
|
84
|
+
tone: 'accent',
|
|
85
|
+
controlSize: 'medium',
|
|
86
|
+
iconOnly: false,
|
|
87
|
+
fullWidth: false
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
)
|
package/src/cn.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { cva } from 'class-variance-authority'
|
|
2
|
+
|
|
3
|
+
// Interactive boundaries need more contrast than passive surface dividers.
|
|
4
|
+
// Keep the derivation private so every control follows the same semantic palette.
|
|
5
|
+
export const controlBorderClass =
|
|
6
|
+
'[--_rad-control-border:color-mix(in_oklch,var(--rad-color-border,oklch(0.885_0.005_286))_55%,var(--rad-color-foreground,oklch(0.21_0.006_286)))]'
|
|
7
|
+
export const controlMetrics = cva('', {
|
|
8
|
+
variants: {
|
|
9
|
+
controlSize: {
|
|
10
|
+
small:
|
|
11
|
+
'[--_rad-control-height:var(--rad-control-small-height,2rem)] [--_rad-control-padding:var(--rad-control-small-padding-inline,0.75rem)] [--_rad-control-font-size:var(--rad-control-small-font-size,0.8125rem)] [--_rad-control-indicator-size:var(--rad-control-small-indicator-size,1rem)]',
|
|
12
|
+
medium:
|
|
13
|
+
'[--_rad-control-height:var(--rad-control-medium-height,2.5rem)] [--_rad-control-padding:var(--rad-control-medium-padding-inline,1rem)] [--_rad-control-font-size:var(--rad-control-medium-font-size,0.875rem)] [--_rad-control-indicator-size:var(--rad-control-medium-indicator-size,1.125rem)]',
|
|
14
|
+
large:
|
|
15
|
+
'[--_rad-control-height:var(--rad-control-large-height,3rem)] [--_rad-control-padding:var(--rad-control-large-padding-inline,1.375rem)] [--_rad-control-font-size:var(--rad-control-large-font-size,0.9375rem)] [--_rad-control-indicator-size:var(--rad-control-large-indicator-size,1.25rem)]'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: { controlSize: 'medium' }
|
|
19
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,94 @@
|
|
|
1
1
|
export { Button } from './Button.js'
|
|
2
|
-
export
|
|
2
|
+
export { Link } from './Link.js'
|
|
3
|
+
export type { LinkProps, LinkRenderProps, LinkVariant } from './Link.js'
|
|
4
|
+
export { Field, useField } from './Field.js'
|
|
5
|
+
export type { FieldControlProps, FieldLayout, FieldProps, FieldState } from './Field.js'
|
|
6
|
+
export { Input } from './Input.js'
|
|
7
|
+
export type { InputProps } from './Input.js'
|
|
8
|
+
export { Checkbox } from './Checkbox.js'
|
|
9
|
+
export type { CheckboxProps } from './Checkbox.js'
|
|
10
|
+
export { Radio, RadioGroup } from './RadioGroup.js'
|
|
11
|
+
export type { RadioGroupProps, RadioProps } from './RadioGroup.js'
|
|
12
|
+
export {
|
|
13
|
+
Dialog,
|
|
14
|
+
DialogClose,
|
|
15
|
+
DialogContent,
|
|
16
|
+
DialogDescription,
|
|
17
|
+
DialogTitle,
|
|
18
|
+
DialogTrigger,
|
|
19
|
+
useDialog
|
|
20
|
+
} from './Dialog.js'
|
|
21
|
+
export type {
|
|
22
|
+
DialogCloseProps,
|
|
23
|
+
DialogContentProps,
|
|
24
|
+
DialogDescriptionProps,
|
|
25
|
+
DialogProps,
|
|
26
|
+
DialogRenderProps,
|
|
27
|
+
DialogState,
|
|
28
|
+
DialogTitleProps,
|
|
29
|
+
DialogTriggerProps
|
|
30
|
+
} from './Dialog.js'
|
|
31
|
+
export {
|
|
32
|
+
Collapsible,
|
|
33
|
+
CollapsibleContent,
|
|
34
|
+
CollapsibleTrigger,
|
|
35
|
+
useCollapsible
|
|
36
|
+
} from './Collapsible.js'
|
|
37
|
+
export type {
|
|
38
|
+
CollapsibleContentProps,
|
|
39
|
+
CollapsibleProps,
|
|
40
|
+
CollapsibleState,
|
|
41
|
+
CollapsibleTriggerProps
|
|
42
|
+
} from './Collapsible.js'
|
|
43
|
+
export {
|
|
44
|
+
Accordion,
|
|
45
|
+
AccordionContent,
|
|
46
|
+
AccordionItem,
|
|
47
|
+
AccordionTrigger,
|
|
48
|
+
useAccordion
|
|
49
|
+
} from './Accordion.js'
|
|
50
|
+
export type {
|
|
51
|
+
AccordionContentProps,
|
|
52
|
+
AccordionHeadingLevel,
|
|
53
|
+
AccordionItemProps,
|
|
54
|
+
AccordionProps,
|
|
55
|
+
AccordionState,
|
|
56
|
+
AccordionTriggerProps,
|
|
57
|
+
AccordionValue
|
|
58
|
+
} from './Accordion.js'
|
|
59
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from './Card.js'
|
|
60
|
+
export type {
|
|
61
|
+
CardContentProps,
|
|
62
|
+
CardDescriptionProps,
|
|
63
|
+
CardFooterProps,
|
|
64
|
+
CardHeaderProps,
|
|
65
|
+
CardHeadingLevel,
|
|
66
|
+
CardProps,
|
|
67
|
+
CardTitleProps
|
|
68
|
+
} from './Card.js'
|
|
69
|
+
export {
|
|
70
|
+
defineTheme,
|
|
71
|
+
themes,
|
|
72
|
+
radiant,
|
|
73
|
+
defaultTheme,
|
|
74
|
+
soft,
|
|
75
|
+
expressive,
|
|
76
|
+
glass,
|
|
77
|
+
sharp,
|
|
78
|
+
jelly,
|
|
79
|
+
ticket
|
|
80
|
+
} from './themes/index.js'
|
|
81
|
+
export type {
|
|
82
|
+
SharedTokens,
|
|
83
|
+
Theme,
|
|
84
|
+
ThemeComponentOverrides,
|
|
85
|
+
ThemeDefinition,
|
|
86
|
+
ThemeLayer,
|
|
87
|
+
ThemeMode,
|
|
88
|
+
ThemeStyle,
|
|
89
|
+
ThemeTokens
|
|
90
|
+
} from './themes/index.js'
|
|
91
|
+
export { ThemeScope } from './ThemeScope.js'
|
|
92
|
+
export type { ThemeScopeProps } from './ThemeScope.js'
|
|
93
|
+
export type { ButtonProps, ButtonRenderProps, ButtonVariant } from './Button.js'
|
|
94
|
+
export type { ControlSize, Tone } from './presentation.js'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type CancellableEvent = { defaultPrevented: boolean; preventDefault(): void }
|
|
2
|
+
|
|
3
|
+
/** Activation guards precede the consumer, who can cancel the library action. */
|
|
4
|
+
export function composeAction<Event extends CancellableEvent>(
|
|
5
|
+
consumer: ((event: Event) => void) | undefined,
|
|
6
|
+
action: ((event: Event) => void) | undefined,
|
|
7
|
+
blocked?: (event: Event) => boolean
|
|
8
|
+
) {
|
|
9
|
+
return (event: Event) => {
|
|
10
|
+
if (blocked?.(event)) {
|
|
11
|
+
event.preventDefault()
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
consumer?.(event)
|
|
15
|
+
if (!event.defaultPrevented) action?.(event)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Preserve owned relationships first, then append each external ID once. */
|
|
2
|
+
export function joinIds(...parts: Array<string | undefined>) {
|
|
3
|
+
const ids = new Set(parts.flatMap(part => part?.split(/\s+/) ?? []).filter(Boolean))
|
|
4
|
+
return ids.size > 0 ? [...ids].join(' ') : undefined
|
|
5
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Selection = string | null | string[]
|
|
2
|
+
|
|
3
|
+
export function isItemOpen(value: Selection, item: string) {
|
|
4
|
+
return Array.isArray(value) ? value.includes(item) : value === item
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function sameSelection(left: Selection, right: Selection) {
|
|
8
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
9
|
+
return left.length === right.length && left.every((item, index) => item === right[index])
|
|
10
|
+
}
|
|
11
|
+
return left === right
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function nextSelection(current: Selection, item: string, open: boolean): Selection {
|
|
15
|
+
if (Array.isArray(current)) {
|
|
16
|
+
if (open) return current.includes(item) ? current : [...current, item]
|
|
17
|
+
return current.filter(value => value !== item)
|
|
18
|
+
}
|
|
19
|
+
return open ? item : current === item ? null : current
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
2
|
+
import type { actionVariants } from './actionStyles.js'
|
|
3
|
+
import type { ThemeStyle } from './themes/defineTheme.js'
|
|
4
|
+
|
|
5
|
+
type ActionPresentation = VariantProps<typeof actionVariants>
|
|
6
|
+
|
|
7
|
+
export type ButtonVariant = NonNullable<ActionPresentation['variant']>
|
|
8
|
+
export type Tone = NonNullable<ActionPresentation['tone']>
|
|
9
|
+
export type ControlSize = 'small' | 'medium' | 'large'
|
|
10
|
+
|
|
11
|
+
export type PartStyle = { className?: string; style?: ThemeStyle }
|
|
12
|
+
export type ControlParts = { wrapper?: PartStyle; label?: PartStyle; indicator?: PartStyle }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMemo, type Ref, type RefCallback } from 'react'
|
|
4
|
+
|
|
5
|
+
/** Compose library and caller refs without discarding React callback cleanup. */
|
|
6
|
+
export function useComposedRefs<Node>(
|
|
7
|
+
libraryRef: Ref<Node> | undefined,
|
|
8
|
+
callerRef: Ref<Node> | undefined
|
|
9
|
+
): RefCallback<Node> {
|
|
10
|
+
return useMemo(
|
|
11
|
+
() => node => {
|
|
12
|
+
const cleanups = [libraryRef, callerRef].map(ref => {
|
|
13
|
+
if (typeof ref === 'function') {
|
|
14
|
+
const cleanup = ref(node)
|
|
15
|
+
return typeof cleanup === 'function'
|
|
16
|
+
? cleanup
|
|
17
|
+
: () => {
|
|
18
|
+
ref(null)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (ref) ref.current = node
|
|
22
|
+
return () => {
|
|
23
|
+
if (ref) ref.current = null
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
return () => {
|
|
27
|
+
for (const cleanup of cleanups) cleanup()
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
[libraryRef, callerRef]
|
|
31
|
+
)
|
|
32
|
+
}
|