@placeholderco/placeholder-ui 1.0.3 → 1.0.5

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 (135) 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 +197 -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 +279 -279
  114. package/dist/ui/Breadcrumbs.svelte +131 -131
  115. package/dist/ui/Button.svelte +370 -370
  116. package/dist/ui/Dialog.svelte +307 -307
  117. package/dist/ui/Drawer.svelte +524 -524
  118. package/dist/ui/Dropdown.svelte +97 -97
  119. package/dist/ui/Dropzone.svelte +122 -122
  120. package/dist/ui/Link.svelte +32 -32
  121. package/dist/ui/Loader.svelte +70 -70
  122. package/dist/ui/LoadingOverlay.svelte +53 -53
  123. package/dist/ui/Pagination.svelte +135 -135
  124. package/dist/ui/Popover.svelte +225 -225
  125. package/dist/ui/Progress.svelte +191 -191
  126. package/dist/ui/RingProgress.svelte +141 -141
  127. package/dist/ui/Skeleton.svelte +85 -85
  128. package/dist/ui/Stepper.svelte +355 -355
  129. package/dist/ui/Table.svelte +345 -345
  130. package/dist/ui/Tabs.svelte +146 -146
  131. package/dist/ui/ThemeSwitcher.svelte +39 -39
  132. package/dist/ui/Timeline.svelte +225 -225
  133. package/dist/ui/Toaster.svelte +6 -6
  134. package/dist/ui/Tooltip.svelte +434 -434
  135. package/package.json +14 -14
