@placeholderco/placeholder-ui 1.0.3 → 1.0.6

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.
Files changed (136) hide show
  1. package/LICENSE +26 -26
  2. package/README.md +179 -179
  3. package/dist/display/Alert.svelte +179 -179
  4. package/dist/display/Avatar.svelte +166 -166
  5. package/dist/display/LinkCollection.svelte +161 -161
  6. package/dist/display/Paper.svelte +118 -118
  7. package/dist/form/Autocomplete.svelte +223 -191
  8. package/dist/form/Autocomplete.svelte.d.ts +3 -1
  9. package/dist/form/AutocompleteMulti.svelte +356 -0
  10. package/dist/form/AutocompleteMulti.svelte.d.ts +28 -0
  11. package/dist/form/Checkbox.svelte +201 -201
  12. package/dist/form/Chips.svelte +128 -128
  13. package/dist/form/ComboBox.svelte +158 -158
  14. package/dist/form/ComboBox.svelte.d.ts +1 -1
  15. package/dist/form/ComboBoxItemBuilder.svelte +460 -460
  16. package/dist/form/ComboBoxMulti.svelte +197 -197
  17. package/dist/form/ComboBoxMulti.svelte.d.ts +1 -1
  18. package/dist/form/CronBuilder.svelte +693 -693
  19. package/dist/form/DatePicker.svelte +672 -672
  20. package/dist/form/DateTimePicker.svelte +712 -712
  21. package/dist/form/FileInput.svelte +235 -235
  22. package/dist/form/FormGroup.svelte +68 -68
  23. package/dist/form/Number.svelte +238 -238
  24. package/dist/form/PasswordInput.svelte +252 -252
  25. package/dist/form/RadioGroup.svelte +210 -210
  26. package/dist/form/Rating.svelte +235 -235
  27. package/dist/form/SegmentedControl.svelte +149 -149
  28. package/dist/form/Select.svelte +590 -590
  29. package/dist/form/Select.svelte.d.ts +1 -1
  30. package/dist/form/SelectMulti.svelte +613 -613
  31. package/dist/form/SelectMulti.svelte.d.ts +1 -1
  32. package/dist/form/Slider.svelte +358 -358
  33. package/dist/form/Switch.svelte +147 -147
  34. package/dist/form/TextArea.svelte +148 -148
  35. package/dist/form/Textbox.svelte +228 -228
  36. package/dist/form/TimePicker.svelte +267 -267
  37. package/dist/icon/Icon.svelte +52 -52
  38. package/dist/icon/alert-octagon.svg +5 -5
  39. package/dist/icon/alert-triangle.svg +5 -5
  40. package/dist/icon/archive.svg +1 -1
  41. package/dist/icon/arrow-down.svg +1 -1
  42. package/dist/icon/arrow-left.svg +1 -1
  43. package/dist/icon/arrow-right.svg +1 -1
  44. package/dist/icon/arrow-up.svg +1 -1
  45. package/dist/icon/at.svg +1 -1
  46. package/dist/icon/bell.svg +1 -1
  47. package/dist/icon/bookmark.svg +1 -1
  48. package/dist/icon/calendar.svg +1 -1
  49. package/dist/icon/camera.svg +1 -1
  50. package/dist/icon/chart-bar.svg +1 -1
  51. package/dist/icon/chart-line.svg +1 -1
  52. package/dist/icon/chart-pie.svg +1 -1
  53. package/dist/icon/checkbox.svg +1 -1
  54. package/dist/icon/checklist.svg +1 -1
  55. package/dist/icon/circle-check.svg +1 -1
  56. package/dist/icon/circle-x.svg +1 -1
  57. package/dist/icon/clock.svg +1 -1
  58. package/dist/icon/credit-card.svg +1 -1
  59. package/dist/icon/dots-vertical.svg +1 -1
  60. package/dist/icon/dots.svg +1 -1
  61. package/dist/icon/external-link.svg +1 -1
  62. package/dist/icon/eye-off.svg +1 -1
  63. package/dist/icon/eye.svg +1 -1
  64. package/dist/icon/filter.svg +1 -1
  65. package/dist/icon/fingerprint.svg +1 -1
  66. package/dist/icon/flag.svg +1 -1
  67. package/dist/icon/heart.svg +1 -1
  68. package/dist/icon/home.svg +1 -1
  69. package/dist/icon/key.svg +1 -1
  70. package/dist/icon/list-check.svg +1 -1
  71. package/dist/icon/login.svg +1 -1
  72. package/dist/icon/logout.svg +1 -1
  73. package/dist/icon/map-pin.svg +1 -1
  74. package/dist/icon/maximize.svg +1 -1
  75. package/dist/icon/microphone.svg +1 -1
  76. package/dist/icon/minimize.svg +1 -1
  77. package/dist/icon/note.svg +1 -1
  78. package/dist/icon/player-pause.svg +1 -1
  79. package/dist/icon/printer.svg +1 -1
  80. package/dist/icon/qrcode.svg +1 -1
  81. package/dist/icon/send.svg +1 -1
  82. package/dist/icon/settings.svg +1 -1
  83. package/dist/icon/share.svg +1 -1
  84. package/dist/icon/shopping-cart.svg +1 -1
  85. package/dist/icon/sort-ascending.svg +1 -1
  86. package/dist/icon/sort-descending.svg +1 -1
  87. package/dist/icon/star.svg +1 -1
  88. package/dist/icon/tag.svg +1 -1
  89. package/dist/icon/trending-down.svg +1 -1
  90. package/dist/icon/trending-up.svg +1 -1
  91. package/dist/icon/upload.svg +1 -1
  92. package/dist/icon/volume-off.svg +1 -1
  93. package/dist/icon/volume.svg +1 -1
  94. package/dist/icon/world.svg +1 -1
  95. package/dist/icon/zoom-in.svg +1 -1
  96. package/dist/icon/zoom-out.svg +1 -1
  97. package/dist/index.d.ts +1 -0
  98. package/dist/index.js +1 -0
  99. package/dist/layout/AppShell.svelte +169 -169
  100. package/dist/layout/CustomNavbar.svelte +61 -61
  101. package/dist/layout/Navbar.svelte +206 -206
  102. package/dist/layout/NavbarItemDisplay.svelte +29 -29
  103. package/dist/layout/Sidenav.svelte +712 -712
  104. package/dist/styles/components.css +199 -199
  105. package/dist/styles/dark.css +146 -146
  106. package/dist/styles/index.css +116 -116
  107. package/dist/styles/reset.css +110 -110
  108. package/dist/styles/semantic.css +86 -86
  109. package/dist/styles/tokens.css +203 -197
  110. package/dist/styles/utilities.css +523 -523
  111. package/dist/ui/Accordion.svelte +289 -289
  112. package/dist/ui/ActionIcon.svelte +76 -76
  113. package/dist/ui/Badge.svelte +329 -279
  114. package/dist/ui/Breadcrumbs.svelte +131 -131
  115. package/dist/ui/Button.svelte +432 -370
  116. package/dist/ui/ButtonVariant.d.ts +1 -1
  117. package/dist/ui/Dialog.svelte +307 -307
  118. package/dist/ui/Drawer.svelte +524 -524
  119. package/dist/ui/Dropdown.svelte +97 -97
  120. package/dist/ui/Dropzone.svelte +122 -122
  121. package/dist/ui/Link.svelte +32 -32
  122. package/dist/ui/Loader.svelte +70 -70
  123. package/dist/ui/LoadingOverlay.svelte +53 -53
  124. package/dist/ui/Pagination.svelte +135 -135
  125. package/dist/ui/Popover.svelte +225 -225
  126. package/dist/ui/Progress.svelte +191 -191
  127. package/dist/ui/RingProgress.svelte +141 -141
  128. package/dist/ui/Skeleton.svelte +85 -85
  129. package/dist/ui/Stepper.svelte +355 -355
  130. package/dist/ui/Table.svelte +345 -345
  131. package/dist/ui/Tabs.svelte +146 -146
  132. package/dist/ui/ThemeSwitcher.svelte +39 -39
  133. package/dist/ui/Timeline.svelte +225 -225
  134. package/dist/ui/Toaster.svelte +6 -6
  135. package/dist/ui/Tooltip.svelte +434 -434
  136. package/package.json +14 -14
