mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
* docs: update number of available Carbon icons * docs: add svelte:head example for loading CDN styles * chore(deps-dev): upgrade svelte to 3.40.1 * fix(a11y): disable a11y-mouse-events-have-key-events warning #760 * fix(deps): upgrade carbon-icons-svelte to v10.36.0 to avoid a11y warnings #760 * refactor(overflow-menu): remove formatStyle utility * docs: links in paragraphs should be inline * docs: add note on using all styles for dynamic theming
75 lines
1.8 KiB
Svelte
75 lines
1.8 KiB
Svelte
<script>
|
|
/** Specify the current step index */
|
|
export let currentIndex = 0;
|
|
|
|
/** Set to `true` to use the vertical variant */
|
|
export let vertical = false;
|
|
|
|
/** Set to `true` to specify whether the progress steps should be split equally in size in the div */
|
|
export let spaceEqually = false;
|
|
|
|
/** Set to `true` to prevent `currentIndex` from updating */
|
|
export let preventChangeOnClick = false;
|
|
|
|
import { createEventDispatcher, setContext } from "svelte";
|
|
import { writable, derived } from "svelte/store";
|
|
|
|
const dispatch = createEventDispatcher();
|
|
const steps = writable([]);
|
|
const stepsById = derived(steps, ($) =>
|
|
$.reduce((a, c) => ({ ...a, [c.id]: c }), {})
|
|
);
|
|
|
|
setContext("ProgressIndicator", {
|
|
steps,
|
|
stepsById,
|
|
add: (step) => {
|
|
steps.update((_) => {
|
|
if (step.id in $stepsById) {
|
|
return _.map((_step) => {
|
|
if (_step.id === step.id) return { ..._step, ...step };
|
|
return _step;
|
|
});
|
|
}
|
|
|
|
return [
|
|
..._,
|
|
{
|
|
...step,
|
|
index: _.length,
|
|
current: _.length === currentIndex,
|
|
complete: step.complete,
|
|
},
|
|
];
|
|
});
|
|
},
|
|
change: (index) => {
|
|
if (preventChangeOnClick) return;
|
|
currentIndex = index;
|
|
|
|
/** @event {number} change */
|
|
dispatch("change", index);
|
|
},
|
|
});
|
|
|
|
$: steps.update((_) =>
|
|
_.map((step, i) => ({
|
|
...step,
|
|
current: i === currentIndex,
|
|
}))
|
|
);
|
|
</script>
|
|
|
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
<ul
|
|
class:bx--progress="{true}"
|
|
class:bx--progress--vertical="{vertical}"
|
|
class:bx--progress--space-equal="{spaceEqually && !vertical}"
|
|
{...$$restProps}
|
|
on:click
|
|
on:mouseover
|
|
on:mouseenter
|
|
on:mouseleave
|
|
>
|
|
<slot />
|
|
</ul>
|