@glasshome/ui 1.41.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/SPEC.md +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/anchor-placement.d.ts +34 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +26 -0
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +32 -0
- package/dist/lib/behavior/controllable.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +13 -0
- package/dist/lib/behavior/focus-scope.d.ts +24 -0
- package/dist/lib/behavior/hide-outside.d.ts +7 -0
- package/dist/lib/behavior/layer-stack.d.ts +34 -0
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +68 -0
- package/dist/lib/behavior/polymorphic.d.ts +6 -0
- package/dist/lib/behavior/presence.d.ts +18 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/behavior/solid.d.ts +13 -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 +5 -2
- package/dist/lib/overlay-classes.d.ts +4 -0
- package/dist/lib/page-cover.d.ts +8 -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 -43
- 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/alert-dialog.d.ts +5 -8
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
- package/dist/solid/bottom-sheet/constants.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 +53 -16
- package/dist/solid/dialog.d.ts +7 -10
- 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 +5 -2
- package/dist/solid/index.js +8671 -14317
- 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 +3 -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 +6 -9
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/stale-veil.d.ts +7 -0
- package/dist/solid/tabs.d.ts +28 -9
- package/dist/solid/toggle-group.d.ts +30 -5
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +71 -9
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
- package/package.json +6 -7
- package/src/index.ts +1 -0
- package/src/lib/anchor-placement.ts +77 -4
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +106 -0
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +218 -0
- package/src/lib/behavior/controllable.ts +22 -0
- package/src/lib/behavior/dismiss.ts +185 -0
- package/src/lib/behavior/focus-scope.ts +227 -0
- package/src/lib/behavior/hide-outside.ts +85 -0
- package/src/lib/behavior/layer-stack.ts +150 -0
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +452 -0
- package/src/lib/behavior/polymorphic.tsx +30 -0
- package/src/lib/behavior/presence.ts +89 -0
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/behavior/solid.ts +30 -0
- package/src/lib/clipboard.ts +4 -4
- 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 +33 -8
- package/src/lib/overlay-classes.ts +8 -3
- package/src/lib/page-cover.ts +47 -0
- 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 -136
- 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/alert-dialog.tsx +36 -85
- package/src/solid/area-picker.tsx +5 -3
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/badge.tsx +5 -5
- package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
- package/src/solid/bottom-sheet/constants.ts +3 -1
- package/src/solid/bottom-sheet/drag-controller.ts +11 -0
- package/src/solid/breadcrumb.tsx +4 -4
- package/src/solid/button-group.tsx +4 -4
- package/src/solid/button.tsx +12 -6
- package/src/solid/card.tsx +5 -4
- 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 +287 -86
- package/src/solid/dialog-parts.tsx +135 -46
- package/src/solid/dialog.tsx +44 -76
- package/src/solid/dock-edit.tsx +5 -4
- package/src/solid/dock.tsx +6 -5
- package/src/solid/dropdown-menu.tsx +252 -107
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +5 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +9 -9
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +288 -21
- package/src/solid/icon-picker.tsx +2 -1
- package/src/solid/image-picker.tsx +6 -5
- package/src/solid/index.ts +5 -4
- package/src/solid/input-group.tsx +7 -5
- package/src/solid/input-otp.tsx +2 -1
- package/src/solid/item.tsx +5 -5
- package/src/solid/logo.tsx +5 -4
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +10 -5
- package/src/solid/picker-search.tsx +2 -1
- package/src/solid/popover.tsx +424 -71
- 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 +10 -10
- 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 +48 -80
- 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/spotlight.tsx +23 -11
- package/src/solid/stale-veil.tsx +20 -0
- package/src/solid/switch.tsx +8 -6
- package/src/solid/tabs.tsx +377 -52
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +237 -95
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +285 -26
- package/src/styles/globals.css +64 -10
- package/src/styles/theme.css +12 -4
- package/src/tokens/material.ts +11 -2
- package/dist/lib/when-animations-settle.d.ts +0 -4
- package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
- package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
- package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
- package/src/lib/when-animations-settle.ts +0 -12
- package/src/solid/bottom-sheet/focus-trap.ts +0 -63
- package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
- package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
|
@@ -1,145 +1,287 @@
|
|
|
1
|
-
import { ToggleGroup as ToggleGroupPrimitive } from "@kobalte/core/toggle-group";
|
|
2
1
|
import type { VariantProps } from "cva";
|
|
3
2
|
import {
|
|
3
|
+
type Accessor,
|
|
4
|
+
children,
|
|
4
5
|
type Component,
|
|
5
6
|
type ComponentProps,
|
|
6
7
|
createContext,
|
|
7
|
-
|
|
8
|
+
createSignal,
|
|
9
|
+
type JSX,
|
|
8
10
|
onCleanup,
|
|
9
11
|
onMount,
|
|
12
|
+
type ParentComponent,
|
|
10
13
|
Show,
|
|
11
14
|
splitProps,
|
|
12
15
|
useContext,
|
|
16
|
+
type ValidComponent,
|
|
13
17
|
} from "solid-js";
|
|
14
|
-
import {
|
|
18
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
19
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
20
|
+
import { merge, omit } from "../lib/behavior/solid.js";
|
|
21
|
+
import { BALANCE_CONTENT, BALANCED_ROWS, balanceRows } from "../lib/balance-rows.js";
|
|
15
22
|
import { TRACK_SURFACE } from "../lib/card-classes.js";
|
|
16
23
|
import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
24
|
+
import { SEGMENT_RADIUS } from "../lib/segment-classes.js";
|
|
25
|
+
import { createToggleItem, createToggleSet, type ToggleSet } from "../lib/toggle-set.js";
|
|
17
26
|
import { cn } from "../lib/utils.js";
|
|
18
27
|
import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
19
28
|
import { toggleVariants } from "./toggle.js";
|
|
20
29
|
|
|
30
|
+
type Orientation = "horizontal" | "vertical";
|
|
31
|
+
|
|
32
|
+
type SingleSelection = {
|
|
33
|
+
multiple?: false;
|
|
34
|
+
value?: string | null;
|
|
35
|
+
defaultValue?: string | null;
|
|
36
|
+
onChange?: (value: string | null) => void;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type MultipleSelection = {
|
|
40
|
+
multiple: true;
|
|
41
|
+
value?: string[];
|
|
42
|
+
defaultValue?: string[];
|
|
43
|
+
onChange?: (value: string[]) => void;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type ToggleGroupProps = Omit<ComponentProps<"div">, "onChange"> &
|
|
47
|
+
VariantProps<typeof toggleVariants> &
|
|
48
|
+
(SingleSelection | MultipleSelection) & {
|
|
49
|
+
as?: ValidComponent;
|
|
50
|
+
orientation?: Orientation;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
/** CSS colour for the selected segment's glass. Default `var(--material-accent)`. */
|
|
53
|
+
tone?: string;
|
|
54
|
+
/** One row that scrolls sideways when it outgrows its container, instead of wrapping. */
|
|
55
|
+
scroll?: boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
21
58
|
// Single-select paints the pressed segment with the selection highlight; multi-select has none.
|
|
22
|
-
type ToggleGroupContextValue = VariantProps<typeof toggleVariants> & {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
type ToggleGroupContextValue = VariantProps<typeof toggleVariants> & {
|
|
60
|
+
sliding: boolean;
|
|
61
|
+
disabled: Accessor<boolean>;
|
|
62
|
+
set: ToggleSet;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const ToggleGroupContext = createContext<ToggleGroupContextValue | null>(null);
|
|
66
|
+
|
|
67
|
+
const useToggleGroup = (): ToggleGroupContextValue => {
|
|
68
|
+
const ctx = useContext(ToggleGroupContext);
|
|
69
|
+
if (!ctx) throw new Error("ToggleGroupItem renders inside a ToggleGroup");
|
|
70
|
+
return ctx;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const ITEM = '[data-slot="toggle-group-item"]';
|
|
74
|
+
|
|
75
|
+
const toList = (value: string | string[] | null | undefined): string[] | undefined => {
|
|
76
|
+
if (value === undefined) return undefined;
|
|
77
|
+
if (value === null) return [];
|
|
78
|
+
return typeof value === "string" ? [value] : value;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const sameList = (a: string[], b: string[]) =>
|
|
82
|
+
a.length === b.length && a.every((v, i) => v === b[i]);
|
|
83
|
+
|
|
84
|
+
const ToggleGroup: ParentComponent<ToggleGroupProps> = (props) => {
|
|
85
|
+
const rest = omit(
|
|
86
|
+
props,
|
|
40
87
|
"class",
|
|
41
88
|
"variant",
|
|
42
89
|
"size",
|
|
43
90
|
"tone",
|
|
44
91
|
"scroll",
|
|
45
92
|
"children",
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
93
|
+
"value",
|
|
94
|
+
"defaultValue",
|
|
95
|
+
"onChange",
|
|
96
|
+
"multiple",
|
|
97
|
+
"orientation",
|
|
98
|
+
"disabled",
|
|
99
|
+
"id",
|
|
100
|
+
"ref",
|
|
101
|
+
"as",
|
|
102
|
+
);
|
|
103
|
+
const sliding = () => !props.multiple;
|
|
104
|
+
const orientation = () => props.orientation ?? "horizontal";
|
|
105
|
+
const vertical = () => orientation() === "vertical";
|
|
106
|
+
const [values, setValues] = createControllableSignal<string[]>({
|
|
107
|
+
value: () => toList(props.value),
|
|
108
|
+
defaultValue: () => toList(props.defaultValue) ?? [],
|
|
109
|
+
equals: sameList,
|
|
110
|
+
onChange: (next) => {
|
|
111
|
+
if (props.multiple) props.onChange?.(next);
|
|
112
|
+
else props.onChange?.(next[0] ?? null);
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
const [root, setRoot] = createSignal<HTMLElement>();
|
|
116
|
+
const [scope, setScope] = createSignal<HTMLElement>();
|
|
117
|
+
const set = createToggleSet({
|
|
118
|
+
root,
|
|
119
|
+
itemSelector: `${ITEM}[data-key]`,
|
|
120
|
+
values,
|
|
121
|
+
setValues,
|
|
122
|
+
multiple: () => props.multiple ?? false,
|
|
123
|
+
orientation,
|
|
124
|
+
id: () => props.id,
|
|
125
|
+
});
|
|
126
|
+
|
|
55
127
|
onMount(() => {
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
128
|
+
const el = root();
|
|
129
|
+
if (!el) return;
|
|
130
|
+
if (props.scroll) onCleanup(trackScroll(el, "[data-pressed]", values));
|
|
131
|
+
else if (!vertical()) onCleanup(balanceRows(el, scope() ?? el, ITEM, set.members));
|
|
60
132
|
});
|
|
133
|
+
|
|
134
|
+
const context: ToggleGroupContextValue = {
|
|
135
|
+
get variant() {
|
|
136
|
+
return props.variant;
|
|
137
|
+
},
|
|
138
|
+
get size() {
|
|
139
|
+
return props.size;
|
|
140
|
+
},
|
|
141
|
+
get sliding() {
|
|
142
|
+
return sliding();
|
|
143
|
+
},
|
|
144
|
+
disabled: () => props.disabled ?? false,
|
|
145
|
+
set,
|
|
146
|
+
};
|
|
147
|
+
|
|
61
148
|
return (
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
149
|
+
<Polymorphic
|
|
150
|
+
{...merge({ "data-slot": "toggle-group" }, rest, {
|
|
151
|
+
as: props.as,
|
|
152
|
+
defaultAs: "div" as ValidComponent,
|
|
153
|
+
ref: (el: HTMLElement) => {
|
|
154
|
+
setRoot(el);
|
|
155
|
+
if (typeof props.ref === "function") props.ref(el as HTMLDivElement);
|
|
156
|
+
},
|
|
157
|
+
role: "group",
|
|
158
|
+
get id() {
|
|
159
|
+
return set.id();
|
|
160
|
+
},
|
|
161
|
+
get "data-orientation"() {
|
|
162
|
+
return orientation();
|
|
163
|
+
},
|
|
164
|
+
get "data-variant"() {
|
|
165
|
+
return props.variant;
|
|
166
|
+
},
|
|
167
|
+
get "data-size"() {
|
|
168
|
+
return props.size;
|
|
169
|
+
},
|
|
170
|
+
get "data-scroll"() {
|
|
171
|
+
return props.scroll ? "" : undefined;
|
|
172
|
+
},
|
|
173
|
+
get [BALANCED_ROWS]() {
|
|
174
|
+
return props.scroll || vertical() || sliding() ? undefined : "";
|
|
175
|
+
},
|
|
176
|
+
"on:keydown": (event: KeyboardEvent) => set.collection.onKeyDown(event),
|
|
177
|
+
get class() {
|
|
178
|
+
return cn(
|
|
179
|
+
`group/toggle-group w-fit max-w-full items-center gap-y-1 rounded-lg data-[wrapped]:w-full ${TRACK_SURFACE} p-1 data-[variant=outline]:shadow-xs`,
|
|
180
|
+
props.scroll
|
|
181
|
+
? `flex [scrollbar-width:none] flex-nowrap overflow-x-auto ${SCROLL_TRACK_FADE}`
|
|
182
|
+
: vertical()
|
|
183
|
+
? "flex flex-col items-stretch"
|
|
184
|
+
: sliding()
|
|
185
|
+
? "flex"
|
|
186
|
+
: undefined,
|
|
187
|
+
props.class,
|
|
188
|
+
);
|
|
189
|
+
},
|
|
190
|
+
})}
|
|
80
191
|
>
|
|
81
|
-
<ToggleGroupContext.Provider
|
|
82
|
-
|
|
83
|
-
>
|
|
84
|
-
<Show when={sliding()} fallback={local.children}>
|
|
192
|
+
<ToggleGroupContext.Provider value={context}>
|
|
193
|
+
<Show when={sliding()} fallback={props.children}>
|
|
85
194
|
{/* w-full, not w-fit: a shrink-to-fit root still sizes to content, and a
|
|
86
195
|
`class="w-full"` root can finally let its items share the width. */}
|
|
87
196
|
<SelectionScope
|
|
88
|
-
ref={
|
|
197
|
+
ref={setScope}
|
|
89
198
|
marker="pressed"
|
|
90
|
-
|
|
199
|
+
radius={SEGMENT_RADIUS}
|
|
200
|
+
tone={props.tone}
|
|
201
|
+
{...{ [BALANCED_ROWS]: props.scroll || vertical() ? undefined : "" }}
|
|
91
202
|
class={
|
|
92
|
-
|
|
203
|
+
props.scroll
|
|
93
204
|
? "flex w-max flex-nowrap items-center"
|
|
94
205
|
: vertical()
|
|
95
206
|
? "flex w-full flex-col items-stretch gap-y-0.5"
|
|
96
|
-
:
|
|
207
|
+
: "w-full items-center gap-y-1"
|
|
97
208
|
}
|
|
98
209
|
>
|
|
99
|
-
{
|
|
210
|
+
{props.children}
|
|
100
211
|
</SelectionScope>
|
|
101
212
|
</Show>
|
|
102
213
|
</ToggleGroupContext.Provider>
|
|
103
|
-
</
|
|
214
|
+
</Polymorphic>
|
|
104
215
|
);
|
|
105
216
|
};
|
|
106
217
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
218
|
+
type ToggleGroupItemState = { pressed: Accessor<boolean> };
|
|
219
|
+
|
|
220
|
+
type ToggleGroupItemProps = Omit<ComponentProps<"button">, "children"> &
|
|
221
|
+
VariantProps<typeof toggleVariants> & {
|
|
222
|
+
as?: ValidComponent;
|
|
223
|
+
value: string;
|
|
224
|
+
disabled?: boolean;
|
|
225
|
+
children?: JSX.Element | ((state: ToggleGroupItemState) => JSX.Element);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const ToggleGroupItem: Component<ToggleGroupItemProps> = (props) => {
|
|
229
|
+
const context = useToggleGroup();
|
|
230
|
+
const [local, rest] = splitProps(props, [
|
|
231
|
+
"class",
|
|
232
|
+
"variant",
|
|
233
|
+
"size",
|
|
234
|
+
"children",
|
|
235
|
+
"value",
|
|
236
|
+
"disabled",
|
|
237
|
+
"id",
|
|
238
|
+
"ref",
|
|
239
|
+
"as",
|
|
240
|
+
]);
|
|
241
|
+
const disabled = () => local.disabled || context.disabled();
|
|
242
|
+
const item = createToggleItem(context.set, { value: () => local.value, disabled });
|
|
243
|
+
const content = children(() => {
|
|
244
|
+
const body = local.children;
|
|
245
|
+
return typeof body === "function" ? body({ pressed: item.pressed }) : body;
|
|
246
|
+
});
|
|
112
247
|
|
|
113
248
|
return (
|
|
114
|
-
<
|
|
115
|
-
data-slot
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
249
|
+
<Polymorphic
|
|
250
|
+
{...merge({ "data-slot": "toggle-group-item" }, rest, item.props, {
|
|
251
|
+
as: local.as,
|
|
252
|
+
defaultAs: "button" as ValidComponent,
|
|
253
|
+
ref: (node: HTMLElement) => {
|
|
254
|
+
item.ref(node);
|
|
255
|
+
if (typeof local.ref === "function") local.ref(node as HTMLButtonElement);
|
|
256
|
+
},
|
|
257
|
+
get id() {
|
|
258
|
+
return local.id ?? item.props.id;
|
|
259
|
+
},
|
|
260
|
+
get "data-variant"() {
|
|
261
|
+
return context.variant || local.variant;
|
|
262
|
+
},
|
|
263
|
+
get "data-size"() {
|
|
264
|
+
return context.size || local.size;
|
|
265
|
+
},
|
|
266
|
+
get class() {
|
|
267
|
+
return cn(
|
|
268
|
+
toggleVariants({
|
|
269
|
+
variant: context.variant || local.variant,
|
|
270
|
+
size: context.size || local.size,
|
|
271
|
+
}),
|
|
272
|
+
"relative isolate min-w-max flex-1 shrink-0 rounded-md px-4 shadow-none focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first-of-type:border-l",
|
|
273
|
+
// A hover fill would read as a second, squarer selection, so hover only tints the text.
|
|
274
|
+
context.sliding
|
|
275
|
+
? "hover:text-(--material-accent)"
|
|
276
|
+
: "data-[pressed]:bg-muted data-[pressed]:text-foreground not-data-[pressed]:hover:text-(--material-accent)",
|
|
277
|
+
local.class,
|
|
278
|
+
);
|
|
279
|
+
},
|
|
280
|
+
})}
|
|
131
281
|
>
|
|
132
|
-
{(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<>
|
|
137
|
-
<SelectionHighlight />
|
|
138
|
-
{typeof content === "function" ? content(state) : content}
|
|
139
|
-
</>
|
|
140
|
-
);
|
|
141
|
-
}}
|
|
142
|
-
</ToggleGroupPrimitive.Item>
|
|
282
|
+
<SelectionHighlight active={item.pressed()} />
|
|
283
|
+
<span {...{ [BALANCE_CONTENT]: "" }}>{content()}</span>
|
|
284
|
+
</Polymorphic>
|
|
143
285
|
);
|
|
144
286
|
};
|
|
145
287
|
|
package/src/solid/toggle.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ToggleButton as ToggleButtonPrimitive } from "@kobalte/core/toggle-button";
|
|
2
1
|
import { cva, type VariantProps } from "cva";
|
|
3
|
-
import { type
|
|
2
|
+
import { type Accessor, children, type JSX, splitProps } from "solid-js";
|
|
3
|
+
import { ButtonRoot, type ButtonRootProps } from "../lib/behavior/button-root.js";
|
|
4
|
+
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
5
|
+
import { callEventHandler } from "../lib/behavior/solid.js";
|
|
4
6
|
import { OUTLINE_SURFACE } from "../lib/button-variants.js";
|
|
5
7
|
import { CONTROL_H } from "../lib/input-classes.js";
|
|
6
8
|
import { SEGMENT_ITEM } from "../lib/segment-classes.js";
|
|
@@ -36,13 +38,39 @@ const TOGGLE_HOVER: Record<"default" | "outline", string> = {
|
|
|
36
38
|
outline: "",
|
|
37
39
|
};
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
type ToggleProps = Omit<ButtonRootProps<"button">, "children" | "onChange"> &
|
|
42
|
+
VariantProps<typeof toggleVariants> & {
|
|
43
|
+
pressed?: boolean;
|
|
44
|
+
defaultPressed?: boolean;
|
|
45
|
+
onChange?: (pressed: boolean) => void;
|
|
46
|
+
children?: JSX.Element | ((state: { pressed: Accessor<boolean> }) => JSX.Element);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function Toggle(props: ToggleProps) {
|
|
50
|
+
const [local, rest] = splitProps(props, [
|
|
51
|
+
"class",
|
|
52
|
+
"variant",
|
|
53
|
+
"size",
|
|
54
|
+
"pressed",
|
|
55
|
+
"defaultPressed",
|
|
56
|
+
"onChange",
|
|
57
|
+
"onClick",
|
|
58
|
+
"children",
|
|
59
|
+
]);
|
|
60
|
+
const [pressed, setPressed] = createControllableSignal({
|
|
61
|
+
value: () => local.pressed,
|
|
62
|
+
defaultValue: () => local.defaultPressed ?? false,
|
|
63
|
+
onChange: (next) => local.onChange?.(next),
|
|
64
|
+
});
|
|
65
|
+
const content = children(() => {
|
|
66
|
+
const body = local.children;
|
|
67
|
+
return typeof body === "function" ? body({ pressed }) : body;
|
|
68
|
+
});
|
|
43
69
|
return (
|
|
44
|
-
<
|
|
70
|
+
<ButtonRoot
|
|
45
71
|
data-slot="toggle"
|
|
72
|
+
aria-pressed={pressed()}
|
|
73
|
+
data-pressed={pressed() ? "" : undefined}
|
|
46
74
|
class={cn(
|
|
47
75
|
toggleVariants({ variant: local.variant, size: local.size }),
|
|
48
76
|
TOGGLE_HOVER[local.variant ?? "default"],
|
|
@@ -50,8 +78,14 @@ const Toggle: Component<
|
|
|
50
78
|
local.class,
|
|
51
79
|
)}
|
|
52
80
|
{...rest}
|
|
53
|
-
|
|
81
|
+
onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
|
|
82
|
+
callEventHandler(event, local.onClick);
|
|
83
|
+
if (!rest.disabled) setPressed(!pressed());
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
{content()}
|
|
87
|
+
</ButtonRoot>
|
|
54
88
|
);
|
|
55
|
-
}
|
|
89
|
+
}
|
|
56
90
|
|
|
57
91
|
export { Toggle, toggleVariants };
|