@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,432 @@
|
|
|
1
|
+
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
|
+
import { STAGGER } from "../lib/motion-classes.js";
|
|
3
|
+
import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
|
|
4
|
+
import { CHIP, ICON_PILL_TINT } from "../lib/pill-classes.js";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
import { Icon } from "./icon.js";
|
|
7
|
+
import { PickerSearch } from "./picker-search.js";
|
|
8
|
+
import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
|
|
9
|
+
|
|
10
|
+
const ICON_LIBRARIES = [
|
|
11
|
+
{ prefix: "", label: "All" },
|
|
12
|
+
{ prefix: "mdi", label: "MDI" },
|
|
13
|
+
{ prefix: "lucide", label: "Lucide" },
|
|
14
|
+
{ prefix: "solar", label: "Solar" },
|
|
15
|
+
{ prefix: "tabler", label: "Tabler" },
|
|
16
|
+
{ prefix: "ph", label: "Phosphor" },
|
|
17
|
+
{ prefix: "fluent", label: "Fluent" },
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
const COMMON_ICONS: Record<string, string[]> = {
|
|
21
|
+
mdi: [
|
|
22
|
+
"mdi:home",
|
|
23
|
+
"mdi:home-outline",
|
|
24
|
+
"mdi:lightbulb",
|
|
25
|
+
"mdi:lightbulb-outline",
|
|
26
|
+
"mdi:lamp",
|
|
27
|
+
"mdi:ceiling-light",
|
|
28
|
+
"mdi:floor-lamp",
|
|
29
|
+
"mdi:led-strip",
|
|
30
|
+
"mdi:power-plug",
|
|
31
|
+
"mdi:power-socket",
|
|
32
|
+
"mdi:toggle-switch",
|
|
33
|
+
"mdi:thermometer",
|
|
34
|
+
"mdi:thermostat",
|
|
35
|
+
"mdi:air-conditioner",
|
|
36
|
+
"mdi:fan",
|
|
37
|
+
"mdi:water",
|
|
38
|
+
"mdi:fire",
|
|
39
|
+
"mdi:snowflake",
|
|
40
|
+
"mdi:weather-partly-cloudy",
|
|
41
|
+
"mdi:lock",
|
|
42
|
+
"mdi:lock-open",
|
|
43
|
+
"mdi:door",
|
|
44
|
+
"mdi:door-open",
|
|
45
|
+
"mdi:window-closed",
|
|
46
|
+
"mdi:window-open",
|
|
47
|
+
"mdi:garage",
|
|
48
|
+
"mdi:gate",
|
|
49
|
+
"mdi:blinds",
|
|
50
|
+
"mdi:television",
|
|
51
|
+
"mdi:speaker",
|
|
52
|
+
"mdi:cast",
|
|
53
|
+
"mdi:camera",
|
|
54
|
+
"mdi:cctv",
|
|
55
|
+
"mdi:motion-sensor",
|
|
56
|
+
"mdi:smoke-detector",
|
|
57
|
+
"mdi:bell",
|
|
58
|
+
"mdi:battery",
|
|
59
|
+
"mdi:solar-power",
|
|
60
|
+
"mdi:robot-vacuum",
|
|
61
|
+
"mdi:washing-machine",
|
|
62
|
+
"mdi:fridge",
|
|
63
|
+
"mdi:stove",
|
|
64
|
+
"mdi:bed",
|
|
65
|
+
"mdi:sofa",
|
|
66
|
+
"mdi:shower",
|
|
67
|
+
"mdi:car",
|
|
68
|
+
"mdi:wifi",
|
|
69
|
+
"mdi:router-wireless",
|
|
70
|
+
"mdi:view-dashboard",
|
|
71
|
+
"mdi:cog",
|
|
72
|
+
"mdi:star",
|
|
73
|
+
"mdi:heart",
|
|
74
|
+
"mdi:shield-home",
|
|
75
|
+
"mdi:home-floor-1",
|
|
76
|
+
"mdi:home-floor-2",
|
|
77
|
+
"mdi:home-floor-3",
|
|
78
|
+
"mdi:home-group",
|
|
79
|
+
"mdi:office-building",
|
|
80
|
+
],
|
|
81
|
+
lucide: [
|
|
82
|
+
"lucide:home",
|
|
83
|
+
"lucide:lightbulb",
|
|
84
|
+
"lucide:lamp",
|
|
85
|
+
"lucide:lamp-desk",
|
|
86
|
+
"lucide:plug",
|
|
87
|
+
"lucide:power",
|
|
88
|
+
"lucide:thermometer",
|
|
89
|
+
"lucide:flame",
|
|
90
|
+
"lucide:snowflake",
|
|
91
|
+
"lucide:wind",
|
|
92
|
+
"lucide:droplets",
|
|
93
|
+
"lucide:sun",
|
|
94
|
+
"lucide:cloud-sun",
|
|
95
|
+
"lucide:lock",
|
|
96
|
+
"lucide:lock-open",
|
|
97
|
+
"lucide:door-open",
|
|
98
|
+
"lucide:door-closed",
|
|
99
|
+
"lucide:blinds",
|
|
100
|
+
"lucide:tv",
|
|
101
|
+
"lucide:speaker",
|
|
102
|
+
"lucide:camera",
|
|
103
|
+
"lucide:bell",
|
|
104
|
+
"lucide:battery",
|
|
105
|
+
"lucide:car",
|
|
106
|
+
"lucide:wifi",
|
|
107
|
+
"lucide:router",
|
|
108
|
+
"lucide:layout-dashboard",
|
|
109
|
+
"lucide:settings",
|
|
110
|
+
"lucide:star",
|
|
111
|
+
"lucide:heart",
|
|
112
|
+
"lucide:shield",
|
|
113
|
+
"lucide:eye",
|
|
114
|
+
"lucide:zap",
|
|
115
|
+
"lucide:clock",
|
|
116
|
+
"lucide:calendar",
|
|
117
|
+
"lucide:link",
|
|
118
|
+
"lucide:image",
|
|
119
|
+
"lucide:music",
|
|
120
|
+
"lucide:map-pin",
|
|
121
|
+
"lucide:user",
|
|
122
|
+
],
|
|
123
|
+
solar: [
|
|
124
|
+
"solar:home-bold",
|
|
125
|
+
"solar:home-linear",
|
|
126
|
+
"solar:lamp-bold",
|
|
127
|
+
"solar:lightbulb-bolt-bold",
|
|
128
|
+
"solar:plug-circle-bold",
|
|
129
|
+
"solar:temperature-bold",
|
|
130
|
+
"solar:fire-bold",
|
|
131
|
+
"solar:snowflake-bold",
|
|
132
|
+
"solar:lock-bold",
|
|
133
|
+
"solar:lock-unlocked-bold",
|
|
134
|
+
"solar:tv-bold",
|
|
135
|
+
"solar:speaker-bold",
|
|
136
|
+
"solar:camera-bold",
|
|
137
|
+
"solar:bell-bold",
|
|
138
|
+
"solar:battery-charge-bold",
|
|
139
|
+
"solar:wi-fi-router-bold",
|
|
140
|
+
"solar:widget-bold",
|
|
141
|
+
"solar:settings-bold",
|
|
142
|
+
"solar:star-bold",
|
|
143
|
+
"solar:heart-bold",
|
|
144
|
+
"solar:shield-bold",
|
|
145
|
+
"solar:eye-bold",
|
|
146
|
+
"solar:bolt-bold",
|
|
147
|
+
"solar:clock-circle-bold",
|
|
148
|
+
"solar:calendar-bold",
|
|
149
|
+
"solar:link-bold",
|
|
150
|
+
"solar:gallery-bold",
|
|
151
|
+
"solar:music-note-bold",
|
|
152
|
+
"solar:map-point-bold",
|
|
153
|
+
"solar:user-bold",
|
|
154
|
+
],
|
|
155
|
+
tabler: [
|
|
156
|
+
"tabler:home",
|
|
157
|
+
"tabler:bulb",
|
|
158
|
+
"tabler:lamp",
|
|
159
|
+
"tabler:plug",
|
|
160
|
+
"tabler:power",
|
|
161
|
+
"tabler:temperature",
|
|
162
|
+
"tabler:flame",
|
|
163
|
+
"tabler:snowflake",
|
|
164
|
+
"tabler:wind",
|
|
165
|
+
"tabler:droplet",
|
|
166
|
+
"tabler:sun",
|
|
167
|
+
"tabler:cloud",
|
|
168
|
+
"tabler:lock",
|
|
169
|
+
"tabler:lock-open",
|
|
170
|
+
"tabler:door",
|
|
171
|
+
"tabler:window",
|
|
172
|
+
"tabler:device-tv",
|
|
173
|
+
"tabler:speaker",
|
|
174
|
+
"tabler:camera",
|
|
175
|
+
"tabler:bell",
|
|
176
|
+
"tabler:battery",
|
|
177
|
+
"tabler:car",
|
|
178
|
+
"tabler:wifi",
|
|
179
|
+
"tabler:router",
|
|
180
|
+
"tabler:dashboard",
|
|
181
|
+
"tabler:settings",
|
|
182
|
+
"tabler:star",
|
|
183
|
+
"tabler:heart",
|
|
184
|
+
"tabler:shield",
|
|
185
|
+
"tabler:eye",
|
|
186
|
+
],
|
|
187
|
+
ph: [
|
|
188
|
+
"ph:house-bold",
|
|
189
|
+
"ph:lightbulb-bold",
|
|
190
|
+
"ph:lamp-bold",
|
|
191
|
+
"ph:plug-bold",
|
|
192
|
+
"ph:power-bold",
|
|
193
|
+
"ph:thermometer-bold",
|
|
194
|
+
"ph:fire-bold",
|
|
195
|
+
"ph:snowflake-bold",
|
|
196
|
+
"ph:wind-bold",
|
|
197
|
+
"ph:drop-bold",
|
|
198
|
+
"ph:sun-bold",
|
|
199
|
+
"ph:cloud-sun-bold",
|
|
200
|
+
"ph:lock-bold",
|
|
201
|
+
"ph:lock-open-bold",
|
|
202
|
+
"ph:door-bold",
|
|
203
|
+
"ph:television-bold",
|
|
204
|
+
"ph:speaker-high-bold",
|
|
205
|
+
"ph:camera-bold",
|
|
206
|
+
"ph:bell-bold",
|
|
207
|
+
"ph:battery-charging-bold",
|
|
208
|
+
"ph:car-bold",
|
|
209
|
+
"ph:wifi-high-bold",
|
|
210
|
+
"ph:squares-four-bold",
|
|
211
|
+
"ph:gear-bold",
|
|
212
|
+
"ph:star-bold",
|
|
213
|
+
"ph:heart-bold",
|
|
214
|
+
"ph:shield-bold",
|
|
215
|
+
"ph:eye-bold",
|
|
216
|
+
"ph:lightning-bold",
|
|
217
|
+
"ph:clock-bold",
|
|
218
|
+
],
|
|
219
|
+
fluent: [
|
|
220
|
+
"fluent:home-24-filled",
|
|
221
|
+
"fluent:lightbulb-24-filled",
|
|
222
|
+
"fluent:plug-connected-24-filled",
|
|
223
|
+
"fluent:power-24-filled",
|
|
224
|
+
"fluent:temperature-24-filled",
|
|
225
|
+
"fluent:fire-24-filled",
|
|
226
|
+
"fluent:weather-snowflake-24-filled",
|
|
227
|
+
"fluent:lock-closed-24-filled",
|
|
228
|
+
"fluent:lock-open-24-filled",
|
|
229
|
+
"fluent:door-24-filled",
|
|
230
|
+
"fluent:tv-24-filled",
|
|
231
|
+
"fluent:speaker-2-24-filled",
|
|
232
|
+
"fluent:camera-24-filled",
|
|
233
|
+
"fluent:alert-24-filled",
|
|
234
|
+
"fluent:battery-charge-24-filled",
|
|
235
|
+
"fluent:vehicle-car-24-filled",
|
|
236
|
+
"fluent:wifi-1-24-filled",
|
|
237
|
+
"fluent:board-24-filled",
|
|
238
|
+
"fluent:settings-24-filled",
|
|
239
|
+
"fluent:star-24-filled",
|
|
240
|
+
"fluent:heart-24-filled",
|
|
241
|
+
"fluent:shield-24-filled",
|
|
242
|
+
"fluent:eye-24-filled",
|
|
243
|
+
"fluent:flash-24-filled",
|
|
244
|
+
"fluent:clock-24-filled",
|
|
245
|
+
"fluent:calendar-24-filled",
|
|
246
|
+
"fluent:link-24-filled",
|
|
247
|
+
"fluent:image-24-filled",
|
|
248
|
+
"fluent:music-note-1-24-filled",
|
|
249
|
+
"fluent:person-24-filled",
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export interface IconPickerProps {
|
|
254
|
+
value: string;
|
|
255
|
+
onChange: (value: string) => void;
|
|
256
|
+
placeholder?: string;
|
|
257
|
+
class?: string;
|
|
258
|
+
/**
|
|
259
|
+
* Host-provided icon search. The design system carries no network or CSP
|
|
260
|
+
* policy of its own: dash proxies the Iconify API same-origin so its
|
|
261
|
+
* connect-src allowlist stays free of third-party origins. Without this the
|
|
262
|
+
* picker still works, showing the curated set only.
|
|
263
|
+
*/
|
|
264
|
+
searchIcons?: (query: string, prefix: string) => Promise<string[]>;
|
|
265
|
+
/** Id of the element naming the trigger, for forms that label it outside. */
|
|
266
|
+
"aria-labelledby"?: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function IconPicker(props: IconPickerProps) {
|
|
270
|
+
const [open, setOpen] = createSignal(false);
|
|
271
|
+
const [search, setSearch] = createSignal("");
|
|
272
|
+
const [activeLib, setActiveLib] = createSignal("");
|
|
273
|
+
const [apiResults, setApiResults] = createSignal<string[]>([]);
|
|
274
|
+
const [loading, setLoading] = createSignal(false);
|
|
275
|
+
|
|
276
|
+
let debounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
277
|
+
let searchRef: HTMLInputElement | undefined;
|
|
278
|
+
|
|
279
|
+
const searchIcons = (query: string, prefix: string) => {
|
|
280
|
+
clearTimeout(debounceTimer);
|
|
281
|
+
if (!query.trim()) {
|
|
282
|
+
setApiResults([]);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const search = props.searchIcons;
|
|
286
|
+
if (!search) return;
|
|
287
|
+
setLoading(true);
|
|
288
|
+
debounceTimer = setTimeout(async () => {
|
|
289
|
+
try {
|
|
290
|
+
setApiResults(await search(query, prefix));
|
|
291
|
+
} catch {
|
|
292
|
+
setApiResults([]);
|
|
293
|
+
} finally {
|
|
294
|
+
setLoading(false);
|
|
295
|
+
}
|
|
296
|
+
}, 300);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const defaultIcons = createMemo(() => {
|
|
300
|
+
const lib = activeLib();
|
|
301
|
+
if (!lib) {
|
|
302
|
+
return Object.values(COMMON_ICONS).flat().slice(0, 60);
|
|
303
|
+
}
|
|
304
|
+
return COMMON_ICONS[lib] ?? [];
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const displayIcons = createMemo(() => {
|
|
308
|
+
const q = search().toLowerCase().trim();
|
|
309
|
+
if (!q) return defaultIcons();
|
|
310
|
+
if (apiResults().length > 0) return apiResults();
|
|
311
|
+
return defaultIcons().filter((icon) => icon.toLowerCase().includes(q));
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const selectIcon = (icon: string) => {
|
|
315
|
+
props.onChange(icon);
|
|
316
|
+
setOpen(false);
|
|
317
|
+
setSearch("");
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const handleLibChange = (prefix: string) => {
|
|
321
|
+
setActiveLib(prefix);
|
|
322
|
+
setApiResults([]);
|
|
323
|
+
if (search().trim()) {
|
|
324
|
+
searchIcons(search(), prefix);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
return (
|
|
329
|
+
<Popover surface="field" open={open()} onOpenChange={setOpen} modal>
|
|
330
|
+
<PopoverAnchor as="div" class={props.class}>
|
|
331
|
+
<button
|
|
332
|
+
type="button"
|
|
333
|
+
data-slot="icon-picker-trigger"
|
|
334
|
+
data-expanded={open() || undefined}
|
|
335
|
+
aria-labelledby={props["aria-labelledby"]}
|
|
336
|
+
class={PICKER_TRIGGER}
|
|
337
|
+
onClick={() => setOpen(!open())}
|
|
338
|
+
>
|
|
339
|
+
<Show
|
|
340
|
+
when={props.value.trim()}
|
|
341
|
+
fallback={
|
|
342
|
+
<span class="flex-1 text-left text-muted-foreground">
|
|
343
|
+
{props.placeholder ?? "mdi:home"}
|
|
344
|
+
</span>
|
|
345
|
+
}
|
|
346
|
+
>
|
|
347
|
+
<Icon icon={props.value.trim()} width={18} height={18} class="shrink-0" />
|
|
348
|
+
<span class="flex-1 truncate text-left">{props.value}</span>
|
|
349
|
+
</Show>
|
|
350
|
+
<Icon
|
|
351
|
+
icon="mdi:chevron-down"
|
|
352
|
+
width={16}
|
|
353
|
+
height={16}
|
|
354
|
+
class="shrink-0 text-muted-foreground"
|
|
355
|
+
/>
|
|
356
|
+
</button>
|
|
357
|
+
</PopoverAnchor>
|
|
358
|
+
<PopoverContent
|
|
359
|
+
onOpenAutoFocus={(e) => {
|
|
360
|
+
e.preventDefault();
|
|
361
|
+
// preventScroll: the panel is portalled at (0,0) until the popper places it,
|
|
362
|
+
// so a plain focus() scrolls the page to the top.
|
|
363
|
+
searchRef?.focus({ preventScroll: true });
|
|
364
|
+
}}
|
|
365
|
+
onInteractOutside={() => setOpen(false)}
|
|
366
|
+
>
|
|
367
|
+
<div class="flex flex-col">
|
|
368
|
+
<PickerSearch
|
|
369
|
+
inputRef={(el) => {
|
|
370
|
+
searchRef = el;
|
|
371
|
+
}}
|
|
372
|
+
value={search()}
|
|
373
|
+
onValueChange={(next) => {
|
|
374
|
+
setSearch(next);
|
|
375
|
+
searchIcons(next, activeLib());
|
|
376
|
+
}}
|
|
377
|
+
placeholder="Search icons..."
|
|
378
|
+
aria-label="Search icons"
|
|
379
|
+
/>
|
|
380
|
+
<div class="flex flex-wrap gap-1 border-border/50 border-b px-2 py-1.5">
|
|
381
|
+
<For each={ICON_LIBRARIES}>
|
|
382
|
+
{(lib) => (
|
|
383
|
+
<button
|
|
384
|
+
type="button"
|
|
385
|
+
data-slot="icon-picker-library"
|
|
386
|
+
aria-pressed={activeLib() === lib.prefix}
|
|
387
|
+
class={cn(
|
|
388
|
+
CHIP,
|
|
389
|
+
"cursor-pointer transition-glass",
|
|
390
|
+
activeLib() === lib.prefix
|
|
391
|
+
? "[--glass-tone:var(--primary)]"
|
|
392
|
+
: "text-muted-foreground [--glass-base:transparent] [--glass-edge:transparent] [--glass-light:0] [--glass-rim:0] hover:text-foreground",
|
|
393
|
+
)}
|
|
394
|
+
onClick={() => handleLibChange(lib.prefix)}
|
|
395
|
+
>
|
|
396
|
+
{lib.label}
|
|
397
|
+
</button>
|
|
398
|
+
)}
|
|
399
|
+
</For>
|
|
400
|
+
</div>
|
|
401
|
+
<div class={cn(PICKER_LIST, "p-2")}>
|
|
402
|
+
<Show when={loading() && displayIcons().length === 0}>
|
|
403
|
+
<div class="py-4 text-center text-muted-foreground text-sm">Searching...</div>
|
|
404
|
+
</Show>
|
|
405
|
+
<Show when={!loading() && search().trim() && displayIcons().length === 0}>
|
|
406
|
+
<div class="py-4 text-center text-muted-foreground text-sm">No icons found</div>
|
|
407
|
+
</Show>
|
|
408
|
+
<div class={cn("grid grid-cols-6 gap-1", STAGGER)}>
|
|
409
|
+
<For each={displayIcons()}>
|
|
410
|
+
{(icon) => (
|
|
411
|
+
<button
|
|
412
|
+
type="button"
|
|
413
|
+
aria-pressed={props.value === icon}
|
|
414
|
+
class={cn(
|
|
415
|
+
"mx-auto flex size-11 cursor-pointer items-center justify-center rounded-full transition-glass hover:bg-accent",
|
|
416
|
+
props.value === icon &&
|
|
417
|
+
`${ICON_PILL_TINT} text-foreground [--glass-tone:var(--primary)] hover:bg-transparent`,
|
|
418
|
+
)}
|
|
419
|
+
onClick={() => selectIcon(icon)}
|
|
420
|
+
title={icon}
|
|
421
|
+
>
|
|
422
|
+
<Icon icon={icon} width={22} height={22} />
|
|
423
|
+
</button>
|
|
424
|
+
)}
|
|
425
|
+
</For>
|
|
426
|
+
</div>
|
|
427
|
+
</div>
|
|
428
|
+
</div>
|
|
429
|
+
</PopoverContent>
|
|
430
|
+
</Popover>
|
|
431
|
+
);
|
|
432
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { IconifyIcon } from "@iconify/types";
|
|
2
|
+
import { iconToSVG } from "@iconify/utils";
|
|
3
|
+
import { createMemo, createSignal, type JSX, splitProps } from "solid-js";
|
|
4
|
+
|
|
5
|
+
export type IconData = IconifyIcon;
|
|
6
|
+
|
|
7
|
+
export interface IconSource {
|
|
8
|
+
/** Icons known at build time, keyed `prefix:name`. */
|
|
9
|
+
bundled: Record<string, IconData>;
|
|
10
|
+
/** Resolves the rest in one batch; a name the source does not have maps to null. */
|
|
11
|
+
load?: (names: string[]) => Promise<Record<string, IconData | null>>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Module-level singleton, the same shape as provideEntityData: widget sandboxes
|
|
16
|
+
* mount their own Solid roots but resolve this module through the host import
|
|
17
|
+
* map, so the host's source reaches them too.
|
|
18
|
+
*/
|
|
19
|
+
let source: IconSource | undefined;
|
|
20
|
+
const loaded = new Map<string, IconData | null>();
|
|
21
|
+
const [generation, setGeneration] = createSignal(0);
|
|
22
|
+
let pending = new Set<string>();
|
|
23
|
+
let flush: Promise<void> | null = null;
|
|
24
|
+
|
|
25
|
+
/** Host apps call this once at startup; every mounted Icon re-resolves. */
|
|
26
|
+
export function provideIcons(next: IconSource): void {
|
|
27
|
+
source = next;
|
|
28
|
+
loaded.clear();
|
|
29
|
+
setGeneration((g) => g + 1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function request(name: string): void {
|
|
33
|
+
const load = source?.load;
|
|
34
|
+
if (!load || pending.has(name)) return;
|
|
35
|
+
pending.add(name);
|
|
36
|
+
if (flush) return;
|
|
37
|
+
flush = Promise.resolve().then(async () => {
|
|
38
|
+
const names = [...pending];
|
|
39
|
+
pending = new Set();
|
|
40
|
+
flush = null;
|
|
41
|
+
let result: Record<string, IconData | null> = {};
|
|
42
|
+
try {
|
|
43
|
+
result = await load(names);
|
|
44
|
+
} catch {
|
|
45
|
+
result = {};
|
|
46
|
+
}
|
|
47
|
+
for (const n of names) loaded.set(n, result[n] ?? null);
|
|
48
|
+
setGeneration((g) => g + 1);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function lookup(name: string): IconData | undefined {
|
|
53
|
+
generation();
|
|
54
|
+
const bundled = source?.bundled[name];
|
|
55
|
+
if (bundled) return bundled;
|
|
56
|
+
if (loaded.has(name)) return loaded.get(name) ?? undefined;
|
|
57
|
+
request(name);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface TrustedPolicy {
|
|
62
|
+
createHTML(input: string): string;
|
|
63
|
+
}
|
|
64
|
+
let policy: TrustedPolicy | null | undefined;
|
|
65
|
+
|
|
66
|
+
// Icon bodies come from the build or the host's own icon route; under a
|
|
67
|
+
// require-trusted-types-for CSP the assignment still needs a policy.
|
|
68
|
+
function trusted(html: string): string {
|
|
69
|
+
if (policy === undefined) {
|
|
70
|
+
const tt = (
|
|
71
|
+
globalThis as {
|
|
72
|
+
trustedTypes?: { createPolicy(name: string, rules: TrustedPolicy): TrustedPolicy };
|
|
73
|
+
}
|
|
74
|
+
).trustedTypes;
|
|
75
|
+
try {
|
|
76
|
+
policy = tt ? tt.createPolicy("glasshome-ui", { createHTML: (s) => s }) : null;
|
|
77
|
+
} catch {
|
|
78
|
+
policy = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return policy ? policy.createHTML(html) : html;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface IconProps
|
|
85
|
+
extends Omit<JSX.SvgSVGAttributes<SVGSVGElement>, "width" | "height" | "children"> {
|
|
86
|
+
/** `prefix:name`, e.g. `lucide:plus`. */
|
|
87
|
+
icon: string;
|
|
88
|
+
/** Unitless = px; both omitted = 1em, one omitted = the icon's own ratio. */
|
|
89
|
+
width?: number | string;
|
|
90
|
+
height?: number | string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const EMPTY = { attributes: { viewBox: "0 0 16 16", width: "1em", height: "1em" }, body: "" };
|
|
94
|
+
|
|
95
|
+
/** One inline `<svg>` per icon: no shadow root, no observer, rendered once and kept. */
|
|
96
|
+
export function Icon(props: IconProps) {
|
|
97
|
+
const [local, rest] = splitProps(props, ["icon", "width", "height"]);
|
|
98
|
+
const built = createMemo(() => {
|
|
99
|
+
const data = lookup(local.icon);
|
|
100
|
+
const size = {
|
|
101
|
+
width: local.width == null ? null : String(local.width),
|
|
102
|
+
height: local.height == null ? null : String(local.height),
|
|
103
|
+
};
|
|
104
|
+
if (!data) return { ...EMPTY, attributes: { ...EMPTY.attributes, ...sizeOrDefault(size) } };
|
|
105
|
+
return iconToSVG(data, size);
|
|
106
|
+
});
|
|
107
|
+
return (
|
|
108
|
+
<svg
|
|
109
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
110
|
+
data-slot="icon"
|
|
111
|
+
data-icon={local.icon}
|
|
112
|
+
aria-hidden="true"
|
|
113
|
+
fill="currentColor"
|
|
114
|
+
{...rest}
|
|
115
|
+
viewBox={built().attributes.viewBox}
|
|
116
|
+
width={built().attributes.width}
|
|
117
|
+
height={built().attributes.height}
|
|
118
|
+
innerHTML={trusted(built().body)}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function sizeOrDefault(size: { width: string | null; height: string | null }) {
|
|
124
|
+
if (size.width == null && size.height == null) return { width: "1em", height: "1em" };
|
|
125
|
+
return { width: size.width ?? size.height ?? "1em", height: size.height ?? size.width ?? "1em" };
|
|
126
|
+
}
|