Skip to content

Commit

Permalink
Update wizard to support additional action buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
stnguyen90 authored and TorstenDittmann committed Jan 22, 2024
1 parent c0a8bf9 commit 6605171
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/layout/wizard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
component: typeof SvelteComponent<unknown>;
optional?: boolean;
disabled?: boolean;
actions?: {
label: string;
onClick: () => Promise<void>;
}[];
}
>;
</script>
Expand Down Expand Up @@ -127,6 +131,7 @@
$: sortedSteps = [...steps].sort(([a], [b]) => (a > b ? 1 : -1));
$: isLastStep = $wizard.step === steps.size;
$: currentStep = steps.get($wizard.step);
</script>

<svelte:window on:keydown={handleKeydown} />
Expand Down Expand Up @@ -175,7 +180,7 @@
{/each}
<div class="form-footer">
<div class="u-flex u-main-end u-gap-12">
{#if !isLastStep && sortedSteps[$wizard.step - 1]?.[1]?.optional}
{#if !isLastStep && currentStep?.optional}
<Button text on:click={() => dispatch('finish')}>
Skip optional steps
</Button>
Expand All @@ -187,6 +192,13 @@
<Button secondary on:click={previousStep}>Back</Button>
{/if}

{#if currentStep?.actions}
{#each currentStep.actions as action}
<Button secondary on:click={action.onClick}>
{action.label}</Button>
{/each}
{/if}

<Button submit disabled={$wizard.nextDisabled}>
{isLastStep ? finalAction : 'Next'}
</Button>
Expand Down

0 comments on commit 6605171

Please sign in to comment.