@makolabs/ripple 2.2.0 → 2.3.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.
Files changed (38) hide show
  1. package/dist/charts/Chart.svelte +307 -53
  2. package/dist/charts/chart-types.d.ts +12 -0
  3. package/dist/elements/accordion/Accordion.svelte +27 -10
  4. package/dist/elements/accordion/accordion-types.d.ts +6 -0
  5. package/dist/elements/dropdown/Select.svelte +191 -63
  6. package/dist/elements/dropdown/dropdown-types.d.ts +13 -1
  7. package/dist/elements/dropdown/select.d.ts +15 -0
  8. package/dist/elements/dropdown/select.js +14 -8
  9. package/dist/forms/DateRange.svelte +16 -3
  10. package/dist/forms/Input.svelte +6 -4
  11. package/dist/forms/MarketSelector.svelte +7 -27
  12. package/dist/forms/NumberInput.svelte +9 -6
  13. package/dist/forms/SegmentedControl.svelte +5 -18
  14. package/dist/forms/Tags.svelte +1 -1
  15. package/dist/forms/form-types.d.ts +2 -31
  16. package/dist/forms/market/market-selector-types.d.ts +1 -21
  17. package/dist/forms/segmented-control.d.ts +4 -34
  18. package/dist/forms/segmented-control.js +19 -59
  19. package/dist/index.d.ts +3 -9
  20. package/dist/index.js +0 -6
  21. package/dist/variants.js +6 -6
  22. package/package.json +1 -1
  23. package/dist/elements/collapsible/Collapsible.svelte +0 -79
  24. package/dist/elements/collapsible/Collapsible.svelte.d.ts +0 -4
  25. package/dist/elements/collapsible/CollapsibleTestWrapper.svelte +0 -23
  26. package/dist/elements/collapsible/CollapsibleTestWrapper.svelte.d.ts +0 -8
  27. package/dist/elements/collapsible/collapsible-types.d.ts +0 -16
  28. package/dist/elements/collapsible/collapsible-types.js +0 -1
  29. package/dist/elements/combobox/Combobox.svelte +0 -274
  30. package/dist/elements/combobox/Combobox.svelte.d.ts +0 -25
  31. package/dist/elements/combobox/ComboboxTestWrapper.svelte +0 -38
  32. package/dist/elements/combobox/ComboboxTestWrapper.svelte.d.ts +0 -4
  33. package/dist/elements/combobox/combobox-types.d.ts +0 -39
  34. package/dist/elements/combobox/combobox-types.js +0 -1
  35. package/dist/forms/RadioInputs.svelte +0 -73
  36. package/dist/forms/RadioInputs.svelte.d.ts +0 -4
  37. package/dist/forms/RadioPill.svelte +0 -66
  38. package/dist/forms/RadioPill.svelte.d.ts +0 -4
