@adea-ai/ui 0.151.15 → 0.152.0
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/dist/components/composites/accent-picker/accent-picker.d.ts +44 -10
- package/dist/components/composites/accent-picker/accent-picker.d.ts.map +1 -1
- package/dist/components/composites/accent-picker/accent-picker.js +155 -58
- package/dist/components/composites/accent-picker/accent-picker.js.map +1 -1
- package/dist/components/composites/accent-picker/color-math.d.ts +13 -0
- package/dist/components/composites/accent-picker/color-math.d.ts.map +1 -0
- package/dist/components/composites/accent-picker/color-math.js +61 -0
- package/dist/components/composites/accent-picker/color-math.js.map +1 -0
- package/dist/components/composites/accent-picker/custom-color-popover.d.ts +18 -0
- package/dist/components/composites/accent-picker/custom-color-popover.d.ts.map +1 -0
- package/dist/components/composites/accent-picker/custom-color-popover.js +248 -0
- package/dist/components/composites/accent-picker/custom-color-popover.js.map +1 -0
- package/dist/components/composites/accent-picker/index.d.ts +1 -1
- package/dist/components/composites/accent-picker/index.d.ts.map +1 -1
- package/dist/components/composites/accent-picker/index.js +1 -1
- package/dist/components/composites/appearance-editor/appearance-choices.d.ts.map +1 -1
- package/dist/components/composites/appearance-editor/appearance-choices.js +37 -74
- package/dist/components/composites/appearance-editor/appearance-choices.js.map +1 -1
- package/dist/components/composites/icon-picker/icon-picker.js +1 -1
- package/dist/components/composites/icon-picker/icon-picker.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/r/accent-picker.json +13 -0
- package/dist/r/appearance-editor.json +1 -0
- package/dist/r/registry.json +14 -0
- package/dist/r/src/components/composites/accent-picker/accent-picker.tsx +154 -38
- package/dist/r/src/components/composites/accent-picker/color-math.ts +54 -0
- package/dist/r/src/components/composites/accent-picker/custom-color-popover.tsx +220 -0
- package/dist/r/src/components/composites/accent-picker/index.ts +6 -1
- package/dist/r/src/components/composites/appearance-editor/appearance-choices.tsx +34 -58
- package/dist/r/src/components/composites/icon-picker/icon-picker.tsx +1 -1
- package/package.json +1 -1
- package/registry.json +14 -0
- package/src/components/composites/accent-picker/accent-picker.tsx +154 -38
- package/src/components/composites/accent-picker/color-math.ts +54 -0
- package/src/components/composites/accent-picker/custom-color-popover.tsx +220 -0
- package/src/components/composites/accent-picker/index.ts +6 -1
- package/src/components/composites/appearance-editor/appearance-choices.tsx +34 -58
- package/src/components/composites/icon-picker/icon-picker.tsx +1 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { JSX } from 'solid-js'
|
|
2
|
+
import { Show, createSignal } from 'solid-js'
|
|
3
|
+
import { cn } from '../../../lib/utils'
|
|
4
|
+
import { Button } from '../../ui/button'
|
|
5
|
+
import { Input } from '../../ui/input'
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
7
|
+
import { clamp, hexToHsv, hsvToHex, type Hsv } from './color-math'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Custom entry of the accent picker: a button that opens a colour picker
|
|
11
|
+
* anchored right under it, right edges aligned since Custom ends the row (a
|
|
12
|
+
* saturation/brightness field, a hue strip and a hex field). Nothing is committed while the colour is being explored; Apply (or
|
|
13
|
+
* Enter in the hex field) commits it and closes, Escape or a click outside
|
|
14
|
+
* leaves the stored colour alone. The operating system's colour panel is not
|
|
15
|
+
* used because on macOS it floats wherever it was last left, not by the button.
|
|
16
|
+
*/
|
|
17
|
+
export function CustomColorPopover(props: {
|
|
18
|
+
/** The stored custom colour, or `undefined` while a preset or inherit is chosen. */
|
|
19
|
+
value: string | undefined
|
|
20
|
+
/** Where the picker starts while no custom colour is stored. */
|
|
21
|
+
seed: string
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
onCommit(value: `#${string}`): void
|
|
24
|
+
}) {
|
|
25
|
+
const [open, setOpen] = createSignal(false)
|
|
26
|
+
const [draft, setDraft] = createSignal<Hsv>({ h: 0, s: 0, v: 0 })
|
|
27
|
+
const [hexText, setHexText] = createSignal('')
|
|
28
|
+
const draftHex = () => hsvToHex(draft())
|
|
29
|
+
// The hex field is what Apply commits, so text that is not a colour yet blocks it.
|
|
30
|
+
const typedHex = () => {
|
|
31
|
+
const text = hexText().trim()
|
|
32
|
+
return hexToHsv(text.startsWith('#') ? text : `#${text}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const start = () => {
|
|
36
|
+
const initial = hexToHsv(props.value ?? props.seed) ?? { h: 262, s: 0.8, v: 0.9 }
|
|
37
|
+
setDraft(initial)
|
|
38
|
+
setHexText(hsvToHex(initial))
|
|
39
|
+
}
|
|
40
|
+
const update = (next: Hsv) => {
|
|
41
|
+
setDraft(next)
|
|
42
|
+
setHexText(hsvToHex(next))
|
|
43
|
+
}
|
|
44
|
+
const commit = () => {
|
|
45
|
+
if (!typedHex()) return
|
|
46
|
+
props.onCommit(draftHex())
|
|
47
|
+
setOpen(false)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Popover
|
|
52
|
+
open={open()}
|
|
53
|
+
onOpenChange={(next) => {
|
|
54
|
+
if (next) start()
|
|
55
|
+
setOpen(next)
|
|
56
|
+
}}
|
|
57
|
+
placement="bottom-end"
|
|
58
|
+
>
|
|
59
|
+
<PopoverTrigger
|
|
60
|
+
as={Button}
|
|
61
|
+
type="button"
|
|
62
|
+
variant={props.value ? 'secondary' : 'outline'}
|
|
63
|
+
size="sm"
|
|
64
|
+
data-slot="swatch-custom"
|
|
65
|
+
disabled={props.disabled}
|
|
66
|
+
aria-pressed={props.value !== undefined}
|
|
67
|
+
class="shrink-0 gap-1.5"
|
|
68
|
+
>
|
|
69
|
+
<Show when={props.value}>
|
|
70
|
+
{(color) => (
|
|
71
|
+
<span
|
|
72
|
+
aria-hidden="true"
|
|
73
|
+
data-slot="swatch-custom-chip"
|
|
74
|
+
class="size-3 rounded-full border border-border bg-(--swatch-custom)"
|
|
75
|
+
style={{ '--swatch-custom': color() }}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
</Show>
|
|
79
|
+
Custom
|
|
80
|
+
</PopoverTrigger>
|
|
81
|
+
<PopoverContent class="w-60" aria-label="Custom colour">
|
|
82
|
+
<div class="flex flex-col gap-3" data-slot="custom-color">
|
|
83
|
+
<DragArea
|
|
84
|
+
label="Saturation and brightness"
|
|
85
|
+
value={Math.round(draft().s * 100)}
|
|
86
|
+
max={100}
|
|
87
|
+
valueText={`Saturation ${Math.round(draft().s * 100)}%, brightness ${Math.round(draft().v * 100)}%`}
|
|
88
|
+
class="h-36 rounded-md"
|
|
89
|
+
style={{
|
|
90
|
+
'background-image': `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${draft().h} 100% 50%))`,
|
|
91
|
+
}}
|
|
92
|
+
thumb={{ x: draft().s, y: 1 - draft().v }}
|
|
93
|
+
onPoint={(x, y) => update({ ...draft(), s: x, v: 1 - y })}
|
|
94
|
+
onStep={(dx, dy) =>
|
|
95
|
+
update({ ...draft(), s: clamp(draft().s + dx), v: clamp(draft().v - dy) })
|
|
96
|
+
}
|
|
97
|
+
/>
|
|
98
|
+
<DragArea
|
|
99
|
+
label="Hue"
|
|
100
|
+
value={Math.round(draft().h)}
|
|
101
|
+
max={360}
|
|
102
|
+
valueText={`${Math.round(draft().h)} degrees`}
|
|
103
|
+
class="h-3 rounded-full"
|
|
104
|
+
style={{
|
|
105
|
+
'background-image':
|
|
106
|
+
'linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)',
|
|
107
|
+
}}
|
|
108
|
+
thumb={{ x: draft().h / 360, y: 0.5 }}
|
|
109
|
+
onPoint={(x) => update({ ...draft(), h: Math.min(359.99, x * 360) })}
|
|
110
|
+
onStep={(dx) =>
|
|
111
|
+
update({ ...draft(), h: Math.min(359.99, Math.max(0, draft().h + dx * 360)) })
|
|
112
|
+
}
|
|
113
|
+
/>
|
|
114
|
+
<div class="flex items-center gap-2">
|
|
115
|
+
<span
|
|
116
|
+
aria-hidden="true"
|
|
117
|
+
class="size-8 shrink-0 rounded-md border border-border bg-(--swatch-draft)"
|
|
118
|
+
style={{ '--swatch-draft': draftHex() }}
|
|
119
|
+
/>
|
|
120
|
+
<Input
|
|
121
|
+
aria-label="Hex colour"
|
|
122
|
+
class="min-w-0 flex-1 font-mono"
|
|
123
|
+
value={hexText()}
|
|
124
|
+
maxLength={7}
|
|
125
|
+
spellcheck={false}
|
|
126
|
+
aria-invalid={typedHex() ? undefined : true}
|
|
127
|
+
onInput={(event) => {
|
|
128
|
+
const text = event.currentTarget.value.trim()
|
|
129
|
+
setHexText(text)
|
|
130
|
+
const parsed = typedHex()
|
|
131
|
+
if (parsed) setDraft(parsed)
|
|
132
|
+
}}
|
|
133
|
+
onKeyDown={(event) => {
|
|
134
|
+
if (event.key === 'Enter') {
|
|
135
|
+
event.preventDefault()
|
|
136
|
+
commit()
|
|
137
|
+
}
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
<Button type="button" size="sm" disabled={!typedHex()} onClick={commit}>
|
|
141
|
+
Apply
|
|
142
|
+
</Button>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</PopoverContent>
|
|
146
|
+
</Popover>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A pointer- and keyboard-driven area reporting a position in [0, 1] on each
|
|
152
|
+
* axis: the saturation/brightness field and the hue strip. Its listeners are
|
|
153
|
+
* native (`on:`) rather than delegated, so this module registers nothing on
|
|
154
|
+
* `window.document` when it loads.
|
|
155
|
+
*/
|
|
156
|
+
function DragArea(props: {
|
|
157
|
+
label: string
|
|
158
|
+
/** The value assistive technology reads, from 0 to `max`; the 2D field reports saturation and names both axes in `valueText`. */
|
|
159
|
+
value: number
|
|
160
|
+
max: number
|
|
161
|
+
valueText: string
|
|
162
|
+
class: string
|
|
163
|
+
style: JSX.CSSProperties
|
|
164
|
+
thumb: { x: number; y: number }
|
|
165
|
+
onPoint(x: number, y: number): void
|
|
166
|
+
onStep(dx: number, dy: number): void
|
|
167
|
+
}) {
|
|
168
|
+
const point = (event: PointerEvent) => {
|
|
169
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
|
170
|
+
if (rect.width === 0 || rect.height === 0) return
|
|
171
|
+
props.onPoint(
|
|
172
|
+
clamp((event.clientX - rect.left) / rect.width),
|
|
173
|
+
clamp((event.clientY - rect.top) / rect.height)
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
return (
|
|
177
|
+
<div
|
|
178
|
+
role="slider"
|
|
179
|
+
tabIndex={0}
|
|
180
|
+
aria-label={props.label}
|
|
181
|
+
aria-valuemin={0}
|
|
182
|
+
aria-valuemax={props.max}
|
|
183
|
+
aria-valuenow={props.value}
|
|
184
|
+
aria-valuetext={props.valueText}
|
|
185
|
+
data-slot="custom-color-area"
|
|
186
|
+
class={cn(
|
|
187
|
+
'relative w-full cursor-crosshair touch-none border border-border outline-none',
|
|
188
|
+
'focus-visible:ring-3 focus-visible:ring-primary-subtle',
|
|
189
|
+
props.class
|
|
190
|
+
)}
|
|
191
|
+
style={props.style}
|
|
192
|
+
on:pointerdown={(event) => {
|
|
193
|
+
event.currentTarget.setPointerCapture?.(event.pointerId)
|
|
194
|
+
point(event)
|
|
195
|
+
}}
|
|
196
|
+
on:pointermove={(event) => {
|
|
197
|
+
if (event.buttons & 1) point(event)
|
|
198
|
+
}}
|
|
199
|
+
on:keydown={(event) => {
|
|
200
|
+
const step = event.shiftKey ? 0.1 : 0.02
|
|
201
|
+
const moves: Record<string, [number, number]> = {
|
|
202
|
+
ArrowLeft: [-step, 0],
|
|
203
|
+
ArrowRight: [step, 0],
|
|
204
|
+
ArrowUp: [0, -step],
|
|
205
|
+
ArrowDown: [0, step],
|
|
206
|
+
}
|
|
207
|
+
const move = moves[event.key]
|
|
208
|
+
if (!move) return
|
|
209
|
+
event.preventDefault()
|
|
210
|
+
props.onStep(move[0], move[1])
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
<span
|
|
214
|
+
aria-hidden="true"
|
|
215
|
+
class="pointer-events-none absolute size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-background shadow-sm ring-1 ring-border"
|
|
216
|
+
style={{ left: `${props.thumb.x * 100}%`, top: `${props.thumb.y * 100}%` }}
|
|
217
|
+
/>
|
|
218
|
+
</div>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
@@ -28,8 +28,7 @@ import { Monitor, Moon, Sun } from 'lucide-solid'
|
|
|
28
28
|
import { For, Show } from 'solid-js'
|
|
29
29
|
import { isThemeAccentId } from '../../../lib/theme-accents'
|
|
30
30
|
import { THEME_DEFAULT_ID } from '../../../lib/theme-defaults'
|
|
31
|
-
import {
|
|
32
|
-
import { Input } from '../../ui/input'
|
|
31
|
+
import { AccentPicker, isCustomAccentValue } from '../accent-picker'
|
|
33
32
|
import { AccentSwatchGroups } from './accent-swatch-groups'
|
|
34
33
|
import type { AppearanceEditorProps } from './appearance-types'
|
|
35
34
|
import { ThemeMiniature, ThemeMiniatureSplit } from './theme-preview'
|
|
@@ -135,15 +134,24 @@ export function AccentChoices(props: AppearanceEditorProps) {
|
|
|
135
134
|
? [{ id: THEME_DEFAULT_ID, label: 'Theme default' }, ...presets]
|
|
136
135
|
: presets
|
|
137
136
|
}
|
|
138
|
-
// The `row` style
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
// The `row` style is the shared AccentPicker every accent setting uses: the
|
|
138
|
+
// swatches, then a Custom button that opens the native colour selector, so the
|
|
139
|
+
// draft only changes once a colour is chosen there. The app has nothing to
|
|
140
|
+
// inherit from, so there is no inherit swatch; "Theme default" leads when the
|
|
141
|
+
// host keeps it.
|
|
142
|
+
const rowOptions = () => {
|
|
143
|
+
const presets = props.accentOptions.filter((option) => option.id !== THEME_DEFAULT_ID)
|
|
144
|
+
return showThemeDefault()
|
|
145
|
+
? [
|
|
146
|
+
{
|
|
147
|
+
id: THEME_DEFAULT_ID,
|
|
148
|
+
label: 'Theme default',
|
|
149
|
+
light: themeDefaultColor(),
|
|
150
|
+
dark: themeDefaultColor(),
|
|
151
|
+
},
|
|
152
|
+
...presets,
|
|
153
|
+
]
|
|
154
|
+
: presets
|
|
147
155
|
}
|
|
148
156
|
return (
|
|
149
157
|
<Show
|
|
@@ -209,53 +217,21 @@ export function AccentChoices(props: AppearanceEditorProps) {
|
|
|
209
217
|
</Radio>
|
|
210
218
|
}
|
|
211
219
|
>
|
|
212
|
-
<
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/>
|
|
228
|
-
</Radio>
|
|
229
|
-
<Button
|
|
230
|
-
type="button"
|
|
231
|
-
variant="outline"
|
|
232
|
-
size="sm"
|
|
233
|
-
tabIndex={0}
|
|
234
|
-
disabled={props.saving}
|
|
235
|
-
aria-pressed={isCustomAccent(props)}
|
|
236
|
-
onClick={openCustomColor}
|
|
237
|
-
>
|
|
238
|
-
Custom
|
|
239
|
-
</Button>
|
|
240
|
-
<Input
|
|
241
|
-
ref={(element) => {
|
|
242
|
-
colorPicker = element
|
|
243
|
-
}}
|
|
244
|
-
type="color"
|
|
245
|
-
// `w-px` beats the Input's own `w-full`: an absolutely positioned
|
|
246
|
-
// full-width input sized the sheet's scroll width.
|
|
247
|
-
class="sr-only w-px"
|
|
248
|
-
tabIndex={-1}
|
|
249
|
-
aria-label="Custom accent color"
|
|
250
|
-
value={
|
|
251
|
-
/^#[0-9a-f]{6}$/i.test(props.draft.accent)
|
|
252
|
-
? props.draft.accent
|
|
253
|
-
: (props.customAccentValue ?? '#000000')
|
|
254
|
-
}
|
|
255
|
-
disabled={props.saving}
|
|
256
|
-
onChange={(event) => props.onChange({ accent: event.currentTarget.value })}
|
|
257
|
-
/>
|
|
258
|
-
</div>
|
|
220
|
+
<AccentPicker
|
|
221
|
+
label="Accent"
|
|
222
|
+
inherit={false}
|
|
223
|
+
options={rowOptions()}
|
|
224
|
+
layout="row"
|
|
225
|
+
appearance={resolvedAppearance()}
|
|
226
|
+
value={props.draft.accent}
|
|
227
|
+
customSeed={
|
|
228
|
+
isCustomAccentValue(props.customAccentValue) ? props.customAccentValue : '#000000'
|
|
229
|
+
}
|
|
230
|
+
disabled={props.saving}
|
|
231
|
+
onValueChange={(accent) => {
|
|
232
|
+
if (accent !== null) props.onChange({ accent })
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
259
235
|
</Show>
|
|
260
236
|
)
|
|
261
237
|
}
|
|
@@ -231,7 +231,7 @@ export function IconPickerDropdown(props: IconPickerDropdownProps) {
|
|
|
231
231
|
</span>
|
|
232
232
|
<ChevronDown class="size-4 text-muted-foreground" aria-hidden="true" />
|
|
233
233
|
</PopoverTrigger>
|
|
234
|
-
<PopoverContent class="w-
|
|
234
|
+
<PopoverContent class="w-88 max-w-(--kb-popper-content-available-width)">
|
|
235
235
|
<IconPicker
|
|
236
236
|
{...picker}
|
|
237
237
|
onValueChange={(key) => {
|
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -2248,6 +2248,9 @@
|
|
|
2248
2248
|
"@kobalte/core@^0.13.14"
|
|
2249
2249
|
],
|
|
2250
2250
|
"registryDependencies": [
|
|
2251
|
+
"@adea-ai/ui/button",
|
|
2252
|
+
"@adea-ai/ui/input",
|
|
2253
|
+
"@adea-ai/ui/popover",
|
|
2251
2254
|
"@adea-ai/ui/tooltip",
|
|
2252
2255
|
"lib"
|
|
2253
2256
|
],
|
|
@@ -2257,6 +2260,16 @@
|
|
|
2257
2260
|
"type": "registry:ui",
|
|
2258
2261
|
"target": "components/composites/accent-picker/accent-picker.tsx"
|
|
2259
2262
|
},
|
|
2263
|
+
{
|
|
2264
|
+
"path": "src/components/composites/accent-picker/color-math.ts",
|
|
2265
|
+
"type": "registry:ui",
|
|
2266
|
+
"target": "components/composites/accent-picker/color-math.ts"
|
|
2267
|
+
},
|
|
2268
|
+
{
|
|
2269
|
+
"path": "src/components/composites/accent-picker/custom-color-popover.tsx",
|
|
2270
|
+
"type": "registry:ui",
|
|
2271
|
+
"target": "components/composites/accent-picker/custom-color-popover.tsx"
|
|
2272
|
+
},
|
|
2260
2273
|
{
|
|
2261
2274
|
"path": "src/components/composites/accent-picker/index.ts",
|
|
2262
2275
|
"type": "registry:ui",
|
|
@@ -2328,6 +2341,7 @@
|
|
|
2328
2341
|
"lucide-solid@^1.65.0"
|
|
2329
2342
|
],
|
|
2330
2343
|
"registryDependencies": [
|
|
2344
|
+
"@adea-ai/ui/accent-picker",
|
|
2331
2345
|
"@adea-ai/ui/action-button",
|
|
2332
2346
|
"@adea-ai/ui/button",
|
|
2333
2347
|
"@adea-ai/ui/dropdown-menu",
|
|
@@ -1,66 +1,177 @@
|
|
|
1
1
|
import { RadioGroup as Radio } from '@kobalte/core/radio-group'
|
|
2
2
|
import type { JSX } from 'solid-js'
|
|
3
|
-
import { For } from 'solid-js'
|
|
3
|
+
import { For, Show } from 'solid-js'
|
|
4
4
|
import { accents } from '#lib/accent-presets'
|
|
5
5
|
import { cn } from '#lib/utils'
|
|
6
|
+
import { Input } from '../../ui/input'
|
|
6
7
|
import { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip'
|
|
8
|
+
import { CustomColorPopover } from './custom-color-popover'
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* AccentPicker.
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* workspace's
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* The one accent control every level of the app uses: the app's own appearance,
|
|
14
|
+
* a workspace's accent over the app's, a project's icon colour over its
|
|
15
|
+
* workspace's. It is a row of preset swatches, optionally led by an "inherit"
|
|
16
|
+
* swatch and followed by a Custom button that opens a colour picker anchored
|
|
17
|
+
* under it.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* no
|
|
19
|
+
* - `null` is a real value, not an empty one: it means "do not override", so
|
|
20
|
+
* with `inherit` on the swatch row never has an unchecked state and the
|
|
21
|
+
* control can say what the inherited colour is through `inheritLabel`.
|
|
22
|
+
* - A custom colour is a lowercase `#rrggbb`. While one is set no swatch is
|
|
23
|
+
* checked; the Custom button reads pressed and shows the colour. Opening the
|
|
24
|
+
* picker changes nothing until Apply.
|
|
25
|
+
*
|
|
26
|
+
* Swatches paint each preset's light and dark colour on the `dark` class, so a
|
|
27
|
+
* swatch is the colour the setting produces in whichever appearance is in
|
|
28
|
+
* force and the picker needs no theme provider. A host previewing a different
|
|
29
|
+
* appearance (the appearance editor's draft) pins the side with `appearance`.
|
|
21
30
|
*/
|
|
31
|
+
export type AccentPickerOption = Readonly<{
|
|
32
|
+
id: string
|
|
33
|
+
label: string
|
|
34
|
+
light?: string
|
|
35
|
+
dark?: string
|
|
36
|
+
}>
|
|
37
|
+
|
|
22
38
|
export type AccentPickerProps = {
|
|
23
39
|
/** The group's accessible name, e.g. "Icon colour". */
|
|
24
40
|
label: string
|
|
25
|
-
/**
|
|
41
|
+
/** A preset id, a custom `#rrggbb`, or `null` for no override. */
|
|
26
42
|
value: string | null
|
|
27
43
|
onValueChange(value: string | null): void
|
|
44
|
+
/**
|
|
45
|
+
* Whether the row leads with the "inherit" swatch (`null`). On by default;
|
|
46
|
+
* the app's own appearance, which has nothing above it, turns it off.
|
|
47
|
+
*/
|
|
48
|
+
inherit?: boolean
|
|
28
49
|
/** What `null` means here, e.g. "Inherit workspace accent". Also the first swatch's name and tooltip. */
|
|
29
50
|
inheritLabel?: string
|
|
51
|
+
/** The swatches after the inherit one. Defaults to the six brand presets. */
|
|
52
|
+
options?: readonly AccentPickerOption[]
|
|
53
|
+
/** Whether the Custom button follows the swatches. On by default. */
|
|
54
|
+
custom?: boolean
|
|
55
|
+
/** The colour the Custom picker starts on while no custom colour is set. */
|
|
56
|
+
customSeed?: string
|
|
57
|
+
/** Pins the swatches to one side of each preset pair instead of following the `dark` class. */
|
|
58
|
+
appearance?: 'light' | 'dark'
|
|
59
|
+
/**
|
|
60
|
+
* `wrap` (the default) wraps at the container's edge. `row` keeps every
|
|
61
|
+
* swatch on one line at a smaller size, sharing the width equally, so a
|
|
62
|
+
* narrow panel does not wrap them.
|
|
63
|
+
*/
|
|
64
|
+
layout?: 'wrap' | 'row'
|
|
30
65
|
disabled?: boolean
|
|
31
66
|
class?: string
|
|
32
67
|
}
|
|
33
68
|
|
|
34
69
|
const NONE = '__none__'
|
|
70
|
+
const CUSTOM = '__custom__'
|
|
71
|
+
const HEX = /^#[0-9a-f]{6}$/i
|
|
72
|
+
const DEFAULT_CUSTOM_SEED = '#7c3aed'
|
|
73
|
+
|
|
74
|
+
/** Whether a stored accent is a custom `#rrggbb` colour rather than a preset id or `null`. */
|
|
75
|
+
export function isCustomAccentValue(value: string | null | undefined): value is `#${string}` {
|
|
76
|
+
return typeof value === 'string' && HEX.test(value)
|
|
77
|
+
}
|
|
35
78
|
|
|
36
79
|
export function AccentPicker(props: AccentPickerProps) {
|
|
80
|
+
const customValue = () =>
|
|
81
|
+
isCustomAccentValue(props.value) ? props.value.toLowerCase() : undefined
|
|
82
|
+
const inherit = () => props.inherit ?? true
|
|
83
|
+
const row = () => props.layout === 'row'
|
|
84
|
+
const radioValue = () => (customValue() ? CUSTOM : (props.value ?? NONE))
|
|
85
|
+
|
|
86
|
+
// The native colour field stays in the tree, visually hidden, as the
|
|
87
|
+
// control assistive technology and automation can set directly; people use
|
|
88
|
+
// the anchored picker behind the Custom button.
|
|
89
|
+
const commitCustom = (raw: string) => {
|
|
90
|
+
const value = raw.trim().toLowerCase()
|
|
91
|
+
// Only `#rrggbb` is stored; anything else is ignored rather than saved.
|
|
92
|
+
if (HEX.test(value) && value !== customValue()) props.onValueChange(value)
|
|
93
|
+
}
|
|
94
|
+
|
|
37
95
|
return (
|
|
38
|
-
<
|
|
39
|
-
data-slot="swatch-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
disabled={props.disabled}
|
|
43
|
-
onChange={(id) => props.onValueChange(id === NONE ? null : id)}
|
|
44
|
-
class={cn('flex flex-wrap items-center gap-2', props.class)}
|
|
96
|
+
<div
|
|
97
|
+
data-slot="swatch-row"
|
|
98
|
+
data-accent-choices
|
|
99
|
+
class={cn('flex min-w-0 items-center gap-2', row() ? 'w-full' : 'flex-wrap', props.class)}
|
|
45
100
|
>
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</SwatchItem>
|
|
101
|
+
<Radio
|
|
102
|
+
data-slot="swatch-picker"
|
|
103
|
+
aria-label={props.label}
|
|
104
|
+
orientation="horizontal"
|
|
105
|
+
value={radioValue()}
|
|
106
|
+
disabled={props.disabled}
|
|
107
|
+
onChange={(id) => {
|
|
108
|
+
if (id === CUSTOM) return
|
|
109
|
+
props.onValueChange(id === NONE ? null : id)
|
|
110
|
+
}}
|
|
111
|
+
class={cn(
|
|
112
|
+
row()
|
|
113
|
+
? 'grid min-w-0 flex-1 auto-cols-fr grid-flow-col'
|
|
114
|
+
: 'flex flex-wrap items-center gap-2'
|
|
61
115
|
)}
|
|
62
|
-
|
|
63
|
-
|
|
116
|
+
>
|
|
117
|
+
<Show when={inherit()}>
|
|
118
|
+
<SwatchItem id={NONE} label={props.inheritLabel ?? 'Inherit (default)'} row={row()}>
|
|
119
|
+
<InheritSwatch />
|
|
120
|
+
</SwatchItem>
|
|
121
|
+
</Show>
|
|
122
|
+
<For each={props.options ?? accents}>
|
|
123
|
+
{(option) => {
|
|
124
|
+
const light = () => option.light ?? ''
|
|
125
|
+
const dark = () => option.dark ?? option.light ?? ''
|
|
126
|
+
return (
|
|
127
|
+
<SwatchItem id={option.id} label={option.label} row={row()}>
|
|
128
|
+
<svg class="size-full" viewBox="0 0 16 16" aria-hidden="true">
|
|
129
|
+
<Show
|
|
130
|
+
when={props.appearance}
|
|
131
|
+
fallback={
|
|
132
|
+
<circle
|
|
133
|
+
cx="8"
|
|
134
|
+
cy="8"
|
|
135
|
+
r="8"
|
|
136
|
+
class="fill-(--swatch-light) dark:fill-(--swatch-dark)"
|
|
137
|
+
style={{ '--swatch-light': light(), '--swatch-dark': dark() }}
|
|
138
|
+
/>
|
|
139
|
+
}
|
|
140
|
+
>
|
|
141
|
+
{(appearance) => (
|
|
142
|
+
<circle
|
|
143
|
+
cx="8"
|
|
144
|
+
cy="8"
|
|
145
|
+
r="8"
|
|
146
|
+
fill={appearance() === 'light' ? light() : dark()}
|
|
147
|
+
/>
|
|
148
|
+
)}
|
|
149
|
+
</Show>
|
|
150
|
+
</svg>
|
|
151
|
+
</SwatchItem>
|
|
152
|
+
)
|
|
153
|
+
}}
|
|
154
|
+
</For>
|
|
155
|
+
</Radio>
|
|
156
|
+
<Show when={props.custom ?? true}>
|
|
157
|
+
<CustomColorPopover
|
|
158
|
+
value={customValue()}
|
|
159
|
+
seed={props.customSeed ?? DEFAULT_CUSTOM_SEED}
|
|
160
|
+
disabled={props.disabled}
|
|
161
|
+
onCommit={commitCustom}
|
|
162
|
+
/>
|
|
163
|
+
<Input
|
|
164
|
+
type="color"
|
|
165
|
+
// `w-px` beats the Input's own `w-full` and keeps the hidden field from sizing a narrow panel's scroll width.
|
|
166
|
+
class="sr-only w-px"
|
|
167
|
+
tabIndex={-1}
|
|
168
|
+
aria-label="Custom accent color"
|
|
169
|
+
value={customValue() ?? props.customSeed ?? DEFAULT_CUSTOM_SEED}
|
|
170
|
+
disabled={props.disabled}
|
|
171
|
+
onChange={(event) => commitCustom(event.currentTarget.value)}
|
|
172
|
+
/>
|
|
173
|
+
</Show>
|
|
174
|
+
</div>
|
|
64
175
|
)
|
|
65
176
|
}
|
|
66
177
|
|
|
@@ -82,15 +193,20 @@ function InheritSwatch() {
|
|
|
82
193
|
)
|
|
83
194
|
}
|
|
84
195
|
|
|
85
|
-
function SwatchItem(props: { id: string; label: string; children: JSX.Element }) {
|
|
196
|
+
function SwatchItem(props: { id: string; label: string; row: boolean; children: JSX.Element }) {
|
|
86
197
|
return (
|
|
87
|
-
<Radio.Item
|
|
198
|
+
<Radio.Item
|
|
199
|
+
value={props.id}
|
|
200
|
+
data-accent-option={props.id}
|
|
201
|
+
class={props.row ? 'flex justify-center' : 'contents'}
|
|
202
|
+
>
|
|
88
203
|
<Radio.ItemInput class="peer" />
|
|
89
204
|
<Tooltip>
|
|
90
205
|
<TooltipTrigger
|
|
91
206
|
as={Radio.ItemLabel}
|
|
92
207
|
class={cn(
|
|
93
|
-
'flex
|
|
208
|
+
'flex cursor-pointer items-center justify-center rounded-full border border-border p-0.5',
|
|
209
|
+
props.row ? 'size-6' : 'size-7',
|
|
94
210
|
'peer-focus-visible:border-ring peer-focus-visible:ring-3 peer-focus-visible:ring-primary-subtle',
|
|
95
211
|
'data-[checked]:border-primary data-[checked]:ring-1 data-[checked]:ring-primary',
|
|
96
212
|
'data-[disabled]:pointer-events-none data-[disabled]:opacity-50'
|