refactor(progress-indicator): make currentIndex reactive, add preventChangeOnClick

This commit is contained in:
Eric Liu 2020-10-20 18:21:36 -07:00
commit 4113ae95da
6 changed files with 134 additions and 74 deletions

View file

@ -17,6 +17,12 @@
*/
export let spaceEqually = false;
/**
* Set to `true` to prevent updating `currentIndex`
* @type {boolean} [preventChangeOnClick=false]
*/
export let preventChangeOnClick = false;
import { createEventDispatcher, setContext } from "svelte";
import { writable, derived } from "svelte/store";
@ -41,6 +47,14 @@
]);
},
change: (index) => {
if (preventChangeOnClick) return;
currentIndex = index;
steps.update((_) =>
[..._].map((step, i) => ({
...step,
current: i === index,
}))
);
dispatch("change", index);
},
});

View file

@ -80,6 +80,7 @@
class:bx--progress-step-button--unclickable="{current}"
on:click
on:click="{() => {
if (!step.complete) return;
change(step.index);
}}"
on:mouseover