@@ -1,274 +0,0 @@
1
- <script lang="ts" generics="T extends ComboboxItem">
2
- import { cn } from '../../helper/cls.js';
3
- import { buildTestId } from '../../helper/testid.js';
4
- import type { ComboboxItem, ComboboxProps } from '../../index.js';
5
-
6
- let {
7
- items,
8
- onsearch,
9
- value = null,
10
- onselect,
11
- placeholder = 'Search...',
12
- emptyText = 'No results',
13
- loadingText = 'Loading...',
14
- debounceMs = 200,
15
- minSearchLength = 0,
16
- disabled = false,
17
- class: className = '',
18
- inputClass = '',
19
- listClass = '',
20
- itemSnippet,
21
- testId
22
- }: ComboboxProps<T> = $props();
23
-
24
- let inputValue = $state(value?.label ?? '');
25
- let isOpen = $state(false);
26
- let highlightedIndex = $state(0);
27
- let asyncResults = $state<T[]>([]);
28
- let loading = $state(false);
29
- let hasSearched = $state(false);
30
- let rootEl: HTMLDivElement | undefined = $state();
31
- let debounceTimer: ReturnType<typeof setTimeout> | undefined;
32
- let searchSeq = 0;
33
-
34
- function normalizeFilter(q: string): string {
35
- return q.trim().toLowerCase();
36
- }
37
-
38
- function filterStatic(query: string, list: T[]): T[] {
39
- const q = normalizeFilter(query);
40
- if (!q) return list;
41
- return list.filter(
42
- (item) =>
43
- item.label.toLowerCase().includes(q) || (item.description ?? '').toLowerCase().includes(q)
44
- );
45
- }
46
-
47
- // Static filtering is pure and runs every render — no side effects needed.
48
- const results = $derived.by<T[]>(() => {
49
- if (items !== undefined) return filterStatic(inputValue, items);
50
- return asyncResults;
51
- });
52
-
53
- // Async search: only triggered after user has interacted (hasSearched flag).
54
- // Mount alone never fires onsearch, so static-mode tests and first-render
55
- // async-mode tests don't see a spurious onsearch('') call.
56
- $effect(() => {
57
- if (items !== undefined) return;
58
- if (!onsearch) return;
59
- if (!hasSearched) return;
60
-
61
- const query = inputValue;
62
- clearTimeout(debounceTimer);
63
-
64
- if (query.length < minSearchLength) {
65
- asyncResults = [] as T[];
66
- loading = false;
67
- return;
68
- }
69
-
70
- debounceTimer = setTimeout(async () => {
71
- const currentSeq = ++searchSeq;
72
- loading = true;
73
- try {
74
- const fetched = await onsearch(query);
75
- if (currentSeq !== searchSeq) return;
76
- asyncResults = fetched as T[];
77
- } finally {
78
- if (currentSeq === searchSeq) loading = false;
79
- }
80
- }, debounceMs);
81
-
82
- return () => {
83
- clearTimeout(debounceTimer);
84
- };
85
- });
86
-
87
- // Group results, preserving order of first appearance.
88
- // Uses a plain object as the lookup (local to derivation, no reactivity needed).
89
- const groupedResults = $derived.by(() => {
90
- const groups: Array<{ label: string | null; items: T[] }> = [];
91
- const indexByGroup: Record<string, number> = {};
92
- let nullGroupIdx = -1;
93
- for (const item of results) {
94
- const key = item.group;
95
- let idx: number;
96
- if (key === undefined || key === null) {
97
- if (nullGroupIdx === -1) {
98
- nullGroupIdx = groups.length;
99
- groups.push({ label: null, items: [] });
100
- }
101
- idx = nullGroupIdx;
102
- } else {
103
- idx = indexByGroup[key] ?? -1;
104
- if (idx === -1) {
105
- idx = groups.length;
106
- indexByGroup[key] = idx;
107
- groups.push({ label: key, items: [] });
108
- }
109
- }
110
- groups[idx].items.push(item);
111
- }
112
- return groups;
113
- });
114
-
115
- // Flat enabled index for keyboard nav
116
- const flatEnabled = $derived(results.filter((i) => !i.disabled));
117
-
118
- function open() {
119
- if (disabled) return;
120
- isOpen = true;
121
- highlightedIndex = 0;
122
- }
123
-
124
- function close() {
125
- isOpen = false;
126
- }
127
-
128
- function selectItem(item: T) {
129
- if (item.disabled) return;
130
- onselect?.(item);
131
- inputValue = item.label;
132
- close();
133
- }
134
-
135
- function handleInput(event: Event) {
136
- const target = event.target as HTMLInputElement;
137
- inputValue = target.value;
138
- hasSearched = true;
139
- if (!isOpen) open();
140
- }
141
-
142
- function handleKeydown(event: KeyboardEvent) {
143
- if (disabled) return;
144
- if (event.key === 'ArrowDown') {
145
- event.preventDefault();
146
- if (!isOpen) open();
147
- highlightedIndex = Math.min(highlightedIndex + 1, Math.max(flatEnabled.length - 1, 0));
148
- } else if (event.key === 'ArrowUp') {
149
- event.preventDefault();
150
- highlightedIndex = Math.max(highlightedIndex - 1, 0);
151
- } else if (event.key === 'Enter') {
152
- if (isOpen && flatEnabled.length > 0) {
153
- event.preventDefault();
154
- selectItem(flatEnabled[highlightedIndex]);
155
- }
156
- } else if (event.key === 'Escape') {
157
- close();
158
- }
159
- }
160
-
161
- // Click-outside handling
162
- $effect(() => {
163
- if (!isOpen) return;
164
- function onDocClick(e: MouseEvent) {
165
- if (rootEl && !rootEl.contains(e.target as Node)) {
166
- close();
167
- }
168
- }
169
- document.addEventListener('mousedown', onDocClick);
170
- return () => document.removeEventListener('mousedown', onDocClick);
171
- });
172
-
173
- function isHighlighted(item: T): boolean {
174
- const idx = flatEnabled.indexOf(item);
175
- return idx !== -1 && idx === highlightedIndex;
176
- }
177
-
178
- function isSelected(item: T): boolean {
179
- return value != null && value.id === item.id;
180
- }
181
- </script>
182
-
183
- <div
184
- bind:this={rootEl}
185
- class={cn('relative inline-flex w-full flex-col', className)}
186
- data-testid={buildTestId('combobox', undefined, testId)}
187
- >
188
- <input
189
- type="text"
190
- role="combobox"
191
- aria-expanded={isOpen}
192
- aria-controls="combobox-listbox"
193
- aria-autocomplete="list"
194
- aria-disabled={disabled ? 'true' : undefined}
195
- {disabled}
196
- value={inputValue}
197
- {placeholder}
198
- class={cn(
199
- 'border-default-300 w-full rounded-md border bg-white px-3 py-2 text-sm',
200
- 'focus:border-primary-500 focus:ring-primary-500 focus:ring-1 focus:outline-none',
201
- disabled && 'cursor-not-allowed opacity-50',
202
- inputClass
203
- )}
204
- oninput={handleInput}
205
- onfocus={open}
206
- onkeydown={handleKeydown}
207
- />
208
-
209
- {#if isOpen}
210
- <ul
211
- id="combobox-listbox"
212
- role="listbox"
213
- data-combobox-listbox=""
214
- class={cn(
215
- 'border-default-200 absolute top-full left-0 z-50 mt-1 max-h-64 w-full overflow-y-auto rounded-md border bg-white shadow-lg',
216
- listClass
217
- )}
218
- >
219
- {#if loading}
220
- <li class="text-default-500 px-3 py-2 text-sm" data-combobox-loading="">
221
- {loadingText}
222
- </li>
223
- {:else if results.length === 0}
224
- <li class="text-default-500 px-3 py-2 text-sm" data-combobox-empty="">
225
- {emptyText}
226
- </li>
227
- {:else}
228
- {#each groupedResults as group, groupIdx (group.label ?? `__null__${groupIdx}`)}
229
- {#if group.label !== null}
230
- <li
231
- class="text-default-500 bg-default-50 px-3 py-1.5 text-xs font-semibold tracking-wide uppercase"
232
- data-combobox-group={group.label}
233
- role="presentation"
234
- >
235
- {group.label}
236
- </li>
237
- {/if}
238
- {#each group.items as item (item.id)}
239
- {@const highlighted = isHighlighted(item)}
240
- {@const selected = isSelected(item)}
241
- <li
242
- role="option"
243
- aria-selected={selected}
244
- aria-disabled={item.disabled ? 'true' : undefined}
245
- data-combobox-item=""
246
- data-combobox-item-id={item.id}
247
- class={cn(
248
- 'cursor-pointer px-3 py-2 text-sm',
249
- highlighted && 'bg-primary-50',
250
- selected && 'font-semibold',
251
- item.disabled && 'cursor-not-allowed opacity-50'
252
- )}
253
- onclick={() => selectItem(item)}
254
- onkeydown={() => {}}
255
- onmouseenter={() => {
256
- const idx = flatEnabled.indexOf(item);
257
- if (idx !== -1) highlightedIndex = idx;
258
- }}
259
- >
260
- {#if itemSnippet}
261
- {@render itemSnippet(item, { highlighted, selected })}
262
- {:else}
263
- <div class="text-default-800 font-medium">{item.label}</div>
264
- {#if item.description}
265
- <div class="text-default-500 text-xs">{item.description}</div>
266
- {/if}
267
- {/if}
268
- </li>
269
- {/each}
270
- {/each}
271
- {/if}
272
- </ul>
273
- {/if}
274
- </div>
@@ -1,25 +0,0 @@
1
- import type { ComboboxItem, ComboboxProps } from '../../index.js';
2
- declare function $$render<T extends ComboboxItem>(): {
3
- props: ComboboxProps<T>;
4
- exports: {};
5
- bindings: "";
6
- slots: {};
7
- events: {};
8
- };
9
- declare class __sveltets_Render<T extends ComboboxItem> {
10
- props(): ReturnType<typeof $$render<T>>['props'];
11
- events(): ReturnType<typeof $$render<T>>['events'];
12
- slots(): ReturnType<typeof $$render<T>>['slots'];
13
- bindings(): "";
14
- exports(): {};
15
- }
16
- interface $$IsomorphicComponent {
17
- new <T extends ComboboxItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
18
- $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
19
- } & ReturnType<__sveltets_Render<T>['exports']>;
20
- <T extends ComboboxItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
21
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
22
- }
23
- declare const Combobox: $$IsomorphicComponent;
24
- type Combobox<T extends ComboboxItem> = InstanceType<typeof Combobox<T>>;
25
- export default Combobox;
@@ -1,38 +0,0 @@
1
- <script lang="ts">
2
- import Combobox from './Combobox.svelte';
3
- import type { ComboboxItem, ComboboxProps } from '../../index.js';
4
-
5
- let {
6
- items,
7
- onsearch,
8
- value,
9
- onselect,
10
- placeholder,
11
- emptyText,
12
- loadingText,
13
- debounceMs,
14
- minSearchLength,
15
- disabled,
16
- class: className,
17
- inputClass,
18
- listClass,
19
- testId
20
- }: ComboboxProps<ComboboxItem> = $props();
21
- </script>
22
-
23
- <Combobox
24
- {items}
25
- {onsearch}
26
- {value}
27
- {onselect}
28
- {placeholder}
29
- {emptyText}
30
- {loadingText}
31
- {debounceMs}
32
- {minSearchLength}
33
- {disabled}
34
- class={className}
35
- {inputClass}
36
- {listClass}
37
- {testId}
38
- />
@@ -1,4 +0,0 @@
1
- import type { ComboboxItem, ComboboxProps } from '../../index.js';
2
- declare const ComboboxTestWrapper: import("svelte").Component<ComboboxProps<ComboboxItem>, {}, "">;
3
- type ComboboxTestWrapper = ReturnType<typeof ComboboxTestWrapper>;
4
- export default ComboboxTestWrapper;
@@ -1,39 +0,0 @@
1
- import type { ClassValue } from 'tailwind-variants';
2
- import type { Snippet } from 'svelte';
3
- export type ComboboxItem = {
4
- id: string | number;
5
- label: string;
6
- description?: string;
7
- group?: string;
8
- disabled?: boolean;
9
- };
10
- export type ComboboxProps<T extends ComboboxItem = ComboboxItem> = {
11
- /** Static items for client-side filtering. Provide this OR `onsearch`. */
12
- items?: T[];
13
- /**
14
- * Async/sync search callback. Called with the debounced query string.
15
- * Returns the list of items to display.
16
- */
17
- onsearch?: (query: string) => T[] | Promise<T[]>;
18
- /** Currently selected item (controlled). */
19
- value?: T | null;
20
- /** Fires when the user selects an item (click or Enter on highlighted). */
21
- onselect?: (item: T) => void;
22
- placeholder?: string;
23
- emptyText?: string;
24
- loadingText?: string;
25
- /** Milliseconds to debounce onsearch calls (default 200). */
26
- debounceMs?: number;
27
- /** Minimum query length before onsearch fires (default 0). */
28
- minSearchLength?: number;
29
- disabled?: boolean;
30
- class?: ClassValue;
31
- inputClass?: ClassValue;
32
- listClass?: ClassValue;
33
- /** Optional snippet to override the default item rendering. */
34
- itemSnippet?: Snippet<[T, {
35
- highlighted: boolean;
36
- selected: boolean;
37
- }]>;
38
- testId?: string;
39
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,73 +0,0 @@
1
- <script lang="ts">
2
- import { cn } from '../helper/cls.js';
3
- import { buildTestId } from '../helper/testid.js';
4
- import type { RadioInputsProps } from '../index.js';
5
-
6
- let {
7
- name,
8
- label,
9
- options,
10
- value = $bindable(),
11
- disabled = false,
12
- class: className = '',
13
- errors = [],
14
- required = false,
15
- testId
16
- }: RadioInputsProps = $props();
17
-
18
- const containerClass = $derived(cn('space-y-2', className));
19
-
20
- const radioClass = $derived(
21
- cn('w-4 h-4 text-primary-600 border-default-300 focus:ring-primary-500', {
22
- 'opacity-50 cursor-not-allowed': disabled,
23
- 'border-danger-300 focus:ring-danger-500': errors.length
24
- })
25
- );
26
-
27
- const labelClass = $derived(
28
- cn('block text-sm font-medium', {
29
- 'text-default-700': !errors.length,
30
- 'text-danger-600': errors.length
31
- })
32
- );
33
- </script>
34
-
35
- <div class={containerClass}>
36
- {#if label}
37
- <label class={labelClass} for={`${name}-${value || options[0].value}`}>{label}</label>
38
- {/if}
39
- <div class="space-y-2">
40
- {#each options as option, index (option.value)}
41
- <div class="flex items-center gap-2">
42
- <input
43
- type="radio"
44
- {name}
45
- id={`${name}-${option.value}`}
46
- value={option.value}
47
- bind:group={value}
48
- class={radioClass}
49
- {disabled}
50
- {required}
51
- aria-describedby={errors.length
52
- ? errors.map((_, i) => `${name}-error-${i}`).join(' ')
53
- : undefined}
54
- data-testid={buildTestId('radio', 'option', testId, index)}
55
- />
56
- <label
57
- for={`${name}-${option.value}`}
58
- class="text-default-700 text-sm"
59
- data-testid={buildTestId('radio', 'label', testId, index)}
60
- >
61
- {option.label}
62
- </label>
63
- </div>
64
- {/each}
65
- </div>
66
- {#if errors.length}
67
- {#each errors as error, i (i)}
68
- <p id={`${name}-error-${i}`} class="text-danger-600 mt-1 text-sm" role="alert">
69
- {error}
70
- </p>
71
- {/each}
72
- {/if}
73
- </div>
@@ -1,4 +0,0 @@
1
- import type { RadioInputsProps } from '../index.js';
2
- declare const RadioInputs: import("svelte").Component<RadioInputsProps, {}, "value">;
3
- type RadioInputs = ReturnType<typeof RadioInputs>;
4
- export default RadioInputs;
@@ -1,66 +0,0 @@
1
- <script lang="ts">
2
- import { cn } from '../helper/cls.js';
3
- import type { RadioPillProps } from '../index.js';
4
-
5
- let {
6
- options = [],
7
- value = $bindable(options.length > 0 ? options[0].value : ''),
8
- name = '',
9
- class: className = '',
10
- errors = [],
11
- onchange = undefined,
12
- label = ''
13
- }: RadioPillProps = $props();
14
-
15
- function handleSelect(optionValue: string) {
16
- value = optionValue;
17
- if (onchange) onchange(optionValue);
18
- }
19
-
20
- let pillDivRef: HTMLDivElement;
21
- const hasError = $derived(errors && errors.length > 0);
22
-
23
- $effect(() => {
24
- if (errors.length) {
25
- pillDivRef.scrollIntoView({ behavior: 'smooth', block: 'center' });
26
- }
27
- });
28
- </script>
29
-
30
- <div class={cn('flex flex-col space-y-2', className)} bind:this={pillDivRef}>
31
- {#if hasError}
32
- <div class="text-danger-500 text-sm">{errors[0]}</div>
33
- {/if}
34
- {#if label}
35
- <label
36
- class={cn('text-sm font-medium', hasError ? 'text-danger-500' : 'text-default-700')}
37
- for={value}>{label}</label
38
- >
39
- {/if}
40
- <div class="inline-flex flex-wrap gap-2">
41
- {#each options as option (option.value)}
42
- <button
43
- id={option.value}
44
- type="button"
45
- onclick={() => handleSelect(option.value)}
46
- class={cn(
47
- 'border-default-200 cursor-pointer rounded-lg border px-4 py-2 text-sm font-medium transition-all',
48
- {
49
- 'border-info-600 bg-info-600 text-white': value === option.value && !hasError,
50
- 'border-danger-500 bg-danger-500 text-white': value === option.value && hasError,
51
- 'text-default-800 hover:border-default-300 bg-white':
52
- value !== option.value && !hasError,
53
- 'border-danger-500 text-danger-500 hover:bg-danger-50':
54
- value !== option.value && hasError,
55
- 'text-default-400': value !== option.value && option.value === '128' && !hasError
56
- }
57
- )}
58
- aria-pressed={value === option.value}
59
- >
60
- {option.label}
61
- </button>
62
- {/each}
63
- </div>
64
- </div>
65
-
66
- <input type="hidden" {name} {value} />
@@ -1,4 +0,0 @@
1
- import type { RadioPillProps } from '../index.js';
2
- declare const RadioPill: import("svelte").Component<RadioPillProps, {}, "value">;
3
- type RadioPill = ReturnType<typeof RadioPill>;
4
- export default RadioPill;