@@ -0,0 +1,356 @@
1
+ <script lang="ts">
2
+ import { clickOutside } from "../actions/ClickOutside.js";
3
+ import type { NotifyModel } from "../models/NotifyModel.js";
4
+ import type {
5
+ ComboBoxItem,
6
+ FetchFunctionType,
7
+ SearchFunctionType,
8
+ } from "../models/ComboBoxItem.js";
9
+ import ComboBoxMulti from "./ComboBoxMulti.svelte";
10
+ import FormGroup from "./FormGroup.svelte";
11
+ import Badge from "../ui/Badge.svelte";
12
+ import { onMount, tick, type Snippet } from "svelte";
13
+
14
+ interface Props {
15
+ label?: string;
16
+ values?: string[];
17
+ rawValues?: ComboBoxItem[];
18
+ placeholder?: string;
19
+ class?: string;
20
+ disabled?: boolean;
21
+ required?: boolean;
22
+ showError?: boolean;
23
+ errorText?: string;
24
+ autofocus?: boolean;
25
+ showNoResultsMessage?: boolean;
26
+ loadingText?: string;
27
+ options?: ComboBoxItem[];
28
+ fetchFunction?: FetchFunctionType;
29
+ searchFunction?: SearchFunctionType;
30
+ tooltipLocation?: "top" | "bottom" | "left" | "right";
31
+ tooltipContent?: Snippet;
32
+ tooltipText?: string;
33
+ onchange?: (e: string[]) => void;
34
+ onchangeRaw?: (e: ComboBoxItem[]) => void;
35
+ onCreate?: (value: string) => void;
36
+ }
37
+
38
+ let {
39
+ label = "",
40
+ values = $bindable([]),
41
+ rawValues = $bindable([]),
42
+ placeholder = "Start typing to search...",
43
+ class: classes = "",
44
+ disabled = false,
45
+ required = false,
46
+ showError = false,
47
+ errorText = "",
48
+ autofocus = false,
49
+ showNoResultsMessage = false,
50
+ loadingText = "",
51
+ options = [],
52
+ fetchFunction,
53
+ searchFunction,
54
+ tooltipLocation = "top",
55
+ tooltipContent,
56
+ tooltipText,
57
+ onchange,
58
+ onchangeRaw,
59
+ onCreate,
60
+ }: Props = $props();
61
+
62
+ const CREATE_PREFIX = "__create__";
63
+
64
+ let filterString = $state("");
65
+ let preloading = $state(false);
66
+ let searching = $state(false);
67
+ let timeout: number;
68
+
69
+ let allOptions: ComboBoxItem[] = [];
70
+ let filteredOptions: ComboBoxItem[] = $state([]);
71
+
72
+ let open = $state(false);
73
+
74
+ if (values === null || values === undefined) values = [];
75
+
76
+ onMount(() => {
77
+ if (fetchFunction) {
78
+ preloading = true;
79
+ fetchFunction().then((response: NotifyModel<ComboBoxItem[]>) => {
80
+ convertOptions(response.object!);
81
+ preloadValues();
82
+ preloading = false;
83
+ });
84
+ } else {
85
+ if (options.length) convertOptions(options);
86
+ preloadValues();
87
+ }
88
+
89
+ if (autofocus) {
90
+ tick().then(() => textboxElement?.focus());
91
+ }
92
+ });
93
+
94
+ function preloadValues() {
95
+ if (!values || values.length === 0) {
96
+ rawValues = [];
97
+ return;
98
+ }
99
+
100
+ if (rawValues.length > 0) return;
101
+
102
+ let newRawValues: ComboBoxItem[] = [];
103
+
104
+ for (let value of values) {
105
+ const foundOption = allOptions.find((x) => x.value === value);
106
+ if (foundOption) {
107
+ foundOption.selected = true;
108
+ newRawValues.push({ ...foundOption });
109
+ } else if (value != null) {
110
+ newRawValues.push({
111
+ label: String(value),
112
+ value: value,
113
+ selected: true,
114
+ });
115
+ }
116
+ }
117
+
118
+ rawValues = newRawValues;
119
+ }
120
+
121
+ function convertOptions(opts: ComboBoxItem[]) {
122
+ allOptions = opts.map((option) => ({
123
+ ...option,
124
+ selected: values && values.some((x) => x === option.value),
125
+ }));
126
+ filteredOptions = [...allOptions];
127
+ }
128
+
129
+ function appendCreateOption(opts: ComboBoxItem[], query: string): ComboBoxItem[] {
130
+ if (!query.trim()) return opts;
131
+ const normalizedQuery = query.trim().toLowerCase();
132
+ const exactMatch = opts.some((o) => o.label.toLowerCase() === normalizedQuery);
133
+ if (exactMatch) return opts;
134
+ // Don't offer create for values already selected
135
+ if (values.some((v) => v.toLowerCase() === normalizedQuery)) return opts;
136
+ return [...opts, { label: `Create "${query.trim()}"`, value: CREATE_PREFIX + query.trim() }];
137
+ }
138
+
139
+ function onSelection(selectedValue: ComboBoxItem) {
140
+ if (selectedValue.value.startsWith(CREATE_PREFIX)) {
141
+ const newValue = selectedValue.value.slice(CREATE_PREFIX.length);
142
+ const newItem: ComboBoxItem = { label: newValue, value: newValue, selected: true };
143
+
144
+ // Add to allOptions so it's available going forward
145
+ allOptions = [...allOptions, newItem];
146
+ if (options) {
147
+ options.push({ label: newValue, value: newValue });
148
+ }
149
+
150
+ values = [...values, newValue];
151
+ rawValues = [...rawValues, newItem];
152
+
153
+ onchange?.(values);
154
+ onchangeRaw?.(rawValues);
155
+ onCreate?.(newValue);
156
+
157
+ filterString = "";
158
+ filteredOptions = appendCreateOption(
159
+ allOptions.filter((o) => !values.includes(o.value) || o.value === newValue),
160
+ "",
161
+ );
162
+ filteredOptions = [...allOptions];
163
+ return;
164
+ }
165
+
166
+ // Toggle selection
167
+ const alreadySelected = values.includes(selectedValue.value);
168
+
169
+ if (alreadySelected) {
170
+ values = values.filter((v) => v !== selectedValue.value);
171
+ rawValues = rawValues.filter((rv) => rv.value !== selectedValue.value);
172
+ const opt = allOptions.find((o) => o.value === selectedValue.value);
173
+ if (opt) opt.selected = false;
174
+ } else {
175
+ const opt = allOptions.find((o) => o.value === selectedValue.value);
176
+ if (opt) opt.selected = true;
177
+ values = [...values, selectedValue.value];
178
+ rawValues = [...rawValues, opt ?? selectedValue];
179
+ }
180
+
181
+ onchange?.(values);
182
+ onchangeRaw?.(rawValues);
183
+
184
+ filterString = "";
185
+ filteredOptions = [...allOptions];
186
+ }
187
+
188
+ function removeValue(item: ComboBoxItem) {
189
+ values = values.filter((v) => v !== item.value);
190
+ rawValues = rawValues.filter((rv) => rv.value !== item.value);
191
+ const opt = allOptions.find((o) => o.value === item.value);
192
+ if (opt) opt.selected = false;
193
+ onchange?.(values);
194
+ onchangeRaw?.(rawValues);
195
+ }
196
+
197
+ function onFilterChange(value: string) {
198
+ if (searchFunction && value) {
199
+ clearTimeout(timeout);
200
+ searching = true;
201
+ timeout = window.setTimeout(() => {
202
+ searchFunction(value).then(
203
+ (response: NotifyModel<ComboBoxItem[]>) => {
204
+ convertOptions(response.object!);
205
+ filteredOptions = appendCreateOption(filteredOptions, value);
206
+ searching = false;
207
+ open = true;
208
+ },
209
+ );
210
+ }, 300);
211
+ } else if (allOptions) {
212
+ filteredOptions = allOptions.filter((option) =>
213
+ option.label.toLowerCase().includes(value.toLowerCase()),
214
+ );
215
+ filteredOptions = appendCreateOption(filteredOptions, value);
216
+ open = true;
217
+ }
218
+ }
219
+
220
+ let comboBoxEl: ReturnType<typeof ComboBoxMulti> | undefined = $state(undefined);
221
+ let textboxElement: HTMLElement | undefined = $state(undefined);
222
+
223
+ function onKeyDown(e: KeyboardEvent) {
224
+ if (e.key === "Backspace" && filterString === "" && rawValues.length > 0) {
225
+ // Remove last selected value on backspace when input is empty
226
+ removeValue(rawValues[rawValues.length - 1]);
227
+ return;
228
+ }
229
+
230
+ if (!open) return;
231
+
232
+ if (e.key === "Escape") {
233
+ e.preventDefault();
234
+ open = false;
235
+ }
236
+
237
+ comboBoxEl?.handleKeyDown?.(e);
238
+ }
239
+
240
+ function onFocus() {
241
+ open = true;
242
+ }
243
+
244
+ function closePopover(e: MouseEvent) {
245
+ if (textboxElement?.contains(e.target as HTMLElement)) return;
246
+
247
+ open = false;
248
+ }
249
+
250
+ // Build grouped options for ComboBoxMulti
251
+ let groupedOptions = $derived([{ label: "", items: filteredOptions }]);
252
+ </script>
253
+
254
+ <div class="autocomplete-multi-container" class:show-error={showError}>
255
+ <FormGroup {label} {required} {tooltipContent} {tooltipLocation} {tooltipText}>
256
+ <div class="autocomplete-multi-input {classes}" class:focused={open} class:disabled use:clickOutside={closePopover}>
257
+ {#each rawValues as item}
258
+ {#if disabled}
259
+ <Badge>{item.label}</Badge>
260
+ {:else}
261
+ <Badge onDelete={() => removeValue(item)}>{item.label}</Badge>
262
+ {/if}
263
+ {/each}
264
+ <input
265
+ class="inline-input"
266
+ bind:this={textboxElement}
267
+ bind:value={filterString}
268
+ {placeholder}
269
+ {disabled}
270
+ autocomplete="off"
271
+ onfocus={onFocus}
272
+ oninput={() => onFilterChange(filterString)}
273
+ onkeydown={onKeyDown}
274
+ />
275
+ </div>
276
+ <div class="relative w-full">
277
+ <ComboBoxMulti
278
+ bind:this={comboBoxEl}
279
+ {filterString}
280
+ values={rawValues}
281
+ onSelection={onSelection}
282
+ {groupedOptions}
283
+ {open}
284
+ loading={searching || preloading}
285
+ {showNoResultsMessage}
286
+ {loadingText}
287
+ />
288
+ </div>
289
+ </FormGroup>
290
+ {#if showError && errorText}
291
+ <div class="text-error">{errorText}</div>
292
+ {/if}
293
+ </div>
294
+
295
+ <style>
296
+ .autocomplete-multi-container {
297
+ position: relative;
298
+ }
299
+
300
+ .autocomplete-multi-input {
301
+ display: flex;
302
+ flex-wrap: wrap;
303
+ align-items: center;
304
+ gap: var(--pui-spacing-1);
305
+ padding: var(--pui-spacing-1) var(--pui-spacing-2);
306
+ border: 1px solid var(--pui-input-border);
307
+ background-color: var(--pui-input-bg);
308
+ color: var(--pui-input-text);
309
+ border-radius: var(--pui-radius-base);
310
+ cursor: text;
311
+ min-height: 2.25rem;
312
+ }
313
+
314
+ .autocomplete-multi-input.focused {
315
+ border-color: var(--pui-input-border-focus);
316
+ }
317
+
318
+ .autocomplete-multi-input.disabled {
319
+ opacity: 0.5;
320
+ cursor: not-allowed;
321
+ background-color: var(--pui-bg-disabled);
322
+ }
323
+
324
+ .inline-input {
325
+ flex: 1;
326
+ min-width: 4rem;
327
+ border: none;
328
+ outline: none;
329
+ background: transparent;
330
+ color: var(--pui-input-text);
331
+ font-size: var(--pui-font-size-md);
332
+ line-height: var(--pui-line-height-normal);
333
+ padding: 0;
334
+ }
335
+
336
+ .inline-input::placeholder {
337
+ color: var(--pui-text-placeholder);
338
+ }
339
+
340
+ .relative {
341
+ position: relative;
342
+ }
343
+
344
+ .w-full {
345
+ width: 100%;
346
+ }
347
+
348
+ .show-error .autocomplete-multi-input {
349
+ border-color: var(--pui-text-danger);
350
+ }
351
+
352
+ .text-error {
353
+ color: var(--pui-text-danger);
354
+ font-size: var(--pui-font-size-sm);
355
+ }
356
+ </style>
@@ -0,0 +1,28 @@
1
+ import type { ComboBoxItem, FetchFunctionType, SearchFunctionType } from "../models/ComboBoxItem.js";
2
+ import { type Snippet } from "svelte";
3
+ interface Props {
4
+ label?: string;
5
+ values?: string[];
6
+ rawValues?: ComboBoxItem[];
7
+ placeholder?: string;
8
+ class?: string;
9
+ disabled?: boolean;
10
+ required?: boolean;
11
+ showError?: boolean;
12
+ errorText?: string;
13
+ autofocus?: boolean;
14
+ showNoResultsMessage?: boolean;
15
+ loadingText?: string;
16
+ options?: ComboBoxItem[];
17
+ fetchFunction?: FetchFunctionType;
18
+ searchFunction?: SearchFunctionType;
19
+ tooltipLocation?: "top" | "bottom" | "left" | "right";
20
+ tooltipContent?: Snippet;
21
+ tooltipText?: string;
22
+ onchange?: (e: string[]) => void;
23
+ onchangeRaw?: (e: ComboBoxItem[]) => void;
24
+ onCreate?: (value: string) => void;
25
+ }
26
+ declare const AutocompleteMulti: import("svelte").Component<Props, {}, "values" | "rawValues">;
27
+ type AutocompleteMulti = ReturnType<typeof AutocompleteMulti>;
28
+ export default AutocompleteMulti;