@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
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
useContext,
|
|
6
|
-
useEffect,
|
|
7
|
-
useId,
|
|
8
|
-
useRef,
|
|
9
|
-
useState,
|
|
10
|
-
type ComponentProps
|
|
11
|
-
} from 'react'
|
|
3
|
+
import { createContext, useContext, useId, type ComponentProps } from 'react'
|
|
12
4
|
import { Button, type ButtonProps, type ButtonRenderProps } from '../Button/Button.js'
|
|
13
5
|
import { ScrollArea, type ScrollAreaProps } from '../ScrollArea/ScrollArea.js'
|
|
14
6
|
import { cn } from 'cn'
|
|
@@ -16,10 +8,9 @@ import { joinIds } from '../../internal/ids.js'
|
|
|
16
8
|
import { composeAction } from '../../internal/events.js'
|
|
17
9
|
import type { DistributiveOmit, WithoutToggle } from '../../internal/types.js'
|
|
18
10
|
import type { PartStyle } from '../../presentation.js'
|
|
11
|
+
import { useClipboardCopy } from '../../react/useClipboardCopy.js'
|
|
19
12
|
import type { ThemeStyle } from '../../themes/defineTheme.js'
|
|
20
13
|
|
|
21
|
-
type Phase = 'idle' | 'pending' | 'success' | 'error'
|
|
22
|
-
type Feedback = { source: string; phase: Phase }
|
|
23
14
|
type Native<Host extends 'div' | 'pre'> = Omit<ComponentProps<Host>, 'style'> & {
|
|
24
15
|
style?: ThemeStyle
|
|
25
16
|
'data-slot'?: string
|
|
@@ -68,41 +59,8 @@ export function CodeBlock({
|
|
|
68
59
|
...props
|
|
69
60
|
}: CodeBlockProps) {
|
|
70
61
|
if (typeof code !== 'string') throw new TypeError('CodeBlock code must be a string.')
|
|
71
|
-
const [feedback, setFeedback] = useState<Feedback>({ source: code, phase: 'idle' })
|
|
72
|
-
const [pending, setPending] = useState(false)
|
|
73
|
-
const busy = useRef(false),
|
|
74
|
-
mounted = useRef(true),
|
|
75
|
-
operation = useRef(0)
|
|
76
62
|
const statusId = useId()
|
|
77
|
-
|
|
78
|
-
if (feedback.source !== code) setFeedback({ source: code, phase: 'idle' })
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
mounted.current = true
|
|
81
|
-
return () => {
|
|
82
|
-
mounted.current = false
|
|
83
|
-
operation.current += 1
|
|
84
|
-
}
|
|
85
|
-
}, [])
|
|
86
|
-
const copy = async (win: Window | null) => {
|
|
87
|
-
if (busy.current) return
|
|
88
|
-
const source = code,
|
|
89
|
-
request = ++operation.current
|
|
90
|
-
busy.current = true
|
|
91
|
-
setPending(true)
|
|
92
|
-
setFeedback({ source, phase: 'pending' })
|
|
93
|
-
let phase: Phase = 'success'
|
|
94
|
-
try {
|
|
95
|
-
if (!win?.navigator.clipboard?.writeText) throw new Error('Clipboard writing is unavailable.')
|
|
96
|
-
await win.navigator.clipboard.writeText(source)
|
|
97
|
-
} catch {
|
|
98
|
-
phase = 'error'
|
|
99
|
-
}
|
|
100
|
-
if (!mounted.current || request !== operation.current) return
|
|
101
|
-
busy.current = false
|
|
102
|
-
setPending(false)
|
|
103
|
-
setFeedback(current => (current.source === source ? { source, phase } : current))
|
|
104
|
-
}
|
|
105
|
-
const phase = feedback.source === code ? feedback.phase : 'idle'
|
|
63
|
+
const { copy, pending, phase } = useClipboardCopy(code)
|
|
106
64
|
const message =
|
|
107
65
|
phase === 'pending'
|
|
108
66
|
? loadingText
|
|
@@ -28,11 +28,12 @@ const collapsibleVariants = cva([
|
|
|
28
28
|
'[color:var(--rad-collapsible-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))]',
|
|
29
29
|
'[box-shadow:var(--rad-collapsible-shadow,var(--rad-surface-shadow,none))] [backdrop-filter:var(--rad-surface-backdrop-filter,none)]',
|
|
30
30
|
'[&::details-content]:overflow-hidden',
|
|
31
|
+
'[--_rad-disclosure-preview:0px]',
|
|
31
32
|
'[&::details-content]:[interpolate-size:allow-keywords]',
|
|
32
33
|
'[&::details-content]:transition-[height]',
|
|
33
34
|
'[&::details-content]:duration-[var(--rad-collapsible-duration,var(--rad-motion-disclosure-duration,150ms))]',
|
|
34
35
|
'[&::details-content]:ease-out',
|
|
35
|
-
'[&:not([open])::details-content]:h-
|
|
36
|
+
'[&:not([open])::details-content]:h-[var(--_rad-disclosure-preview,0px)]',
|
|
36
37
|
'open:[&::details-content]:h-auto',
|
|
37
38
|
'motion-reduce:[&::details-content]:transition-none',
|
|
38
39
|
'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]'
|
|
@@ -108,7 +109,12 @@ function useCollapsibleContext() {
|
|
|
108
109
|
return collapsible
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
export function Collapsible({
|
|
112
|
+
export function Collapsible(props: CollapsibleProps) {
|
|
113
|
+
return <CollapsibleRoot {...props} />
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Private collapsed preview seam for Spoiler. */
|
|
117
|
+
export function CollapsibleRoot({
|
|
112
118
|
open,
|
|
113
119
|
defaultOpen,
|
|
114
120
|
motion = 'inherit',
|
|
@@ -117,8 +123,10 @@ export function Collapsible({
|
|
|
117
123
|
onToggle,
|
|
118
124
|
className,
|
|
119
125
|
children,
|
|
126
|
+
previewHeight,
|
|
127
|
+
style,
|
|
120
128
|
...props
|
|
121
|
-
}: CollapsibleProps) {
|
|
129
|
+
}: CollapsibleProps & { previewHeight?: number }) {
|
|
122
130
|
const node = useRef<HTMLDetailsElement>(null)
|
|
123
131
|
const nativeRef = useComposedRefs(node, ref)
|
|
124
132
|
const transition = useTransitionHost<HTMLDetailsElement>(
|
|
@@ -160,11 +168,21 @@ export function Collapsible({
|
|
|
160
168
|
collapsibleVariants(),
|
|
161
169
|
transition.active &&
|
|
162
170
|
transition.ready &&
|
|
163
|
-
'[&::details-content]:[content-visibility:visible] [&::details-content]:transition-none [&:not([open])::details-content]:h-[var(--_rad-spring-details-height,0px)] open:[&::details-content]:h-[var(--_rad-spring-details-height,auto)]',
|
|
171
|
+
'[&::details-content]:[content-visibility:visible] [&::details-content]:transition-none [&:not([open])::details-content]:h-[var(--_rad-spring-details-height,var(--_rad-disclosure-preview,0px))] open:[&::details-content]:h-[var(--_rad-spring-details-height,auto)]',
|
|
172
|
+
previewHeight !== undefined && '[&::details-content]:[content-visibility:visible]',
|
|
164
173
|
motionOff && '[&::details-content]:transition-none [&>summary>svg]:transition-none',
|
|
165
174
|
className
|
|
166
175
|
)}
|
|
167
176
|
data-slot={joinIds('collapsible', props['data-slot'])}
|
|
177
|
+
data-rad-disclosure-preview={previewHeight}
|
|
178
|
+
style={
|
|
179
|
+
previewHeight === undefined
|
|
180
|
+
? style
|
|
181
|
+
: {
|
|
182
|
+
...style,
|
|
183
|
+
'--_rad-disclosure-preview': `${previewHeight}px`
|
|
184
|
+
}
|
|
185
|
+
}
|
|
168
186
|
data-state={isOpen ? 'open' : 'closed'}
|
|
169
187
|
open={isOpen}
|
|
170
188
|
onToggle={event => {
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useRef, useState } from 'react'
|
|
4
|
+
import { cn } from 'cn'
|
|
5
|
+
import { formatColor, parseColor, type ColorFormat } from '../../color/colorValue.js'
|
|
6
|
+
import { joinIds } from '../../internal/ids.js'
|
|
7
|
+
import type { PartStyle } from '../../presentation.js'
|
|
8
|
+
import { useComposedRefs } from '../../react/useComposedRefs.js'
|
|
9
|
+
import { useControllableState } from '../../react/useControllableState.js'
|
|
10
|
+
import { useFormReset } from '../../react/useFormReset.js'
|
|
11
|
+
import type { ValueOwner } from '../../react/useNativeOwner.js'
|
|
12
|
+
import { ColorPicker, type ColorPickerProps } from '../ColorPicker/ColorPicker.js'
|
|
13
|
+
import { WithoutField, useFieldControl } from '../Field/Field.js'
|
|
14
|
+
import type { InputProps } from '../Input/Input.js'
|
|
15
|
+
import { InputGroup, InputGroupAddon, InputGroupInput } from '../InputGroup/InputGroup.js'
|
|
16
|
+
import { Popover, PopoverContent, PopoverPortal, PopoverTrigger } from '../Popover/Popover.js'
|
|
17
|
+
|
|
18
|
+
export type ColorInputProps = Omit<InputProps, 'defaultValue' | 'value' | 'type' | 'children'> &
|
|
19
|
+
ValueOwner<string> & {
|
|
20
|
+
format?: ColorFormat
|
|
21
|
+
/** Receives edits as typed and canonical values after blur or picker selection. */
|
|
22
|
+
onValueChange?: (value: string) => void
|
|
23
|
+
pickerLabel?: string
|
|
24
|
+
invalidText?: string
|
|
25
|
+
swatches?: ColorPickerProps['swatches']
|
|
26
|
+
eyedropper?: boolean
|
|
27
|
+
pickerLabels?: ColorPickerProps['labels']
|
|
28
|
+
parts?: { input?: PartStyle; trigger?: PartStyle; popup?: PartStyle }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const checker =
|
|
32
|
+
'repeating-conic-gradient(var(--rad-color-neutral) 0% 25%,var(--rad-color-surface) 0% 50%) 0 0/8px 8px'
|
|
33
|
+
|
|
34
|
+
export function ColorInput({
|
|
35
|
+
value,
|
|
36
|
+
defaultValue,
|
|
37
|
+
onValueChange,
|
|
38
|
+
format = 'hex',
|
|
39
|
+
pickerLabel = 'Choose color',
|
|
40
|
+
invalidText = 'Enter a hex, RGB, or OKLCH color.',
|
|
41
|
+
swatches,
|
|
42
|
+
eyedropper,
|
|
43
|
+
pickerLabels,
|
|
44
|
+
controlSize = 'medium',
|
|
45
|
+
className,
|
|
46
|
+
style,
|
|
47
|
+
parts,
|
|
48
|
+
name,
|
|
49
|
+
form,
|
|
50
|
+
readOnly,
|
|
51
|
+
onChange,
|
|
52
|
+
onBlur,
|
|
53
|
+
ref,
|
|
54
|
+
'data-slot': slot,
|
|
55
|
+
...props
|
|
56
|
+
}: ColorInputProps) {
|
|
57
|
+
const state = useControllableState({
|
|
58
|
+
name: 'ColorInput value',
|
|
59
|
+
value,
|
|
60
|
+
defaultValue,
|
|
61
|
+
initialValue: '',
|
|
62
|
+
onChange: onValueChange
|
|
63
|
+
})
|
|
64
|
+
const color = parseColor(state.value)
|
|
65
|
+
const normalized = color ? formatColor(color, format) : ''
|
|
66
|
+
const preview = color ? formatColor(color, 'oklch') : ''
|
|
67
|
+
const invalid = state.value !== '' && !color
|
|
68
|
+
const message = invalid ? invalidText || 'Enter a hex, RGB, or OKLCH color.' : ''
|
|
69
|
+
const control = useFieldControl(props)
|
|
70
|
+
const blocked = control.disabled || readOnly
|
|
71
|
+
const input = useRef<HTMLInputElement>(null)
|
|
72
|
+
const inputRef = useComposedRefs(input, ref)
|
|
73
|
+
const popup = useRef<HTMLDivElement>(null)
|
|
74
|
+
const [open, setOpen] = useState(false)
|
|
75
|
+
// Keep the focused descendant mounted while Popover returns focus on close.
|
|
76
|
+
const [pickerMounted, setPickerMounted] = useState(false)
|
|
77
|
+
if (open && blocked) setOpen(false)
|
|
78
|
+
const shown = open && !blocked
|
|
79
|
+
|
|
80
|
+
useLayoutEffect(() => {
|
|
81
|
+
input.current?.setCustomValidity(message)
|
|
82
|
+
}, [message])
|
|
83
|
+
useFormReset(input, () => {
|
|
84
|
+
state.reset()
|
|
85
|
+
setOpen(false)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Popover
|
|
90
|
+
open={shown}
|
|
91
|
+
onOpenChange={next => {
|
|
92
|
+
setOpen(next)
|
|
93
|
+
if (next) setPickerMounted(true)
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<InputGroup
|
|
97
|
+
data-slot={joinIds('color-input', slot)}
|
|
98
|
+
controlSize={controlSize}
|
|
99
|
+
className={className}
|
|
100
|
+
style={style}
|
|
101
|
+
>
|
|
102
|
+
<InputGroupInput
|
|
103
|
+
{...props}
|
|
104
|
+
ref={inputRef}
|
|
105
|
+
type="text"
|
|
106
|
+
form={form}
|
|
107
|
+
readOnly={readOnly}
|
|
108
|
+
value={state.value}
|
|
109
|
+
aria-invalid={invalid ? true : props['aria-invalid']}
|
|
110
|
+
data-slot="color-input-input"
|
|
111
|
+
className={parts?.input?.className}
|
|
112
|
+
style={parts?.input?.style}
|
|
113
|
+
onChange={event => {
|
|
114
|
+
onChange?.(event)
|
|
115
|
+
state.request(event.currentTarget.value)
|
|
116
|
+
}}
|
|
117
|
+
onBlur={event => {
|
|
118
|
+
onBlur?.(event)
|
|
119
|
+
if (!blocked && normalized) state.request(normalized)
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
<InputGroupAddon>
|
|
123
|
+
<PopoverTrigger
|
|
124
|
+
iconOnly
|
|
125
|
+
variant="ghost"
|
|
126
|
+
tone="neutral"
|
|
127
|
+
controlSize={controlSize}
|
|
128
|
+
disabled={blocked}
|
|
129
|
+
aria-label={pickerLabel}
|
|
130
|
+
aria-haspopup="dialog"
|
|
131
|
+
data-slot="color-input-trigger"
|
|
132
|
+
className={cn(
|
|
133
|
+
'size-[calc(var(--_rad-control-height)_-_0.5rem)] px-0 focus-visible:[--_rad-focus-offset:-1px]',
|
|
134
|
+
parts?.trigger?.className
|
|
135
|
+
)}
|
|
136
|
+
style={parts?.trigger?.style}
|
|
137
|
+
motion="off"
|
|
138
|
+
>
|
|
139
|
+
<span
|
|
140
|
+
aria-hidden="true"
|
|
141
|
+
data-slot="color-input-swatch"
|
|
142
|
+
className="size-[calc(var(--_rad-control-height)*0.48)] rounded-[var(--rad-control-radius,0.25rem)] border border-[var(--rad-color-border)] forced-color-adjust-none"
|
|
143
|
+
style={{
|
|
144
|
+
background: preview ? `linear-gradient(${preview},${preview}),${checker}` : checker
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
</PopoverTrigger>
|
|
148
|
+
<PopoverPortal>
|
|
149
|
+
<PopoverContent
|
|
150
|
+
ref={popup}
|
|
151
|
+
initialFocusRef={popup}
|
|
152
|
+
tabIndex={-1}
|
|
153
|
+
// oxlint-disable-next-line jsx-a11y/prefer-tag-over-role -- Popover owns the nonmodal top layer.
|
|
154
|
+
role="dialog"
|
|
155
|
+
aria-label={pickerLabel}
|
|
156
|
+
align="end"
|
|
157
|
+
data-slot="color-input-popup"
|
|
158
|
+
className={cn('w-[min(20rem,calc(100vw_-_1rem))] p-3', parts?.popup?.className)}
|
|
159
|
+
style={parts?.popup?.style}
|
|
160
|
+
>
|
|
161
|
+
{pickerMounted && (
|
|
162
|
+
<WithoutField>
|
|
163
|
+
<ColorPicker
|
|
164
|
+
label={pickerLabel}
|
|
165
|
+
value={normalized || '#456BE4'}
|
|
166
|
+
format={format}
|
|
167
|
+
controlSize={controlSize}
|
|
168
|
+
swatches={swatches}
|
|
169
|
+
eyedropper={shown && eyedropper}
|
|
170
|
+
labels={pickerLabels}
|
|
171
|
+
onValueChange={state.request}
|
|
172
|
+
/>
|
|
173
|
+
</WithoutField>
|
|
174
|
+
)}
|
|
175
|
+
</PopoverContent>
|
|
176
|
+
</PopoverPortal>
|
|
177
|
+
</InputGroupAddon>
|
|
178
|
+
</InputGroup>
|
|
179
|
+
{name && (
|
|
180
|
+
<input
|
|
181
|
+
type="hidden"
|
|
182
|
+
name={name}
|
|
183
|
+
form={form}
|
|
184
|
+
value={normalized}
|
|
185
|
+
disabled={control.disabled}
|
|
186
|
+
data-slot="color-input-native"
|
|
187
|
+
/>
|
|
188
|
+
)}
|
|
189
|
+
</Popover>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useRef, type PointerEvent } from 'react'
|
|
4
|
+
import { cn } from 'cn'
|
|
5
|
+
import { clamp, srgbMapper } from '../../color/oklch.js'
|
|
6
|
+
import { formatColor, type ColorChannels } from '../../color/colorValue.js'
|
|
7
|
+
import type { PartStyle } from '../../presentation.js'
|
|
8
|
+
|
|
9
|
+
const width = 56
|
|
10
|
+
const height = 48
|
|
11
|
+
|
|
12
|
+
/** The pointer area and the two keyboard sliders share the same color channels. */
|
|
13
|
+
export function ColorArea({
|
|
14
|
+
color,
|
|
15
|
+
maxChroma,
|
|
16
|
+
disabled,
|
|
17
|
+
part,
|
|
18
|
+
onChange
|
|
19
|
+
}: {
|
|
20
|
+
color: ColorChannels
|
|
21
|
+
maxChroma: number
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
part?: PartStyle
|
|
24
|
+
onChange(color: ColorChannels): void
|
|
25
|
+
}) {
|
|
26
|
+
const canvas = useRef<HTMLCanvasElement>(null)
|
|
27
|
+
const hue = color.h
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
const context = canvas.current?.getContext('2d')
|
|
30
|
+
if (!context) return
|
|
31
|
+
const pixels = context.createImageData(width, height)
|
|
32
|
+
const mapper = srgbMapper()
|
|
33
|
+
for (let y = 0; y < height; y++) {
|
|
34
|
+
for (let x = 0; x < width; x++) {
|
|
35
|
+
const hex = mapper.toHex(1 - y / (height - 1), (x / (width - 1)) * maxChroma, hue)
|
|
36
|
+
const offset = (y * width + x) * 4
|
|
37
|
+
pixels.data[offset] = parseInt(hex.slice(1, 3), 16)
|
|
38
|
+
pixels.data[offset + 1] = parseInt(hex.slice(3, 5), 16)
|
|
39
|
+
pixels.data[offset + 2] = parseInt(hex.slice(5, 7), 16)
|
|
40
|
+
pixels.data[offset + 3] = 255
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
context.putImageData(pixels, 0, 0)
|
|
44
|
+
}, [hue, maxChroma])
|
|
45
|
+
|
|
46
|
+
function pick(event: PointerEvent<HTMLDivElement>) {
|
|
47
|
+
const node = event.currentTarget
|
|
48
|
+
const { left, top, width, height } = node.getBoundingClientRect()
|
|
49
|
+
if (!width || !height || disabled || node.closest('fieldset:disabled')) return
|
|
50
|
+
const rtl = node.ownerDocument.defaultView?.getComputedStyle(node).direction === 'rtl'
|
|
51
|
+
const x = clamp((event.clientX - left) / width)
|
|
52
|
+
const y = clamp((event.clientY - top) / height)
|
|
53
|
+
onChange({ ...color, L: 1 - y, C: (rtl ? 1 - x : x) * maxChroma })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div
|
|
58
|
+
aria-hidden="true"
|
|
59
|
+
data-slot="color-picker-area"
|
|
60
|
+
className={cn(
|
|
61
|
+
'relative isolate h-36 overflow-hidden rounded-[var(--rad-control-radius,0.5rem)] [corner-shape:var(--rad-control-corner-shape,round)]',
|
|
62
|
+
disabled ? 'cursor-not-allowed' : 'touch-none cursor-crosshair',
|
|
63
|
+
part?.className
|
|
64
|
+
)}
|
|
65
|
+
style={part?.style}
|
|
66
|
+
onPointerDown={event => {
|
|
67
|
+
if (
|
|
68
|
+
!event.isPrimary ||
|
|
69
|
+
event.button !== 0 ||
|
|
70
|
+
disabled ||
|
|
71
|
+
event.currentTarget.closest('fieldset:disabled')
|
|
72
|
+
)
|
|
73
|
+
return
|
|
74
|
+
event.currentTarget.setPointerCapture(event.pointerId)
|
|
75
|
+
pick(event)
|
|
76
|
+
}}
|
|
77
|
+
onPointerMove={event => {
|
|
78
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) pick(event)
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<canvas
|
|
82
|
+
ref={canvas}
|
|
83
|
+
width={width}
|
|
84
|
+
height={height}
|
|
85
|
+
className="absolute inset-0 size-full rtl:-scale-x-100"
|
|
86
|
+
/>
|
|
87
|
+
<span
|
|
88
|
+
className="pointer-events-none absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_black] rtl:translate-x-1/2"
|
|
89
|
+
data-slot="color-picker-marker"
|
|
90
|
+
style={{
|
|
91
|
+
insetInlineStart: `${(color.C / maxChroma) * 100}%`,
|
|
92
|
+
top: `${(1 - color.L) * 100}%`,
|
|
93
|
+
background: formatColor({ ...color, alpha: 1 }, 'oklch')
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
)
|
|
98
|
+
}
|