@glasshome/ui 1.14.0 → 1.15.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 +1 -0
- package/dist/solid/index.d.ts +1 -0
- package/dist/solid/index.js +3641 -3569
- package/dist/solid/picker-trigger.d.ts +11 -0
- package/package.json +1 -1
- package/src/solid/area-picker.tsx +18 -14
- package/src/solid/entity-selector.tsx +30 -47
- package/src/solid/icon-picker.tsx +13 -15
- package/src/solid/image-picker.tsx +15 -15
- package/src/solid/index.ts +1 -0
- package/src/solid/picker-trigger.tsx +68 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type JSX } from "solid-js";
|
|
2
|
+
export interface PickerTriggerProps extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> {
|
|
3
|
+
/** data-slot for the button, so each picker keeps its own test and style hook. */
|
|
4
|
+
slot: string;
|
|
5
|
+
open: boolean;
|
|
6
|
+
onToggle: () => void;
|
|
7
|
+
/** Passed only when there is a value to drop: its presence paints the clear button. */
|
|
8
|
+
onClear?: () => void;
|
|
9
|
+
clearLabel?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function PickerTrigger(props: PickerTriggerProps): JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
2
|
import { MENU_ITEM } from "../lib/menu-classes.js";
|
|
3
3
|
import { STAGGER } from "../lib/motion-classes.js";
|
|
4
|
-
import { PICKER_LIST
|
|
4
|
+
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
5
5
|
import { cn } from "../lib/utils.js";
|
|
6
6
|
import { useEntityData } from "./entity-data.js";
|
|
7
7
|
import { Icon } from "./icon.js";
|
|
8
8
|
import { PickerRow } from "./picker-row.js";
|
|
9
9
|
import { PickerSearch } from "./picker-search.js";
|
|
10
|
+
import { PickerTrigger } from "./picker-trigger.js";
|
|
10
11
|
import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
|
|
11
12
|
import { SlidingIndicator } from "./sliding-indicator.js";
|
|
12
13
|
|
|
@@ -106,6 +107,15 @@ export function AreaPicker(props: AreaPickerProps) {
|
|
|
106
107
|
setSearch("");
|
|
107
108
|
};
|
|
108
109
|
|
|
110
|
+
const showTriggerClear = () =>
|
|
111
|
+
props.allowClear !== false && (multi() ? selected().length > 0 : Boolean(props.value));
|
|
112
|
+
|
|
113
|
+
const clearSelection = () => {
|
|
114
|
+
if (props.disabled) return;
|
|
115
|
+
props.onChange?.("");
|
|
116
|
+
props.onValuesChange?.([]);
|
|
117
|
+
};
|
|
118
|
+
|
|
109
119
|
const toggleArea = (areaId: string) => {
|
|
110
120
|
if (props.disabled) return;
|
|
111
121
|
const current = selected();
|
|
@@ -127,14 +137,14 @@ export function AreaPicker(props: AreaPickerProps) {
|
|
|
127
137
|
modal
|
|
128
138
|
>
|
|
129
139
|
<PopoverAnchor as="div" class={props.class}>
|
|
130
|
-
<
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
<PickerTrigger
|
|
141
|
+
slot="area-picker-trigger"
|
|
142
|
+
open={open()}
|
|
143
|
+
onToggle={() => setOpen(!open())}
|
|
134
144
|
aria-labelledby={props["aria-labelledby"]}
|
|
135
|
-
class={PICKER_TRIGGER}
|
|
136
145
|
disabled={props.disabled}
|
|
137
|
-
|
|
146
|
+
onClear={showTriggerClear() ? clearSelection : undefined}
|
|
147
|
+
clearLabel={multi() ? "Clear areas" : "Clear area"}
|
|
138
148
|
>
|
|
139
149
|
<Show
|
|
140
150
|
when={triggerArea()}
|
|
@@ -160,13 +170,7 @@ export function AreaPicker(props: AreaPickerProps) {
|
|
|
160
170
|
</>
|
|
161
171
|
)}
|
|
162
172
|
</Show>
|
|
163
|
-
|
|
164
|
-
icon="mdi:chevron-down"
|
|
165
|
-
width={16}
|
|
166
|
-
height={16}
|
|
167
|
-
class="shrink-0 text-muted-foreground"
|
|
168
|
-
/>
|
|
169
|
-
</button>
|
|
173
|
+
</PickerTrigger>
|
|
170
174
|
</PopoverAnchor>
|
|
171
175
|
<PopoverContent
|
|
172
176
|
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
Show,
|
|
11
11
|
} from "solid-js";
|
|
12
12
|
import { MENU_LABEL } from "../lib/menu-classes.js";
|
|
13
|
-
import { PICKER_LIST
|
|
13
|
+
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
14
14
|
import { createIsMobile } from "../lib/use-is-mobile.js";
|
|
15
15
|
import { cn } from "../lib/utils.js";
|
|
16
16
|
import {
|
|
@@ -24,6 +24,7 @@ import { type EntityViewLike, useEntityData } from "./entity-data.js";
|
|
|
24
24
|
import { Icon } from "./icon.js";
|
|
25
25
|
import { PICKER_ROW_HEIGHT, PickerRow } from "./picker-row.js";
|
|
26
26
|
import { PickerSearch } from "./picker-search.js";
|
|
27
|
+
import { PickerTrigger } from "./picker-trigger.js";
|
|
27
28
|
import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
|
|
28
29
|
import { SlidingIndicator } from "./sliding-indicator.js";
|
|
29
30
|
|
|
@@ -309,9 +310,10 @@ export function EntitySelector(props: EntitySelectorProps) {
|
|
|
309
310
|
setActiveIndex(0);
|
|
310
311
|
};
|
|
311
312
|
|
|
313
|
+
// A re-tap on the picked entity clears it, the way every picker toggles.
|
|
312
314
|
const toggleEntity = (entityId: string) => {
|
|
313
315
|
if (props.multiple === false) {
|
|
314
|
-
props.onEntityIdsChange([entityId]);
|
|
316
|
+
props.onEntityIdsChange(props.entityIds.includes(entityId) ? [] : [entityId]);
|
|
315
317
|
closePicker();
|
|
316
318
|
return;
|
|
317
319
|
}
|
|
@@ -375,59 +377,40 @@ export function EntitySelector(props: EntitySelectorProps) {
|
|
|
375
377
|
};
|
|
376
378
|
|
|
377
379
|
const isSingle = () => props.multiple === false;
|
|
378
|
-
const showTriggerClear = () =>
|
|
380
|
+
const showTriggerClear = () => props.entityIds.length > 0;
|
|
379
381
|
|
|
380
382
|
const clearSelection = () => {
|
|
381
383
|
props.onEntityIdsChange([]);
|
|
382
384
|
};
|
|
383
385
|
|
|
384
386
|
const TriggerButton = (p: { onClick: () => void }) => (
|
|
385
|
-
<
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
387
|
+
<PickerTrigger
|
|
388
|
+
slot="entity-selector-trigger"
|
|
389
|
+
role="combobox"
|
|
390
|
+
open={open()}
|
|
391
|
+
onToggle={p.onClick}
|
|
392
|
+
aria-labelledby={props["aria-labelledby"]}
|
|
393
|
+
aria-expanded={open()}
|
|
394
|
+
aria-controls={listboxId}
|
|
395
|
+
aria-haspopup="listbox"
|
|
396
|
+
onClear={showTriggerClear() ? clearSelection : undefined}
|
|
397
|
+
>
|
|
398
|
+
<Show when={triggerIcon()}>
|
|
399
|
+
{(icon) => (
|
|
400
|
+
<Icon icon={icon()} width={16} height={16} class="shrink-0 text-muted-foreground" />
|
|
401
|
+
)}
|
|
402
|
+
</Show>
|
|
403
|
+
<Show
|
|
404
|
+
when={triggerLabel()}
|
|
405
|
+
fallback={
|
|
406
|
+
<span class="flex-1 truncate text-left text-muted-foreground">
|
|
407
|
+
Select {props.domain} {isSingle() ? "entity" : "entities"}...
|
|
408
|
+
</span>
|
|
409
|
+
}
|
|
397
410
|
>
|
|
398
|
-
<
|
|
399
|
-
{(icon) => (
|
|
400
|
-
<Icon icon={icon()} width={16} height={16} class="shrink-0 text-muted-foreground" />
|
|
401
|
-
)}
|
|
402
|
-
</Show>
|
|
403
|
-
<Show
|
|
404
|
-
when={triggerLabel()}
|
|
405
|
-
fallback={
|
|
406
|
-
<span class="flex-1 truncate text-left text-muted-foreground">
|
|
407
|
-
Select {props.domain} {isSingle() ? "entity" : "entities"}...
|
|
408
|
-
</span>
|
|
409
|
-
}
|
|
410
|
-
>
|
|
411
|
-
{(label) => <span class="flex-1 truncate text-left">{label()}</span>}
|
|
412
|
-
</Show>
|
|
413
|
-
<Icon
|
|
414
|
-
icon="mdi:chevron-down"
|
|
415
|
-
width={16}
|
|
416
|
-
height={16}
|
|
417
|
-
class={`shrink-0 text-muted-foreground transition-transform ${open() ? "rotate-180" : ""}`}
|
|
418
|
-
/>
|
|
419
|
-
</button>
|
|
420
|
-
<Show when={showTriggerClear()}>
|
|
421
|
-
<button
|
|
422
|
-
type="button"
|
|
423
|
-
aria-label="Clear selection"
|
|
424
|
-
class="absolute top-1/2 right-8 flex -translate-y-1/2 items-center rounded-sm p-1 text-muted-foreground transition-colors hover:text-foreground"
|
|
425
|
-
onClick={clearSelection}
|
|
426
|
-
>
|
|
427
|
-
<Icon icon="mdi:close-circle" width={16} height={16} />
|
|
428
|
-
</button>
|
|
411
|
+
{(label) => <span class="flex-1 truncate text-left">{label()}</span>}
|
|
429
412
|
</Show>
|
|
430
|
-
</
|
|
413
|
+
</PickerTrigger>
|
|
431
414
|
);
|
|
432
415
|
|
|
433
416
|
const EntityRow = (p: { id: string; entityIndex: number; top: number }) => {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
2
|
import { STAGGER } from "../lib/motion-classes.js";
|
|
3
|
-
import { PICKER_LIST
|
|
3
|
+
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
4
4
|
import { CHIP, ICON_PILL_TINT } from "../lib/pill-classes.js";
|
|
5
5
|
import { cn } from "../lib/utils.js";
|
|
6
6
|
import { Icon } from "./icon.js";
|
|
7
7
|
import { PickerSearch } from "./picker-search.js";
|
|
8
|
+
import { PickerTrigger } from "./picker-trigger.js";
|
|
8
9
|
import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
|
|
9
10
|
|
|
10
11
|
const ICON_LIBRARIES = [
|
|
@@ -311,12 +312,15 @@ export function IconPicker(props: IconPickerProps) {
|
|
|
311
312
|
return defaultIcons().filter((icon) => icon.toLowerCase().includes(q));
|
|
312
313
|
});
|
|
313
314
|
|
|
315
|
+
// A re-tap on the picked icon clears it, the way every picker toggles.
|
|
314
316
|
const selectIcon = (icon: string) => {
|
|
315
|
-
props.onChange(icon);
|
|
317
|
+
props.onChange(icon === props.value.trim() ? "" : icon);
|
|
316
318
|
setOpen(false);
|
|
317
319
|
setSearch("");
|
|
318
320
|
};
|
|
319
321
|
|
|
322
|
+
const clearIcon = () => props.onChange("");
|
|
323
|
+
|
|
320
324
|
const handleLibChange = (prefix: string) => {
|
|
321
325
|
setActiveLib(prefix);
|
|
322
326
|
setApiResults([]);
|
|
@@ -328,13 +332,13 @@ export function IconPicker(props: IconPickerProps) {
|
|
|
328
332
|
return (
|
|
329
333
|
<Popover surface="field" open={open()} onOpenChange={setOpen} modal>
|
|
330
334
|
<PopoverAnchor as="div" class={props.class}>
|
|
331
|
-
<
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
+
<PickerTrigger
|
|
336
|
+
slot="icon-picker-trigger"
|
|
337
|
+
open={open()}
|
|
338
|
+
onToggle={() => setOpen(!open())}
|
|
335
339
|
aria-labelledby={props["aria-labelledby"]}
|
|
336
|
-
|
|
337
|
-
|
|
340
|
+
onClear={props.value.trim() ? clearIcon : undefined}
|
|
341
|
+
clearLabel="Clear icon"
|
|
338
342
|
>
|
|
339
343
|
<Show
|
|
340
344
|
when={props.value.trim()}
|
|
@@ -347,13 +351,7 @@ export function IconPicker(props: IconPickerProps) {
|
|
|
347
351
|
<Icon icon={props.value.trim()} width={18} height={18} class="shrink-0" />
|
|
348
352
|
<span class="flex-1 truncate text-left">{props.value}</span>
|
|
349
353
|
</Show>
|
|
350
|
-
|
|
351
|
-
icon="mdi:chevron-down"
|
|
352
|
-
width={16}
|
|
353
|
-
height={16}
|
|
354
|
-
class="shrink-0 text-muted-foreground"
|
|
355
|
-
/>
|
|
356
|
-
</button>
|
|
354
|
+
</PickerTrigger>
|
|
357
355
|
</PopoverAnchor>
|
|
358
356
|
<PopoverContent
|
|
359
357
|
onOpenAutoFocus={(e) => {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Show,
|
|
9
9
|
Switch,
|
|
10
10
|
} from "solid-js";
|
|
11
|
-
import { PICKER_LIST
|
|
11
|
+
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
12
12
|
import { cn } from "../lib/utils.js";
|
|
13
13
|
import { Alert } from "./alert.js";
|
|
14
14
|
import {
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
PaginationNext,
|
|
50
50
|
PaginationPrevious,
|
|
51
51
|
} from "./pagination.js";
|
|
52
|
+
import { PickerTrigger } from "./picker-trigger.js";
|
|
52
53
|
import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
|
|
53
54
|
import { SectionMeta } from "./section-card.js";
|
|
54
55
|
import { Skeleton } from "./skeleton.js";
|
|
@@ -103,6 +104,11 @@ export function ImagePicker(props: ImagePickerProps) {
|
|
|
103
104
|
: `This image is used in ${used} widget${used === 1 ? "" : "s"}. Deleting it will leave those widgets without an image.`;
|
|
104
105
|
});
|
|
105
106
|
|
|
107
|
+
const clearImage = () => {
|
|
108
|
+
props.onChange("");
|
|
109
|
+
setThumbBroken(false);
|
|
110
|
+
};
|
|
111
|
+
|
|
106
112
|
const openGallery = (next: boolean) => {
|
|
107
113
|
if (next) setEverOpened(true);
|
|
108
114
|
setOpen(next);
|
|
@@ -154,13 +160,13 @@ export function ImagePicker(props: ImagePickerProps) {
|
|
|
154
160
|
<div data-slot="image-picker" class={cn(props.class)}>
|
|
155
161
|
<Popover surface="field" open={open()} onOpenChange={openGallery} modal>
|
|
156
162
|
<PopoverAnchor as="div">
|
|
157
|
-
<
|
|
158
|
-
type="button"
|
|
163
|
+
<PickerTrigger
|
|
159
164
|
id={props.id}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
slot="image-picker-trigger"
|
|
166
|
+
open={open()}
|
|
167
|
+
onToggle={() => openGallery(!open())}
|
|
168
|
+
onClear={props.value ? clearImage : undefined}
|
|
169
|
+
clearLabel="Clear image"
|
|
164
170
|
>
|
|
165
171
|
<Show
|
|
166
172
|
when={!thumbBroken() && props.value}
|
|
@@ -189,13 +195,7 @@ export function ImagePicker(props: ImagePickerProps) {
|
|
|
189
195
|
/>
|
|
190
196
|
<span class="flex-1 truncate text-left">Image selected</span>
|
|
191
197
|
</Show>
|
|
192
|
-
|
|
193
|
-
icon="lucide:chevron-down"
|
|
194
|
-
width={16}
|
|
195
|
-
height={16}
|
|
196
|
-
class="shrink-0 text-muted-foreground"
|
|
197
|
-
/>
|
|
198
|
-
</button>
|
|
198
|
+
</PickerTrigger>
|
|
199
199
|
</PopoverAnchor>
|
|
200
200
|
<PopoverContent class="min-w-72" onInteractOutside={() => setOpen(false)}>
|
|
201
201
|
{/* The panel owns no padding: the gallery body owns its own inset. */}
|
|
@@ -268,7 +268,7 @@ export function ImagePicker(props: ImagePickerProps) {
|
|
|
268
268
|
markUnused
|
|
269
269
|
selected={props.value === image.id}
|
|
270
270
|
onSelect={() => {
|
|
271
|
-
props.onChange(image.id);
|
|
271
|
+
props.onChange(props.value === image.id ? "" : image.id);
|
|
272
272
|
setThumbBroken(false);
|
|
273
273
|
setOpen(false);
|
|
274
274
|
}}
|
package/src/solid/index.ts
CHANGED
|
@@ -300,6 +300,7 @@ export {
|
|
|
300
300
|
export { PasswordInput } from "./password-input.js";
|
|
301
301
|
export { PICKER_ROW_HEIGHT, PickerRow } from "./picker-row.js";
|
|
302
302
|
export { PickerSearch, type PickerSearchProps } from "./picker-search.js";
|
|
303
|
+
export { PickerTrigger, type PickerTriggerProps } from "./picker-trigger.js";
|
|
303
304
|
export {
|
|
304
305
|
Popover,
|
|
305
306
|
PopoverAnchor,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type JSX, Show, splitProps } from "solid-js";
|
|
2
|
+
import { PICKER_TRIGGER } from "../lib/picker-classes.js";
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { Icon } from "./icon.js";
|
|
5
|
+
|
|
6
|
+
export interface PickerTriggerProps
|
|
7
|
+
extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> {
|
|
8
|
+
/** data-slot for the button, so each picker keeps its own test and style hook. */
|
|
9
|
+
slot: string;
|
|
10
|
+
open: boolean;
|
|
11
|
+
onToggle: () => void;
|
|
12
|
+
/** Passed only when there is a value to drop: its presence paints the clear button. */
|
|
13
|
+
onClear?: () => void;
|
|
14
|
+
clearLabel?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function PickerTrigger(props: PickerTriggerProps) {
|
|
18
|
+
const [own, rest] = splitProps(props, [
|
|
19
|
+
"slot",
|
|
20
|
+
"open",
|
|
21
|
+
"onToggle",
|
|
22
|
+
"onClear",
|
|
23
|
+
"clearLabel",
|
|
24
|
+
"class",
|
|
25
|
+
"children",
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div class="relative">
|
|
30
|
+
<button
|
|
31
|
+
type="button"
|
|
32
|
+
data-slot={own.slot}
|
|
33
|
+
data-expanded={own.open || undefined}
|
|
34
|
+
class={cn(PICKER_TRIGGER, own.class)}
|
|
35
|
+
onClick={() => own.onToggle()}
|
|
36
|
+
{...rest}
|
|
37
|
+
>
|
|
38
|
+
{own.children}
|
|
39
|
+
{/* The clear button cannot nest inside the trigger button, so it is
|
|
40
|
+
positioned over this gap, left of the chevron. */}
|
|
41
|
+
<Show when={own.onClear}>
|
|
42
|
+
<span class="w-6 shrink-0" />
|
|
43
|
+
</Show>
|
|
44
|
+
<Icon
|
|
45
|
+
icon="lucide:chevron-down"
|
|
46
|
+
width={16}
|
|
47
|
+
height={16}
|
|
48
|
+
class={cn(
|
|
49
|
+
"shrink-0 text-muted-foreground transition-transform",
|
|
50
|
+
own.open && "rotate-180",
|
|
51
|
+
)}
|
|
52
|
+
/>
|
|
53
|
+
</button>
|
|
54
|
+
<Show when={own.onClear}>
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
data-slot="picker-trigger-clear"
|
|
58
|
+
aria-label={own.clearLabel ?? "Clear selection"}
|
|
59
|
+
disabled={rest.disabled}
|
|
60
|
+
class="absolute top-1/2 right-9 flex -translate-y-1/2 items-center rounded-sm p-1 text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50"
|
|
61
|
+
onClick={() => own.onClear?.()}
|
|
62
|
+
>
|
|
63
|
+
<Icon icon="lucide:circle-x" width={16} height={16} />
|
|
64
|
+
</button>
|
|
65
|
+
</Show>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|