@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
package/src/solid/checkbox.tsx
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { Checkbox as CheckboxPrimitive } from "@kobalte/core/checkbox";
|
|
2
1
|
import {
|
|
3
2
|
children,
|
|
4
|
-
type Component,
|
|
5
3
|
type ComponentProps,
|
|
4
|
+
createSignal,
|
|
5
|
+
createUniqueId,
|
|
6
6
|
type JSX,
|
|
7
7
|
type ParentComponent,
|
|
8
8
|
Show,
|
|
9
9
|
splitProps,
|
|
10
10
|
} from "solid-js";
|
|
11
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
12
|
+
import { effect } from "../lib/behavior/solid.js";
|
|
11
13
|
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
12
14
|
import { cn } from "../lib/utils.js";
|
|
15
|
+
import { VISUALLY_HIDDEN } from "../lib/visually-hidden.js";
|
|
13
16
|
import { Icon } from "./icon.js";
|
|
14
17
|
|
|
15
18
|
/* Two box sizes and the glyph that fits each: `sm` is the row-embedded control
|
|
@@ -21,7 +24,6 @@ const CHECKBOX_SIZE = {
|
|
|
21
24
|
|
|
22
25
|
type CheckboxSize = keyof typeof CHECKBOX_SIZE;
|
|
23
26
|
|
|
24
|
-
// Its own component so the label resolves once, under the checkbox's Kobalte context.
|
|
25
27
|
const CheckboxText: ParentComponent = (props) => {
|
|
26
28
|
const label = children(() => props.children);
|
|
27
29
|
return (
|
|
@@ -33,52 +35,173 @@ const CheckboxText: ParentComponent = (props) => {
|
|
|
33
35
|
);
|
|
34
36
|
};
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
type CheckboxProps = Omit<ComponentProps<"div">, "onChange" | "children"> & {
|
|
39
|
+
checked?: boolean;
|
|
40
|
+
defaultChecked?: boolean;
|
|
41
|
+
onChange?: (checked: boolean) => void;
|
|
42
|
+
indeterminate?: boolean;
|
|
43
|
+
value?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
required?: boolean;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
readOnly?: boolean;
|
|
48
|
+
size?: CheckboxSize;
|
|
49
|
+
children?: JSX.Element;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const Checkbox = (props: CheckboxProps) => {
|
|
53
|
+
const [local, field, others] = splitProps(
|
|
54
|
+
props,
|
|
55
|
+
[
|
|
56
|
+
"class",
|
|
57
|
+
"children",
|
|
58
|
+
"size",
|
|
59
|
+
"checked",
|
|
60
|
+
"defaultChecked",
|
|
61
|
+
"onChange",
|
|
62
|
+
"indeterminate",
|
|
63
|
+
"value",
|
|
64
|
+
"name",
|
|
65
|
+
"required",
|
|
66
|
+
"disabled",
|
|
67
|
+
"readOnly",
|
|
68
|
+
"id",
|
|
69
|
+
"ref",
|
|
70
|
+
],
|
|
71
|
+
["aria-label", "aria-labelledby", "aria-describedby"],
|
|
72
|
+
);
|
|
73
|
+
const fallbackId = `checkbox-${createUniqueId()}`;
|
|
74
|
+
const id = () => local.id ?? fallbackId;
|
|
40
75
|
const size = () => CHECKBOX_SIZE[local.size ?? "default"];
|
|
76
|
+
const [checked, setChecked] = createControllableSignal({
|
|
77
|
+
value: () => local.checked,
|
|
78
|
+
defaultValue: () => local.defaultChecked ?? false,
|
|
79
|
+
onChange: (next) => local.onChange?.(next),
|
|
80
|
+
});
|
|
81
|
+
const [input, setInput] = createSignal<HTMLInputElement>();
|
|
82
|
+
const [root, setRoot] = createSignal<HTMLDivElement>();
|
|
83
|
+
let focused = false;
|
|
84
|
+
|
|
85
|
+
effect(
|
|
86
|
+
() => [input(), local.indeterminate ?? false, checked()] as const,
|
|
87
|
+
([el, indeterminate]) => {
|
|
88
|
+
if (el) el.indeterminate = indeterminate;
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
// The browser's own reset restores this, so a reset lands where the state does.
|
|
92
|
+
effect(
|
|
93
|
+
() => [input(), local.defaultChecked ?? false] as const,
|
|
94
|
+
([el, defaultChecked]) => {
|
|
95
|
+
if (el) el.defaultChecked = defaultChecked;
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
effect(
|
|
99
|
+
() => root()?.closest("form"),
|
|
100
|
+
(form) => {
|
|
101
|
+
if (!form) return;
|
|
102
|
+
const reset = () => setChecked(local.defaultChecked ?? false);
|
|
103
|
+
form.addEventListener("reset", reset);
|
|
104
|
+
return () => form.removeEventListener("reset", reset);
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const state = () => ({
|
|
109
|
+
"data-required": local.required ? "" : undefined,
|
|
110
|
+
"data-disabled": local.disabled ? "" : undefined,
|
|
111
|
+
"data-readonly": local.readOnly ? "" : undefined,
|
|
112
|
+
"data-checked": checked() ? "" : undefined,
|
|
113
|
+
"data-indeterminate": local.indeterminate ? "" : undefined,
|
|
114
|
+
});
|
|
115
|
+
const labelledBy = () =>
|
|
116
|
+
[
|
|
117
|
+
`${id()}-label`,
|
|
118
|
+
field["aria-labelledby"],
|
|
119
|
+
field["aria-labelledby"] || field["aria-label"] ? `${id()}-input` : undefined,
|
|
120
|
+
]
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
.join(" ");
|
|
123
|
+
|
|
124
|
+
const change = (event: Event) => {
|
|
125
|
+
const target = event.currentTarget as HTMLInputElement;
|
|
126
|
+
if (!local.readOnly) setChecked(target.checked);
|
|
127
|
+
target.checked = checked();
|
|
128
|
+
};
|
|
129
|
+
|
|
41
130
|
return (
|
|
42
|
-
<
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
131
|
+
<div
|
|
132
|
+
ref={(el) => {
|
|
133
|
+
setRoot(el);
|
|
134
|
+
if (typeof local.ref === "function") local.ref(el);
|
|
135
|
+
}}
|
|
136
|
+
role="group"
|
|
137
|
+
id={id()}
|
|
138
|
+
on:pointerdown={(event) => {
|
|
139
|
+
if (focused) event.preventDefault();
|
|
140
|
+
}}
|
|
141
|
+
{...state()}
|
|
142
|
+
data-slot="checkbox"
|
|
143
|
+
{...others}
|
|
144
|
+
>
|
|
145
|
+
<label
|
|
146
|
+
for={`${id()}-input`}
|
|
147
|
+
id={`${id()}-label`}
|
|
148
|
+
{...state()}
|
|
149
|
+
data-slot="checkbox-label"
|
|
150
|
+
class="group inline-flex cursor-pointer items-center gap-2.5 select-none data-[disabled]:cursor-not-allowed"
|
|
151
|
+
>
|
|
152
|
+
<input
|
|
153
|
+
ref={setInput}
|
|
154
|
+
type="checkbox"
|
|
155
|
+
id={`${id()}-input`}
|
|
156
|
+
name={local.name ?? id()}
|
|
157
|
+
value={local.value ?? "on"}
|
|
158
|
+
checked={checked()}
|
|
159
|
+
required={local.required}
|
|
160
|
+
disabled={local.disabled}
|
|
161
|
+
readOnly={local.readOnly}
|
|
162
|
+
style={VISUALLY_HIDDEN}
|
|
163
|
+
aria-label={field["aria-label"]}
|
|
164
|
+
aria-labelledby={labelledBy()}
|
|
165
|
+
aria-describedby={field["aria-describedby"]}
|
|
166
|
+
aria-required={local.required || undefined}
|
|
167
|
+
aria-disabled={local.disabled || undefined}
|
|
168
|
+
aria-readonly={local.readOnly || undefined}
|
|
169
|
+
{...state()}
|
|
170
|
+
class="peer"
|
|
171
|
+
on:change={change}
|
|
172
|
+
on:focus={() => (focused = true)}
|
|
173
|
+
on:blur={() => (focused = false)}
|
|
174
|
+
/>
|
|
175
|
+
<span
|
|
176
|
+
aria-hidden="true"
|
|
177
|
+
data-slot="checkbox-box"
|
|
178
|
+
data-size={local.size ?? "default"}
|
|
179
|
+
class={cn(
|
|
180
|
+
"transition-glass box-border inline-flex shrink-0 items-center justify-center overflow-hidden rounded-xs duration-(--duration-expand) ease-out group-active:scale-90",
|
|
181
|
+
size().box,
|
|
182
|
+
"peer-focus-visible:ring-ring/50 peer-focus-visible:ring-[3px] peer-focus-visible:[--glass-edge:var(--ring)]",
|
|
183
|
+
checked()
|
|
184
|
+
? "glass glass-tint text-foreground [--glass-tone:var(--material-accent)]"
|
|
185
|
+
: FIELD_CHROME,
|
|
186
|
+
local.disabled && "cursor-not-allowed opacity-40",
|
|
187
|
+
local.class,
|
|
188
|
+
)}
|
|
49
189
|
>
|
|
50
|
-
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
190
|
+
{/* Always mounted so the box keeps constant height. */}
|
|
191
|
+
<Icon
|
|
192
|
+
icon="lucide:check"
|
|
193
|
+
width={size().px}
|
|
194
|
+
height={size().px}
|
|
55
195
|
class={cn(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
state.checked()
|
|
60
|
-
? "glass glass-tint text-foreground [--glass-tone:var(--material-accent)]"
|
|
61
|
-
: FIELD_CHROME,
|
|
62
|
-
props.disabled && "cursor-not-allowed opacity-40",
|
|
63
|
-
local.class,
|
|
196
|
+
size().glyph,
|
|
197
|
+
"transition-glass duration-(--duration-expand) ease-out",
|
|
198
|
+
checked() ? "scale-100 opacity-100" : "scale-0 opacity-0",
|
|
64
199
|
)}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
height={size().px}
|
|
71
|
-
class={cn(
|
|
72
|
-
size().glyph,
|
|
73
|
-
"transition-glass duration-200 ease-out",
|
|
74
|
-
state.checked() ? "scale-100 opacity-100" : "scale-0 opacity-0",
|
|
75
|
-
)}
|
|
76
|
-
/>
|
|
77
|
-
</span>
|
|
78
|
-
<CheckboxText>{local.children as JSX.Element}</CheckboxText>
|
|
79
|
-
</CheckboxPrimitive.Label>
|
|
80
|
-
)}
|
|
81
|
-
</CheckboxPrimitive>
|
|
200
|
+
/>
|
|
201
|
+
</span>
|
|
202
|
+
<CheckboxText>{local.children}</CheckboxText>
|
|
203
|
+
</label>
|
|
204
|
+
</div>
|
|
82
205
|
);
|
|
83
206
|
};
|
|
84
207
|
|
|
@@ -1,17 +1,267 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Accessor,
|
|
3
|
+
type Component,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
createContext,
|
|
6
|
+
createMemo,
|
|
7
|
+
createSignal,
|
|
8
|
+
createUniqueId,
|
|
9
|
+
onCleanup,
|
|
10
|
+
onMount,
|
|
11
|
+
Show,
|
|
12
|
+
splitProps,
|
|
13
|
+
useContext,
|
|
14
|
+
type ValidComponent,
|
|
15
|
+
} from "solid-js";
|
|
16
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
17
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
18
|
+
import { createPresence } from "../lib/behavior/presence.js";
|
|
19
|
+
import { callEventHandler, effect, merge } from "../lib/behavior/solid.js";
|
|
20
|
+
import { MOTION_EXIT_MS } from "../lib/motion-classes.js";
|
|
3
21
|
import { cn } from "../lib/utils.js";
|
|
4
22
|
|
|
5
|
-
|
|
6
|
-
|
|
23
|
+
type CollapsibleProps = Omit<ComponentProps<"div">, "onChange"> & {
|
|
24
|
+
as?: ValidComponent;
|
|
25
|
+
open?: boolean;
|
|
26
|
+
defaultOpen?: boolean;
|
|
27
|
+
onOpenChange?: (open: boolean) => void;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
forceMount?: boolean;
|
|
7
30
|
};
|
|
8
31
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
32
|
+
type CollapsibleTriggerProps = ComponentProps<"button"> & { as?: ValidComponent };
|
|
33
|
+
|
|
34
|
+
type CollapsibleContentProps = ComponentProps<"div"> & { as?: ValidComponent };
|
|
35
|
+
|
|
36
|
+
type Markers = Record<"data-expanded" | "data-closed" | "data-disabled", "" | undefined>;
|
|
37
|
+
|
|
38
|
+
interface CollapsibleContextValue {
|
|
39
|
+
open: Accessor<boolean>;
|
|
40
|
+
disabled: Accessor<boolean>;
|
|
41
|
+
forceMount: Accessor<boolean>;
|
|
42
|
+
markers: Markers;
|
|
43
|
+
toggle: () => void;
|
|
44
|
+
defaultContentId: Accessor<string>;
|
|
45
|
+
controls: Accessor<string | undefined>;
|
|
46
|
+
registerContent: (id: string) => () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const CollapsibleContext = createContext<CollapsibleContextValue>();
|
|
50
|
+
|
|
51
|
+
export function useCollapsible(): CollapsibleContextValue {
|
|
52
|
+
const ctx = useContext(CollapsibleContext);
|
|
53
|
+
if (!ctx) throw new Error("A collapsible part renders inside a Collapsible");
|
|
54
|
+
return ctx;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const SIZE_VARS = {
|
|
58
|
+
height: ["--collapsible-content-height", "--kb-collapsible-content-height"],
|
|
59
|
+
width: ["--collapsible-content-width", "--kb-collapsible-content-width"],
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
function freeze(node: HTMLElement, still: boolean) {
|
|
63
|
+
node.style.transitionDuration = still ? "0s" : "";
|
|
64
|
+
node.style.animationName = still ? "none" : "";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function writeSize(node: HTMLElement) {
|
|
68
|
+
const box = node.getBoundingClientRect();
|
|
69
|
+
for (const side of ["height", "width"] as const) {
|
|
70
|
+
for (const name of SIZE_VARS[side]) {
|
|
71
|
+
if (box[side]) node.style.setProperty(name, `${box[side]}px`);
|
|
72
|
+
else node.style.removeProperty(name);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const CollapsibleRoot: Component<CollapsibleProps> = (props) => {
|
|
78
|
+
const fallbackId = `collapsible-${createUniqueId()}`;
|
|
79
|
+
const [local, others] = splitProps(props, [
|
|
80
|
+
"as",
|
|
81
|
+
"open",
|
|
82
|
+
"defaultOpen",
|
|
83
|
+
"onOpenChange",
|
|
84
|
+
"disabled",
|
|
85
|
+
"forceMount",
|
|
86
|
+
]);
|
|
87
|
+
const [state, setOpen] = createControllableSignal<boolean>({
|
|
88
|
+
value: () => local.open,
|
|
89
|
+
defaultValue: () => local.defaultOpen ?? false,
|
|
90
|
+
onChange: (next) => local.onOpenChange?.(next),
|
|
91
|
+
});
|
|
92
|
+
// An accordion item's open state derives from the whole selection; a sibling's change must not wake it.
|
|
93
|
+
const open = createMemo(state);
|
|
94
|
+
const disabled = () => local.disabled ?? false;
|
|
95
|
+
const [content, setContent] = createSignal<string>();
|
|
96
|
+
|
|
97
|
+
const ctx: CollapsibleContextValue = {
|
|
98
|
+
open,
|
|
99
|
+
disabled,
|
|
100
|
+
forceMount: () => local.forceMount ?? false,
|
|
101
|
+
markers: {
|
|
102
|
+
get "data-expanded"() {
|
|
103
|
+
return open() ? "" : undefined;
|
|
104
|
+
},
|
|
105
|
+
get "data-closed"() {
|
|
106
|
+
return open() ? undefined : "";
|
|
107
|
+
},
|
|
108
|
+
get "data-disabled"() {
|
|
109
|
+
return disabled() ? "" : undefined;
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
toggle: () => setOpen(!open()),
|
|
113
|
+
defaultContentId: () => `${others.id ?? fallbackId}-content`,
|
|
114
|
+
controls: () => (open() ? content() : undefined),
|
|
115
|
+
registerContent: (id) => {
|
|
116
|
+
setContent(id);
|
|
117
|
+
return () => setContent((current) => (current === id ? undefined : current));
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<CollapsibleContext.Provider value={ctx}>
|
|
123
|
+
<Polymorphic
|
|
124
|
+
{...merge({ id: fallbackId }, ctx.markers, others, {
|
|
125
|
+
as: local.as,
|
|
126
|
+
defaultAs: "div" as ValidComponent,
|
|
127
|
+
})}
|
|
128
|
+
/>
|
|
129
|
+
</CollapsibleContext.Provider>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const CollapsibleTriggerRoot: Component<CollapsibleTriggerProps> = (props) => {
|
|
134
|
+
const ctx = useCollapsible();
|
|
135
|
+
const [local, others] = splitProps(props, ["as", "ref", "onClick"]);
|
|
136
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
137
|
+
const native = () => (local.as ?? "button") === "button";
|
|
138
|
+
|
|
139
|
+
// Bound on the element: a delegated handler never hears a press inside a closed shadow root.
|
|
140
|
+
effect(el, (node) => {
|
|
141
|
+
if (!node) return;
|
|
142
|
+
const click = (event: MouseEvent) => {
|
|
143
|
+
callEventHandler(
|
|
144
|
+
event as MouseEvent & { currentTarget: HTMLButtonElement; target: Element },
|
|
145
|
+
local.onClick,
|
|
146
|
+
);
|
|
147
|
+
if (!ctx.disabled()) ctx.toggle();
|
|
148
|
+
};
|
|
149
|
+
node.addEventListener("click", click);
|
|
150
|
+
return () => node.removeEventListener("click", click);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<Polymorphic
|
|
155
|
+
{...merge(
|
|
156
|
+
{
|
|
157
|
+
get "aria-expanded"() {
|
|
158
|
+
return ctx.open();
|
|
159
|
+
},
|
|
160
|
+
get "aria-controls"() {
|
|
161
|
+
return ctx.controls();
|
|
162
|
+
},
|
|
163
|
+
get role() {
|
|
164
|
+
return native() ? undefined : "button";
|
|
165
|
+
},
|
|
166
|
+
get tabIndex() {
|
|
167
|
+
return native() || ctx.disabled() ? undefined : 0;
|
|
168
|
+
},
|
|
169
|
+
get disabled() {
|
|
170
|
+
return native() ? ctx.disabled() : undefined;
|
|
171
|
+
},
|
|
172
|
+
get "aria-disabled"() {
|
|
173
|
+
return !native() && ctx.disabled() ? true : undefined;
|
|
174
|
+
},
|
|
175
|
+
get "data-disabled"() {
|
|
176
|
+
return ctx.disabled() ? "" : undefined;
|
|
177
|
+
},
|
|
178
|
+
get "data-expanded"() {
|
|
179
|
+
return ctx.open() ? "" : undefined;
|
|
180
|
+
},
|
|
181
|
+
get "data-closed"() {
|
|
182
|
+
return ctx.open() ? undefined : "";
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
others,
|
|
186
|
+
{
|
|
187
|
+
as: local.as,
|
|
188
|
+
defaultAs: "button" as ValidComponent,
|
|
189
|
+
ref: (node: HTMLElement) => {
|
|
190
|
+
setEl(node);
|
|
191
|
+
if (typeof local.ref === "function") local.ref(node as HTMLButtonElement);
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
)}
|
|
195
|
+
/>
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export const CollapsibleContentRoot: Component<CollapsibleContentProps> = (props) => {
|
|
200
|
+
const ctx = useCollapsible();
|
|
201
|
+
const [local, others] = splitProps(props, ["as", "ref", "id"]);
|
|
202
|
+
const id = () => local.id ?? ctx.defaultContentId();
|
|
203
|
+
effect(id, (value) => ctx.registerContent(value));
|
|
204
|
+
|
|
205
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
206
|
+
const presence = createPresence({
|
|
207
|
+
present: ctx.open,
|
|
208
|
+
element: el,
|
|
209
|
+
exitMs: MOTION_EXIT_MS.disclosure,
|
|
210
|
+
keep: ctx.forceMount,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Open from the start, the content shows at once: its motion stays off until it first closes.
|
|
214
|
+
let still = ctx.open();
|
|
215
|
+
onMount(() => {
|
|
216
|
+
const frame = requestAnimationFrame(() => (still = false));
|
|
217
|
+
onCleanup(() => cancelAnimationFrame(frame));
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
effect(
|
|
221
|
+
() => [el(), ctx.open()] as const,
|
|
222
|
+
([node, open]) => {
|
|
223
|
+
if (!node) return;
|
|
224
|
+
if (!open) return freeze(node, false);
|
|
225
|
+
freeze(node, true);
|
|
226
|
+
writeSize(node);
|
|
227
|
+
if (!still) freeze(node, false);
|
|
228
|
+
},
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const Panel: Component = () => {
|
|
232
|
+
onCleanup(() => setEl(undefined));
|
|
233
|
+
return (
|
|
234
|
+
<Polymorphic
|
|
235
|
+
{...merge(ctx.markers, others, {
|
|
236
|
+
as: local.as,
|
|
237
|
+
defaultAs: "div" as ValidComponent,
|
|
238
|
+
get id() {
|
|
239
|
+
return id();
|
|
240
|
+
},
|
|
241
|
+
ref: (node: HTMLElement) => {
|
|
242
|
+
setEl(node);
|
|
243
|
+
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
244
|
+
},
|
|
245
|
+
})}
|
|
246
|
+
/>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<Show when={presence.mounted()}>
|
|
252
|
+
<Panel />
|
|
253
|
+
</Show>
|
|
254
|
+
);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const Collapsible: Component<CollapsibleProps> = (props) => {
|
|
258
|
+
return <CollapsibleRoot data-slot="collapsible" {...props} />;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const CollapsibleTrigger: Component<CollapsibleTriggerProps> = (props) => {
|
|
12
262
|
const [local, rest] = splitProps(props, ["class"]);
|
|
13
263
|
return (
|
|
14
|
-
<
|
|
264
|
+
<CollapsibleTriggerRoot
|
|
15
265
|
data-slot="collapsible-trigger"
|
|
16
266
|
class={cn("cursor-pointer py-3", local.class)}
|
|
17
267
|
{...rest}
|
|
@@ -19,12 +269,10 @@ const CollapsibleTrigger: Component<ComponentProps<typeof CollapsiblePrimitive.T
|
|
|
19
269
|
);
|
|
20
270
|
};
|
|
21
271
|
|
|
22
|
-
const CollapsibleContent: Component<
|
|
23
|
-
props,
|
|
24
|
-
) => {
|
|
272
|
+
const CollapsibleContent: Component<CollapsibleContentProps> = (props) => {
|
|
25
273
|
const [local, rest] = splitProps(props, ["class"]);
|
|
26
274
|
return (
|
|
27
|
-
<
|
|
275
|
+
<CollapsibleContentRoot
|
|
28
276
|
data-slot="collapsible-content"
|
|
29
277
|
class={cn(
|
|
30
278
|
"data-closed:animate-collapsible-up data-expanded:animate-collapsible-down overflow-hidden",
|
package/src/solid/color-disc.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { parseColor } from "@kobalte/core/colors";
|
|
1
|
+
import { type Color, parseColor } from "../lib/color/index.js";
|
|
3
2
|
import { type Component, createSignal, type JSX } from "solid-js";
|
|
4
3
|
import { FOCUS_RING } from "../lib/input-classes.js";
|
|
5
4
|
import { THUMB_COLOR_RING } from "../lib/thumb-classes.js";
|
|
@@ -91,22 +90,22 @@ const ColorDisc: Component<ColorDiscProps> = (props) => {
|
|
|
91
90
|
background: discBackground,
|
|
92
91
|
"box-shadow": "inset 0 0 0 1px rgb(255 255 255 / 0.15)",
|
|
93
92
|
}}
|
|
94
|
-
|
|
93
|
+
on:pointerdown={(e) => {
|
|
95
94
|
if (props.disabled || e.button !== 0) return;
|
|
96
95
|
const el = e.currentTarget;
|
|
97
96
|
el.setPointerCapture?.(e.pointerId);
|
|
98
97
|
setDragging(true);
|
|
99
98
|
props.onChange?.(colourAt(e, el));
|
|
100
99
|
}}
|
|
101
|
-
|
|
100
|
+
on:pointermove={(e) => {
|
|
102
101
|
if (dragging()) props.onChange?.(colourAt(e, e.currentTarget));
|
|
103
102
|
}}
|
|
104
|
-
|
|
103
|
+
on:pointerup={(e) => {
|
|
105
104
|
if (!dragging()) return;
|
|
106
105
|
setDragging(false);
|
|
107
106
|
props.onChangeEnd?.(colourAt(e, e.currentTarget));
|
|
108
107
|
}}
|
|
109
|
-
|
|
108
|
+
on:pointercancel={() => {
|
|
110
109
|
if (!dragging()) return;
|
|
111
110
|
setDragging(false);
|
|
112
111
|
if (last) props.onChangeEnd?.(last);
|
|
@@ -135,7 +134,7 @@ const ColorDisc: Component<ColorDiscProps> = (props) => {
|
|
|
135
134
|
background: value().toString("css"),
|
|
136
135
|
"pointer-events": "none",
|
|
137
136
|
}}
|
|
138
|
-
|
|
137
|
+
on:keydown={onKeyDown}
|
|
139
138
|
/>
|
|
140
139
|
</div>
|
|
141
140
|
);
|
|
@@ -195,21 +194,21 @@ const TemperatureBar: Component<TemperatureBarProps> = (props) => {
|
|
|
195
194
|
props.class,
|
|
196
195
|
)}
|
|
197
196
|
style={gradient()}
|
|
198
|
-
|
|
197
|
+
on:pointerdown={(e) => {
|
|
199
198
|
if (props.disabled || e.button !== 0) return;
|
|
200
199
|
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
201
200
|
setDragging(true);
|
|
202
201
|
props.onChange?.(kelvinAt(e, e.currentTarget));
|
|
203
202
|
}}
|
|
204
|
-
|
|
203
|
+
on:pointermove={(e) => {
|
|
205
204
|
if (dragging()) props.onChange?.(kelvinAt(e, e.currentTarget));
|
|
206
205
|
}}
|
|
207
|
-
|
|
206
|
+
on:pointerup={(e) => {
|
|
208
207
|
if (!dragging()) return;
|
|
209
208
|
setDragging(false);
|
|
210
209
|
props.onChangeEnd?.(kelvinAt(e, e.currentTarget));
|
|
211
210
|
}}
|
|
212
|
-
|
|
211
|
+
on:pointercancel={() => {
|
|
213
212
|
if (!dragging()) return;
|
|
214
213
|
setDragging(false);
|
|
215
214
|
if (last !== undefined) props.onChangeEnd?.(last);
|
|
@@ -236,7 +235,7 @@ const TemperatureBar: Component<TemperatureBarProps> = (props) => {
|
|
|
236
235
|
translate: "-50% -50%",
|
|
237
236
|
background: kelvinToCss(props.value),
|
|
238
237
|
}}
|
|
239
|
-
|
|
238
|
+
on:keydown={(e) => {
|
|
240
239
|
const step = e.shiftKey ? 500 : 100;
|
|
241
240
|
const d = e.key === "ArrowRight" ? step : e.key === "ArrowLeft" ? -step : 0;
|
|
242
241
|
if (!d || props.disabled) return;
|