@glasshome/ui 1.42.0 → 1.43.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/index.js +2 -2
- package/dist/lib/anchor-placement.d.ts +4 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +16 -2
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +6 -4
- package/dist/lib/behavior/focus-scope.d.ts +7 -1
- package/dist/lib/behavior/hide-outside.d.ts +1 -1
- package/dist/lib/behavior/layer-stack.d.ts +3 -2
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +2 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/color/color.d.ts +41 -0
- package/dist/lib/color/index.d.ts +2 -0
- package/dist/lib/color/intl.d.ts +40 -0
- package/dist/lib/dock-slot-classes.d.ts +2 -0
- package/dist/lib/hold.d.ts +1 -1
- package/dist/lib/locale.d.ts +3 -0
- package/dist/lib/menu-classes.d.ts +2 -0
- package/dist/lib/motion-classes.d.ts +1 -1
- package/dist/lib/overlay-classes.d.ts +1 -0
- package/dist/lib/scroll-track.d.ts +3 -2
- package/dist/lib/section-tokens.d.ts +1 -1
- package/dist/lib/segment-classes.d.ts +2 -0
- package/dist/lib/shadow-layer.d.ts +0 -45
- package/dist/lib/toggle-set.d.ts +44 -0
- package/dist/lib/visually-hidden.d.ts +3 -0
- package/dist/solid/accordion.d.ts +35 -11
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +1 -1
- package/dist/solid/button.d.ts +5 -4
- package/dist/solid/charts.d.ts +1 -1
- package/dist/solid/checkbox.d.ts +14 -4
- package/dist/solid/collapsible.d.ts +33 -5
- package/dist/solid/color-disc.d.ts +1 -1
- package/dist/solid/color-slider.d.ts +1 -1
- package/dist/solid/color-wheel.d.ts +1 -1
- package/dist/solid/context-menu.d.ts +58 -24
- package/dist/solid/dialog-parts.d.ts +8 -8
- package/dist/solid/dropdown-menu.d.ts +55 -24
- package/dist/solid/empty.d.ts +1 -1
- package/dist/solid/form.d.ts +5 -6
- package/dist/solid/hover-card.d.ts +65 -9
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +7725 -13458
- package/dist/solid/input-group.d.ts +6 -6
- package/dist/solid/item.d.ts +1 -1
- package/dist/solid/menu-parts.d.ts +175 -24
- package/dist/solid/option-card.d.ts +1 -4
- package/dist/solid/picker-row.d.ts +2 -0
- package/dist/solid/popover.d.ts +77 -12
- package/dist/solid/progress.d.ts +11 -3
- package/dist/solid/radio-group.d.ts +31 -6
- package/dist/solid/responsive-dialog.d.ts +1 -1
- package/dist/solid/scroll-area.d.ts +1 -1
- package/dist/solid/section-card.d.ts +2 -3
- package/dist/solid/select.d.ts +107 -10
- package/dist/solid/selection.d.ts +10 -1
- package/dist/solid/sheet.d.ts +1 -1
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +22 -22
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CxAii-e9.js → utils-3Codx-NZ.js} +527 -489
- package/package.json +3 -6
- package/src/lib/anchor-placement.ts +10 -3
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +26 -8
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +66 -29
- package/src/lib/behavior/dismiss.ts +61 -21
- package/src/lib/behavior/focus-scope.ts +31 -6
- package/src/lib/behavior/hide-outside.ts +2 -2
- package/src/lib/behavior/layer-stack.ts +33 -8
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +24 -18
- package/src/lib/behavior/polymorphic.tsx +1 -1
- package/src/lib/behavior/presence.ts +1 -1
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/clipboard.ts +2 -3
- package/src/lib/color/color.ts +746 -0
- package/src/lib/color/index.ts +2 -0
- package/src/lib/color/intl.ts +60 -0
- package/src/lib/dock-slot-classes.ts +3 -0
- package/src/lib/hold.ts +1 -1
- package/src/lib/locale.ts +62 -0
- package/src/lib/menu-classes.ts +3 -0
- package/src/lib/motion-classes.ts +7 -7
- package/src/lib/overlay-classes.ts +1 -3
- package/src/lib/scroll-track.ts +11 -6
- package/src/lib/section-tokens.ts +1 -1
- package/src/lib/segment-classes.ts +3 -0
- package/src/lib/shadow-layer.ts +0 -118
- package/src/lib/toggle-set.ts +133 -0
- package/src/lib/visually-hidden.ts +15 -0
- package/src/solid/accordion.tsx +294 -20
- package/src/solid/area-picker.tsx +3 -2
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/bottom-sheet/bottom-sheet.tsx +1 -1
- package/src/solid/button.tsx +12 -6
- package/src/solid/charts.tsx +1 -1
- package/src/solid/checkbox.tsx +167 -44
- package/src/solid/collapsible.tsx +260 -12
- package/src/solid/color-disc.tsx +11 -12
- package/src/solid/color-slider.tsx +114 -47
- package/src/solid/color-wheel.tsx +137 -39
- package/src/solid/context-menu.tsx +285 -94
- package/src/solid/dialog-parts.tsx +9 -9
- package/src/solid/dock.tsx +3 -2
- package/src/solid/dropdown-menu.tsx +252 -115
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +3 -2
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +5 -6
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +287 -25
- package/src/solid/image-picker.tsx +2 -2
- package/src/solid/index.ts +1 -3
- package/src/solid/input-group.tsx +2 -2
- package/src/solid/item.tsx +1 -1
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +5 -1
- package/src/solid/popover.tsx +424 -79
- package/src/solid/preview-tile.tsx +1 -1
- package/src/solid/progress.tsx +84 -15
- package/src/solid/radio-group.tsx +271 -34
- package/src/solid/responsive-dialog.tsx +1 -1
- package/src/solid/schema-form.tsx +1 -6
- package/src/solid/scroll-area.tsx +1 -1
- package/src/solid/section-card.tsx +3 -4
- package/src/solid/select.tsx +950 -95
- package/src/solid/selection.tsx +142 -66
- package/src/solid/sheet.tsx +1 -1
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +1 -1
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/tabs.tsx +12 -6
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +29 -99
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +24 -24
- package/src/styles/globals.css +61 -7
- package/src/styles/theme.css +7 -4
- package/src/tokens/material.ts +11 -2
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { ColorSlider as KColorSlider } from "@kobalte/core/color-slider";
|
|
2
|
-
import type { Color, ColorChannel } from "@kobalte/core/colors";
|
|
3
1
|
import type { Component } from "solid-js";
|
|
4
|
-
import {
|
|
2
|
+
import { createSignal } from "solid-js";
|
|
3
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
4
|
+
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
5
|
+
import { alongTrack, createDrag, createRange } from "../lib/behavior/range.js";
|
|
6
|
+
import {
|
|
7
|
+
type Color,
|
|
8
|
+
type ColorChannel,
|
|
9
|
+
COLOR_INTL_TRANSLATIONS,
|
|
10
|
+
parseColor,
|
|
11
|
+
} from "../lib/color/index.js";
|
|
5
12
|
import { FOCUS_RING } from "../lib/input-classes.js";
|
|
13
|
+
import { readingDirection } from "../lib/locale.js";
|
|
6
14
|
import { THUMB_CLASS, THUMB_COLOR_RING, THUMB_RAIL_PAD } from "../lib/thumb-classes.js";
|
|
7
15
|
import { cn } from "../lib/utils.js";
|
|
8
16
|
|
|
@@ -17,81 +25,140 @@ interface ColorSliderProps {
|
|
|
17
25
|
"aria-label"?: string;
|
|
18
26
|
}
|
|
19
27
|
|
|
28
|
+
const rtl = readingDirection === "rtl";
|
|
29
|
+
const START = rtl ? "right" : "left";
|
|
30
|
+
const THUMB_SHIFT = rtl ? "translateX(50%)" : "translateX(-50%)";
|
|
31
|
+
const RED = parseColor("hsl(0, 100%, 50%)");
|
|
32
|
+
|
|
33
|
+
const valueText = (color: Color, channel: ColorChannel) => {
|
|
34
|
+
const formatted = color.formatChannelValue(channel);
|
|
35
|
+
if (channel === "alpha") return formatted;
|
|
36
|
+
if (channel === "hue") {
|
|
37
|
+
const hue = parseColor(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
|
|
38
|
+
return `${formatted}, ${hue.getHueName(COLOR_INTL_TRANSLATIONS)}`;
|
|
39
|
+
}
|
|
40
|
+
return `${formatted}, ${color.withChannelValue("alpha", 1).getColorName(COLOR_INTL_TRANSLATIONS)}`;
|
|
41
|
+
};
|
|
42
|
+
|
|
20
43
|
const ColorSlider: Component<ColorSliderProps> = (props) => {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
const disabled = () => props.disabled ?? false;
|
|
45
|
+
const [color, setColor] = createControllableSignal({
|
|
46
|
+
value: () => props.value,
|
|
47
|
+
defaultValue: () => props.defaultValue ?? RED,
|
|
48
|
+
onChange: (next) => props.onChange?.(next),
|
|
49
|
+
});
|
|
50
|
+
const channelRange = () => color().getChannelRange(props.channel);
|
|
51
|
+
const range = createRange({
|
|
52
|
+
values: () => [color().getChannelValue(props.channel)],
|
|
53
|
+
defaultValues: () => [color().getChannelValue(props.channel)],
|
|
54
|
+
min: () => channelRange().minValue,
|
|
55
|
+
max: () => channelRange().maxValue,
|
|
56
|
+
step: () => channelRange().step,
|
|
57
|
+
disabled,
|
|
58
|
+
onChange: ([v = 0]) => setColor(color().withChannelValue(props.channel, v)),
|
|
59
|
+
onChangeEnd: ([v = 0]) => props.onChangeEnd?.(color().withChannelValue(props.channel, v)),
|
|
60
|
+
});
|
|
61
|
+
const percent = () => range.fraction(range.values()[0] ?? 0) * 100;
|
|
62
|
+
const [thumb, setThumb] = createSignal<HTMLElement>();
|
|
63
|
+
let grab = 0;
|
|
31
64
|
|
|
32
|
-
|
|
33
|
-
|
|
65
|
+
const drag = createDrag({
|
|
66
|
+
disabled,
|
|
67
|
+
start: (e, rect) => {
|
|
68
|
+
const at = alongTrack(e, rect);
|
|
69
|
+
if (thumb()?.contains(e.target as Node)) {
|
|
70
|
+
grab = at - percent() / 100;
|
|
71
|
+
} else {
|
|
72
|
+
const { minValue, maxValue } = channelRange();
|
|
73
|
+
grab = 0;
|
|
74
|
+
range.setThumb(0, minValue + at * (maxValue - minValue));
|
|
75
|
+
}
|
|
76
|
+
focusWithoutTracking(thumb());
|
|
77
|
+
},
|
|
78
|
+
move: (e, rect) => range.setThumb(0, range.valueAt(alongTrack(e, rect) - grab)),
|
|
79
|
+
end: range.dragEnd,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// The channel gradient runs under the whole root, thumb padding included, so the ends show no bare strip.
|
|
34
83
|
const gradient = () => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const channel = local.channel;
|
|
84
|
+
const c = color();
|
|
85
|
+
const channel = props.channel;
|
|
38
86
|
if (channel === "hue") {
|
|
39
87
|
const stops = [0, 60, 120, 180, 240, 300, 360]
|
|
40
|
-
.map((h) =>
|
|
88
|
+
.map((h) => c.withChannelValue("hue", h).toString("css"))
|
|
41
89
|
.join(", ");
|
|
42
90
|
return `linear-gradient(to right, ${stops})`;
|
|
43
91
|
}
|
|
44
|
-
const { minValue, maxValue } =
|
|
45
|
-
const start =
|
|
46
|
-
const end =
|
|
92
|
+
const { minValue, maxValue } = c.getChannelRange(channel);
|
|
93
|
+
const start = c.withChannelValue(channel, minValue).toString("css");
|
|
94
|
+
const end = c.withChannelValue(channel, maxValue).toString("css");
|
|
47
95
|
if (channel === "lightness") {
|
|
48
|
-
const middle =
|
|
96
|
+
const middle = c.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
|
|
49
97
|
return `linear-gradient(to right, ${start}, ${middle}, ${end})`;
|
|
50
98
|
}
|
|
51
99
|
return `linear-gradient(to right, ${start}, ${end})`;
|
|
52
100
|
};
|
|
53
101
|
|
|
102
|
+
const disabledMark = () => (disabled() ? "" : undefined);
|
|
103
|
+
|
|
54
104
|
return (
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
defaultValue={local.defaultValue}
|
|
58
|
-
channel={local.channel}
|
|
59
|
-
onChange={local.onChange}
|
|
60
|
-
onChangeEnd={local.onChangeEnd}
|
|
61
|
-
disabled={local.disabled}
|
|
105
|
+
<div
|
|
106
|
+
role="group"
|
|
62
107
|
data-slot="color-slider"
|
|
108
|
+
data-orientation="horizontal"
|
|
109
|
+
data-disabled={disabledMark()}
|
|
63
110
|
class={cn(
|
|
64
111
|
"relative flex w-full touch-none items-center rounded-xl select-none",
|
|
65
112
|
THUMB_RAIL_PAD,
|
|
66
|
-
|
|
67
|
-
|
|
113
|
+
disabled() && "cursor-not-allowed opacity-50",
|
|
114
|
+
props.class,
|
|
68
115
|
)}
|
|
69
116
|
style={{ background: gradient() }}
|
|
70
117
|
>
|
|
71
|
-
<
|
|
118
|
+
<div
|
|
72
119
|
data-slot="color-slider-track"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
120
|
+
data-orientation="horizontal"
|
|
121
|
+
data-disabled={disabledMark()}
|
|
122
|
+
class={cn("relative h-7 w-full", disabled() ? "cursor-not-allowed" : "cursor-pointer")}
|
|
123
|
+
style={{ "forced-color-adjust": "none" }}
|
|
124
|
+
on:pointerdown={drag.onPointerDown}
|
|
125
|
+
on:pointermove={drag.onPointerMove}
|
|
126
|
+
on:pointerup={drag.onPointerUp}
|
|
127
|
+
on:pointercancel={drag.onPointerCancel}
|
|
78
128
|
>
|
|
79
|
-
<
|
|
129
|
+
<span
|
|
130
|
+
ref={setThumb}
|
|
131
|
+
role="slider"
|
|
80
132
|
data-slot="color-slider-thumb"
|
|
133
|
+
data-orientation="horizontal"
|
|
134
|
+
data-disabled={disabledMark()}
|
|
135
|
+
tabIndex={disabled() ? undefined : 0}
|
|
136
|
+
aria-label={props["aria-label"] ?? props.channel}
|
|
137
|
+
aria-valuemin={channelRange().minValue}
|
|
138
|
+
aria-valuemax={channelRange().maxValue}
|
|
139
|
+
aria-valuenow={range.values()[0]}
|
|
140
|
+
aria-valuetext={valueText(color(), props.channel)}
|
|
141
|
+
aria-orientation="horizontal"
|
|
142
|
+
aria-disabled={disabled() || undefined}
|
|
81
143
|
class={cn(
|
|
82
144
|
THUMB_CLASS,
|
|
83
145
|
FOCUS_RING,
|
|
84
146
|
THUMB_COLOR_RING,
|
|
85
147
|
"absolute top-0",
|
|
86
|
-
|
|
148
|
+
disabled() && "cursor-not-allowed",
|
|
87
149
|
)}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
150
|
+
style={{
|
|
151
|
+
[START]: `calc(${percent()}%)`,
|
|
152
|
+
transform: THUMB_SHIFT,
|
|
153
|
+
"touch-action": "none",
|
|
154
|
+
"forced-color-adjust": "none",
|
|
155
|
+
background: color().toString("css"),
|
|
156
|
+
}}
|
|
157
|
+
on:keydown={(e) => range.keyDown(e, 0)}
|
|
158
|
+
onBlur={range.blur}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
95
162
|
);
|
|
96
163
|
};
|
|
97
164
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ColorWheel as KColorWheel } from "@kobalte/core/color-wheel";
|
|
2
|
-
import type { Color } from "@kobalte/core/colors";
|
|
3
1
|
import type { Component } from "solid-js";
|
|
4
|
-
import {
|
|
2
|
+
import { createMemo, createSignal } from "solid-js";
|
|
3
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
4
|
+
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
5
|
+
import { createDrag, type RangeKey, rangeKeyOf } from "../lib/behavior/range.js";
|
|
6
|
+
import { type Color, COLOR_INTL_TRANSLATIONS, parseColor } from "../lib/color/index.js";
|
|
5
7
|
import { FOCUS_RING } from "../lib/input-classes.js";
|
|
6
8
|
import { THUMB_CLASS, THUMB_COLOR_RING, THUMB_SIZE } from "../lib/thumb-classes.js";
|
|
7
9
|
import { cn } from "../lib/utils.js";
|
|
@@ -20,57 +22,153 @@ interface ColorWheelProps {
|
|
|
20
22
|
"aria-label"?: string;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
const RED = parseColor("hsl(0, 100%, 50%)");
|
|
26
|
+
const PAGE = 15;
|
|
27
|
+
const RING = `conic-gradient(from 90deg, ${Array.from({ length: 13 }, (_, i) => `hsl(${i * 30} 100% 50%)`).join(", ")})`;
|
|
28
|
+
|
|
29
|
+
const mod = (n: number, m: number) => ((n % m) + m) % m;
|
|
30
|
+
const roundToStep = (value: number, step: number) => Math.round(value / step) * step;
|
|
31
|
+
const roundDown = (v: number) => (Math.floor(v) === v ? v - 1 : Math.floor(v));
|
|
32
|
+
const angleOf = (x: number, y: number) => mod((Math.atan2(y, x) * 180) / Math.PI, 360);
|
|
33
|
+
|
|
23
34
|
const ColorWheel: Component<ColorWheelProps> = (props) => {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
"defaultValue",
|
|
27
|
-
"onChange",
|
|
28
|
-
"onChangeEnd",
|
|
29
|
-
"size",
|
|
30
|
-
"thickness",
|
|
31
|
-
"disabled",
|
|
32
|
-
"class",
|
|
33
|
-
"aria-label",
|
|
34
|
-
]);
|
|
35
|
-
const size = () => local.size ?? 200;
|
|
36
|
-
// Kobalte reads `thickness` as a percentage of the radius, so a px thumb
|
|
37
|
-
// only fits if the ring is sized from the same number the class resolves to.
|
|
38
|
-
// Clamped at the top of that range: past it Kobalte's mask radius goes
|
|
39
|
-
// negative and the ring renders as a filled disc.
|
|
35
|
+
const size = () => props.size ?? 200;
|
|
36
|
+
// A percentage of the radius sized to the px thumb; past 100 the mask radius goes negative.
|
|
40
37
|
const thickness = () =>
|
|
41
|
-
|
|
38
|
+
props.thickness ?? Math.min(100, Math.ceil((THUMB_SIZE / (size() / 2)) * 100));
|
|
39
|
+
const disabled = () => props.disabled ?? false;
|
|
40
|
+
const [value, setValue] = createControllableSignal({
|
|
41
|
+
value: () => props.value,
|
|
42
|
+
defaultValue: () => props.defaultValue ?? RED,
|
|
43
|
+
onChange: (next) => props.onChange?.(next),
|
|
44
|
+
});
|
|
45
|
+
const color = createMemo(() => {
|
|
46
|
+
const v = value();
|
|
47
|
+
const space = v.getColorSpace();
|
|
48
|
+
return space === "hsl" || space === "hsb" ? v : v.toFormat("hsl");
|
|
49
|
+
});
|
|
50
|
+
const hue = () => color().getChannelValue("hue");
|
|
51
|
+
const outerRadius = () => size() / 2;
|
|
52
|
+
const thumbRadius = () => ((139.75 - (thickness() / 100) * 70) * outerRadius()) / 140;
|
|
53
|
+
const [thumb, setThumb] = createSignal<HTMLElement>();
|
|
54
|
+
let keyed = false;
|
|
55
|
+
|
|
56
|
+
const setHue = (next: number) => {
|
|
57
|
+
if (disabled()) return;
|
|
58
|
+
const turned = roundToStep(mod(next > 360 ? 0 : next, 360), 1);
|
|
59
|
+
if (hue() !== turned) setValue(color().withChannelValue("hue", turned));
|
|
60
|
+
};
|
|
61
|
+
const increment = (by: number) => {
|
|
62
|
+
const step = Math.max(by, 1);
|
|
63
|
+
const next = hue() + step;
|
|
64
|
+
setHue(roundToStep(mod(next >= 360 ? 0 : next, 360), step));
|
|
65
|
+
};
|
|
66
|
+
const decrement = (by: number) => {
|
|
67
|
+
const step = Math.max(by, 1);
|
|
68
|
+
if (hue() === 0) setHue(roundDown(360 / step) * step);
|
|
69
|
+
else setHue(roundToStep(mod(hue() - step, 360), step));
|
|
70
|
+
};
|
|
71
|
+
const ACTIONS: Record<RangeKey, () => void> = {
|
|
72
|
+
decrease: () => decrement(1),
|
|
73
|
+
increase: () => increment(1),
|
|
74
|
+
pageDown: () => decrement(PAGE),
|
|
75
|
+
pageUp: () => increment(PAGE),
|
|
76
|
+
first: () => setHue(0),
|
|
77
|
+
last: () => setHue(360),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const pointerHue = (e: PointerEvent, rect: DOMRect) =>
|
|
81
|
+
angleOf(e.clientX - rect.left - rect.width / 2, e.clientY - rect.top - rect.height / 2);
|
|
82
|
+
|
|
83
|
+
const drag = createDrag({
|
|
84
|
+
disabled,
|
|
85
|
+
start: (e, rect) => {
|
|
86
|
+
focusWithoutTracking(thumb());
|
|
87
|
+
setHue(pointerHue(e, rect));
|
|
88
|
+
},
|
|
89
|
+
move: (e, rect) => setHue(pointerHue(e, rect)),
|
|
90
|
+
end: () => props.onChangeEnd?.(color()),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
94
|
+
const key = rangeKeyOf(e);
|
|
95
|
+
if (!key || disabled()) return;
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
keyed = true;
|
|
99
|
+
ACTIONS[key]();
|
|
100
|
+
};
|
|
101
|
+
const onBlur = () => {
|
|
102
|
+
if (!keyed) return;
|
|
103
|
+
keyed = false;
|
|
104
|
+
props.onChangeEnd?.(color());
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const disabledMark = () => (disabled() ? "" : undefined);
|
|
108
|
+
const place = () => {
|
|
109
|
+
const a = (hue() * Math.PI) / 180;
|
|
110
|
+
return {
|
|
111
|
+
x: outerRadius() + thumbRadius() * Math.cos(a),
|
|
112
|
+
y: outerRadius() + thumbRadius() * Math.sin(a),
|
|
113
|
+
};
|
|
114
|
+
};
|
|
42
115
|
|
|
43
116
|
return (
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
defaultValue={local.defaultValue}
|
|
47
|
-
onChange={local.onChange}
|
|
48
|
-
onChangeEnd={local.onChangeEnd}
|
|
49
|
-
thickness={thickness()}
|
|
50
|
-
disabled={local.disabled}
|
|
117
|
+
<div
|
|
118
|
+
role="group"
|
|
51
119
|
data-slot="color-wheel"
|
|
120
|
+
data-disabled={disabledMark()}
|
|
52
121
|
class={cn(
|
|
53
122
|
"relative touch-none select-none",
|
|
54
|
-
|
|
55
|
-
|
|
123
|
+
disabled() && "cursor-not-allowed opacity-50",
|
|
124
|
+
props.class,
|
|
56
125
|
)}
|
|
57
126
|
style={{ width: `${size()}px`, height: `${size()}px` }}
|
|
58
127
|
>
|
|
59
|
-
<
|
|
128
|
+
<div
|
|
60
129
|
data-slot="color-wheel-track"
|
|
61
|
-
|
|
130
|
+
data-disabled={disabledMark()}
|
|
131
|
+
class={cn("h-full w-full", disabled() ? "cursor-not-allowed" : "cursor-pointer")}
|
|
132
|
+
style={{
|
|
133
|
+
"touch-action": "none",
|
|
134
|
+
"forced-color-adjust": "none",
|
|
135
|
+
background: RING,
|
|
136
|
+
"clip-path": "circle(50%)",
|
|
137
|
+
mask: `radial-gradient(#0000 ${70 - (thickness() / 100) * 70}%, #000 ${70.5 - (thickness() / 100) * 70}%)`,
|
|
138
|
+
}}
|
|
139
|
+
on:pointerdown={drag.onPointerDown}
|
|
140
|
+
on:pointermove={drag.onPointerMove}
|
|
141
|
+
on:pointerup={drag.onPointerUp}
|
|
142
|
+
on:pointercancel={drag.onPointerCancel}
|
|
62
143
|
>
|
|
63
144
|
{/* Always a circle: the thumb rides a circular track, theme corner radius looks broken there. */}
|
|
64
|
-
<
|
|
145
|
+
<span
|
|
146
|
+
ref={setThumb}
|
|
147
|
+
role="slider"
|
|
65
148
|
data-slot="color-wheel-thumb"
|
|
149
|
+
data-disabled={disabledMark()}
|
|
150
|
+
tabIndex={disabled() ? undefined : 0}
|
|
151
|
+
aria-label={props["aria-label"] ?? "Hue"}
|
|
152
|
+
aria-valuemin={0}
|
|
153
|
+
aria-valuemax={360}
|
|
154
|
+
aria-valuenow={hue()}
|
|
155
|
+
aria-valuetext={`${color().formatChannelValue("hue")}, ${color().getHueName(COLOR_INTL_TRANSLATIONS)}`}
|
|
156
|
+
aria-disabled={disabled() || undefined}
|
|
66
157
|
class={cn(THUMB_CLASS, FOCUS_RING, THUMB_COLOR_RING, "rounded-full")}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
158
|
+
style={{
|
|
159
|
+
position: "absolute",
|
|
160
|
+
left: `${place().x}px`,
|
|
161
|
+
top: `${place().y}px`,
|
|
162
|
+
transform: "translate(-50%, -50%)",
|
|
163
|
+
"forced-color-adjust": "none",
|
|
164
|
+
"touch-action": "none",
|
|
165
|
+
background: color().toString("css"),
|
|
166
|
+
}}
|
|
167
|
+
on:keydown={onKeyDown}
|
|
168
|
+
onBlur={onBlur}
|
|
169
|
+
/>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
74
172
|
);
|
|
75
173
|
};
|
|
76
174
|
|