@glasshome/ui 1.10.0 → 1.10.1
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/package.json +5 -2
- package/scripts/check-pack.ts +32 -0
- package/src/index.ts +111 -0
- 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 +20 -0
- package/src/solid/image-picker.tsx +380 -0
- package/src/solid/index.ts +417 -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 +219 -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/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,159 @@
|
|
|
1
|
+
import { createUniqueId, type JSX, Show } from "solid-js";
|
|
2
|
+
import { Button } from "./button.js";
|
|
3
|
+
import { Field, FieldContent, FieldDescription, FieldLabel } from "./field.js";
|
|
4
|
+
import { Icon } from "./icon.js";
|
|
5
|
+
import { IconPicker, type IconPickerProps } from "./icon-picker.js";
|
|
6
|
+
import { Input } from "./input.js";
|
|
7
|
+
import { Switch } from "./switch.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generic settings/list row primitives, shared by dash settings and any list UI.
|
|
11
|
+
* Presentational only — no app data or routing.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export function SectionAddButton(props: { onClick: () => void }) {
|
|
15
|
+
return (
|
|
16
|
+
<Button variant="outline" size="sm" onClick={props.onClick}>
|
|
17
|
+
<Icon icon="lucide:plus" width={14} height={14} />
|
|
18
|
+
Add
|
|
19
|
+
</Button>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function SectionEmpty(props: { children: JSX.Element }) {
|
|
24
|
+
return (
|
|
25
|
+
<p data-slot="section-empty" class="py-4 text-center text-muted-foreground text-sm">
|
|
26
|
+
{props.children}
|
|
27
|
+
</p>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function RowActions(props: {
|
|
32
|
+
onEdit: () => void;
|
|
33
|
+
onDelete: () => void;
|
|
34
|
+
deleteDisabled?: boolean;
|
|
35
|
+
deleteTitle?: string;
|
|
36
|
+
showDelete?: boolean;
|
|
37
|
+
}) {
|
|
38
|
+
return (
|
|
39
|
+
<div data-slot="row-actions" class="flex items-center gap-1">
|
|
40
|
+
<Button variant="ghost" size="icon" class="size-8" onClick={props.onEdit}>
|
|
41
|
+
<Icon icon="lucide:pencil" width={14} height={14} />
|
|
42
|
+
</Button>
|
|
43
|
+
<Show when={props.showDelete ?? true}>
|
|
44
|
+
<Button
|
|
45
|
+
variant="ghost"
|
|
46
|
+
size="icon"
|
|
47
|
+
class="size-8 text-destructive hover:text-destructive"
|
|
48
|
+
onClick={props.onDelete}
|
|
49
|
+
disabled={props.deleteDisabled}
|
|
50
|
+
title={props.deleteTitle}
|
|
51
|
+
>
|
|
52
|
+
<Icon icon="lucide:trash-2" width={14} height={14} />
|
|
53
|
+
</Button>
|
|
54
|
+
</Show>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function LabeledField(props: { label: string; children: JSX.Element }) {
|
|
60
|
+
return (
|
|
61
|
+
<div data-slot="labeled-field" class="flex flex-col gap-1">
|
|
62
|
+
<p data-slot="labeled-field-label" class="font-medium text-sm">
|
|
63
|
+
{props.label}
|
|
64
|
+
</p>
|
|
65
|
+
{props.children}
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function LabeledIconPicker(props: {
|
|
71
|
+
label: string;
|
|
72
|
+
value: string;
|
|
73
|
+
onChange: (value: string) => void;
|
|
74
|
+
placeholder?: string;
|
|
75
|
+
searchIcons?: IconPickerProps["searchIcons"];
|
|
76
|
+
}) {
|
|
77
|
+
return (
|
|
78
|
+
<LabeledField label={props.label}>
|
|
79
|
+
<IconPicker
|
|
80
|
+
value={props.value}
|
|
81
|
+
onChange={props.onChange}
|
|
82
|
+
placeholder={props.placeholder}
|
|
83
|
+
searchIcons={props.searchIcons}
|
|
84
|
+
/>
|
|
85
|
+
</LabeledField>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function LabeledInput(props: {
|
|
90
|
+
label: string;
|
|
91
|
+
value: string;
|
|
92
|
+
onInput: (value: string) => void;
|
|
93
|
+
placeholder?: string;
|
|
94
|
+
}) {
|
|
95
|
+
return (
|
|
96
|
+
<LabeledField label={props.label}>
|
|
97
|
+
<Input
|
|
98
|
+
value={props.value}
|
|
99
|
+
onInput={(e) => props.onInput(e.currentTarget.value)}
|
|
100
|
+
placeholder={props.placeholder}
|
|
101
|
+
/>
|
|
102
|
+
</LabeledField>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function SwitchRow(props: {
|
|
107
|
+
label: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
/** Iconify id shown before the label (sensitive-device rows, platform toggles). */
|
|
110
|
+
icon?: string;
|
|
111
|
+
checked: boolean;
|
|
112
|
+
disabled?: boolean;
|
|
113
|
+
onChange: (value: boolean) => void;
|
|
114
|
+
}) {
|
|
115
|
+
const id = createUniqueId();
|
|
116
|
+
return (
|
|
117
|
+
<Field
|
|
118
|
+
orientation="horizontal"
|
|
119
|
+
class="py-2"
|
|
120
|
+
data-disabled={props.disabled ? "true" : undefined}
|
|
121
|
+
>
|
|
122
|
+
<Show when={props.icon}>
|
|
123
|
+
{(icon) => (
|
|
124
|
+
<Icon
|
|
125
|
+
icon={icon()}
|
|
126
|
+
width={16}
|
|
127
|
+
height={16}
|
|
128
|
+
aria-hidden="true"
|
|
129
|
+
class="shrink-0 text-muted-foreground"
|
|
130
|
+
/>
|
|
131
|
+
)}
|
|
132
|
+
</Show>
|
|
133
|
+
<Show
|
|
134
|
+
when={props.description}
|
|
135
|
+
fallback={
|
|
136
|
+
<FieldLabel for={id} class="cursor-pointer">
|
|
137
|
+
{props.label}
|
|
138
|
+
</FieldLabel>
|
|
139
|
+
}
|
|
140
|
+
>
|
|
141
|
+
{(description) => (
|
|
142
|
+
<FieldContent>
|
|
143
|
+
<FieldLabel for={id} class="cursor-pointer">
|
|
144
|
+
{props.label}
|
|
145
|
+
</FieldLabel>
|
|
146
|
+
<FieldDescription class="text-xs">{description()}</FieldDescription>
|
|
147
|
+
</FieldContent>
|
|
148
|
+
)}
|
|
149
|
+
</Show>
|
|
150
|
+
<Switch
|
|
151
|
+
id={id}
|
|
152
|
+
checked={props.checked}
|
|
153
|
+
disabled={props.disabled}
|
|
154
|
+
onChange={props.onChange}
|
|
155
|
+
aria-label={props.label}
|
|
156
|
+
/>
|
|
157
|
+
</Field>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Dialog as DialogPrimitive, useDialogContext } from "@kobalte/core/dialog";
|
|
2
|
+
import type { VariantProps } from "cva";
|
|
3
|
+
import {
|
|
4
|
+
type Component,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
type JSX,
|
|
7
|
+
type ParentComponent,
|
|
8
|
+
Show,
|
|
9
|
+
splitProps,
|
|
10
|
+
} from "solid-js";
|
|
11
|
+
import { buttonVariants } from "../lib/button-variants.js";
|
|
12
|
+
import { Z_CLASS } from "../lib/layers.js";
|
|
13
|
+
import { SCRIM_MOTION } from "../lib/motion-classes.js";
|
|
14
|
+
import { OVERLAY_SURFACE, SCRIM_CLASS } from "../lib/overlay-classes.js";
|
|
15
|
+
import { cn } from "../lib/utils.js";
|
|
16
|
+
import {
|
|
17
|
+
createModalDismiss,
|
|
18
|
+
createModalParts,
|
|
19
|
+
MODAL_DESCRIPTION,
|
|
20
|
+
MODAL_MAX_H,
|
|
21
|
+
MODAL_TITLE,
|
|
22
|
+
type ModalDismissProps,
|
|
23
|
+
ModalScrollLock,
|
|
24
|
+
} from "./dialog-parts.js";
|
|
25
|
+
|
|
26
|
+
/* Kobalte's own scroll lock is off here too: ModalScrollLock is the one
|
|
27
|
+
* refcounted page lock every modal family shares. */
|
|
28
|
+
const Sheet: ParentComponent<ComponentProps<typeof DialogPrimitive>> = (props) => (
|
|
29
|
+
<DialogPrimitive {...props} preventScroll={false} />
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const SheetTrigger: Component<ComponentProps<typeof DialogPrimitive.Trigger>> = (props) => (
|
|
33
|
+
<DialogPrimitive.Trigger data-slot="sheet-trigger" {...props} />
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
type SheetCloseProps = ModalDismissProps &
|
|
37
|
+
Partial<Pick<VariantProps<typeof buttonVariants>, "variant" | "size">>;
|
|
38
|
+
|
|
39
|
+
const SheetDismiss = createModalDismiss("sheet-close");
|
|
40
|
+
|
|
41
|
+
/** Already the outline button; see DialogClose on why `as={Button}` is wrong. */
|
|
42
|
+
const SheetClose: ParentComponent<SheetCloseProps> = (props) => {
|
|
43
|
+
const [local, rest] = splitProps(props, ["class", "variant", "size", "children"]);
|
|
44
|
+
return (
|
|
45
|
+
<SheetDismiss
|
|
46
|
+
class={cn(
|
|
47
|
+
buttonVariants({ variant: local.variant ?? "outline", size: local.size }),
|
|
48
|
+
local.class,
|
|
49
|
+
)}
|
|
50
|
+
{...rest}
|
|
51
|
+
>
|
|
52
|
+
{local.children ?? "Close"}
|
|
53
|
+
</SheetDismiss>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const SheetOverlay: Component<ComponentProps<typeof DialogPrimitive.Overlay>> = (props) => {
|
|
58
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
59
|
+
return (
|
|
60
|
+
<DialogPrimitive.Overlay
|
|
61
|
+
data-slot="sheet-overlay"
|
|
62
|
+
class={cn(
|
|
63
|
+
`${SCRIM_MOTION} pointer-events-auto fixed inset-0 select-none ${Z_CLASS.overlay} ${SCRIM_CLASS}`,
|
|
64
|
+
local.class,
|
|
65
|
+
)}
|
|
66
|
+
{...rest}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/* A viewport-tall panel would stretch the percentage-sized sheen into a small
|
|
72
|
+
* blob over a flat field; pinned lengths match the ellipse a dialog gets. */
|
|
73
|
+
const SHEET_SURFACE = `${OVERLAY_SURFACE} [--glass-sheen:600px_300px]`;
|
|
74
|
+
|
|
75
|
+
const SHEET_PANEL = `fixed ${Z_CLASS.overlay} flex flex-col overflow-hidden rounded-lg ${SHEET_SURFACE} transition ease-in-out focus:outline-none focus-visible:outline-none data-[closed]:animate-out data-[expanded]:animate-in data-[closed]:duration-300 data-[expanded]:duration-500`;
|
|
76
|
+
|
|
77
|
+
const SHEET_SIDE = {
|
|
78
|
+
right:
|
|
79
|
+
"data-[closed]:slide-out-to-right data-[expanded]:slide-in-from-right inset-y-3 right-3 w-3/4 sm:max-w-sm",
|
|
80
|
+
left: "data-[closed]:slide-out-to-left data-[expanded]:slide-in-from-left inset-y-3 left-3 w-3/4 sm:max-w-sm",
|
|
81
|
+
top: `data-[closed]:slide-out-to-top data-[expanded]:slide-in-from-top inset-x-3 top-3 ${MODAL_MAX_H}`,
|
|
82
|
+
/** @deprecated a modal from the bottom is `BottomSheet` / `ResponsiveDialog`. */
|
|
83
|
+
bottom: `data-[closed]:slide-out-to-bottom data-[expanded]:slide-in-from-bottom inset-x-3 bottom-3 ${MODAL_MAX_H}`,
|
|
84
|
+
} as const;
|
|
85
|
+
|
|
86
|
+
type SheetSide = keyof typeof SHEET_SIDE;
|
|
87
|
+
|
|
88
|
+
type SheetContentProps = ComponentProps<typeof DialogPrimitive.Content> & {
|
|
89
|
+
/** A modal belongs in `ResponsiveDialog`; this family slides from an edge. */
|
|
90
|
+
side?: SheetSide;
|
|
91
|
+
above?: JSX.Element;
|
|
92
|
+
/** Names a panel that has no `SheetTitle`. A registered Title wins. */
|
|
93
|
+
ariaLabel?: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const SheetAbove: Component<{ above?: JSX.Element }> = (props) => (
|
|
97
|
+
<Show when={props.above}>
|
|
98
|
+
<div data-slot="sheet-content-above" class="flex w-full shrink-0 items-end justify-center">
|
|
99
|
+
{props.above}
|
|
100
|
+
</div>
|
|
101
|
+
</Show>
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const SheetContent: ParentComponent<SheetContentProps> = (props) => {
|
|
105
|
+
const [local, rest] = splitProps(props, ["class", "children", "side", "above", "ariaLabel"]);
|
|
106
|
+
const context = useDialogContext();
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<DialogPrimitive.Portal>
|
|
110
|
+
<ModalScrollLock />
|
|
111
|
+
<SheetOverlay />
|
|
112
|
+
<DialogPrimitive.Content
|
|
113
|
+
data-slot="sheet-content"
|
|
114
|
+
role="dialog"
|
|
115
|
+
aria-label={context.titleId() ? undefined : local.ariaLabel}
|
|
116
|
+
class={cn(SHEET_PANEL, SHEET_SIDE[local.side ?? "right"], local.class)}
|
|
117
|
+
onOpenAutoFocus={(e: Event) => e.preventDefault()}
|
|
118
|
+
{...rest}
|
|
119
|
+
>
|
|
120
|
+
<SheetAbove above={local.above} />
|
|
121
|
+
{local.children}
|
|
122
|
+
</DialogPrimitive.Content>
|
|
123
|
+
</DialogPrimitive.Portal>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const { Header: SheetHeader, Body: SheetBody, Footer: SheetFooter } = createModalParts("sheet");
|
|
128
|
+
|
|
129
|
+
const SheetTitle: Component<ComponentProps<typeof DialogPrimitive.Title>> = (props) => {
|
|
130
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
131
|
+
return (
|
|
132
|
+
<DialogPrimitive.Title data-slot="sheet-title" class={cn(MODAL_TITLE, local.class)} {...rest} />
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const SheetDescription: Component<ComponentProps<typeof DialogPrimitive.Description>> = (props) => {
|
|
137
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
138
|
+
return (
|
|
139
|
+
<DialogPrimitive.Description
|
|
140
|
+
data-slot="sheet-description"
|
|
141
|
+
class={cn(MODAL_DESCRIPTION, local.class)}
|
|
142
|
+
{...rest}
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
Sheet,
|
|
149
|
+
SheetBody,
|
|
150
|
+
SheetClose,
|
|
151
|
+
SheetContent,
|
|
152
|
+
SheetDescription,
|
|
153
|
+
SheetFooter,
|
|
154
|
+
SheetHeader,
|
|
155
|
+
SheetTitle,
|
|
156
|
+
SheetTrigger,
|
|
157
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Component, type ComponentProps, splitProps } from "solid-js";
|
|
2
|
+
import { cn } from "../lib/utils.js";
|
|
3
|
+
|
|
4
|
+
const Skeleton: Component<ComponentProps<"div">> = (props) => {
|
|
5
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
data-slot="skeleton"
|
|
9
|
+
class={cn("animate-pulse rounded-md bg-muted", local.class)}
|
|
10
|
+
{...others}
|
|
11
|
+
/>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { Skeleton };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Slider as KSlider } from "@kobalte/core/slider";
|
|
2
|
+
import type { Component } from "solid-js";
|
|
3
|
+
import { Index, splitProps } from "solid-js";
|
|
4
|
+
import { FIELD_CHROME, FOCUS_RING } from "../lib/input-classes.js";
|
|
5
|
+
import { THUMB_CLASS, THUMB_RAIL_BLEED, THUMB_RAIL_PAD } from "../lib/thumb-classes.js";
|
|
6
|
+
import { cn } from "../lib/utils.js";
|
|
7
|
+
|
|
8
|
+
interface SliderProps {
|
|
9
|
+
value?: number[];
|
|
10
|
+
defaultValue?: number[];
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
step?: number;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
onChange?: (values: number[]) => void;
|
|
16
|
+
onChangeEnd?: (values: number[]) => void;
|
|
17
|
+
class?: string;
|
|
18
|
+
trackClass?: string;
|
|
19
|
+
thumbClass?: string;
|
|
20
|
+
/** Per-thumb background color, index-matched to value[]. Color only; the thumb keeps its material. */
|
|
21
|
+
thumbColors?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Fill tint. A single color swaps --glass-tone; a pair runs a horizontal
|
|
24
|
+
* two-tone wash via the glass tone-2 knobs. The fill stays the one glass
|
|
25
|
+
* material either way.
|
|
26
|
+
*/
|
|
27
|
+
fillTone?: string | [string, string];
|
|
28
|
+
/** Value-positioned tick annotations on the track (e.g. a current-temperature reading). */
|
|
29
|
+
markers?: number[];
|
|
30
|
+
minStepsBetweenThumbs?: number;
|
|
31
|
+
"aria-label"?: string;
|
|
32
|
+
"aria-labelledby"?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const Slider: Component<SliderProps> = (props) => {
|
|
36
|
+
const [local] = splitProps(props, [
|
|
37
|
+
"value",
|
|
38
|
+
"defaultValue",
|
|
39
|
+
"min",
|
|
40
|
+
"max",
|
|
41
|
+
"step",
|
|
42
|
+
"disabled",
|
|
43
|
+
"onChange",
|
|
44
|
+
"onChangeEnd",
|
|
45
|
+
"class",
|
|
46
|
+
"trackClass",
|
|
47
|
+
"thumbClass",
|
|
48
|
+
"thumbColors",
|
|
49
|
+
"fillTone",
|
|
50
|
+
"markers",
|
|
51
|
+
"minStepsBetweenThumbs",
|
|
52
|
+
"aria-label",
|
|
53
|
+
"aria-labelledby",
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const markerPct = (v: number) => {
|
|
57
|
+
const min = local.min ?? 0;
|
|
58
|
+
const max = local.max ?? 100;
|
|
59
|
+
return max === min ? 0 : ((v - min) / (max - min)) * 100;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<KSlider
|
|
64
|
+
value={local.value}
|
|
65
|
+
defaultValue={local.defaultValue}
|
|
66
|
+
minValue={local.min ?? 0}
|
|
67
|
+
maxValue={local.max ?? 100}
|
|
68
|
+
step={local.step ?? 1}
|
|
69
|
+
minStepsBetweenThumbs={local.minStepsBetweenThumbs}
|
|
70
|
+
disabled={local.disabled}
|
|
71
|
+
onChange={local.onChange}
|
|
72
|
+
onChangeEnd={local.onChangeEnd}
|
|
73
|
+
data-slot="slider"
|
|
74
|
+
class={cn(
|
|
75
|
+
// The rail wears the shared toggle/rail chrome, so it reads as an empty
|
|
76
|
+
// well in both themes (a field's light-theme fill rises to the card).
|
|
77
|
+
"relative flex w-full touch-none select-none items-center rounded-xl",
|
|
78
|
+
THUMB_RAIL_PAD,
|
|
79
|
+
FIELD_CHROME,
|
|
80
|
+
local.disabled && "cursor-not-allowed opacity-50",
|
|
81
|
+
local.class,
|
|
82
|
+
)}
|
|
83
|
+
>
|
|
84
|
+
<KSlider.Track
|
|
85
|
+
data-slot="slider-track"
|
|
86
|
+
class={cn(
|
|
87
|
+
"relative h-7 w-full",
|
|
88
|
+
local.disabled ? "cursor-not-allowed" : "cursor-pointer",
|
|
89
|
+
local.trackClass,
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
<KSlider.Fill
|
|
93
|
+
data-slot="slider-fill"
|
|
94
|
+
class={cn(
|
|
95
|
+
// The fill sits sunk inside the recessed rail: the tinted-surface
|
|
96
|
+
// outer drop shadow would read as a halo leaking out of the groove.
|
|
97
|
+
"glass glass-tint absolute inset-y-0 rounded-xl [--glass-drop:0%]",
|
|
98
|
+
THUMB_RAIL_BLEED,
|
|
99
|
+
Array.isArray(local.fillTone) && "glass-edge-gradient",
|
|
100
|
+
)}
|
|
101
|
+
style={
|
|
102
|
+
Array.isArray(local.fillTone)
|
|
103
|
+
? {
|
|
104
|
+
"--glass-tone": local.fillTone[0],
|
|
105
|
+
"--glass-tone-2": local.fillTone[1],
|
|
106
|
+
"--glass-wash-2": "var(--glass-wash)",
|
|
107
|
+
"--glass-wash-angle": "90deg",
|
|
108
|
+
}
|
|
109
|
+
: { "--glass-tone": local.fillTone ?? "var(--primary)" }
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
<Index each={local.markers ?? []}>
|
|
113
|
+
{(marker) => (
|
|
114
|
+
<span
|
|
115
|
+
data-slot="slider-marker"
|
|
116
|
+
class="pointer-events-none absolute top-1/2 h-3 w-0.5 -translate-x-1/2 -translate-y-1/2 rounded-full"
|
|
117
|
+
style={{
|
|
118
|
+
left: `${markerPct(marker())}%`,
|
|
119
|
+
background: "color-mix(in oklab, var(--foreground) 60%, transparent)",
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
</Index>
|
|
124
|
+
<Index each={local.value ?? local.defaultValue ?? [0]}>
|
|
125
|
+
{(_, thumbIndex) => (
|
|
126
|
+
<KSlider.Thumb
|
|
127
|
+
data-slot="slider-thumb"
|
|
128
|
+
class={cn(
|
|
129
|
+
THUMB_CLASS,
|
|
130
|
+
FOCUS_RING,
|
|
131
|
+
"absolute top-0 transition-transform duration-200 ease-out hover:scale-125 active:scale-110",
|
|
132
|
+
local.disabled && "cursor-not-allowed",
|
|
133
|
+
local.thumbClass,
|
|
134
|
+
)}
|
|
135
|
+
aria-label={local["aria-label"]}
|
|
136
|
+
aria-labelledby={local["aria-labelledby"]}
|
|
137
|
+
style={{ background: local.thumbColors?.[thumbIndex] ?? "var(--primary)" }}
|
|
138
|
+
>
|
|
139
|
+
<KSlider.Input />
|
|
140
|
+
</KSlider.Thumb>
|
|
141
|
+
)}
|
|
142
|
+
</Index>
|
|
143
|
+
</KSlider.Track>
|
|
144
|
+
</KSlider>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export { Slider };
|