@glasshome/ui 1.10.0 → 1.11.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 +7 -0
- package/dist/index.js +1 -1
- package/dist/lib/menu-classes.d.ts +2 -2
- package/dist/solid/icon.d.ts +18 -12
- package/dist/solid/index.d.ts +1 -0
- package/dist/solid/index.js +3692 -3490
- package/dist/{utils-CIwpbaOd.js → utils-CdUh67Y9.js} +1 -1
- package/package.json +7 -3
- package/scripts/check-pack.ts +32 -0
- package/src/index.ts +111 -0
- package/src/lib/menu-classes.ts +1 -1
- package/src/solid/accordion.tsx +60 -0
- package/src/solid/alert-dialog.tsx +148 -0
- package/src/solid/alert.tsx +118 -0
- package/src/solid/area-picker.tsx +225 -0
- package/src/solid/aspect-ratio.tsx +21 -0
- package/src/solid/avatar.tsx +41 -0
- package/src/solid/badge.tsx +74 -0
- package/src/solid/bottom-sheet/arbitration.ts +40 -0
- package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
- package/src/solid/bottom-sheet/constants.ts +8 -0
- package/src/solid/bottom-sheet/drag-controller.ts +221 -0
- package/src/solid/bottom-sheet/focus-trap.ts +56 -0
- package/src/solid/bottom-sheet/index.ts +14 -0
- package/src/solid/bottom-sheet/keyboard.ts +35 -0
- package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
- package/src/solid/bottom-sheet/state-machine.ts +40 -0
- package/src/solid/bottom-sheet/velocity.ts +42 -0
- package/src/solid/breadcrumb.tsx +105 -0
- package/src/solid/button-group.tsx +66 -0
- package/src/solid/button.tsx +20 -0
- package/src/solid/card.tsx +101 -0
- package/src/solid/carousel.tsx +302 -0
- package/src/solid/charts.tsx +338 -0
- package/src/solid/checkbox.tsx +70 -0
- package/src/solid/collapsible.tsx +38 -0
- package/src/solid/color-slider.tsx +98 -0
- package/src/solid/color-wheel.tsx +77 -0
- package/src/solid/context-menu.tsx +109 -0
- package/src/solid/copy-button.tsx +46 -0
- package/src/solid/count-pill.tsx +24 -0
- package/src/solid/data-table.tsx +248 -0
- package/src/solid/dialog-parts.tsx +242 -0
- package/src/solid/dialog.tsx +121 -0
- package/src/solid/dock.tsx +186 -0
- package/src/solid/dropdown-menu.tsx +130 -0
- package/src/solid/empty.tsx +99 -0
- package/src/solid/entity-data.ts +78 -0
- package/src/solid/entity-selector.tsx +697 -0
- package/src/solid/field.tsx +253 -0
- package/src/solid/form.tsx +231 -0
- package/src/solid/hero-action.tsx +117 -0
- package/src/solid/hover-card.tsx +26 -0
- package/src/solid/icon-picker.tsx +432 -0
- package/src/solid/icon.tsx +126 -0
- package/src/solid/image-picker.tsx +380 -0
- package/src/solid/index.ts +413 -0
- package/src/solid/input-group.tsx +170 -0
- package/src/solid/input-otp.tsx +175 -0
- package/src/solid/input.tsx +12 -0
- package/src/solid/item.tsx +179 -0
- package/src/solid/kbd.tsx +30 -0
- package/src/solid/label.tsx +19 -0
- package/src/solid/list-reorder.ts +148 -0
- package/src/solid/logo.tsx +79 -0
- package/src/solid/media-copy.ts +37 -0
- package/src/solid/media-store.ts +110 -0
- package/src/solid/media-tile.tsx +100 -0
- package/src/solid/menu-parts.tsx +248 -0
- package/src/solid/number-field.tsx +72 -0
- package/src/solid/option-card.tsx +218 -0
- package/src/solid/ornament.tsx +53 -0
- package/src/solid/overlay.tsx +16 -0
- package/src/solid/page-header.tsx +102 -0
- package/src/solid/pagination.tsx +111 -0
- package/src/solid/password-input.tsx +69 -0
- package/src/solid/picker-row.tsx +102 -0
- package/src/solid/picker-search.tsx +78 -0
- package/src/solid/popover.tsx +103 -0
- package/src/solid/progress.tsx +31 -0
- package/src/solid/radio-group.tsx +60 -0
- package/src/solid/resizable.tsx +149 -0
- package/src/solid/responsive-dialog.tsx +180 -0
- package/src/solid/schema-form.tsx +830 -0
- package/src/solid/scope-indicator.tsx +13 -0
- package/src/solid/scroll-area.tsx +27 -0
- package/src/solid/section-card.tsx +358 -0
- package/src/solid/select.tsx +139 -0
- package/src/solid/separator.tsx +35 -0
- package/src/solid/settings-row.tsx +159 -0
- package/src/solid/sheet.tsx +157 -0
- package/src/solid/skeleton.tsx +15 -0
- package/src/solid/slider.tsx +148 -0
- package/src/solid/sliding-indicator.tsx +294 -0
- package/src/solid/sonner.tsx +217 -0
- package/src/solid/spinner.tsx +20 -0
- package/src/solid/step-indicator.tsx +30 -0
- package/src/solid/switch.tsx +62 -0
- package/src/solid/table.tsx +98 -0
- package/src/solid/tabs.tsx +86 -0
- package/src/solid/textarea.tsx +16 -0
- package/src/solid/toggle-group.tsx +102 -0
- package/src/solid/toggle.tsx +57 -0
- package/src/solid/tooltip.tsx +38 -0
- package/src/solid/widget-card.tsx +117 -0
- package/src/solid/widget-identity.tsx +135 -0
- package/src/solid/widget-trust-badge.tsx +37 -0
- package/src/styles/globals.css +7 -0
- package/src/styles/theme.css +8 -0
- package/src/tokens/hex.ts +50 -0
- package/src/tokens/index.ts +8 -0
- package/src/tokens/presets.ts +192 -0
- package/src/tokens/theme-colors.ts +147 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "cva";
|
|
2
|
+
import {
|
|
3
|
+
type Component,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
createMemo,
|
|
6
|
+
For,
|
|
7
|
+
type ParentComponent,
|
|
8
|
+
Show,
|
|
9
|
+
splitProps,
|
|
10
|
+
} from "solid-js";
|
|
11
|
+
import { cn } from "../lib/utils.js";
|
|
12
|
+
import { Label } from "./label.js";
|
|
13
|
+
import { Separator } from "./separator.js";
|
|
14
|
+
|
|
15
|
+
const FieldSet: Component<ComponentProps<"fieldset">> = (props) => {
|
|
16
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
17
|
+
return (
|
|
18
|
+
<fieldset
|
|
19
|
+
data-slot="field-set"
|
|
20
|
+
class={cn(
|
|
21
|
+
// min-w-0: a native <fieldset> computes its own min-content width
|
|
22
|
+
// from its widest child and ignores descendant min-w-0 overrides,
|
|
23
|
+
// so wide unwrapped content (a card title) can push it past a flex
|
|
24
|
+
// parent's width instead of shrinking with it.
|
|
25
|
+
// [&>legend]: the rendered legend is not a flex item, so the gap
|
|
26
|
+
// above cannot reach it; the container still owns that distance.
|
|
27
|
+
"flex min-w-0 flex-col gap-4 [&>legend]:mb-4",
|
|
28
|
+
local.class,
|
|
29
|
+
)}
|
|
30
|
+
{...rest}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const FieldLegend: Component<ComponentProps<"legend"> & { variant?: "legend" | "label" }> = (
|
|
36
|
+
props,
|
|
37
|
+
) => {
|
|
38
|
+
const [local, rest] = splitProps(props, ["class", "variant"] as const);
|
|
39
|
+
const variant = () => local.variant ?? "legend";
|
|
40
|
+
return (
|
|
41
|
+
<legend
|
|
42
|
+
data-slot="field-legend"
|
|
43
|
+
data-variant={variant()}
|
|
44
|
+
class={cn(
|
|
45
|
+
"leading-tight",
|
|
46
|
+
"data-[variant=legend]:font-semibold data-[variant=legend]:text-base",
|
|
47
|
+
"data-[variant=label]:font-medium data-[variant=label]:text-sm",
|
|
48
|
+
local.class,
|
|
49
|
+
)}
|
|
50
|
+
{...rest}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const FieldGroup: Component<ComponentProps<"div">> = (props) => {
|
|
56
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
data-slot="field-group"
|
|
60
|
+
class={cn("group/field-group @container/field-group flex w-full flex-col gap-6", local.class)}
|
|
61
|
+
{...rest}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const fieldVariants = cva({
|
|
67
|
+
base: "group/field flex w-full data-[invalid=true]:text-destructive",
|
|
68
|
+
variants: {
|
|
69
|
+
orientation: {
|
|
70
|
+
vertical: ["flex-col gap-2 [&>*]:w-full [&>.sr-only]:w-auto"],
|
|
71
|
+
horizontal: [
|
|
72
|
+
// A stack of content tops out against the control; a single-line
|
|
73
|
+
// caption row centres on it.
|
|
74
|
+
"flex-row items-start not-has-[>[data-slot=field-content]]:items-center gap-3",
|
|
75
|
+
"[&>[data-slot=field-label]]:flex-auto [&>[data-slot=field-title]]:flex-auto",
|
|
76
|
+
],
|
|
77
|
+
responsive: [
|
|
78
|
+
"@md/field-group:flex-row flex-col @md/field-group:items-start @md/field-group:gap-3 gap-2 @md/field-group:[&>*]:w-auto [&>*]:w-full [&>.sr-only]:w-auto",
|
|
79
|
+
"@md/field-group:not-has-[>[data-slot=field-content]]:items-center",
|
|
80
|
+
"@md/field-group:[&>[data-slot=field-label]]:flex-auto @md/field-group:[&>[data-slot=field-title]]:flex-auto",
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
defaultVariants: {
|
|
85
|
+
orientation: "vertical",
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const Field: Component<ComponentProps<"div"> & VariantProps<typeof fieldVariants>> = (props) => {
|
|
90
|
+
const [local, rest] = splitProps(props, ["class", "orientation"] as const);
|
|
91
|
+
const orientation = () => local.orientation ?? "vertical";
|
|
92
|
+
return (
|
|
93
|
+
// biome-ignore lint/a11y/useSemanticElements: fieldset would carry default browser styling and break the flex layout; role=group conveys the same semantics.
|
|
94
|
+
<div
|
|
95
|
+
role="group"
|
|
96
|
+
data-slot="field"
|
|
97
|
+
data-orientation={orientation()}
|
|
98
|
+
class={cn(fieldVariants({ orientation: orientation() }), local.class)}
|
|
99
|
+
{...rest}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const FieldContent: Component<ComponentProps<"div">> = (props) => {
|
|
105
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
data-slot="field-content"
|
|
109
|
+
class={cn("group/field-content flex flex-1 flex-col gap-1.5 leading-snug", local.class)}
|
|
110
|
+
{...rest}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const FieldLabel: Component<ComponentProps<typeof Label>> = (props) => {
|
|
116
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
117
|
+
return (
|
|
118
|
+
<Label
|
|
119
|
+
data-slot="field-label"
|
|
120
|
+
class={cn(
|
|
121
|
+
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
|
|
122
|
+
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4",
|
|
123
|
+
// Card-shaped labels only: a plain checkbox label wraps a checked control
|
|
124
|
+
// too, and would take the whole tint with it.
|
|
125
|
+
"has-[>[data-slot=field]]:has-data-[checked]:border-primary has-[>[data-slot=field]]:has-data-[checked]:bg-primary/5 dark:has-[>[data-slot=field]]:has-data-[checked]:bg-primary/10",
|
|
126
|
+
local.class,
|
|
127
|
+
)}
|
|
128
|
+
{...rest}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const FieldTitle: Component<ComponentProps<"div">> = (props) => {
|
|
134
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
135
|
+
return (
|
|
136
|
+
<div
|
|
137
|
+
data-slot="field-title"
|
|
138
|
+
class={cn(
|
|
139
|
+
"flex w-fit items-center gap-2 font-medium text-sm leading-snug group-data-[disabled=true]/field:opacity-50",
|
|
140
|
+
local.class,
|
|
141
|
+
)}
|
|
142
|
+
{...rest}
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const FieldDescription: Component<ComponentProps<"p">> = (props) => {
|
|
148
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
149
|
+
return (
|
|
150
|
+
<p
|
|
151
|
+
data-slot="field-description"
|
|
152
|
+
class={cn(
|
|
153
|
+
"font-normal text-muted-foreground text-sm leading-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
|
|
154
|
+
// Dims with its title, else a disabled row reads as description-first.
|
|
155
|
+
"group-data-[disabled=true]/field:opacity-50",
|
|
156
|
+
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
|
157
|
+
local.class,
|
|
158
|
+
)}
|
|
159
|
+
{...rest}
|
|
160
|
+
/>
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/** Rows that belong to the control above them: stacked flush, grouped by proximity alone. */
|
|
165
|
+
const FieldSubGroup: Component<ComponentProps<"div">> = (props) => {
|
|
166
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
167
|
+
return (
|
|
168
|
+
<div data-slot="field-sub-group" class={cn("flex flex-col gap-1", local.class)} {...rest} />
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const FieldSeparator: ParentComponent<ComponentProps<"div">> = (props) => {
|
|
173
|
+
const [local, rest] = splitProps(props, ["children", "class"]);
|
|
174
|
+
return (
|
|
175
|
+
<div
|
|
176
|
+
data-slot="field-separator"
|
|
177
|
+
data-content={!!local.children}
|
|
178
|
+
class={cn("relative h-5 text-sm", local.class)}
|
|
179
|
+
{...rest}
|
|
180
|
+
>
|
|
181
|
+
<Separator class="absolute inset-0 top-1/2" />
|
|
182
|
+
<Show when={local.children}>
|
|
183
|
+
<span
|
|
184
|
+
class="relative mx-auto block w-fit bg-card px-2 text-muted-foreground"
|
|
185
|
+
data-slot="field-separator-content"
|
|
186
|
+
>
|
|
187
|
+
{local.children}
|
|
188
|
+
</span>
|
|
189
|
+
</Show>
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const FieldError: Component<
|
|
195
|
+
ComponentProps<"div"> & {
|
|
196
|
+
errors?: Array<{ message?: string } | undefined>;
|
|
197
|
+
}
|
|
198
|
+
> = (props) => {
|
|
199
|
+
const [local, rest] = splitProps(props, ["class", "children", "errors"] as const);
|
|
200
|
+
|
|
201
|
+
const content = createMemo(() => {
|
|
202
|
+
if (local.children) {
|
|
203
|
+
return local.children;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (!local.errors?.length) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const uniqueErrors = [
|
|
211
|
+
...new Map(local.errors.map((error) => [error?.message, error])).values(),
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
if (uniqueErrors.length === 1) {
|
|
215
|
+
return uniqueErrors[0]?.message;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<ul class="flex list-disc flex-col gap-1 pl-4">
|
|
220
|
+
<For each={uniqueErrors}>
|
|
221
|
+
{(error) => <Show when={error?.message}>{(message) => <li>{message()}</li>}</Show>}
|
|
222
|
+
</For>
|
|
223
|
+
</ul>
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<Show when={content()}>
|
|
229
|
+
<div
|
|
230
|
+
role="alert"
|
|
231
|
+
data-slot="field-error"
|
|
232
|
+
class={cn("font-normal text-destructive text-sm", local.class)}
|
|
233
|
+
{...rest}
|
|
234
|
+
>
|
|
235
|
+
{content()}
|
|
236
|
+
</div>
|
|
237
|
+
</Show>
|
|
238
|
+
);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
Field,
|
|
243
|
+
FieldContent,
|
|
244
|
+
FieldDescription,
|
|
245
|
+
FieldError,
|
|
246
|
+
FieldGroup,
|
|
247
|
+
FieldLabel,
|
|
248
|
+
FieldLegend,
|
|
249
|
+
FieldSeparator,
|
|
250
|
+
FieldSet,
|
|
251
|
+
FieldSubGroup,
|
|
252
|
+
FieldTitle,
|
|
253
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Component,
|
|
3
|
+
type ComponentProps,
|
|
4
|
+
children,
|
|
5
|
+
createContext,
|
|
6
|
+
createEffect,
|
|
7
|
+
createMemo,
|
|
8
|
+
createSignal,
|
|
9
|
+
createUniqueId,
|
|
10
|
+
type JSX,
|
|
11
|
+
onCleanup,
|
|
12
|
+
onMount,
|
|
13
|
+
type ParentComponent,
|
|
14
|
+
Show,
|
|
15
|
+
splitProps,
|
|
16
|
+
useContext,
|
|
17
|
+
type ValidComponent,
|
|
18
|
+
} from "solid-js";
|
|
19
|
+
import { Dynamic } from "solid-js/web";
|
|
20
|
+
import { cn } from "../lib/utils.js";
|
|
21
|
+
import { Field, FieldDescription, FieldError, FieldLabel } from "./field.js";
|
|
22
|
+
import { Input } from "./input.js";
|
|
23
|
+
|
|
24
|
+
interface FormFieldContextValue {
|
|
25
|
+
name: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface FormItemContextValue {
|
|
29
|
+
id: string;
|
|
30
|
+
hasDescription: () => boolean;
|
|
31
|
+
setHasDescription: (value: boolean) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface FormContextValue {
|
|
35
|
+
errors: () => Record<string, string>;
|
|
36
|
+
setError: (name: string, error: string) => void;
|
|
37
|
+
clearError: (name: string) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const FormFieldContext = createContext<FormFieldContextValue>();
|
|
41
|
+
const FormItemContext = createContext<FormItemContextValue>();
|
|
42
|
+
const FormContext = createContext<FormContextValue>();
|
|
43
|
+
|
|
44
|
+
const Form: ParentComponent<
|
|
45
|
+
ComponentProps<"form"> & {
|
|
46
|
+
errors?: Record<string, string>;
|
|
47
|
+
onSetError?: (name: string, error: string) => void;
|
|
48
|
+
onClearError?: (name: string) => void;
|
|
49
|
+
}
|
|
50
|
+
> = (props) => {
|
|
51
|
+
const [local, rest] = splitProps(props, ["children", "errors", "onSetError", "onClearError"]);
|
|
52
|
+
const errors = () => local.errors ?? {};
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<FormContext.Provider
|
|
56
|
+
value={{
|
|
57
|
+
errors,
|
|
58
|
+
setError: (name, error) => local.onSetError?.(name, error),
|
|
59
|
+
clearError: (name) => local.onClearError?.(name),
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<form data-slot="form" {...rest}>
|
|
63
|
+
{local.children}
|
|
64
|
+
</form>
|
|
65
|
+
</FormContext.Provider>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function useFormField() {
|
|
70
|
+
const fieldContext = useContext(FormFieldContext);
|
|
71
|
+
const itemContext = useContext(FormItemContext);
|
|
72
|
+
const formContext = useContext(FormContext);
|
|
73
|
+
|
|
74
|
+
const id = () => itemContext?.id ?? "";
|
|
75
|
+
const name = () => fieldContext?.name ?? "";
|
|
76
|
+
const error = createMemo(() => formContext?.errors()[name()] ?? "");
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
id,
|
|
80
|
+
name,
|
|
81
|
+
hasDescription: () => itemContext?.hasDescription() ?? false,
|
|
82
|
+
formItemId: () => `${id()}-form-item`,
|
|
83
|
+
formDescriptionId: () => `${id()}-form-item-description`,
|
|
84
|
+
formMessageId: () => `${id()}-form-item-message`,
|
|
85
|
+
error,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const FormField: ParentComponent<{ name: string }> = (props) => {
|
|
90
|
+
return (
|
|
91
|
+
<FormFieldContext.Provider value={{ name: props.name }}>
|
|
92
|
+
{props.children}
|
|
93
|
+
</FormFieldContext.Provider>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** @deprecated Use `Field`. Form* is the same stack with the id wiring attached. */
|
|
98
|
+
const FormItem: ParentComponent<ComponentProps<typeof Field>> = (props) => {
|
|
99
|
+
const id = createUniqueId();
|
|
100
|
+
const [hasDescription, setHasDescription] = createSignal(false);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<FormItemContext.Provider value={{ id, hasDescription, setHasDescription }}>
|
|
104
|
+
<Field {...props} />
|
|
105
|
+
</FormItemContext.Provider>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** @deprecated Use `FieldLabel`. */
|
|
110
|
+
const FormLabel: Component<ComponentProps<typeof FieldLabel>> = (props) => {
|
|
111
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
112
|
+
const { error, formItemId } = useFormField();
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<FieldLabel
|
|
116
|
+
data-error={!!error()}
|
|
117
|
+
class={cn("data-[error=true]:text-destructive", local.class)}
|
|
118
|
+
for={formItemId()}
|
|
119
|
+
{...rest}
|
|
120
|
+
/>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
let warnedFormControlWrapper = false;
|
|
125
|
+
|
|
126
|
+
/** @internal Lets a test assert the once-per-process warning more than once. */
|
|
127
|
+
export function resetFormControlWrapperWarning() {
|
|
128
|
+
warnedFormControlWrapper = false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function warnFormControlWrapper() {
|
|
132
|
+
if (warnedFormControlWrapper) return;
|
|
133
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
|
|
134
|
+
warnedFormControlWrapper = true;
|
|
135
|
+
console.warn(
|
|
136
|
+
'[FormControl] The wrapper shape (<FormControl><Input /></FormControl>) is deprecated: an aria-describedby on a div around an input is read by nothing. Render the control itself instead: <FormControl type="email" /> or <FormControl as={Textarea} />.',
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Renders THE control (default: `Input`, any other through `as`) with the id and
|
|
142
|
+
* aria the field context knows.
|
|
143
|
+
*
|
|
144
|
+
* Passing children keeps the old wrapper shape working: a `div` carrying the
|
|
145
|
+
* same id and aria, with the children inside.
|
|
146
|
+
*
|
|
147
|
+
* @deprecated with `children`. Render the control itself, so the id and the
|
|
148
|
+
* describedby land on the element a screen reader announces.
|
|
149
|
+
*/
|
|
150
|
+
const FormControl = <T extends ValidComponent = typeof Input>(
|
|
151
|
+
props: { as?: T } & ComponentProps<T>,
|
|
152
|
+
) => {
|
|
153
|
+
const { error, hasDescription, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
154
|
+
const [local, rest] = splitProps(props as { as?: ValidComponent; children?: JSX.Element }, [
|
|
155
|
+
"as",
|
|
156
|
+
"children",
|
|
157
|
+
]);
|
|
158
|
+
// Only the ids that actually render: a dangling idref reads as nothing.
|
|
159
|
+
const describedBy = () => {
|
|
160
|
+
const ids = [hasDescription() ? formDescriptionId() : "", error() ? formMessageId() : ""];
|
|
161
|
+
const rendered = ids.filter((id) => id !== "");
|
|
162
|
+
return rendered.length > 0 ? rendered.join(" ") : undefined;
|
|
163
|
+
};
|
|
164
|
+
// Resolved once: `local.children` is a getter, so reading it for the presence
|
|
165
|
+
// check and again in the JSX would instantiate the child component twice.
|
|
166
|
+
const body = children(() => local.children);
|
|
167
|
+
const wrapped = createMemo(() => body() !== undefined);
|
|
168
|
+
createEffect(() => {
|
|
169
|
+
if (wrapped()) warnFormControlWrapper();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<Show
|
|
174
|
+
when={wrapped()}
|
|
175
|
+
fallback={
|
|
176
|
+
<Dynamic
|
|
177
|
+
component={local.as ?? Input}
|
|
178
|
+
id={formItemId()}
|
|
179
|
+
aria-describedby={describedBy()}
|
|
180
|
+
aria-invalid={error() ? true : undefined}
|
|
181
|
+
{...rest}
|
|
182
|
+
/>
|
|
183
|
+
}
|
|
184
|
+
>
|
|
185
|
+
<div
|
|
186
|
+
data-slot="form-control"
|
|
187
|
+
id={formItemId()}
|
|
188
|
+
aria-describedby={describedBy()}
|
|
189
|
+
aria-invalid={error() ? true : undefined}
|
|
190
|
+
{...(rest as ComponentProps<"div">)}
|
|
191
|
+
>
|
|
192
|
+
{body()}
|
|
193
|
+
</div>
|
|
194
|
+
</Show>
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/** @deprecated Use `FieldDescription`. */
|
|
199
|
+
const FormDescription: Component<ComponentProps<typeof FieldDescription>> = (props) => {
|
|
200
|
+
const itemContext = useContext(FormItemContext);
|
|
201
|
+
const { formDescriptionId } = useFormField();
|
|
202
|
+
|
|
203
|
+
onMount(() => itemContext?.setHasDescription(true));
|
|
204
|
+
onCleanup(() => itemContext?.setHasDescription(false));
|
|
205
|
+
|
|
206
|
+
return <FieldDescription id={formDescriptionId()} {...props} />;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/** @deprecated Use `FieldError`. */
|
|
210
|
+
const FormMessage: ParentComponent<ComponentProps<typeof FieldError>> = (props) => {
|
|
211
|
+
const [local, rest] = splitProps(props, ["children"]);
|
|
212
|
+
const { error, formMessageId } = useFormField();
|
|
213
|
+
const body = () => error() || local.children;
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<FieldError id={formMessageId()} {...rest}>
|
|
217
|
+
{body()}
|
|
218
|
+
</FieldError>
|
|
219
|
+
);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export {
|
|
223
|
+
Form,
|
|
224
|
+
FormControl,
|
|
225
|
+
FormDescription,
|
|
226
|
+
FormField,
|
|
227
|
+
FormItem,
|
|
228
|
+
FormLabel,
|
|
229
|
+
FormMessage,
|
|
230
|
+
useFormField,
|
|
231
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type JSX, Show } from "solid-js";
|
|
2
|
+
import { glassToneText, isNeutralTone, NEUTRAL_KNOBS } from "../lib/glass-tone.js";
|
|
3
|
+
import { SECTION_OUTER_RADIUS } from "../lib/section-tokens.js";
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import { Badge } from "./badge.js";
|
|
6
|
+
import { Icon } from "./icon.js";
|
|
7
|
+
import { Ornament } from "./ornament.js";
|
|
8
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
|
|
9
|
+
|
|
10
|
+
/* One card for every "pick one of a few big choices" screen: the setup
|
|
11
|
+
* wizard's connect/sign-in steps and People's pick-one dialogs. Chrome lives
|
|
12
|
+
* here once; the two call shapes below (nav button vs. grouped radio item)
|
|
13
|
+
* share it so neither surface can drift from the other. */
|
|
14
|
+
const HERO_ACTION_CHROME = `glass group relative flex min-h-[6.25rem] items-center gap-4 overflow-hidden ${SECTION_OUTER_RADIUS} p-4 text-left transition-glass duration-200 [--glass-lift:0.4] hover:-translate-y-0.5 active:translate-y-0 active:scale-[0.99] disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:translate-y-0 hover:[--glass-lift:0.85] data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 data-[disabled]:hover:translate-y-0`;
|
|
15
|
+
|
|
16
|
+
/* glassToneText tints a label toward its own tone, which stops being legible
|
|
17
|
+
* on a dark surface once the tone itself is dark (the GlassHome deep blue).
|
|
18
|
+
* Lift dark tones to a readable lightness first; light tones pass through. */
|
|
19
|
+
function titleTone(tone: string): string {
|
|
20
|
+
const l = Number.parseFloat(tone.match(/oklch\(\s*([0-9.]+)/)?.[1] ?? "");
|
|
21
|
+
if (Number.isNaN(l) || l >= 0.68) return tone;
|
|
22
|
+
return tone.replace(/oklch\(\s*[0-9.]+/, "oklch(0.76");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface HeroActionContentProps {
|
|
26
|
+
icon: string;
|
|
27
|
+
iconImage?: string;
|
|
28
|
+
title: string;
|
|
29
|
+
description: string;
|
|
30
|
+
accentVar: string;
|
|
31
|
+
recommended?: boolean;
|
|
32
|
+
recommendedHint?: string;
|
|
33
|
+
/** "arrow" is the go-somewhere-else watermark (setup); "check" is the
|
|
34
|
+
* picked-state glyph for a grouped radio item; "none" suits a picker whose
|
|
35
|
+
* click already moves the step on. */
|
|
36
|
+
ornament: "arrow" | "check" | "none";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function HeroActionContent(props: HeroActionContentProps) {
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<Ornament kind={props.ornament} />
|
|
43
|
+
|
|
44
|
+
<div class="flex w-full items-center gap-4">
|
|
45
|
+
<span
|
|
46
|
+
class="relative flex shrink-0 items-center justify-center"
|
|
47
|
+
style={{ color: "var(--surface-tone)" }}
|
|
48
|
+
>
|
|
49
|
+
<Show
|
|
50
|
+
when={props.iconImage}
|
|
51
|
+
fallback={<Icon icon={props.icon} width={52} aria-hidden="true" />}
|
|
52
|
+
>
|
|
53
|
+
{(src) => <img src={src()} alt="" class="size-14 object-contain" aria-hidden="true" />}
|
|
54
|
+
</Show>
|
|
55
|
+
</span>
|
|
56
|
+
<div class="relative flex min-w-0 flex-1 flex-col gap-1">
|
|
57
|
+
<div class="flex items-center gap-2">
|
|
58
|
+
<h3
|
|
59
|
+
class="font-semibold text-lg leading-tight"
|
|
60
|
+
style={{ color: glassToneText(titleTone(props.accentVar)) }}
|
|
61
|
+
>
|
|
62
|
+
{props.title}
|
|
63
|
+
</h3>
|
|
64
|
+
<Show when={props.recommended}>
|
|
65
|
+
<Tooltip openDelay={150}>
|
|
66
|
+
<TooltipTrigger as={Badge} tone="var(--success)">
|
|
67
|
+
Recommended
|
|
68
|
+
</TooltipTrigger>
|
|
69
|
+
<Show when={props.recommendedHint}>
|
|
70
|
+
{(hint) => <TooltipContent>{hint()}</TooltipContent>}
|
|
71
|
+
</Show>
|
|
72
|
+
</Tooltip>
|
|
73
|
+
</Show>
|
|
74
|
+
</div>
|
|
75
|
+
<p class="truncate text-foreground/80 text-sm">{props.description}</p>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Navigates away immediately on click — the setup wizard's connect/sign-in
|
|
83
|
+
* steps. Not part of a group, no persisted selection. */
|
|
84
|
+
export function HeroAction(props: {
|
|
85
|
+
icon: string;
|
|
86
|
+
iconImage?: string;
|
|
87
|
+
title: string;
|
|
88
|
+
description: string;
|
|
89
|
+
onClick: () => void;
|
|
90
|
+
accentVar: string;
|
|
91
|
+
disabled?: boolean;
|
|
92
|
+
recommended?: boolean;
|
|
93
|
+
recommendedHint?: string;
|
|
94
|
+
class?: string;
|
|
95
|
+
}) {
|
|
96
|
+
return (
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
data-slot="hero-action"
|
|
100
|
+
onClick={() => !props.disabled && props.onClick()}
|
|
101
|
+
disabled={props.disabled}
|
|
102
|
+
class={cn(HERO_ACTION_CHROME, isNeutralTone(props.accentVar) && NEUTRAL_KNOBS, props.class)}
|
|
103
|
+
style={{ "--glass-tone": props.accentVar } as JSX.CSSProperties}
|
|
104
|
+
>
|
|
105
|
+
<HeroActionContent
|
|
106
|
+
icon={props.icon}
|
|
107
|
+
iconImage={props.iconImage}
|
|
108
|
+
title={props.title}
|
|
109
|
+
description={props.description}
|
|
110
|
+
accentVar={props.accentVar}
|
|
111
|
+
recommended={props.recommended}
|
|
112
|
+
recommendedHint={props.recommendedHint}
|
|
113
|
+
ornament="arrow"
|
|
114
|
+
/>
|
|
115
|
+
</button>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HoverCard as HoverCardPrimitive } from "@kobalte/core/hover-card";
|
|
2
|
+
import { type Component, type ComponentProps, splitProps } from "solid-js";
|
|
3
|
+
import { OVERLAY_MOTION } from "../lib/motion-classes.js";
|
|
4
|
+
import { FLOATING_PANEL } from "../lib/overlay-classes.js";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
|
|
7
|
+
const HoverCard = HoverCardPrimitive;
|
|
8
|
+
|
|
9
|
+
const HoverCardTrigger: Component<ComponentProps<typeof HoverCardPrimitive.Trigger>> = (props) => {
|
|
10
|
+
return <HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const HoverCardContent: Component<ComponentProps<typeof HoverCardPrimitive.Content>> = (props) => {
|
|
14
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
15
|
+
return (
|
|
16
|
+
<HoverCardPrimitive.Portal data-slot="hover-card-portal">
|
|
17
|
+
<HoverCardPrimitive.Content
|
|
18
|
+
data-slot="hover-card-content"
|
|
19
|
+
class={cn(FLOATING_PANEL, OVERLAY_MOTION, "w-64 p-4", local.class)}
|
|
20
|
+
{...rest}
|
|
21
|
+
/>
|
|
22
|
+
</HoverCardPrimitive.Portal>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { HoverCard, HoverCardContent, HoverCardTrigger };
|