@@ -1,191 +1,223 @@
1
- <script lang="ts">
2
- import ComboBox from "./ComboBox.svelte";
3
- import { clickOutside } from "../actions/ClickOutside.js";
4
- import Textbox from "./Textbox.svelte";
5
- import type { NotifyModel } from "../models/NotifyModel.js";
6
- import type {
7
- ComboBoxItem,
8
- FetchFunctionType,
9
- SearchFunctionType,
10
- } from "../models/ComboBoxItem.js";
11
- import { onMount } from "svelte";
12
-
13
- interface Props {
14
- label?: string;
15
- value?: string;
16
- placeholder?: string;
17
- showRequired?: boolean;
18
- classes?: string;
19
- autofocus?: boolean;
20
- hideNoResults?: boolean;
21
- preventChangeOnSelection?: boolean;
22
- loadingText?: string;
23
- groupClass?: string;
24
- leftIconSvg?: string;
25
- options?: ComboBoxItem[];
26
- fetchFunction?: FetchFunctionType;
27
- searchFunction?: SearchFunctionType;
28
- onchange?: (e: string) => void;
29
- enterPressed?: (e: string) => void;
30
- onSelect?: (e: ComboBoxItem) => void;
31
- }
32
-
33
- let {
34
- label,
35
- value = $bindable(""),
36
- placeholder = "Start typing to search...",
37
- showRequired = false,
38
- classes = "",
39
- autofocus = false,
40
- hideNoResults = false,
41
- preventChangeOnSelection = false,
42
- loadingText = "",
43
- groupClass = "",
44
- leftIconSvg,
45
- options,
46
- fetchFunction,
47
- searchFunction,
48
- onchange = undefined,
49
- enterPressed = undefined,
50
- onSelect = undefined,
51
- }: Props = $props();
52
-
53
- let preloading = $state(false);
54
- let searching = $state(false);
55
- let timeout = setTimeout(() => {});
56
-
57
- let allOptions: ComboBoxItem[] = [];
58
- let filteredOptions: ComboBoxItem[] = $state([]);
59
-
60
- let open = $state(false);
61
-
62
- onMount(() => {
63
- if (fetchFunction) {
64
- preloading = true;
65
- fetchFunction().then((response: NotifyModel<ComboBoxItem[]>) => {
66
- convertOptions(response.object!);
67
- preloading = false;
68
- });
69
- } else {
70
- if (options) convertOptions(options);
71
- }
72
- });
73
-
74
- function convertOptions(options: ComboBoxItem[]) {
75
- allOptions = options.map((option) => {
76
- return {
77
- html: option.label,
78
- value: option.value,
79
- selected: option.value == value,
80
- label: option.label,
81
- };
82
- });
83
- filteredOptions = [...allOptions];
84
- }
85
-
86
- function onSelection(selectedValue: ComboBoxItem) {
87
- open = false;
88
- if (options) {
89
- options.forEach((option) => {
90
- option.selected = option.value == selectedValue.value;
91
- });
92
- }
93
-
94
- if (!preventChangeOnSelection) value = selectedValue.value;
95
-
96
- onSelect?.(selectedValue);
97
- }
98
-
99
- function onFilterChange(value: string) {
100
- if (searchFunction && value) {
101
- clearTimeout(timeout);
102
- searching = true;
103
- timeout = setTimeout(() => {
104
- searchFunction(value).then(
105
- (response: NotifyModel<ComboBoxItem[]>) => {
106
- convertOptions(response.object!);
107
- searching = false;
108
- },
109
- );
110
- }, 300);
111
- } else if (allOptions) {
112
- filteredOptions = allOptions.filter((option) =>
113
- option.label.toLowerCase().includes(value.toLowerCase()),
114
- );
115
- open = true;
116
- }
117
-
118
- onchange?.(value);
119
- }
120
-
121
- let textboxElement: HTMLElement | undefined = $state(undefined);
122
-
123
- // returns true if an item was selected, false otherwise
124
- let comboBoxKeyDown: ((e: KeyboardEvent) => boolean) | undefined =
125
- $state(undefined);
126
-
127
- function onKeyDown(e: KeyboardEvent) {
128
- if (!open) {
129
- if (e.key === "Enter")
130
- // If combobox is not open return user entered string
131
- enterPressed?.(value);
132
-
133
- return;
134
- }
135
-
136
- if (e.key === "Escape") {
137
- e.preventDefault();
138
- open = false;
139
- } else if (comboBoxKeyDown) {
140
- const itemSelected = comboBoxKeyDown(e);
141
-
142
- if (!itemSelected && e.key === "Enter") enterPressed?.(value);
143
- }
144
- }
145
-
146
- function onFocus(e: any) {
147
- open = true;
148
- const target = e?.target as HTMLInputElement;
149
- target?.select();
150
- }
151
-
152
- function closePopover(e: MouseEvent) {
153
- if (textboxElement?.contains(e.target as HTMLElement)) return;
154
-
155
- open = false;
156
- }
157
- </script>
158
-
159
- <Textbox
160
- {label}
161
- class={classes}
162
- required={showRequired}
163
- bind:textboxElement
164
- placeholder={preloading ? "Loading..." : placeholder}
165
- loading={searching || preloading}
166
- disabled={preloading}
167
- noAutocomplete
168
- {groupClass}
169
- {leftIconSvg}
170
- bind:value
171
- oninput={() => {
172
- onFilterChange(value);
173
- }}
174
- onfocus={onFocus}
175
- onkeydown={onKeyDown}
176
- >
177
- <div class="relative w-full" use:clickOutside={closePopover}>
178
- <ComboBox
179
- {value}
180
- onselection={onSelection}
181
- options={filteredOptions}
182
- {open}
183
- loading={searching}
184
- {hideNoResults}
185
- {loadingText}
186
- />
187
- </div>
188
- </Textbox>
189
-
190
- <style>
191
- </style>
1
+ <script lang="ts">
2
+ import ComboBox from "./ComboBox.svelte";
3
+ import { clickOutside } from "../actions/ClickOutside.js";
4
+ import Textbox from "./Textbox.svelte";
5
+ import type { NotifyModel } from "../models/NotifyModel.js";
6
+ import type {
7
+ ComboBoxItem,
8
+ FetchFunctionType,
9
+ SearchFunctionType,
10
+ } from "../models/ComboBoxItem.js";
11
+ import { onMount } from "svelte";
12
+
13
+ interface Props {
14
+ label?: string;
15
+ value?: string;
16
+ placeholder?: string;
17
+ showRequired?: boolean;
18
+ classes?: string;
19
+ autofocus?: boolean;
20
+ showNoResultsMessage?: boolean;
21
+ preventChangeOnSelection?: boolean;
22
+ allowCreate?: boolean;
23
+ loadingText?: string;
24
+ groupClass?: string;
25
+ leftIconSvg?: string;
26
+ options?: ComboBoxItem[];
27
+ fetchFunction?: FetchFunctionType;
28
+ searchFunction?: SearchFunctionType;
29
+ onchange?: (e: string) => void;
30
+ enterPressed?: (e: string) => void;
31
+ onSelect?: (e: ComboBoxItem) => void;
32
+ onCreate?: (value: string) => void;
33
+ }
34
+
35
+ let {
36
+ label,
37
+ value = $bindable(""),
38
+ placeholder = "Start typing to search...",
39
+ showRequired = false,
40
+ classes = "",
41
+ autofocus = false,
42
+ showNoResultsMessage = false,
43
+ preventChangeOnSelection = false,
44
+ allowCreate = false,
45
+ loadingText = "",
46
+ groupClass = "",
47
+ leftIconSvg,
48
+ options,
49
+ fetchFunction,
50
+ searchFunction,
51
+ onchange = undefined,
52
+ enterPressed = undefined,
53
+ onSelect = undefined,
54
+ onCreate = undefined,
55
+ }: Props = $props();
56
+
57
+ let preloading = $state(false);
58
+ let searching = $state(false);
59
+ let timeout = setTimeout(() => {});
60
+
61
+ let allOptions: ComboBoxItem[] = [];
62
+ let filteredOptions: ComboBoxItem[] = $state([]);
63
+
64
+ let open = $state(false);
65
+
66
+ onMount(() => {
67
+ if (fetchFunction) {
68
+ preloading = true;
69
+ fetchFunction().then((response: NotifyModel<ComboBoxItem[]>) => {
70
+ convertOptions(response.object!);
71
+ preloading = false;
72
+ });
73
+ } else {
74
+ if (options) convertOptions(options);
75
+ }
76
+ });
77
+
78
+ function convertOptions(options: ComboBoxItem[]) {
79
+ allOptions = options.map((option) => {
80
+ return {
81
+ html: option.label,
82
+ value: option.value,
83
+ selected: option.value == value,
84
+ label: option.label,
85
+ };
86
+ });
87
+ filteredOptions = [...allOptions];
88
+ }
89
+
90
+ const CREATE_PREFIX = "__create__";
91
+
92
+ function onSelection(selectedValue: ComboBoxItem) {
93
+ open = false;
94
+
95
+ if (selectedValue.value.startsWith(CREATE_PREFIX)) {
96
+ const newValue = selectedValue.value.slice(CREATE_PREFIX.length);
97
+ const newItem: ComboBoxItem = { label: newValue, value: newValue };
98
+ if (options) {
99
+ options.push(newItem);
100
+ convertOptions(options);
101
+ } else {
102
+ allOptions.push({ ...newItem, selected: true });
103
+ }
104
+ if (!preventChangeOnSelection) value = newValue;
105
+ onSelect?.(newItem);
106
+ onCreate?.(newValue);
107
+ return;
108
+ }
109
+
110
+ if (options) {
111
+ options.forEach((option) => {
112
+ option.selected = option.value == selectedValue.value;
113
+ });
114
+ }
115
+
116
+ if (!preventChangeOnSelection) value = selectedValue.value;
117
+
118
+ onSelect?.(selectedValue);
119
+ }
120
+
121
+ function appendCreateOption(opts: ComboBoxItem[], query: string): ComboBoxItem[] {
122
+ if (!allowCreate || !query.trim()) return opts;
123
+ const normalizedQuery = query.trim().toLowerCase();
124
+ const exactMatch = opts.some((o) => o.label.toLowerCase() === normalizedQuery);
125
+ if (exactMatch) return opts;
126
+ return [...opts, { label: `Create "${query.trim()}"`, value: CREATE_PREFIX + query.trim() }];
127
+ }
128
+
129
+ function onFilterChange(value: string) {
130
+ if (searchFunction && value) {
131
+ clearTimeout(timeout);
132
+ searching = true;
133
+ timeout = setTimeout(() => {
134
+ searchFunction(value).then(
135
+ (response: NotifyModel<ComboBoxItem[]>) => {
136
+ convertOptions(response.object!);
137
+ filteredOptions = appendCreateOption(filteredOptions, value);
138
+ searching = false;
139
+ },
140
+ );
141
+ }, 300);
142
+ } else if (allOptions) {
143
+ filteredOptions = allOptions.filter((option) =>
144
+ option.label.toLowerCase().includes(value.toLowerCase()),
145
+ );
146
+ filteredOptions = appendCreateOption(filteredOptions, value);
147
+ open = true;
148
+ }
149
+
150
+ onchange?.(value);
151
+ }
152
+
153
+ let textboxElement: HTMLElement | undefined = $state(undefined);
154
+
155
+ // returns true if an item was selected, false otherwise
156
+ let comboBoxKeyDown: ((e: KeyboardEvent) => boolean) | undefined =
157
+ $state(undefined);
158
+
159
+ function onKeyDown(e: KeyboardEvent) {
160
+ if (!open) {
161
+ if (e.key === "Enter")
162
+ // If combobox is not open return user entered string
163
+ enterPressed?.(value);
164
+
165
+ return;
166
+ }
167
+
168
+ if (e.key === "Escape") {
169
+ e.preventDefault();
170
+ open = false;
171
+ } else if (comboBoxKeyDown) {
172
+ const itemSelected = comboBoxKeyDown(e);
173
+
174
+ if (!itemSelected && e.key === "Enter") enterPressed?.(value);
175
+ }
176
+ }
177
+
178
+ function onFocus(e: any) {
179
+ open = true;
180
+ const target = e?.target as HTMLInputElement;
181
+ target?.select();
182
+ }
183
+
184
+ function closePopover(e: MouseEvent) {
185
+ if (textboxElement?.contains(e.target as HTMLElement)) return;
186
+
187
+ open = false;
188
+ }
189
+ </script>
190
+
191
+ <Textbox
192
+ {label}
193
+ class={classes}
194
+ required={showRequired}
195
+ bind:textboxElement
196
+ placeholder={preloading ? "Loading..." : placeholder}
197
+ loading={searching || preloading}
198
+ disabled={preloading}
199
+ noAutocomplete
200
+ {groupClass}
201
+ {leftIconSvg}
202
+ bind:value
203
+ oninput={() => {
204
+ onFilterChange(value);
205
+ }}
206
+ onfocus={onFocus}
207
+ onkeydown={onKeyDown}
208
+ >
209
+ <div class="relative w-full" use:clickOutside={closePopover}>
210
+ <ComboBox
211
+ {value}
212
+ onselection={onSelection}
213
+ options={filteredOptions}
214
+ {open}
215
+ loading={searching}
216
+ {showNoResultsMessage}
217
+ {loadingText}
218
+ />
219
+ </div>
220
+ </Textbox>
221
+
222
+ <style>
223
+ </style>
@@ -6,8 +6,9 @@ interface Props {
6
6
  showRequired?: boolean;
7
7
  classes?: string;
8
8
  autofocus?: boolean;
9
- hideNoResults?: boolean;
9
+ showNoResultsMessage?: boolean;
10
10
  preventChangeOnSelection?: boolean;
11
+ allowCreate?: boolean;
11
12
  loadingText?: string;
12
13
  groupClass?: string;
13
14
  leftIconSvg?: string;
@@ -17,6 +18,7 @@ interface Props {
17
18
  onchange?: (e: string) => void;
18
19
  enterPressed?: (e: string) => void;
19
20
  onSelect?: (e: ComboBoxItem) => void;
21
+ onCreate?: (value: string) => void;
20
22
  }
21
23
  declare const Autocomplete: import("svelte").Component<Props, {}, "value">;
22
24
  type Autocomplete = ReturnType<typeof Autocomplete>;