feat: completed steps are clickable

This commit is contained in:
Arman committed 2022-10-12 17:28:12 +02:00
1 parent e096bb7b97
commit a027e7f73f
3 files changed
+17 -2

No files matched your search

+4
View File
@@ -4,11 +4,15 @@
export let currentSub = 0;
export let isSub = false;
export let step: { text: string; substeps?: { text: string }[] };
//TODO: remove inline styling
</script>
<li
on:click|preventDefault
class:steps-item={!isSub}
class:steps-sub-item={isSub}
style={`cursor: ${completed ? 'pointer' : 'default'};`}
aria-label={`${completed ? 'done' : current ? 'current' : ''} step`}>
{#if isSub}
<span class="text">{step.text}</span>
+5 -1
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import Step from './step.svelte';
export let steps: {
@@ -11,6 +12,8 @@
export let currentStep = 1;
export let currentSub = 1;
const dispatch = createEventDispatcher();
$: firstOptional = steps.findIndex((step) => step.optional);
//TODO: remove inline styling
@@ -21,9 +24,10 @@
{#each steps as step, index}
{@const stepNumber = index + 1}
{#if firstOptional === index}
<h3 class="eyebrow-heading-3">OPTIONAL</h3>
<h3 class="eyebrow-heading-3" style="margin-block: 1.5rem;">OPTIONAL</h3>
{/if}
<Step
on:click={() => dispatch('step', stepNumber)}
bind:currentSub
current={currentStep === stepNumber}
completed={stepNumber < currentStep}
+8 -1
View File
@@ -41,6 +41,13 @@
}
}
function handleStepClick(e: CustomEvent<number>) {
const step = e.detail;
if (step < currentStep) {
currentStep = step;
}
}
function submit() {
if (isLastStep) {
dispatch('finish');
@@ -71,7 +78,7 @@
<aside class="wizard-side">
<Steps
on:step={submit}
on:step={handleStepClick}
steps={sortedSteps.map(([, { label, optional }]) => ({
text: label,
optional