@cognitap/radiant 0.0.83 → 0.0.85
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 +36 -0
- package/dist/library/color/colorValue.d.ts +8 -0
- package/dist/library/color/colorValue.d.ts.map +1 -0
- package/dist/library/color/colorValue.js +87 -0
- package/dist/library/color/colorValue.js.map +1 -0
- package/dist/library/color/oklch.d.ts +2 -0
- package/dist/library/color/oklch.d.ts.map +1 -1
- package/dist/library/color/oklch.js +27 -11
- package/dist/library/color/oklch.js.map +1 -1
- package/dist/library/components/Cascader/Cascader.d.ts +25 -0
- package/dist/library/components/Cascader/Cascader.d.ts.map +1 -0
- package/dist/library/components/Cascader/Cascader.js +154 -0
- package/dist/library/components/Cascader/Cascader.js.map +1 -0
- package/dist/library/components/Cascader/CascaderColumn.d.ts +25 -0
- package/dist/library/components/Cascader/CascaderColumn.d.ts.map +1 -0
- package/dist/library/components/Cascader/CascaderColumn.js +80 -0
- package/dist/library/components/Cascader/CascaderColumn.js.map +1 -0
- package/dist/library/components/CodeBlock/CodeBlock.d.ts.map +1 -1
- package/dist/library/components/CodeBlock/CodeBlock.js +3 -37
- package/dist/library/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/library/components/Collapsible/Collapsible.d.ts +5 -1
- package/dist/library/components/Collapsible/Collapsible.d.ts.map +1 -1
- package/dist/library/components/Collapsible/Collapsible.js +13 -3
- package/dist/library/components/Collapsible/Collapsible.js.map +1 -1
- package/dist/library/components/ColorInput/ColorInput.d.ts +22 -0
- package/dist/library/components/ColorInput/ColorInput.d.ts.map +1 -0
- package/dist/library/components/ColorInput/ColorInput.js +63 -0
- package/dist/library/components/ColorInput/ColorInput.js.map +1 -0
- package/dist/library/components/ColorPicker/ColorArea.d.ts +11 -0
- package/dist/library/components/ColorPicker/ColorArea.d.ts.map +1 -0
- package/dist/library/components/ColorPicker/ColorArea.js +58 -0
- package/dist/library/components/ColorPicker/ColorArea.js.map +1 -0
- package/dist/library/components/ColorPicker/ColorPicker.d.ts +37 -0
- package/dist/library/components/ColorPicker/ColorPicker.d.ts.map +1 -0
- package/dist/library/components/ColorPicker/ColorPicker.js +135 -0
- package/dist/library/components/ColorPicker/ColorPicker.js.map +1 -0
- package/dist/library/components/CopyButton/CopyButton.d.ts +17 -0
- package/dist/library/components/CopyButton/CopyButton.d.ts.map +1 -0
- package/dist/library/components/CopyButton/CopyButton.js +22 -0
- package/dist/library/components/CopyButton/CopyButton.js.map +1 -0
- package/dist/library/components/DataTable/DataTable.d.ts +47 -0
- package/dist/library/components/DataTable/DataTable.d.ts.map +1 -0
- package/dist/library/components/DataTable/DataTable.js +146 -0
- package/dist/library/components/DataTable/DataTable.js.map +1 -0
- package/dist/library/components/Dropzone/Dropzone.d.ts +26 -0
- package/dist/library/components/Dropzone/Dropzone.d.ts.map +1 -0
- package/dist/library/components/Dropzone/Dropzone.js +118 -0
- package/dist/library/components/Dropzone/Dropzone.js.map +1 -0
- package/dist/library/components/Highlight/Highlight.d.ts +15 -0
- package/dist/library/components/Highlight/Highlight.d.ts.map +1 -0
- package/dist/library/components/Highlight/Highlight.js +69 -0
- package/dist/library/components/Highlight/Highlight.js.map +1 -0
- package/dist/library/components/Rating/Rating.d.ts +21 -0
- package/dist/library/components/Rating/Rating.d.ts.map +1 -0
- package/dist/library/components/Rating/Rating.js +81 -0
- package/dist/library/components/Rating/Rating.js.map +1 -0
- package/dist/library/components/Select/Select.d.ts +3 -9
- package/dist/library/components/Select/Select.d.ts.map +1 -1
- package/dist/library/components/Select/Select.js +16 -156
- package/dist/library/components/Select/Select.js.map +1 -1
- package/dist/library/components/Select/SelectPopup.d.ts +29 -0
- package/dist/library/components/Select/SelectPopup.d.ts.map +1 -0
- package/dist/library/components/Select/SelectPopup.js +179 -0
- package/dist/library/components/Select/SelectPopup.js.map +1 -0
- package/dist/library/components/Slider/Slider.d.ts +2 -2
- package/dist/library/components/Slider/Slider.d.ts.map +1 -1
- package/dist/library/components/Slider/Slider.js +44 -3
- package/dist/library/components/Slider/Slider.js.map +1 -1
- package/dist/library/components/Spoiler/Spoiler.d.ts +15 -0
- package/dist/library/components/Spoiler/Spoiler.d.ts.map +1 -0
- package/dist/library/components/Spoiler/Spoiler.js +34 -0
- package/dist/library/components/Spoiler/Spoiler.js.map +1 -0
- package/dist/library/components/Stepper/Stepper.d.ts +48 -0
- package/dist/library/components/Stepper/Stepper.d.ts.map +1 -0
- package/dist/library/components/Stepper/Stepper.js +81 -0
- package/dist/library/components/Stepper/Stepper.js.map +1 -0
- package/dist/library/components/Timeline/Timeline.d.ts +30 -0
- package/dist/library/components/Timeline/Timeline.d.ts.map +1 -0
- package/dist/library/components/Timeline/Timeline.js +15 -0
- package/dist/library/components/Timeline/Timeline.js.map +1 -0
- package/dist/library/components/Tour/Tour.d.ts +31 -0
- package/dist/library/components/Tour/Tour.d.ts.map +1 -0
- package/dist/library/components/Tour/Tour.js +145 -0
- package/dist/library/components/Tour/Tour.js.map +1 -0
- package/dist/library/components/Tree/Tree.d.ts +48 -0
- package/dist/library/components/Tree/Tree.d.ts.map +1 -0
- package/dist/library/components/Tree/Tree.js +298 -0
- package/dist/library/components/Tree/Tree.js.map +1 -0
- package/dist/library/components/Tree/treeModel.d.ts +43 -0
- package/dist/library/components/Tree/treeModel.d.ts.map +1 -0
- package/dist/library/components/Tree/treeModel.js +83 -0
- package/dist/library/components/Tree/treeModel.js.map +1 -0
- package/dist/library/components/Tree/useTreeLoading.d.ts +6 -0
- package/dist/library/components/Tree/useTreeLoading.d.ts.map +1 -0
- package/dist/library/components/Tree/useTreeLoading.js +69 -0
- package/dist/library/components/Tree/useTreeLoading.js.map +1 -0
- package/dist/library/components/TreeSelect/TreeSelect.d.ts +29 -0
- package/dist/library/components/TreeSelect/TreeSelect.d.ts.map +1 -0
- package/dist/library/components/TreeSelect/TreeSelect.js +163 -0
- package/dist/library/components/TreeSelect/TreeSelect.js.map +1 -0
- package/dist/library/index.d.ts +19 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +14 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/motion/transitions.d.ts.map +1 -1
- package/dist/library/motion/transitions.js +8 -3
- package/dist/library/motion/transitions.js.map +1 -1
- package/dist/library/react/useClipboardCopy.d.ts +8 -0
- package/dist/library/react/useClipboardCopy.d.ts.map +1 -0
- package/dist/library/react/useClipboardCopy.js +49 -0
- package/dist/library/react/useClipboardCopy.js.map +1 -0
- package/dist/library/react/useFormReset.d.ts +1 -1
- package/dist/library/react/useFormReset.d.ts.map +1 -1
- package/dist/library/react/useFormReset.js.map +1 -1
- package/dist/library/react/usePopoverSurface.d.ts.map +1 -1
- package/dist/library/react/usePopoverSurface.js +3 -2
- package/dist/library/react/usePopoverSurface.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/package.json +1 -1
- package/src/color/colorValue.ts +89 -0
- package/src/color/oklch.ts +33 -14
- package/src/components/Cascader/Cascader.tsx +315 -0
- package/src/components/Cascader/CascaderColumn.tsx +203 -0
- package/src/components/CodeBlock/CodeBlock.tsx +3 -45
- package/src/components/Collapsible/Collapsible.tsx +22 -4
- package/src/components/ColorInput/ColorInput.tsx +191 -0
- package/src/components/ColorPicker/ColorArea.tsx +98 -0
- package/src/components/ColorPicker/ColorPicker.tsx +283 -0
- package/src/components/CopyButton/CopyButton.tsx +75 -0
- package/src/components/DataTable/DataTable.tsx +384 -0
- package/src/components/Dropzone/Dropzone.tsx +230 -0
- package/src/components/Highlight/Highlight.tsx +112 -0
- package/src/components/Rating/Rating.tsx +202 -0
- package/src/components/Select/Select.tsx +20 -192
- package/src/components/Select/SelectPopup.tsx +246 -0
- package/src/components/Slider/Slider.tsx +51 -2
- package/src/components/Spoiler/Spoiler.tsx +96 -0
- package/src/components/Stepper/Stepper.tsx +306 -0
- package/src/components/Timeline/Timeline.tsx +139 -0
- package/src/components/Tour/Tour.tsx +335 -0
- package/src/components/Tree/Tree.tsx +530 -0
- package/src/components/Tree/treeModel.ts +110 -0
- package/src/components/Tree/useTreeLoading.ts +73 -0
- package/src/components/TreeSelect/TreeSelect.tsx +326 -0
- package/src/index.ts +50 -0
- package/src/motion/transitions.ts +8 -3
- package/src/react/useClipboardCopy.ts +54 -0
- package/src/react/useFormReset.ts +4 -1
- package/src/react/usePopoverSurface.ts +3 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
4
|
+
import { buildTree, type TreeItem, type TreeLoad, type TreeNode } from './treeModel.js'
|
|
5
|
+
|
|
6
|
+
export function useTreeLoading(items: readonly TreeItem[]) {
|
|
7
|
+
const [loads, setLoads] = useState<ReadonlyMap<string, TreeLoad>>(() => new Map())
|
|
8
|
+
const cache = useRef(loads)
|
|
9
|
+
const requestItems = useRef(items)
|
|
10
|
+
const pending = useRef(new Map<string, AbortController>())
|
|
11
|
+
const save = useCallback((value: string, load: TreeLoad) => {
|
|
12
|
+
cache.current = new Map(cache.current).set(value, load)
|
|
13
|
+
setLoads(cache.current)
|
|
14
|
+
}, [])
|
|
15
|
+
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
requestItems.current = items
|
|
18
|
+
if (!cache.current.size) return
|
|
19
|
+
const { byValue } = buildTree(items, cache.current)
|
|
20
|
+
const next = new Map(cache.current)
|
|
21
|
+
for (const value of next.keys()) {
|
|
22
|
+
if (byValue.get(value)?.item.loadChildren) continue
|
|
23
|
+
pending.current.get(value)?.abort()
|
|
24
|
+
pending.current.delete(value)
|
|
25
|
+
next.delete(value)
|
|
26
|
+
}
|
|
27
|
+
if (next.size !== cache.current.size) {
|
|
28
|
+
cache.current = next
|
|
29
|
+
setLoads(next)
|
|
30
|
+
}
|
|
31
|
+
}, [items])
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const requests = pending.current
|
|
35
|
+
return () => {
|
|
36
|
+
for (const controller of requests.values()) controller.abort()
|
|
37
|
+
requests.clear()
|
|
38
|
+
}
|
|
39
|
+
}, [])
|
|
40
|
+
|
|
41
|
+
const load = useCallback(
|
|
42
|
+
({ item, value }: TreeNode) => {
|
|
43
|
+
if (
|
|
44
|
+
!item.loadChildren ||
|
|
45
|
+
pending.current.has(value) ||
|
|
46
|
+
cache.current.get(value)?.status === 'loaded'
|
|
47
|
+
)
|
|
48
|
+
return
|
|
49
|
+
const controller = new AbortController()
|
|
50
|
+
const loader = item.loadChildren
|
|
51
|
+
pending.current.set(value, controller)
|
|
52
|
+
save(value, { status: 'loading' })
|
|
53
|
+
void Promise.resolve()
|
|
54
|
+
.then(() => (controller.signal.aborted ? [] : loader(controller.signal)))
|
|
55
|
+
.then(children => {
|
|
56
|
+
if (controller.signal.aborted) return
|
|
57
|
+
// Validate against all accepted results before exposing the new collection.
|
|
58
|
+
const next = new Map(cache.current).set(value, { status: 'loaded', children })
|
|
59
|
+
buildTree(requestItems.current, next)
|
|
60
|
+
save(value, { status: 'loaded', children })
|
|
61
|
+
})
|
|
62
|
+
.catch(() => {
|
|
63
|
+
if (!controller.signal.aborted) save(value, { status: 'error' })
|
|
64
|
+
})
|
|
65
|
+
.finally(() => {
|
|
66
|
+
if (pending.current.get(value) === controller) pending.current.delete(value)
|
|
67
|
+
})
|
|
68
|
+
},
|
|
69
|
+
[save]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
return { loads, load }
|
|
73
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useId, useLayoutEffect, useRef, useState, type ComponentProps } from 'react'
|
|
4
|
+
import { cn } from 'cn'
|
|
5
|
+
import { requireAccessibleName } from '../../internal/accessibleName.js'
|
|
6
|
+
import { composeAction } from '../../internal/events.js'
|
|
7
|
+
import { joinIds } from '../../internal/ids.js'
|
|
8
|
+
import { sameSelection, type Selection } from '../../internal/selection.js'
|
|
9
|
+
import { useComposedRefs } from '../../react/useComposedRefs.js'
|
|
10
|
+
import { useControllableState } from '../../react/useControllableState.js'
|
|
11
|
+
import { useFormReset } from '../../react/useFormReset.js'
|
|
12
|
+
import type { ValueOwner } from '../../react/useNativeOwner.js'
|
|
13
|
+
import type { ControlSize, PartStyle } from '../../presentation.js'
|
|
14
|
+
import type { ThemeStyle } from '../../themes/defineTheme.js'
|
|
15
|
+
import { Badge } from '../Badge/Badge.js'
|
|
16
|
+
import { Button } from '../Button/Button.js'
|
|
17
|
+
import { useField, useFieldControl } from '../Field/Field.js'
|
|
18
|
+
import { SelectIcon, SelectViewport } from '../Select/Select.js'
|
|
19
|
+
import { SelectPopup } from '../Select/SelectPopup.js'
|
|
20
|
+
import { selectTriggerClass } from '../Select/selectStyles.js'
|
|
21
|
+
import { controlMetrics } from '../shared/controlStyles.js'
|
|
22
|
+
import { TreeRoot, treeValues, useTreeCollection, type TreeProps } from '../Tree/Tree.js'
|
|
23
|
+
import { treePath } from '../Tree/treeModel.js'
|
|
24
|
+
|
|
25
|
+
type Choice<Value> = ValueOwner<Value> & { onValueChange?: (value: Value) => void }
|
|
26
|
+
|
|
27
|
+
export type TreeSelectProps = Pick<
|
|
28
|
+
ComponentProps<'button'>,
|
|
29
|
+
| 'id'
|
|
30
|
+
| 'ref'
|
|
31
|
+
| 'name'
|
|
32
|
+
| 'form'
|
|
33
|
+
| 'disabled'
|
|
34
|
+
| 'aria-label'
|
|
35
|
+
| 'aria-labelledby'
|
|
36
|
+
| 'aria-describedby'
|
|
37
|
+
| 'aria-invalid'
|
|
38
|
+
| 'onClick'
|
|
39
|
+
| 'onKeyDown'
|
|
40
|
+
| 'className'
|
|
41
|
+
> &
|
|
42
|
+
Pick<TreeProps, 'items' | 'virtual' | 'loadingText' | 'errorText'> & {
|
|
43
|
+
required?: boolean
|
|
44
|
+
placeholder?: string
|
|
45
|
+
controlSize?: ControlSize
|
|
46
|
+
/** By default, ancestors of initially selected items are expanded. */
|
|
47
|
+
defaultExpanded?: string[]
|
|
48
|
+
parts?: { content?: PartStyle; tree?: PartStyle }
|
|
49
|
+
style?: ThemeStyle
|
|
50
|
+
} & (
|
|
51
|
+
| ({ type?: 'single'; checkboxes?: never } & Choice<string | null>)
|
|
52
|
+
| ({ type: 'multiple'; checkboxes?: boolean } & Choice<string[]>)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
export function TreeSelect(props: TreeSelectProps) {
|
|
56
|
+
const {
|
|
57
|
+
items,
|
|
58
|
+
type = 'single',
|
|
59
|
+
checkboxes,
|
|
60
|
+
value,
|
|
61
|
+
defaultValue,
|
|
62
|
+
onValueChange: _onValueChange,
|
|
63
|
+
defaultExpanded,
|
|
64
|
+
placeholder = 'Select an item',
|
|
65
|
+
controlSize = 'medium',
|
|
66
|
+
virtual,
|
|
67
|
+
loadingText,
|
|
68
|
+
errorText,
|
|
69
|
+
parts,
|
|
70
|
+
className,
|
|
71
|
+
onClick,
|
|
72
|
+
onKeyDown,
|
|
73
|
+
ref,
|
|
74
|
+
name,
|
|
75
|
+
form,
|
|
76
|
+
...attributes
|
|
77
|
+
} = props
|
|
78
|
+
const multiple = type === 'multiple'
|
|
79
|
+
const collection = useTreeCollection(items)
|
|
80
|
+
const selection = useControllableState<Selection>({
|
|
81
|
+
name: 'TreeSelect value',
|
|
82
|
+
value,
|
|
83
|
+
defaultValue,
|
|
84
|
+
initialValue: multiple ? [] : null,
|
|
85
|
+
equal: sameSelection,
|
|
86
|
+
onChange: next => {
|
|
87
|
+
if (props.type === 'multiple') {
|
|
88
|
+
if (Array.isArray(next)) props.onValueChange?.(next)
|
|
89
|
+
} else if (!Array.isArray(next)) props.onValueChange?.(next)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
treeValues(selection.value, multiple, 'selection')
|
|
93
|
+
const values = Array.isArray(selection.value)
|
|
94
|
+
? selection.value
|
|
95
|
+
: selection.value === null
|
|
96
|
+
? []
|
|
97
|
+
: [selection.value]
|
|
98
|
+
const paths = values.map(value => ({
|
|
99
|
+
value,
|
|
100
|
+
path:
|
|
101
|
+
treePath(collection.model.byValue.get(value))
|
|
102
|
+
.map(node => node.textValue)
|
|
103
|
+
.join(' / ') || value
|
|
104
|
+
}))
|
|
105
|
+
const submitted = paths.filter(item => !collection.model.byValue.get(item.value)?.disabled)
|
|
106
|
+
const control = useFieldControl(attributes)
|
|
107
|
+
const field = useField()
|
|
108
|
+
const id = useId()
|
|
109
|
+
const labelId =
|
|
110
|
+
attributes['aria-labelledby'] ?? (field?.layout === 'control' ? field.labelId : undefined)
|
|
111
|
+
requireAccessibleName('TreeSelect', {
|
|
112
|
+
'aria-label': attributes['aria-label'],
|
|
113
|
+
'aria-labelledby': labelId
|
|
114
|
+
})
|
|
115
|
+
const treeLabel = labelId ?? id + '-label'
|
|
116
|
+
const valueId = id + '-value'
|
|
117
|
+
const treeId = id + '-tree'
|
|
118
|
+
const [trigger, setTrigger] = useState<HTMLButtonElement | null>(null)
|
|
119
|
+
const triggerRef = useComposedRefs(ref, setTrigger)
|
|
120
|
+
const bridge = useRef<HTMLSelectElement>(null)
|
|
121
|
+
const root = useRef<HTMLDivElement>(null)
|
|
122
|
+
const content = useRef<HTMLDivElement>(null)
|
|
123
|
+
const restoreFocus = useRef(true)
|
|
124
|
+
const [open, setOpen] = useState(false)
|
|
125
|
+
const [reportedInvalid, setReportedInvalid] = useState(false)
|
|
126
|
+
const [initialExpanded] = useState(() => {
|
|
127
|
+
if (defaultExpanded) return defaultExpanded
|
|
128
|
+
const ancestors = new Set<string>()
|
|
129
|
+
for (const value of values) {
|
|
130
|
+
for (let node = collection.model.byValue.get(value)?.parent; node; node = node.parent)
|
|
131
|
+
ancestors.add(node.value)
|
|
132
|
+
}
|
|
133
|
+
return [...ancestors]
|
|
134
|
+
})
|
|
135
|
+
if (open && control.disabled) setOpen(false)
|
|
136
|
+
const shown = open && !control.disabled
|
|
137
|
+
const invalid =
|
|
138
|
+
control['aria-invalid'] || (reportedInvalid && submitted.length === 0) || undefined
|
|
139
|
+
|
|
140
|
+
function close(restore = true) {
|
|
141
|
+
restoreFocus.current = restore
|
|
142
|
+
setOpen(false)
|
|
143
|
+
}
|
|
144
|
+
function show() {
|
|
145
|
+
if (control.disabled || trigger?.matches(':disabled')) return
|
|
146
|
+
restoreFocus.current = true
|
|
147
|
+
setOpen(true)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
useLayoutEffect(() => {
|
|
151
|
+
// A native reset starts from the committed DOM value. The owner then restores its own default.
|
|
152
|
+
for (const option of bridge.current?.options ?? []) option.defaultSelected = option.selected
|
|
153
|
+
})
|
|
154
|
+
useFormReset(bridge, () => {
|
|
155
|
+
selection.reset()
|
|
156
|
+
setReportedInvalid(false)
|
|
157
|
+
close(false)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
const treeProps: TreeProps = {
|
|
161
|
+
'aria-labelledby': treeLabel,
|
|
162
|
+
id: treeId,
|
|
163
|
+
items,
|
|
164
|
+
defaultExpanded: initialExpanded,
|
|
165
|
+
virtual,
|
|
166
|
+
loadingText,
|
|
167
|
+
errorText,
|
|
168
|
+
ref: root,
|
|
169
|
+
className: cn(
|
|
170
|
+
'w-full',
|
|
171
|
+
virtual && 'max-h-[calc(var(--_rad-select-max-height,100dvh)-0.75rem)]',
|
|
172
|
+
parts?.tree?.className
|
|
173
|
+
),
|
|
174
|
+
style: parts?.tree?.style,
|
|
175
|
+
...(multiple
|
|
176
|
+
? {
|
|
177
|
+
type: 'multiple',
|
|
178
|
+
checkboxes,
|
|
179
|
+
value: values,
|
|
180
|
+
onValueChange: (next: string[]) => selection.request(next)
|
|
181
|
+
}
|
|
182
|
+
: {
|
|
183
|
+
value: values[0] ?? null,
|
|
184
|
+
onValueChange: (next: string | null) => selection.request(next)
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<>
|
|
190
|
+
{!labelId && (
|
|
191
|
+
<span
|
|
192
|
+
id={treeLabel}
|
|
193
|
+
className="sr-only"
|
|
194
|
+
>
|
|
195
|
+
{attributes['aria-label']}
|
|
196
|
+
</span>
|
|
197
|
+
)}
|
|
198
|
+
<Button
|
|
199
|
+
ref={triggerRef}
|
|
200
|
+
id={control.id ?? id + '-trigger'}
|
|
201
|
+
type="button"
|
|
202
|
+
variant="outline"
|
|
203
|
+
tone="neutral"
|
|
204
|
+
controlSize={controlSize}
|
|
205
|
+
disabled={control.disabled}
|
|
206
|
+
motion="off"
|
|
207
|
+
aria-labelledby={joinIds(treeLabel, valueId)}
|
|
208
|
+
aria-describedby={control['aria-describedby']}
|
|
209
|
+
aria-invalid={invalid}
|
|
210
|
+
aria-controls={trigger ? treeId : undefined}
|
|
211
|
+
aria-haspopup="tree"
|
|
212
|
+
aria-expanded={shown}
|
|
213
|
+
data-invalid={invalid && invalid !== 'false' ? '' : undefined}
|
|
214
|
+
data-slot="tree-select-trigger"
|
|
215
|
+
data-state={shown ? 'open' : 'closed'}
|
|
216
|
+
data-placeholder={!paths.length ? '' : undefined}
|
|
217
|
+
style={attributes.style}
|
|
218
|
+
render={resolved => (
|
|
219
|
+
<button
|
|
220
|
+
{...resolved}
|
|
221
|
+
className={cn(
|
|
222
|
+
selectTriggerClass,
|
|
223
|
+
controlMetrics({ controlSize }),
|
|
224
|
+
multiple &&
|
|
225
|
+
'h-auto min-h-[var(--rad-select-height,var(--_rad-control-height))] py-1 [&>span:first-child]:justify-start',
|
|
226
|
+
className
|
|
227
|
+
)}
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
onClick={event => composeAction(onClick, () => (shown ? close() : show()))(event)}
|
|
231
|
+
onKeyDown={event => {
|
|
232
|
+
onKeyDown?.(event)
|
|
233
|
+
if (event.defaultPrevented || event.ctrlKey || event.altKey || event.metaKey) return
|
|
234
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
235
|
+
event.preventDefault()
|
|
236
|
+
show()
|
|
237
|
+
}
|
|
238
|
+
}}
|
|
239
|
+
>
|
|
240
|
+
<span
|
|
241
|
+
id={valueId}
|
|
242
|
+
data-slot="tree-select-value"
|
|
243
|
+
className={multiple ? 'flex min-w-0 flex-wrap items-center gap-1' : 'min-w-0 truncate'}
|
|
244
|
+
>
|
|
245
|
+
{!paths.length
|
|
246
|
+
? placeholder
|
|
247
|
+
: multiple
|
|
248
|
+
? paths.map(({ value, path }) => (
|
|
249
|
+
<Badge
|
|
250
|
+
key={value}
|
|
251
|
+
data-slot="tree-select-tag"
|
|
252
|
+
>
|
|
253
|
+
{path}
|
|
254
|
+
</Badge>
|
|
255
|
+
))
|
|
256
|
+
: paths[0].path}
|
|
257
|
+
</span>
|
|
258
|
+
<SelectIcon data-slot="tree-select-icon" />
|
|
259
|
+
</Button>
|
|
260
|
+
{trigger && (
|
|
261
|
+
<SelectPopup
|
|
262
|
+
state={{
|
|
263
|
+
open: shown,
|
|
264
|
+
trigger,
|
|
265
|
+
restoreFocus,
|
|
266
|
+
content,
|
|
267
|
+
close,
|
|
268
|
+
focusInitial: () => root.current?.focus({ preventScroll: true })
|
|
269
|
+
}}
|
|
270
|
+
controlSize={controlSize}
|
|
271
|
+
position="popper"
|
|
272
|
+
data-slot="tree-select-content"
|
|
273
|
+
className={parts?.content?.className}
|
|
274
|
+
style={parts?.content?.style}
|
|
275
|
+
onKeyDown={event => {
|
|
276
|
+
if (event.defaultPrevented) return
|
|
277
|
+
if (event.key === 'Escape' || (event.key === 'Tab' && event.shiftKey)) {
|
|
278
|
+
event.preventDefault()
|
|
279
|
+
event.stopPropagation()
|
|
280
|
+
close()
|
|
281
|
+
}
|
|
282
|
+
}}
|
|
283
|
+
>
|
|
284
|
+
<SelectViewport className={virtual ? 'overflow-hidden' : undefined}>
|
|
285
|
+
<TreeRoot
|
|
286
|
+
{...treeProps}
|
|
287
|
+
collection={collection}
|
|
288
|
+
revealOnFocus
|
|
289
|
+
onSelectionCommit={multiple ? undefined : () => close()}
|
|
290
|
+
/>
|
|
291
|
+
</SelectViewport>
|
|
292
|
+
</SelectPopup>
|
|
293
|
+
)}
|
|
294
|
+
<select
|
|
295
|
+
ref={bridge}
|
|
296
|
+
name={name}
|
|
297
|
+
form={form}
|
|
298
|
+
multiple={multiple}
|
|
299
|
+
required={control.required}
|
|
300
|
+
disabled={control.disabled}
|
|
301
|
+
value={multiple ? submitted.map(item => item.value) : (submitted[0]?.value ?? '')}
|
|
302
|
+
onChange={() => {}}
|
|
303
|
+
onInvalid={event => {
|
|
304
|
+
event.preventDefault()
|
|
305
|
+
setReportedInvalid(true)
|
|
306
|
+
trigger?.focus()
|
|
307
|
+
}}
|
|
308
|
+
aria-hidden="true"
|
|
309
|
+
aria-labelledby={treeLabel}
|
|
310
|
+
tabIndex={-1}
|
|
311
|
+
className="sr-only"
|
|
312
|
+
data-slot="tree-select-native"
|
|
313
|
+
>
|
|
314
|
+
{!multiple && <option value="">{placeholder || 'No selection'}</option>}
|
|
315
|
+
{submitted.map(({ value, path }) => (
|
|
316
|
+
<option
|
|
317
|
+
key={value}
|
|
318
|
+
value={value}
|
|
319
|
+
>
|
|
320
|
+
{path}
|
|
321
|
+
</option>
|
|
322
|
+
))}
|
|
323
|
+
</select>
|
|
324
|
+
</>
|
|
325
|
+
)
|
|
326
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -833,3 +833,53 @@ export {
|
|
|
833
833
|
type DateRangePreset
|
|
834
834
|
} from './components/DateRangePicker/DateRangePicker.js'
|
|
835
835
|
export { TimeInput, type TimeInputProps } from './components/TimeInput/TimeInput.js'
|
|
836
|
+
|
|
837
|
+
export { Tree, type TreeProps, type TreeItem, type TreeVirtual } from './components/Tree/Tree.js'
|
|
838
|
+
|
|
839
|
+
export { TreeSelect, type TreeSelectProps } from './components/TreeSelect/TreeSelect.js'
|
|
840
|
+
|
|
841
|
+
export { Cascader, type CascaderProps } from './components/Cascader/Cascader.js'
|
|
842
|
+
|
|
843
|
+
export { Stepper, type StepperProps, type StepperStep } from './components/Stepper/Stepper.js'
|
|
844
|
+
|
|
845
|
+
export {
|
|
846
|
+
Timeline,
|
|
847
|
+
TimelineItem,
|
|
848
|
+
type TimelineProps,
|
|
849
|
+
type TimelineItemProps
|
|
850
|
+
} from './components/Timeline/Timeline.js'
|
|
851
|
+
|
|
852
|
+
export {
|
|
853
|
+
DataTable,
|
|
854
|
+
type DataTableColumn,
|
|
855
|
+
type DataTableProps,
|
|
856
|
+
type DataTableSelection,
|
|
857
|
+
type DataTableSort,
|
|
858
|
+
type DataTableVirtual
|
|
859
|
+
} from './components/DataTable/DataTable.js'
|
|
860
|
+
|
|
861
|
+
export { Rating, type RatingProps } from './components/Rating/Rating.js'
|
|
862
|
+
|
|
863
|
+
export {
|
|
864
|
+
ColorPicker,
|
|
865
|
+
type ColorPickerProps,
|
|
866
|
+
type ColorPickerSwatch
|
|
867
|
+
} from './components/ColorPicker/ColorPicker.js'
|
|
868
|
+
export type { ColorFormat } from './color/colorValue.js'
|
|
869
|
+
|
|
870
|
+
export { ColorInput, type ColorInputProps } from './components/ColorInput/ColorInput.js'
|
|
871
|
+
|
|
872
|
+
export {
|
|
873
|
+
Dropzone,
|
|
874
|
+
type DropzoneProps,
|
|
875
|
+
type DropzoneSelection,
|
|
876
|
+
type DropzoneRejection
|
|
877
|
+
} from './components/Dropzone/Dropzone.js'
|
|
878
|
+
export { Tour, TourTrigger } from './components/Tour/Tour.js'
|
|
879
|
+
export type { TourProps, TourStep, TourTriggerProps } from './components/Tour/Tour.js'
|
|
880
|
+
export { CopyButton } from './components/CopyButton/CopyButton.js'
|
|
881
|
+
export type { CopyButtonProps, CopyButtonRenderProps } from './components/CopyButton/CopyButton.js'
|
|
882
|
+
export { Spoiler } from './components/Spoiler/Spoiler.js'
|
|
883
|
+
export type { SpoilerProps } from './components/Spoiler/Spoiler.js'
|
|
884
|
+
export { Highlight } from './components/Highlight/Highlight.js'
|
|
885
|
+
export type { HighlightProps } from './components/Highlight/Highlight.js'
|
|
@@ -13,9 +13,10 @@ export function bindDisclosureMotion(host: HTMLElement, initial: MotionProfile):
|
|
|
13
13
|
)
|
|
14
14
|
const measure = () =>
|
|
15
15
|
contents().reduce((sum, child) => sum + child.getBoundingClientRect().height, 0)
|
|
16
|
+
const preview = () => Number(node.getAttribute('data-rad-disclosure-preview') ?? 0)
|
|
16
17
|
const previous = node.style.getPropertyValue('--_rad-spring-details-height')
|
|
17
18
|
const spring = createSpring(
|
|
18
|
-
node.open ? measure() :
|
|
19
|
+
node.open ? measure() : preview(),
|
|
19
20
|
resolveMotion(profile, 'disclosure', query.matches)
|
|
20
21
|
)
|
|
21
22
|
const saved = new Map<HTMLElement, { inert: boolean; hidden: string | null }>()
|
|
@@ -44,7 +45,7 @@ export function bindDisclosureMotion(host: HTMLElement, initial: MotionProfile):
|
|
|
44
45
|
child.setAttribute('aria-hidden', 'true')
|
|
45
46
|
} else restore(child)
|
|
46
47
|
}
|
|
47
|
-
spring.to(node.open ? measure() :
|
|
48
|
+
spring.to(node.open ? measure() : preview())
|
|
48
49
|
}
|
|
49
50
|
function restore(child: HTMLElement) {
|
|
50
51
|
const prior = saved.get(child)
|
|
@@ -55,7 +56,11 @@ export function bindDisclosureMotion(host: HTMLElement, initial: MotionProfile):
|
|
|
55
56
|
saved.delete(child)
|
|
56
57
|
}
|
|
57
58
|
const observer = new MutationObserver(sync)
|
|
58
|
-
observer.observe(node, {
|
|
59
|
+
observer.observe(node, {
|
|
60
|
+
attributes: true,
|
|
61
|
+
attributeFilter: ['open', 'data-rad-disclosure-preview'],
|
|
62
|
+
childList: true
|
|
63
|
+
})
|
|
59
64
|
const resize = new ResizeObserver(sync)
|
|
60
65
|
function update(next: MotionProfile) {
|
|
61
66
|
profile = next
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react'
|
|
4
|
+
|
|
5
|
+
type Phase = 'idle' | 'pending' | 'success' | 'error'
|
|
6
|
+
type Feedback = { source: string; phase: Phase }
|
|
7
|
+
|
|
8
|
+
export function useClipboardCopy(source: string, resetDelay?: number) {
|
|
9
|
+
const [feedback, setFeedback] = useState<Feedback>({ source, phase: 'idle' })
|
|
10
|
+
const [pending, setPending] = useState(false)
|
|
11
|
+
const busy = useRef(false)
|
|
12
|
+
const operation = useRef(0)
|
|
13
|
+
const cancelReset = useRef<() => void>(() => {})
|
|
14
|
+
// Forget feedback for replaced source while an already requested browser write completes.
|
|
15
|
+
if (feedback.source !== source) setFeedback({ source, phase: 'idle' })
|
|
16
|
+
|
|
17
|
+
useEffect(
|
|
18
|
+
() => () => {
|
|
19
|
+
operation.current += 1
|
|
20
|
+
busy.current = false
|
|
21
|
+
cancelReset.current()
|
|
22
|
+
},
|
|
23
|
+
[]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
async function copy(win: Window | null) {
|
|
27
|
+
if (busy.current) return
|
|
28
|
+
const request = ++operation.current
|
|
29
|
+
busy.current = true
|
|
30
|
+
cancelReset.current()
|
|
31
|
+
setPending(true)
|
|
32
|
+
setFeedback({ source, phase: 'pending' })
|
|
33
|
+
let phase: Phase = 'success'
|
|
34
|
+
try {
|
|
35
|
+
if (!win?.navigator.clipboard?.writeText) throw new Error('Clipboard writing is unavailable.')
|
|
36
|
+
await win.navigator.clipboard.writeText(source)
|
|
37
|
+
} catch {
|
|
38
|
+
phase = 'error'
|
|
39
|
+
}
|
|
40
|
+
if (request !== operation.current) return
|
|
41
|
+
busy.current = false
|
|
42
|
+
setPending(false)
|
|
43
|
+
const result: Feedback = { source, phase }
|
|
44
|
+
setFeedback(current => (current.source === source ? result : current))
|
|
45
|
+
if (phase === 'success' && win && resetDelay !== undefined) {
|
|
46
|
+
const id = win.setTimeout(() => {
|
|
47
|
+
setFeedback(current => (current === result ? { source, phase: 'idle' } : current))
|
|
48
|
+
}, resetDelay)
|
|
49
|
+
cancelReset.current = () => win.clearTimeout(id)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { copy, pending, phase: feedback.source === source ? feedback.phase : 'idle' }
|
|
54
|
+
}
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import { useEffect, useLayoutEffect, useRef, type RefObject } from 'react'
|
|
4
4
|
|
|
5
5
|
/** Native reset can be cancelled and the form owner can live outside the subtree. */
|
|
6
|
-
export function useFormReset(
|
|
6
|
+
export function useFormReset(
|
|
7
|
+
inputRef: RefObject<HTMLInputElement | HTMLSelectElement | HTMLFieldSetElement | null>,
|
|
8
|
+
onReset: () => void
|
|
9
|
+
) {
|
|
7
10
|
const latest = useRef(onReset)
|
|
8
11
|
useLayoutEffect(() => {
|
|
9
12
|
latest.current = onReset
|
|
@@ -229,8 +229,9 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
229
229
|
win.visualViewport?.removeEventListener('scroll', schedule)
|
|
230
230
|
stack.splice(stack.indexOf(node), 1)
|
|
231
231
|
if (!stack.length) layers.delete(doc)
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
const returnTarget = focusTarget()
|
|
233
|
+
if (shouldRestore() && node.contains(doc.activeElement) && returnTarget.isConnected)
|
|
234
|
+
returnTarget.focus({ preventScroll: true })
|
|
234
235
|
if (node.matches(':popover-open')) node.hidePopover()
|
|
235
236
|
reposition.current = () => {}
|
|
236
237
|
}
|