@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
|
@@ -2,27 +2,61 @@ import type { JSX } from 'solid-js';
|
|
|
2
2
|
/**
|
|
3
3
|
* AccentPicker.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* workspace's
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* The one accent control every level of the app uses: the app's own appearance,
|
|
6
|
+
* a workspace's accent over the app's, a project's icon colour over its
|
|
7
|
+
* workspace's. It is a row of preset swatches, optionally led by an "inherit"
|
|
8
|
+
* swatch and followed by a Custom button that opens a colour picker anchored
|
|
9
|
+
* under it.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* no
|
|
11
|
+
* - `null` is a real value, not an empty one: it means "do not override", so
|
|
12
|
+
* with `inherit` on the swatch row never has an unchecked state and the
|
|
13
|
+
* control can say what the inherited colour is through `inheritLabel`.
|
|
14
|
+
* - A custom colour is a lowercase `#rrggbb`. While one is set no swatch is
|
|
15
|
+
* checked; the Custom button reads pressed and shows the colour. Opening the
|
|
16
|
+
* picker changes nothing until Apply.
|
|
17
|
+
*
|
|
18
|
+
* Swatches paint each preset's light and dark colour on the `dark` class, so a
|
|
19
|
+
* swatch is the colour the setting produces in whichever appearance is in
|
|
20
|
+
* force and the picker needs no theme provider. A host previewing a different
|
|
21
|
+
* appearance (the appearance editor's draft) pins the side with `appearance`.
|
|
15
22
|
*/
|
|
23
|
+
export type AccentPickerOption = Readonly<{
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
light?: string;
|
|
27
|
+
dark?: string;
|
|
28
|
+
}>;
|
|
16
29
|
export type AccentPickerProps = {
|
|
17
30
|
/** The group's accessible name, e.g. "Icon colour". */
|
|
18
31
|
label: string;
|
|
19
|
-
/**
|
|
32
|
+
/** A preset id, a custom `#rrggbb`, or `null` for no override. */
|
|
20
33
|
value: string | null;
|
|
21
34
|
onValueChange(value: string | null): void;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the row leads with the "inherit" swatch (`null`). On by default;
|
|
37
|
+
* the app's own appearance, which has nothing above it, turns it off.
|
|
38
|
+
*/
|
|
39
|
+
inherit?: boolean;
|
|
22
40
|
/** What `null` means here, e.g. "Inherit workspace accent". Also the first swatch's name and tooltip. */
|
|
23
41
|
inheritLabel?: string;
|
|
42
|
+
/** The swatches after the inherit one. Defaults to the six brand presets. */
|
|
43
|
+
options?: readonly AccentPickerOption[];
|
|
44
|
+
/** Whether the Custom button follows the swatches. On by default. */
|
|
45
|
+
custom?: boolean;
|
|
46
|
+
/** The colour the Custom picker starts on while no custom colour is set. */
|
|
47
|
+
customSeed?: string;
|
|
48
|
+
/** Pins the swatches to one side of each preset pair instead of following the `dark` class. */
|
|
49
|
+
appearance?: 'light' | 'dark';
|
|
50
|
+
/**
|
|
51
|
+
* `wrap` (the default) wraps at the container's edge. `row` keeps every
|
|
52
|
+
* swatch on one line at a smaller size, sharing the width equally, so a
|
|
53
|
+
* narrow panel does not wrap them.
|
|
54
|
+
*/
|
|
55
|
+
layout?: 'wrap' | 'row';
|
|
24
56
|
disabled?: boolean;
|
|
25
57
|
class?: string;
|
|
26
58
|
};
|
|
59
|
+
/** Whether a stored accent is a custom `#rrggbb` colour rather than a preset id or `null`. */
|
|
60
|
+
export declare function isCustomAccentValue(value: string | null | undefined): value is `#${string}`;
|
|
27
61
|
export declare function AccentPicker(props: AccentPickerProps): JSX.Element;
|
|
28
62
|
//# sourceMappingURL=accent-picker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accent-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/accent-picker/accent-picker.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"accent-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/accent-picker/accent-picker.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAQnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAC,CAAA;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAA;IACb,kEAAkE;IAClE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IACzC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,yGAAyG;IACzG,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAA;IACvC,qEAAqE;IACrE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,+FAA+F;IAC/F,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAOD,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,IAAI,IAAI,MAAM,EAAE,CAE3F;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAiGpD"}
|
|
@@ -1,65 +1,160 @@
|
|
|
1
1
|
import { accents } from "../../../lib/accent-presets.js";
|
|
2
2
|
import { cn } from "../../../lib/utils.js";
|
|
3
|
+
import { Input } from "../../ui/input/input.js";
|
|
3
4
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../../ui/tooltip/tooltip.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { CustomColorPopover } from "./custom-color-popover.js";
|
|
6
|
+
import { className, createComponent, effect, insert, memo, setAttribute, setStyleProperty, template } from "solid-js/web";
|
|
7
|
+
import { For, Show } from "solid-js";
|
|
6
8
|
import { RadioGroup } from "@kobalte/core/radio-group";
|
|
7
9
|
// src/components/composites/accent-picker/accent-picker.tsx
|
|
8
|
-
var _tmpl$ = /*#__PURE__*/ template(`<
|
|
9
|
-
var _tmpl$2 = /*#__PURE__*/ template(`<
|
|
10
|
-
var _tmpl$3 = /*#__PURE__*/ template(`<
|
|
10
|
+
var _tmpl$ = /*#__PURE__*/ template(`<div data-slot=swatch-row data-accent-choices>`);
|
|
11
|
+
var _tmpl$2 = /*#__PURE__*/ template(`<svg class=size-full viewBox="0 0 16 16"aria-hidden=true>`);
|
|
12
|
+
var _tmpl$3 = /*#__PURE__*/ template(`<svg><circle cx=8 cy=8 r=8 class="fill-(--swatch-light) dark:fill-(--swatch-dark)"></svg>`, false, true, false);
|
|
13
|
+
var _tmpl$4 = /*#__PURE__*/ template(`<svg><circle cx=8 cy=8 r=8></svg>`, false, true, false);
|
|
14
|
+
var _tmpl$5 = /*#__PURE__*/ template(`<span aria-hidden=true data-slot=swatch-inherit class="relative block size-full overflow-hidden rounded-full bg-(--swatch-inherit)"style=--swatch-inherit:#000><span class="absolute inset-x-0 top-1/2 h-0.5 -translate-y-1/2 -rotate-45 bg-destructive">`);
|
|
15
|
+
var _tmpl$6 = /*#__PURE__*/ template(`<span class=sr-only>`);
|
|
11
16
|
var NONE = "__none__";
|
|
17
|
+
var CUSTOM = "__custom__";
|
|
18
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
19
|
+
var DEFAULT_CUSTOM_SEED = "#7c3aed";
|
|
20
|
+
/** Whether a stored accent is a custom `#rrggbb` colour rather than a preset id or `null`. */
|
|
21
|
+
function isCustomAccentValue(value) {
|
|
22
|
+
return typeof value === "string" && HEX.test(value);
|
|
23
|
+
}
|
|
12
24
|
function AccentPicker(props) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
const customValue = () => isCustomAccentValue(props.value) ? props.value.toLowerCase() : void 0;
|
|
26
|
+
const inherit = () => props.inherit ?? true;
|
|
27
|
+
const row = () => props.layout === "row";
|
|
28
|
+
const radioValue = () => customValue() ? CUSTOM : props.value ?? NONE;
|
|
29
|
+
const commitCustom = (raw) => {
|
|
30
|
+
const value = raw.trim().toLowerCase();
|
|
31
|
+
if (HEX.test(value) && value !== customValue()) props.onValueChange(value);
|
|
32
|
+
};
|
|
33
|
+
return (() => {
|
|
34
|
+
var _el$ = _tmpl$();
|
|
35
|
+
insert(_el$, createComponent(RadioGroup, {
|
|
36
|
+
"data-slot": "swatch-picker",
|
|
37
|
+
get ["aria-label"]() {
|
|
38
|
+
return props.label;
|
|
39
|
+
},
|
|
40
|
+
orientation: "horizontal",
|
|
41
|
+
get value() {
|
|
42
|
+
return radioValue();
|
|
43
|
+
},
|
|
44
|
+
get disabled() {
|
|
45
|
+
return props.disabled;
|
|
46
|
+
},
|
|
47
|
+
onChange: (id) => {
|
|
48
|
+
if (id === CUSTOM) return;
|
|
49
|
+
props.onValueChange(id === NONE ? null : id);
|
|
50
|
+
},
|
|
51
|
+
get ["class"]() {
|
|
52
|
+
return cn(row() ? "grid min-w-0 flex-1 auto-cols-fr grid-flow-col" : "flex flex-wrap items-center gap-2");
|
|
53
|
+
},
|
|
54
|
+
get children() {
|
|
55
|
+
return [createComponent(Show, {
|
|
56
|
+
get when() {
|
|
57
|
+
return inherit();
|
|
45
58
|
},
|
|
46
59
|
get children() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
return createComponent(SwatchItem, {
|
|
61
|
+
id: NONE,
|
|
62
|
+
get label() {
|
|
63
|
+
return props.inheritLabel ?? "Inherit (default)";
|
|
64
|
+
},
|
|
65
|
+
get row() {
|
|
66
|
+
return row();
|
|
67
|
+
},
|
|
68
|
+
get children() {
|
|
69
|
+
return createComponent(InheritSwatch, {});
|
|
70
|
+
}
|
|
56
71
|
});
|
|
57
|
-
return _el$;
|
|
58
72
|
}
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
}), createComponent(For, {
|
|
74
|
+
get each() {
|
|
75
|
+
return props.options ?? accents;
|
|
76
|
+
},
|
|
77
|
+
children: (option) => {
|
|
78
|
+
const light = () => option.light ?? "";
|
|
79
|
+
const dark = () => option.dark ?? option.light ?? "";
|
|
80
|
+
return createComponent(SwatchItem, {
|
|
81
|
+
get id() {
|
|
82
|
+
return option.id;
|
|
83
|
+
},
|
|
84
|
+
get label() {
|
|
85
|
+
return option.label;
|
|
86
|
+
},
|
|
87
|
+
get row() {
|
|
88
|
+
return row();
|
|
89
|
+
},
|
|
90
|
+
get children() {
|
|
91
|
+
var _el$2 = _tmpl$2();
|
|
92
|
+
insert(_el$2, createComponent(Show, {
|
|
93
|
+
get when() {
|
|
94
|
+
return props.appearance;
|
|
95
|
+
},
|
|
96
|
+
get fallback() {
|
|
97
|
+
return (() => {
|
|
98
|
+
var _el$3 = _tmpl$3();
|
|
99
|
+
effect((_p$) => {
|
|
100
|
+
var _v$ = light(), _v$2 = dark();
|
|
101
|
+
_v$ !== _p$.e && setStyleProperty(_el$3, "--swatch-light", _p$.e = _v$);
|
|
102
|
+
_v$2 !== _p$.t && setStyleProperty(_el$3, "--swatch-dark", _p$.t = _v$2);
|
|
103
|
+
return _p$;
|
|
104
|
+
}, {
|
|
105
|
+
e: void 0,
|
|
106
|
+
t: void 0
|
|
107
|
+
});
|
|
108
|
+
return _el$3;
|
|
109
|
+
})();
|
|
110
|
+
},
|
|
111
|
+
children: (appearance) => (() => {
|
|
112
|
+
var _el$4 = _tmpl$4();
|
|
113
|
+
effect(() => setAttribute(_el$4, "fill", appearance() === "light" ? light() : dark()));
|
|
114
|
+
return _el$4;
|
|
115
|
+
})()
|
|
116
|
+
}));
|
|
117
|
+
return _el$2;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
})];
|
|
122
|
+
}
|
|
123
|
+
}), null);
|
|
124
|
+
insert(_el$, createComponent(Show, {
|
|
125
|
+
get when() {
|
|
126
|
+
return props.custom ?? true;
|
|
127
|
+
},
|
|
128
|
+
get children() {
|
|
129
|
+
return [createComponent(CustomColorPopover, {
|
|
130
|
+
get value() {
|
|
131
|
+
return customValue();
|
|
132
|
+
},
|
|
133
|
+
get seed() {
|
|
134
|
+
return props.customSeed ?? DEFAULT_CUSTOM_SEED;
|
|
135
|
+
},
|
|
136
|
+
get disabled() {
|
|
137
|
+
return props.disabled;
|
|
138
|
+
},
|
|
139
|
+
onCommit: commitCustom
|
|
140
|
+
}), createComponent(Input, {
|
|
141
|
+
type: "color",
|
|
142
|
+
"class": "sr-only w-px",
|
|
143
|
+
tabIndex: -1,
|
|
144
|
+
"aria-label": "Custom accent color",
|
|
145
|
+
get value() {
|
|
146
|
+
return customValue() ?? props.customSeed ?? DEFAULT_CUSTOM_SEED;
|
|
147
|
+
},
|
|
148
|
+
get disabled() {
|
|
149
|
+
return props.disabled;
|
|
150
|
+
},
|
|
151
|
+
onChange: (event) => commitCustom(event.currentTarget.value)
|
|
152
|
+
})];
|
|
153
|
+
}
|
|
154
|
+
}), null);
|
|
155
|
+
effect(() => className(_el$, cn("flex min-w-0 items-center gap-2", row() ? "w-full" : "flex-wrap", props.class)));
|
|
156
|
+
return _el$;
|
|
157
|
+
})();
|
|
63
158
|
}
|
|
64
159
|
/**
|
|
65
160
|
* The "inherit" swatch: a black disc with a red slash, the universal "no
|
|
@@ -67,7 +162,7 @@ function AccentPicker(props) {
|
|
|
67
162
|
* same in every theme and appearance.
|
|
68
163
|
*/
|
|
69
164
|
function InheritSwatch() {
|
|
70
|
-
return _tmpl$
|
|
165
|
+
return _tmpl$5();
|
|
71
166
|
}
|
|
72
167
|
function SwatchItem(props) {
|
|
73
168
|
return createComponent(RadioGroup.Item, {
|
|
@@ -77,7 +172,9 @@ function SwatchItem(props) {
|
|
|
77
172
|
get ["data-accent-option"]() {
|
|
78
173
|
return props.id;
|
|
79
174
|
},
|
|
80
|
-
"class"
|
|
175
|
+
get ["class"]() {
|
|
176
|
+
return props.row ? "flex justify-center" : "contents";
|
|
177
|
+
},
|
|
81
178
|
get children() {
|
|
82
179
|
return [createComponent(RadioGroup.ItemInput, { "class": "peer" }), createComponent(Tooltip, { get children() {
|
|
83
180
|
return [createComponent(TooltipTrigger, {
|
|
@@ -85,13 +182,13 @@ function SwatchItem(props) {
|
|
|
85
182
|
return RadioGroup.ItemLabel;
|
|
86
183
|
},
|
|
87
184
|
get ["class"]() {
|
|
88
|
-
return cn("flex
|
|
185
|
+
return cn("flex cursor-pointer items-center justify-center rounded-full border border-border p-0.5", props.row ? "size-6" : "size-7", "peer-focus-visible:border-ring peer-focus-visible:ring-3 peer-focus-visible:ring-primary-subtle", "data-[checked]:border-primary data-[checked]:ring-1 data-[checked]:ring-primary", "data-[disabled]:pointer-events-none data-[disabled]:opacity-50");
|
|
89
186
|
},
|
|
90
187
|
get children() {
|
|
91
188
|
return [memo(() => props.children), (() => {
|
|
92
|
-
var _el$
|
|
93
|
-
insert(_el$
|
|
94
|
-
return _el$
|
|
189
|
+
var _el$6 = _tmpl$6();
|
|
190
|
+
insert(_el$6, () => props.label);
|
|
191
|
+
return _el$6;
|
|
95
192
|
})()];
|
|
96
193
|
}
|
|
97
194
|
}), createComponent(TooltipContent, { get children() {
|
|
@@ -101,6 +198,6 @@ function SwatchItem(props) {
|
|
|
101
198
|
}
|
|
102
199
|
});
|
|
103
200
|
}
|
|
104
|
-
export { AccentPicker };
|
|
201
|
+
export { AccentPicker, isCustomAccentValue };
|
|
105
202
|
|
|
106
203
|
//# sourceMappingURL=accent-picker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accent-picker.js","names":["RadioGroup","Radio","JSX","For","accents","cn","Tooltip","TooltipContent","TooltipTrigger","AccentPickerProps","label","value","onValueChange","inheritLabel","disabled","class","NONE","AccentPicker","props","_$createComponent","aria-label","onChange","id","children","SwatchItem","InheritSwatch","each","accent","_el$","_tmpl$","_$effect","_p$","_v$","light","_v$2","dark","e","_$setStyleProperty","t","undefined","_tmpl$2","Element","Item","data-accent-option","ItemInput","as","ItemLabel","_$memo","_el$3","_tmpl$3","_$insert","_$createComponent","Radio","_$setStyleProperty","_$memo"],"sources":["../../../../src/components/composites/accent-picker/accent-picker.tsx"],"sourcesContent":["import { RadioGroup as Radio } from '@kobalte/core/radio-group'\nimport type { JSX } from 'solid-js'\nimport { For } from 'solid-js'\nimport { accents } from '#lib/accent-presets'\nimport { cn } from '#lib/utils'\nimport { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip'\n\n/**\n * AccentPicker.\n *\n * A row of accent swatches with a leading \"none\" choice, for a setting that\n * overrides the accent it would otherwise inherit: a project's icon colour, a\n * workspace's colour over the app's. `null` is a real value, not an empty one:\n * it means \"do not override\", so the swatch row never has an unchecked state and\n * the control can say what the inherited colour is through `inheritLabel`.\n *\n * The swatches are the theme's own accent presets, each carrying its light and\n * dark colour and switching on the `dark` class, so a swatch is the colour the\n * setting will produce in whichever appearance is in force and the picker needs\n * no theme provider.\n */\nexport type AccentPickerProps = {\n /** The group's accessible name, e.g. \"Icon colour\". */\n label: string\n /** An accent preset id, or `null` for no override. */\n value: string | null\n onValueChange(value: string | null): void\n /** What `null` means here, e.g. \"Inherit workspace accent\". Also the first swatch's name and tooltip. */\n inheritLabel?: string\n disabled?: boolean\n class?: string\n}\n\nconst NONE = '__none__'\n\nexport function AccentPicker(props: AccentPickerProps) {\n return (\n <Radio\n data-slot=\"swatch-picker\"\n aria-label={props.label}\n value={props.value ?? NONE}\n disabled={props.disabled}\n onChange={(id) => props.onValueChange(id === NONE ? null : id)}\n class={cn('flex flex-wrap items-center gap-2', props.class)}\n >\n <SwatchItem id={NONE} label={props.inheritLabel ?? 'Inherit (default)'}>\n <InheritSwatch />\n </SwatchItem>\n <For each={accents}>\n {(accent) => (\n <SwatchItem id={accent.id} label={accent.label}>\n <span\n aria-hidden=\"true\"\n class=\"block size-full rounded-full bg-(--swatch-light) dark:bg-(--swatch-dark)\"\n style={{\n '--swatch-light': accent.light ?? 'currentColor',\n '--swatch-dark': accent.dark ?? accent.light ?? 'currentColor',\n }}\n />\n </SwatchItem>\n )}\n </For>\n </Radio>\n )\n}\n\n/**\n * The \"inherit\" swatch: a black disc with a red slash, the universal \"no\n * override\" mark. It is drawn rather than painted from a token so it reads the\n * same in every theme and appearance.\n */\nfunction InheritSwatch() {\n return (\n <span\n aria-hidden=\"true\"\n data-slot=\"swatch-inherit\"\n class=\"relative block size-full overflow-hidden rounded-full bg-(--swatch-inherit)\"\n style={{ '--swatch-inherit': '#000' }}\n >\n <span class=\"absolute inset-x-0 top-1/2 h-0.5 -translate-y-1/2 -rotate-45 bg-destructive\" />\n </span>\n )\n}\n\nfunction SwatchItem(props: { id: string; label: string; children: JSX.Element }) {\n return (\n <Radio.Item value={props.id} data-accent-option={props.id} class=\"contents\">\n <Radio.ItemInput class=\"peer\" />\n <Tooltip>\n <TooltipTrigger\n as={Radio.ItemLabel}\n class={cn(\n 'flex size-7 cursor-pointer items-center justify-center rounded-full border border-border p-0.5',\n 'peer-focus-visible:border-ring peer-focus-visible:ring-3 peer-focus-visible:ring-primary-subtle',\n 'data-[checked]:border-primary data-[checked]:ring-1 data-[checked]:ring-primary',\n 'data-[disabled]:pointer-events-none data-[disabled]:opacity-50'\n )}\n >\n {props.children}\n <span class=\"sr-only\">{props.label}</span>\n </TooltipTrigger>\n <TooltipContent>{props.label}</TooltipContent>\n </Tooltip>\n </Radio.Item>\n )\n}\n"],"mappings":";;;;;;;;;;AAiCA,IAAMgB,OAAO;AAEb,SAAgBC,aAAaC,OAA0B;CACrD,OAAAC,gBACGlB,YAAK;EAAA,aAAA;EAAA,KAAA,gBAAA;GAAA,OAEQiB,MAAMR;EAAK;EAAA,IACvBC,QAAK;GAAA,OAAEO,MAAMP,SAASK;EAAI;EAAA,IAC1BF,WAAQ;GAAA,OAAEI,MAAMJ;EAAQ;EACxBO,WAAWC,OAAOJ,MAAMN,cAAcU,OAAON,OAAO,OAAOM,EAAE;EAAC,KAAA,WAAA;GAAA,OACvDjB,GAAG,qCAAqCa,MAAMH,KAAK;EAAC;EAAA,IAAAQ,WAAA;GAAA,OAAA,CAAAJ,gBAE1DK,YAAU;IAACF,IAAIN;IAAI,IAAEN,QAAK;KAAA,OAAEQ,MAAML,gBAAgB;IAAmB;IAAA,IAAAU,WAAA;KAAA,OAAAJ,gBACnEM,eAAa,CAAA,CAAA;IAAA;GAAA,CAAA,GAAAN,gBAEfhB,KAAG;IAACuB,MAAMtB;IAAOmB,WACdI,WAAMR,gB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A;IAAA,CAAA,GAAA7B,gBAEnCZ,gBAAc,EAAA,IAAAgB,WAAA;KAAA,OAAEL,MAAMR;IAAK,EAAA,CAAA,CAAA;GAAA,EAAA,CAAA,CAAA;EAAA;CAAA,CAAA;AAIpC"}
|
|
1
|
+
{"version":3,"file":"accent-picker.js","names":["RadioGroup","Radio","JSX","For","Show","accents","cn","Input","Tooltip","TooltipContent","TooltipTrigger","CustomColorPopover","AccentPickerOption","Readonly","id","label","light","dark","AccentPickerProps","value","onValueChange","inherit","inheritLabel","options","custom","customSeed","appearance","layout","disabled","class","NONE","CUSTOM","HEX","DEFAULT_CUSTOM_SEED","isCustomAccentValue","test","AccentPicker","props","customValue","toLowerCase","undefined","row","radioValue","commitCustom","raw","trim","_el$","_tmpl$","_$insert","_$createComponent","aria-label","orientation","onChange","children","when","SwatchItem","InheritSwatch","each","option","_el$2","_tmpl$2","fallback","_el$3","_tmpl$3","_$effect","_p$","_v$","_v$2","e","_$setStyleProperty","t","_el$4","_tmpl$4","_$setAttribute","seed","onCommit","type","tabIndex","event","currentTarget","_$className","_tmpl$5","Element","Item","data-accent-option","ItemInput","as","ItemLabel","_$memo","_el$6","_tmpl$6","_$createComponent","Radio","_$setStyleProperty","_$setAttribute","_$className","_$memo"],"sources":["../../../../src/components/composites/accent-picker/accent-picker.tsx"],"sourcesContent":["import { RadioGroup as Radio } from '@kobalte/core/radio-group'\nimport type { JSX } from 'solid-js'\nimport { For, Show } from 'solid-js'\nimport { accents } from '#lib/accent-presets'\nimport { cn } from '#lib/utils'\nimport { Input } from '../../ui/input'\nimport { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip'\nimport { CustomColorPopover } from './custom-color-popover'\n\n/**\n * AccentPicker.\n *\n * The one accent control every level of the app uses: the app's own appearance,\n * a workspace's accent over the app's, a project's icon colour over its\n * workspace's. It is a row of preset swatches, optionally led by an \"inherit\"\n * swatch and followed by a Custom button that opens a colour picker anchored\n * under it.\n *\n * - `null` is a real value, not an empty one: it means \"do not override\", so\n * with `inherit` on the swatch row never has an unchecked state and the\n * control can say what the inherited colour is through `inheritLabel`.\n * - A custom colour is a lowercase `#rrggbb`. While one is set no swatch is\n * checked; the Custom button reads pressed and shows the colour. Opening the\n * picker changes nothing until Apply.\n *\n * Swatches paint each preset's light and dark colour on the `dark` class, so a\n * swatch is the colour the setting produces in whichever appearance is in\n * force and the picker needs no theme provider. A host previewing a different\n * appearance (the appearance editor's draft) pins the side with `appearance`.\n */\nexport type AccentPickerOption = Readonly<{\n id: string\n label: string\n light?: string\n dark?: string\n}>\n\nexport type AccentPickerProps = {\n /** The group's accessible name, e.g. \"Icon colour\". */\n label: string\n /** A preset id, a custom `#rrggbb`, or `null` for no override. */\n value: string | null\n onValueChange(value: string | null): void\n /**\n * Whether the row leads with the \"inherit\" swatch (`null`). On by default;\n * the app's own appearance, which has nothing above it, turns it off.\n */\n inherit?: boolean\n /** What `null` means here, e.g. \"Inherit workspace accent\". Also the first swatch's name and tooltip. */\n inheritLabel?: string\n /** The swatches after the inherit one. Defaults to the six brand presets. */\n options?: readonly AccentPickerOption[]\n /** Whether the Custom button follows the swatches. On by default. */\n custom?: boolean\n /** The colour the Custom picker starts on while no custom colour is set. */\n customSeed?: string\n /** Pins the swatches to one side of each preset pair instead of following the `dark` class. */\n appearance?: 'light' | 'dark'\n /**\n * `wrap` (the default) wraps at the container's edge. `row` keeps every\n * swatch on one line at a smaller size, sharing the width equally, so a\n * narrow panel does not wrap them.\n */\n layout?: 'wrap' | 'row'\n disabled?: boolean\n class?: string\n}\n\nconst NONE = '__none__'\nconst CUSTOM = '__custom__'\nconst HEX = /^#[0-9a-f]{6}$/i\nconst DEFAULT_CUSTOM_SEED = '#7c3aed'\n\n/** Whether a stored accent is a custom `#rrggbb` colour rather than a preset id or `null`. */\nexport function isCustomAccentValue(value: string | null | undefined): value is `#${string}` {\n return typeof value === 'string' && HEX.test(value)\n}\n\nexport function AccentPicker(props: AccentPickerProps) {\n const customValue = () =>\n isCustomAccentValue(props.value) ? props.value.toLowerCase() : undefined\n const inherit = () => props.inherit ?? true\n const row = () => props.layout === 'row'\n const radioValue = () => (customValue() ? CUSTOM : (props.value ?? NONE))\n\n // The native colour field stays in the tree, visually hidden, as the\n // control assistive technology and automation can set directly; people use\n // the anchored picker behind the Custom button.\n const commitCustom = (raw: string) => {\n const value = raw.trim().toLowerCase()\n // Only `#rrggbb` is stored; anything else is ignored rather than saved.\n if (HEX.test(value) && value !== customValue()) props.onValueChange(value)\n }\n\n return (\n <div\n data-slot=\"swatch-row\"\n data-accent-choices\n class={cn('flex min-w-0 items-center gap-2', row() ? 'w-full' : 'flex-wrap', props.class)}\n >\n <Radio\n data-slot=\"swatch-picker\"\n aria-label={props.label}\n orientation=\"horizontal\"\n value={radioValue()}\n disabled={props.disabled}\n onChange={(id) => {\n if (id === CUSTOM) return\n props.onValueChange(id === NONE ? null : id)\n }}\n class={cn(\n row()\n ? 'grid min-w-0 flex-1 auto-cols-fr grid-flow-col'\n : 'flex flex-wrap items-center gap-2'\n )}\n >\n <Show when={inherit()}>\n <SwatchItem id={NONE} label={props.inheritLabel ?? 'Inherit (default)'} row={row()}>\n <InheritSwatch />\n </SwatchItem>\n </Show>\n <For each={props.options ?? accents}>\n {(option) => {\n const light = () => option.light ?? ''\n const dark = () => option.dark ?? option.light ?? ''\n return (\n <SwatchItem id={option.id} label={option.label} row={row()}>\n <svg class=\"size-full\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n <Show\n when={props.appearance}\n fallback={\n <circle\n cx=\"8\"\n cy=\"8\"\n r=\"8\"\n class=\"fill-(--swatch-light) dark:fill-(--swatch-dark)\"\n style={{ '--swatch-light': light(), '--swatch-dark': dark() }}\n />\n }\n >\n {(appearance) => (\n <circle\n cx=\"8\"\n cy=\"8\"\n r=\"8\"\n fill={appearance() === 'light' ? light() : dark()}\n />\n )}\n </Show>\n </svg>\n </SwatchItem>\n )\n }}\n </For>\n </Radio>\n <Show when={props.custom ?? true}>\n <CustomColorPopover\n value={customValue()}\n seed={props.customSeed ?? DEFAULT_CUSTOM_SEED}\n disabled={props.disabled}\n onCommit={commitCustom}\n />\n <Input\n type=\"color\"\n // `w-px` beats the Input's own `w-full` and keeps the hidden field from sizing a narrow panel's scroll width.\n class=\"sr-only w-px\"\n tabIndex={-1}\n aria-label=\"Custom accent color\"\n value={customValue() ?? props.customSeed ?? DEFAULT_CUSTOM_SEED}\n disabled={props.disabled}\n onChange={(event) => commitCustom(event.currentTarget.value)}\n />\n </Show>\n </div>\n )\n}\n\n/**\n * The \"inherit\" swatch: a black disc with a red slash, the universal \"no\n * override\" mark. It is drawn rather than painted from a token so it reads the\n * same in every theme and appearance.\n */\nfunction InheritSwatch() {\n return (\n <span\n aria-hidden=\"true\"\n data-slot=\"swatch-inherit\"\n class=\"relative block size-full overflow-hidden rounded-full bg-(--swatch-inherit)\"\n style={{ '--swatch-inherit': '#000' }}\n >\n <span class=\"absolute inset-x-0 top-1/2 h-0.5 -translate-y-1/2 -rotate-45 bg-destructive\" />\n </span>\n )\n}\n\nfunction SwatchItem(props: { id: string; label: string; row: boolean; children: JSX.Element }) {\n return (\n <Radio.Item\n value={props.id}\n data-accent-option={props.id}\n class={props.row ? 'flex justify-center' : 'contents'}\n >\n <Radio.ItemInput class=\"peer\" />\n <Tooltip>\n <TooltipTrigger\n as={Radio.ItemLabel}\n class={cn(\n 'flex cursor-pointer items-center justify-center rounded-full border border-border p-0.5',\n props.row ? 'size-6' : 'size-7',\n 'peer-focus-visible:border-ring peer-focus-visible:ring-3 peer-focus-visible:ring-primary-subtle',\n 'data-[checked]:border-primary data-[checked]:ring-1 data-[checked]:ring-primary',\n 'data-[disabled]:pointer-events-none data-[disabled]:opacity-50'\n )}\n >\n {props.children}\n <span class=\"sr-only\">{props.label}</span>\n </TooltipTrigger>\n <TooltipContent>{props.label}</TooltipContent>\n </Tooltip>\n </Radio.Item>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoEA,IAAM8B,OAAO;AACb,IAAM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AAA,IAAA6C,WAAA;IAAA,OAAA,CAAAJ,gBACLvC,gBAAc;KAAA,IACb4E,KAAE;MAAA,OAAErF,WAAMsF;KAAS;KAAA,KAAA,WAAA;MAAA,OACZjF,GACL,2FACA+B,MAAMI,MAAM,WAAW,UACvB,mGACA,mFACA,gEACF;KAAC;KAAA,IAAAY,WAAA;MAAA,OAAA,CAAAmC,WAEAnD,MAAMgB,QAAQ,UAAA;OAAA,IAAAoC,QAAAC,QAAA;OAAA1C,OAAAyC,aACQpD,MAAMtB,KAAK;OAAA,OAAA0E;MAAA,EAAA,CAAA,CAAA;KAAA;IAAA,CAAA,GAAAxC,gBAEnCxC,gBAAc,EAAA,IAAA4C,WAAA;KAAA,OAAEhB,MAAMtB;IAAK,EAAA,CAAA,CAAA;GAAA,EAAA,CAAA,CAAA;EAAA;CAAA,CAAA;AAIpC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** HSV with hue in degrees [0, 360) and saturation/value in [0, 1]. */
|
|
2
|
+
export type Hsv = Readonly<{
|
|
3
|
+
h: number;
|
|
4
|
+
s: number;
|
|
5
|
+
v: number;
|
|
6
|
+
}>;
|
|
7
|
+
declare const clamp: (value: number, min?: number, max?: number) => number;
|
|
8
|
+
/** `#rrggbb` (any case) to HSV; anything else is `undefined`. */
|
|
9
|
+
export declare function hexToHsv(hex: string): Hsv | undefined;
|
|
10
|
+
/** HSV to lowercase `#rrggbb`. */
|
|
11
|
+
export declare function hsvToHex(hsv: Hsv): `#${string}`;
|
|
12
|
+
export { clamp };
|
|
13
|
+
//# sourceMappingURL=color-math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-math.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/accent-picker/color-math.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,MAAM,GAAG,GAAG,QAAQ,CAAC;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAE/D,QAAA,MAAM,KAAK,UAAW,MAAM,uCAA0D,CAAA;AAEtF,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAkBrD;AAED,kCAAkC;AAClC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,MAAM,EAAE,CAwB/C;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/components/composites/accent-picker/color-math.ts
|
|
2
|
+
var clamp = (value, min = 0, max = 1) => Math.min(max, Math.max(min, value));
|
|
3
|
+
/** `#rrggbb` (any case) to HSV; anything else is `undefined`. */
|
|
4
|
+
function hexToHsv(hex) {
|
|
5
|
+
const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex.trim());
|
|
6
|
+
if (!match) return void 0;
|
|
7
|
+
const [r, g, b] = match.slice(1).map((part) => Number.parseInt(part, 16) / 255);
|
|
8
|
+
const max = Math.max(r, g, b);
|
|
9
|
+
const delta = max - Math.min(r, g, b);
|
|
10
|
+
let h = 0;
|
|
11
|
+
if (delta !== 0) {
|
|
12
|
+
if (max === r) h = (g - b) / delta % 6;
|
|
13
|
+
else if (max === g) h = (b - r) / delta + 2;
|
|
14
|
+
else h = (r - g) / delta + 4;
|
|
15
|
+
}
|
|
16
|
+
h = (h * 60 + 360) % 360;
|
|
17
|
+
return {
|
|
18
|
+
h,
|
|
19
|
+
s: max === 0 ? 0 : delta / max,
|
|
20
|
+
v: max
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** HSV to lowercase `#rrggbb`. */
|
|
24
|
+
function hsvToHex(hsv) {
|
|
25
|
+
const h = (hsv.h % 360 + 360) % 360;
|
|
26
|
+
const s = clamp(hsv.s);
|
|
27
|
+
const v = clamp(hsv.v);
|
|
28
|
+
const c = v * s;
|
|
29
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
30
|
+
const m = v - c;
|
|
31
|
+
const [r, g, b] = h < 60 ? [
|
|
32
|
+
c,
|
|
33
|
+
x,
|
|
34
|
+
0
|
|
35
|
+
] : h < 120 ? [
|
|
36
|
+
x,
|
|
37
|
+
c,
|
|
38
|
+
0
|
|
39
|
+
] : h < 180 ? [
|
|
40
|
+
0,
|
|
41
|
+
c,
|
|
42
|
+
x
|
|
43
|
+
] : h < 240 ? [
|
|
44
|
+
0,
|
|
45
|
+
x,
|
|
46
|
+
c
|
|
47
|
+
] : h < 300 ? [
|
|
48
|
+
x,
|
|
49
|
+
0,
|
|
50
|
+
c
|
|
51
|
+
] : [
|
|
52
|
+
c,
|
|
53
|
+
0,
|
|
54
|
+
x
|
|
55
|
+
];
|
|
56
|
+
const part = (channel) => Math.round((channel + m) * 255).toString(16).padStart(2, "0");
|
|
57
|
+
return `#${part(r)}${part(g)}${part(b)}`;
|
|
58
|
+
}
|
|
59
|
+
export { clamp, hexToHsv, hsvToHex };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=color-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-math.js","names":[],"sources":["../../../../src/components/composites/accent-picker/color-math.ts"],"sourcesContent":["/** HSV with hue in degrees [0, 360) and saturation/value in [0, 1]. */\nexport type Hsv = Readonly<{ h: number; s: number; v: number }>\n\nconst clamp = (value: number, min = 0, max = 1) => Math.min(max, Math.max(min, value))\n\n/** `#rrggbb` (any case) to HSV; anything else is `undefined`. */\nexport function hexToHsv(hex: string): Hsv | undefined {\n const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex.trim())\n if (!match) return undefined\n const [r, g, b] = match.slice(1).map((part) => Number.parseInt(part, 16) / 255) as [\n number,\n number,\n number,\n ]\n const max = Math.max(r, g, b)\n const delta = max - Math.min(r, g, b)\n let h = 0\n if (delta !== 0) {\n if (max === r) h = ((g - b) / delta) % 6\n else if (max === g) h = (b - r) / delta + 2\n else h = (r - g) / delta + 4\n }\n h = (h * 60 + 360) % 360\n return { h, s: max === 0 ? 0 : delta / max, v: max }\n}\n\n/** HSV to lowercase `#rrggbb`. */\nexport function hsvToHex(hsv: Hsv): `#${string}` {\n const h = ((hsv.h % 360) + 360) % 360\n const s = clamp(hsv.s)\n const v = clamp(hsv.v)\n const c = v * s\n const x = c * (1 - Math.abs(((h / 60) % 2) - 1))\n const m = v - c\n const [r, g, b] =\n h < 60\n ? [c, x, 0]\n : h < 120\n ? [x, c, 0]\n : h < 180\n ? [0, c, x]\n : h < 240\n ? [0, x, c]\n : h < 300\n ? [x, 0, c]\n : [c, 0, x]\n const part = (channel: number) =>\n Math.round((channel + m) * 255)\n .toString(16)\n .padStart(2, '0')\n return `#${part(r)}${part(g)}${part(b)}`\n}\n\nexport { clamp }\n"],"mappings":";AAGA,IAAM,SAAS,OAAe,MAAM,GAAG,MAAM,MAAM,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;;AAGrF,SAAgB,SAAS,KAA8B;CACrD,MAAM,QAAQ,8CAA8C,KAAK,IAAI,KAAK,CAAC;CAC3E,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,MAAM,CAAC,GAAG,GAAG,KAAK,MAAM,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,OAAO,SAAS,MAAM,EAAE,IAAI,GAAG;CAK9E,MAAM,MAAM,KAAK,IAAI,GAAG,GAAG,CAAC;CAC5B,MAAM,QAAQ,MAAM,KAAK,IAAI,GAAG,GAAG,CAAC;CACpC,IAAI,IAAI;CACR,IAAI,UAAU,GAAG;EACf,IAAI,QAAQ,GAAG,KAAM,IAAI,KAAK,QAAS;OAClC,IAAI,QAAQ,GAAG,KAAK,IAAI,KAAK,QAAQ;OACrC,KAAK,IAAI,KAAK,QAAQ;CAC7B;CACA,KAAK,IAAI,KAAK,OAAO;CACrB,OAAO;EAAE;EAAG,GAAG,QAAQ,IAAI,IAAI,QAAQ;EAAK,GAAG;CAAI;AACrD;;AAGA,SAAgB,SAAS,KAAwB;CAC/C,MAAM,KAAM,IAAI,IAAI,MAAO,OAAO;CAClC,MAAM,IAAI,MAAM,IAAI,CAAC;CACrB,MAAM,IAAI,MAAM,IAAI,CAAC;CACrB,MAAM,IAAI,IAAI;CACd,MAAM,IAAI,KAAK,IAAI,KAAK,IAAM,IAAI,KAAM,IAAK,CAAC;CAC9C,MAAM,IAAI,IAAI;CACd,MAAM,CAAC,GAAG,GAAG,KACX,IAAI,KACA;EAAC;EAAG;EAAG;CAAC,IACR,IAAI,MACF;EAAC;EAAG;EAAG;CAAC,IACR,IAAI,MACF;EAAC;EAAG;EAAG;CAAC,IACR,IAAI,MACF;EAAC;EAAG;EAAG;CAAC,IACR,IAAI,MACF;EAAC;EAAG;EAAG;CAAC,IACR;EAAC;EAAG;EAAG;CAAC;CACtB,MAAM,QAAQ,YACZ,KAAK,OAAO,UAAU,KAAK,GAAG,CAAC,CAC5B,SAAS,EAAE,CAAC,CACZ,SAAS,GAAG,GAAG;CACpB,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC;AACvC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JSX } from 'solid-js';
|
|
2
|
+
/**
|
|
3
|
+
* The Custom entry of the accent picker: a button that opens a colour picker
|
|
4
|
+
* anchored right under it, right edges aligned since Custom ends the row (a
|
|
5
|
+
* saturation/brightness field, a hue strip and a hex field). Nothing is committed while the colour is being explored; Apply (or
|
|
6
|
+
* Enter in the hex field) commits it and closes, Escape or a click outside
|
|
7
|
+
* leaves the stored colour alone. The operating system's colour panel is not
|
|
8
|
+
* used because on macOS it floats wherever it was last left, not by the button.
|
|
9
|
+
*/
|
|
10
|
+
export declare function CustomColorPopover(props: {
|
|
11
|
+
/** The stored custom colour, or `undefined` while a preset or inherit is chosen. */
|
|
12
|
+
value: string | undefined;
|
|
13
|
+
/** Where the picker starts while no custom colour is stored. */
|
|
14
|
+
seed: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
onCommit(value: `#${string}`): void;
|
|
17
|
+
}): JSX.Element;
|
|
18
|
+
//# sourceMappingURL=custom-color-popover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-color-popover.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/accent-picker/custom-color-popover.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAQnC;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,oFAAoF;IACpF,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,KAAK,EAAE,IAAI,MAAM,EAAE,GAAG,IAAI,CAAA;CACpC,eA4HA"}
|