diff --git a/src/lib/ActionSelect.svelte b/src/lib/ActionSelect.svelte index 13c0e0f..f0d208c 100644 --- a/src/lib/ActionSelect.svelte +++ b/src/lib/ActionSelect.svelte @@ -1,10 +1,10 @@ @@ -19,32 +19,42 @@ interface Props { label?: string; placeholder?: string; + value?: ActionSelectOption; stateless?: boolean; - options: ButtonSelectOption[]; + tabbable?: boolean; + options: ActionSelectOption[]; class?: ClassValue | null | undefined; } let { label, placeholder = 'Choose an action', - stateless = true, + value = $bindable(undefined), + stateless = false, + tabbable = true, options, class: classValue }: Props = $props(); - const select = new Select({ - onValueChange: (value) => { - value?.onchoose?.(value); + const select = new Select({ + value: () => value, + onValueChange: (val) => { + val?.onchoose?.(val); + if (!stateless) value = val; } }); -
+
{#if label} {/if} -
-{#snippet title(opt: ButtonSelectOption)} +{#snippet title(opt: ActionSelectOption)} {#if typeof opt.title === 'string'} {opt.title} {:else} @@ -100,7 +110,7 @@ {/if} {/snippet} -{#snippet icon(opt: ButtonSelectOption)} +{#snippet icon(opt: ActionSelectOption)} {#if opt.icon && typeof opt.icon === 'object'} {:else if opt.icon} diff --git a/src/lib/index.ts b/src/lib/index.ts index 727d9b8..3d4e38c 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,5 +1,5 @@ // Reexport your entry components here -export { default as ActionSelect } from './ActionSelect.svelte'; +export { default as ActionSelect, type ActionSelectOption } from './ActionSelect.svelte'; export { default as Button } from './Button.svelte'; export { default as CenterBox } from './CenterBox.svelte'; export { default as Checkbox, type CheckboxState } from './Checkbox.svelte'; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 9aa049c..424c8a3 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -53,10 +53,23 @@

Button Select

- +
+ + console.log('Chosen:', value) }} + options={[ + { title: 'Action 1', onchoose: (value) => console.log('Action 1 chosen:', value) }, + { title: 'Action 2', onchoose: (value) => console.log('Action 2 chosen:', value) } + ]} + /> +