1 Commits

Author SHA1 Message Date
Elijah Duffy
bb27d0c9d7 dialog: pass state to snippet overrides 2026-03-15 12:58:28 -07:00
2 changed files with 21 additions and 15 deletions

View File

@@ -112,9 +112,9 @@
/** Bindable open state of the dialog */ /** Bindable open state of the dialog */
open?: boolean; open?: boolean;
/** Title of the dialog */ /** Title of the dialog */
title: string | Snippet; title: string | Snippet<[state: DialogState]>;
/** Description of the dialog, optionally rendered below the title */ /** Description of the dialog, optionally rendered below the title */
description?: string | Snippet; description?: string | Snippet<[state: DialogState]>;
/** Size of the dialog (default: 'sm') */ /** Size of the dialog (default: 'sm') */
size?: 'sm' | 'md' | 'lg' | 'max'; size?: 'sm' | 'md' | 'lg' | 'max';
/** Additional classes for the dialog */ /** Additional classes for the dialog */
@@ -122,7 +122,7 @@
/** Content of the dialog */ /** Content of the dialog */
children?: Snippet; children?: Snippet;
/** Bottom controls for the dialog */ /** Bottom controls for the dialog */
controls?: Snippet | DialogControls; controls?: Snippet<[state: DialogState]> | DialogControls;
/** Sets bottom alignment of controls (default: end) */ /** Sets bottom alignment of controls (default: end) */
controlsAlign?: 'start' | 'center' | 'end'; controlsAlign?: 'start' | 'center' | 'end';
/** Top-right close control */ /** Top-right close control */
@@ -342,7 +342,9 @@
controlsAlign === 'end' && 'justify-end' controlsAlign === 'end' && 'justify-end'
]} ]}
> >
{#if controls && typeof controls === 'function'}{@render controls()}{:else if controls?.flip} {#if controls && typeof controls === 'function'}{@render controls(
getState()
)}{:else if controls?.flip}
{#if controls.ok !== null} {#if controls.ok !== null}
{@render dialogOkButton(getState(), controls.ok)} {@render dialogOkButton(getState(), controls.ok)}
{/if} {/if}
@@ -417,10 +419,10 @@
</button> </button>
{/snippet} {/snippet}
{#snippet stringOrSnippet(val: string | Snippet)} {#snippet stringOrSnippet(val: string | Snippet<[state: DialogState]>)}
{#if typeof val === 'string'} {#if typeof val === 'string'}
{val} {val}
{:else} {:else}
{@render val()} {@render val(getState())}
{/if} {/if}
{/snippet} {/snippet}

View File

@@ -537,15 +537,6 @@
bind:open={dialogOpen} bind:open={dialogOpen}
title="Dialog Title" title="Dialog Title"
size="sm" size="sm"
controls={{
ok: {
action: (dialog) => {
dialog.close();
alert('Dialog submitted!');
}
},
cancel: null
}}
onopen={(dialog) => { onopen={(dialog) => {
dialog.error('Example error message!'); dialog.error('Example error message!');
dialog.loading(); dialog.loading();
@@ -554,6 +545,19 @@
}, 2000); }, 2000);
}} }}
> >
{#snippet controls(state)}
<Button onclick={() => state.api.close()}>Cancel</Button>
<Button
onclick={() => {
state.api.close();
alert('Dialog submitted!');
}}
loading={state.loading}
>
Submit
</Button>
{/snippet}
<p>This is a dialog content area.</p> <p>This is a dialog content area.</p>
<Button onclick={() => (nestedDialogOpen = true)}>Open Nested Dialog</Button> <Button onclick={() => (nestedDialogOpen = true)}>Open Nested Dialog</Button>