-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2099 from dusk-network/feature-2071
web-wallet: Update `Stepper` component to new design
- Loading branch information
Showing
14 changed files
with
1,265 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 81 additions & 26 deletions
107
web-wallet/src/lib/dusk/components/Stepper/Stepper.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,98 @@ | ||
<svelte:options immutable={true} /> | ||
|
||
<script> | ||
import { makeClassName, randomUUID } from "$lib/dusk/string"; | ||
import { Icon } from ".."; | ||
/** | ||
* The number of steps – should be greater or equal to two. | ||
* The current active step. | ||
* The value starts from zero as it refers | ||
* to the `steps` array elements. | ||
* @type {number} | ||
*/ | ||
export let activeStep; | ||
/** @type {string | undefined} */ | ||
export let className = undefined; | ||
/** | ||
* Whether to show step numbers or not. | ||
* @type {boolean} | ||
*/ | ||
export let showStepNumbers = true; | ||
/** | ||
* The number of steps, greater or equal to two, | ||
* if a number is passed. | ||
* An array of `StepperStep` objects otherwise. | ||
* | ||
* @type {StepperStep[] | number} | ||
*/ | ||
export let steps; | ||
/** @type {number} */ | ||
export let activeStep; | ||
/** @type {StepperVariant} */ | ||
export let variant = "primary"; | ||
$: classes = makeClassName([ | ||
"dusk-stepper", | ||
`dusk-stepper--variant--${variant}`, | ||
className, | ||
]); | ||
$: stepsAmount = Array.isArray(steps) ? steps.length : steps; | ||
/** | ||
* Calculates the progress percentage based on the active step in a stepper. | ||
* The width of the bar connecting the steps, based on | ||
* the active step and on the amount of steps. | ||
* As the steps are in a grid and centered in the containing | ||
* cell, the width doesn't represent the actual progress percentage. | ||
* | ||
* @constant | ||
* @type {string} | ||
* | ||
* @example | ||
* // If there are 5 steps in total and the active step is 2 | ||
* // progress will be "width: 50%;" | ||
* | ||
* @param {number} steps - Total number of steps in the stepper. | ||
* @param {number} activeStep - The current active step index (starting from 0). | ||
* With 2 steps, if the active step is 1 the width will be 80%. | ||
* The remaining 20% is the blank space before and after the steps. | ||
* | ||
* If there are 5 steps in total and the active step is 2, | ||
* the width will be 40%. | ||
*/ | ||
$: progress = `width: ${(100 / (steps - 1)) * activeStep}%;`; | ||
$: progressWidth = `${(100 * activeStep) / stepsAmount}%`; | ||
</script> | ||
|
||
<div class="dusk-stepper" role="tablist"> | ||
<div class="dusk-stepper__progress-bar"> | ||
<div class="dusk-stepper__progress-filler" style={progress} /> | ||
</div> | ||
|
||
{#if steps >= 2} | ||
<div class="dusk-stepper__steps"> | ||
{#each Array(steps).keys() as currentStep (currentStep)} | ||
<div | ||
{#if stepsAmount >= 2} | ||
<div | ||
class={classes} | ||
style:--columns={stepsAmount} | ||
style:--progress-width={progressWidth} | ||
{...$$restProps} | ||
> | ||
{#if Array.isArray(steps)} | ||
{#each steps as currentStep, idx (currentStep)} | ||
{@const id = `step-${randomUUID()}`} | ||
<span | ||
class="dusk-stepper__step" | ||
class:dusk-stepper__step--processed={currentStep <= activeStep} | ||
aria-selected={currentStep === activeStep} | ||
aria-disabled="true" | ||
/> | ||
class:dusk-stepper__step--processed={idx <= activeStep} | ||
aria-current={idx === activeStep ? "step" : undefined} | ||
aria-labelledby={id} | ||
> | ||
{#if currentStep.iconPath} | ||
<Icon path={currentStep.iconPath} /> | ||
{:else} | ||
{showStepNumbers ? idx + 1 : ""} | ||
{/if} | ||
</span> | ||
<span class="dusk-stepper__step-label" {id}>{currentStep.label}</span> | ||
{/each} | ||
</div> | ||
{/if} | ||
</div> | ||
{:else} | ||
{#each Array(steps).keys() as idx (idx)} | ||
<span | ||
class="dusk-stepper__step" | ||
class:dusk-stepper__step--processed={idx <= activeStep} | ||
aria-current={idx === activeStep ? "step" : undefined} | ||
>{showStepNumbers ? idx + 1 : ""}</span | ||
> | ||
{/each} | ||
{/if} | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 69 additions & 17 deletions
86
web-wallet/src/lib/dusk/components/__tests__/Stepper.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.