Skip to content

Commit

Permalink
[MultiSelect(Field|Menu)] Improve actions with mode="immediate"
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed Jul 9, 2024
1 parent 3b9774c commit 22f26e4
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-geckos-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

[MultiSelect(Field|Menu)] Improve actions with mode="immediate"
2 changes: 1 addition & 1 deletion packages/svelte-ux/src/lib/components/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
class={cls(
'actions',
'flex items-center justify-end',
mode === 'actions' && 'border-t border-surface-content/10 pt-2',
'[&:not(:has(>:first-child))]:hidden border-t border-surface-content/10 pt-2',
settingsClasses.actions,
classes.actions
)}
Expand Down
8 changes: 5 additions & 3 deletions packages/svelte-ux/src/lib/components/MultiSelectField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// MultiSelectMenu props
export let options: MultiSelectMenuProps['options'];
export let value: MultiSelectMenuProps['value'];
export let mode: MultiSelectMenuProps['mode'] | undefined = undefined;
export let maintainOrder: MultiSelectMenuProps['maintainOrder'] | undefined = undefined;
export let indeterminateSelected: typeof value = [];
/** Maximum number of options that can be selected */
export let max: number | undefined = undefined;
Expand Down Expand Up @@ -203,6 +205,8 @@
<MultiSelectMenu
{options}
{value}
{mode}
{maintainOrder}
{indeterminateSelected}
{max}
{placement}
Expand Down Expand Up @@ -237,8 +241,6 @@
</slot>
</svelte:fragment>

<slot name="actions" slot="actions" let:selection {selection}>
<div></div>
</slot>
<slot name="actions" slot="actions" let:selection {selection} />
</MultiSelectMenu>
</div>
12 changes: 7 additions & 5 deletions packages/svelte-ux/src/lib/components/MultiSelectMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
export let options: MultiSelectProps['options'];
export let value: MultiSelectProps['value'];
export let mode: MultiSelectProps['mode'] | undefined = undefined;
export let maintainOrder: MultiSelectProps['maintainOrder'] | undefined = undefined;
export let indeterminateSelected: typeof value = [];
export let open = false;
export let duration = 200;
Expand Down Expand Up @@ -53,6 +55,8 @@
<MultiSelect
{options}
{value}
{mode}
{maintainOrder}
{indeterminateSelected}
{max}
{open}
Expand All @@ -69,9 +73,9 @@
...settingsClasses.multiSelect,
...classes.multiSelect,
}}
on:cancel={() => close()}
on:cancel={() => mode !== 'immediate' && close()}
on:cancel
on:change={() => close()}
on:change={() => mode !== 'immediate' && close()}
on:change
>
<slot name="beforeOptions" slot="beforeOptions" let:selection {selection} />
Expand All @@ -95,8 +99,6 @@
</slot>
</svelte:fragment>

<slot name="actions" slot="actions" let:selection {selection}>
<div></div>
</slot>
<slot name="actions" slot="actions" let:selection {selection} />
</MultiSelect>
</Menu>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<MultiSelect {options} {value} maintainOrder on:change={(e) => (value = e.detail.value)} />
</Preview>

<h2>Immediate apply changes (no actions)</h2>
<h2>Immediately apply changes (no actions)</h2>

<Preview>
{value.length} selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@
/>
</Preview>

<h2>Immediately apply changes (no actions)</h2>

<Preview>
<MultiSelectField
{options}
{value}
on:change={(e) => (value = e.detail.value)}
mode="immediate"
maintainOrder
/>
</Preview>

<h2>Immediately apply changes (with custom action)</h2>

<Preview>
<MultiSelectField
{options}
{value}
on:change={(e) => (value = e.detail.value)}
mode="immediate"
maintainOrder
>
<div slot="actions">
<Button color="primary" icon={mdiPlus}>Add item</Button>
</div>
</MultiSelectField>
</Preview>

<h2>formatSelected</h2>

<Preview>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,52 @@
</span>
</Preview>

<h2>Immediately apply changes (no actions)</h2>
<Preview>
<span>
<ToggleButton let:on={open} let:toggleOff transition={false}>
{value.length} selected
<MultiSelectMenu
{options}
{value}
mode="immediate"
maintainOrder
on:change={(e) => {
// @ts-expect-error
value = e.detail.value;
}}
{open}
on:close={toggleOff}
/>
</ToggleButton>
</span>
</Preview>

<h2>Immediately apply changes (with custom action)</h2>
<Preview>
<span>
<ToggleButton let:on={open} let:toggleOff transition={false}>
{value.length} selected
<MultiSelectMenu
{options}
{value}
mode="immediate"
maintainOrder
on:change={(e) => {
// @ts-expect-error
value = e.detail.value;
}}
{open}
on:close={toggleOff}
>
<div slot="actions">
<Button color="primary" icon={mdiPlus}>Add item</Button>
</div>
</MultiSelectMenu>
</ToggleButton>
</span>
</Preview>

<h2>actions slot</h2>

<Preview>
Expand Down

0 comments on commit 22f26e4

Please sign in to comment.