@aiaiai-pt/design-system 0.4.1 → 0.4.2

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.
@@ -53,6 +53,10 @@
53
53
  size = 'md',
54
54
  /** @type {((value: string) => void) | undefined} */
55
55
  onchange = undefined,
56
+ /** @type {((query: string) => void) | undefined} — async search; when set, disables internal filtering */
57
+ onsearch = undefined,
58
+ /** @type {boolean} */
59
+ loading = false,
56
60
  /** @type {string} */
57
61
  class: className = '',
58
62
  ...rest
@@ -76,8 +80,21 @@
76
80
  // Selected item label for display
77
81
  const selectedItem = $derived(items.find(i => i.value === value));
78
82
 
79
- // Filter items by query
83
+ // Debounced onsearch dispatch
84
+ let _searchTimer = 0;
85
+ $effect(() => {
86
+ // Subscribe to query changes; only fire if onsearch is set
87
+ const q = query;
88
+ if (!onsearch) return;
89
+ clearTimeout(_searchTimer);
90
+ if (!q) return;
91
+ _searchTimer = /** @type {any} */ (setTimeout(() => onsearch(q), 300));
92
+ return () => clearTimeout(_searchTimer);
93
+ });
94
+
95
+ // Filter items by query — skip when onsearch is set (parent controls items)
80
96
  const filtered = $derived.by(() => {
97
+ if (onsearch) return items;
81
98
  if (!query) return items;
82
99
  const q = query.toLowerCase();
83
100
  return items.filter(i =>
@@ -228,7 +245,11 @@
228
245
  role="listbox"
229
246
  aria-label={label ?? 'Options'}
230
247
  >
231
- {#if filtered.length === 0}
248
+ {#if loading}
249
+ <li class="combobox-empty" role="option" aria-selected="false" aria-disabled="true">
250
+ Searching…
251
+ </li>
252
+ {:else if filtered.length === 0}
232
253
  <li class="combobox-empty" role="option" aria-selected="false" aria-disabled="true">
233
254
  No results found
234
255
  </li>
@@ -1,13 +1,13 @@
1
1
  export default Combobox;
2
2
  export type ComboboxItem = {
3
- value: string;
4
- label: string;
5
- group?: string;
6
- description?: string;
3
+ value: string;
4
+ label: string;
5
+ group?: string;
6
+ description?: string;
7
7
  };
8
8
  type Combobox = {
9
- $on?(type: string, callback: (e: any) => void): () => void;
10
- $set?(props: Partial<$$ComponentProps>): void;
9
+ $on?(type: string, callback: (e: any) => void): () => void;
10
+ $set?(props: Partial<$$ComponentProps>): void;
11
11
  };
12
12
  /**
13
13
  * Combobox
@@ -34,7 +34,8 @@ type Combobox = {
34
34
  * bind:value={selected}
35
35
  * />
36
36
  */
37
- declare const Combobox: import("svelte").Component<{
37
+ declare const Combobox: import("svelte").Component<
38
+ {
38
39
  items?: any[];
39
40
  value?: string;
40
41
  label?: any;
@@ -44,17 +45,26 @@ declare const Combobox: import("svelte").Component<{
44
45
  help?: any;
45
46
  size?: string;
46
47
  onchange?: any;
48
+ /** Async search callback; when set, disables internal filtering. Parent must update `items` with results. */
49
+ onsearch?: (query: string) => void;
50
+ /** Show "Searching…" in dropdown while loading async results */
51
+ loading?: boolean;
47
52
  class?: string;
48
- } & Record<string, any>, {}, "value">;
53
+ } & Record<string, any>,
54
+ {},
55
+ "value"
56
+ >;
49
57
  type $$ComponentProps = {
50
- items?: any[];
51
- value?: string;
52
- label?: any;
53
- placeholder?: string;
54
- disabled?: boolean;
55
- error?: any;
56
- help?: any;
57
- size?: string;
58
- onchange?: any;
59
- class?: string;
58
+ items?: any[];
59
+ value?: string;
60
+ label?: any;
61
+ placeholder?: string;
62
+ disabled?: boolean;
63
+ error?: any;
64
+ help?: any;
65
+ size?: string;
66
+ onchange?: any;
67
+ onsearch?: (query: string) => void;
68
+ loading?: boolean;
69
+ class?: string;
60
70
  } & Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/design-system",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Design system tokens and Svelte components for aiaiai products",
5
5
  "license": "MIT",
6
6
  "type": "module",