mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
refactor(progress-indicator): make currentIndex reactive, add preventChangeOnClick
This commit is contained in:
parent
350aad83e0
commit
4113ae95da
6 changed files with 134 additions and 74 deletions
|
@ -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);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue