mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
* feat(code-snippet): add copy functionality - docs: add custom feedback copy text example * feat(tile): support disabled state for SelectableTile, RadioTile Closes #539 * build(rollup): add clipboard-copy to globals * feat(copy-button): add copy functionality * feat(content-switcher): deprecate the light prop - docs: remove the light variant example * fix(toolbar-search): remove outer div * feat(search): add searchClass prop * fix(composed-modal): set hasScrollingContent class on ModalBody * docs(data-table): add expandable size examples * feat(tooltip): add TooltipFooter component * fix(time-picker): correctly display invalidText * feat(breadcrumb): support overflow menu * feat(multi-select): export inputRef prop * chore(deps-dev): upgrade carbon-components to v10.32.0 * feat(form): add noMargin prop to FormGroup * docs(tooltip): document TooltipFooter * feat(context-menu): support danger kind for ContextMenuOption * feat(data-table): support rendering empty table header in skeleton * refactor(types): use shorter import path in DataTableSkeleton * feat(data-table): allow sorting to be disabled for a specific header * docs(data-table): update example to desort the Protocol header As an example, it makes more sense because all the values ("http") are the same. * fix(context-menu): set initial y offset of context menu based on window height #577 * fix(context-menu): render submenu based on viewport constraints #577
79 lines
1.7 KiB
Svelte
79 lines
1.7 KiB
Svelte
<script>
|
|
/**
|
|
* @event {number} change
|
|
*/
|
|
|
|
/** Set the selected index of the switch item */
|
|
export let selectedIndex = 0;
|
|
|
|
/**
|
|
* Set to `true` to enable the light variant
|
|
* @deprecated
|
|
*/
|
|
export let light = false;
|
|
|
|
/**
|
|
* Specify the size of the content switcher
|
|
* @type {"sm" | "xl"}
|
|
*/
|
|
export let size = undefined;
|
|
|
|
import { afterUpdate, createEventDispatcher, setContext } from "svelte";
|
|
import { writable } from "svelte/store";
|
|
|
|
const dispatch = createEventDispatcher();
|
|
const currentId = writable(null);
|
|
|
|
$: currentIndex = -1;
|
|
$: switches = [];
|
|
$: if (switches[currentIndex]) {
|
|
dispatch("change", currentIndex);
|
|
currentId.set(switches[currentIndex].id);
|
|
}
|
|
|
|
setContext("ContentSwitcher", {
|
|
currentId,
|
|
add: ({ id, text, selected }) => {
|
|
if (selected) {
|
|
selectedIndex = switches.length;
|
|
}
|
|
|
|
switches = [...switches, { id, text, selected }];
|
|
},
|
|
update: (id) => {
|
|
selectedIndex = switches.map(({ id }) => id).indexOf(id);
|
|
},
|
|
change: (direction) => {
|
|
let index = currentIndex + direction;
|
|
|
|
if (index < 0) {
|
|
index = switches.length - 1;
|
|
} else if (index >= switches.length) {
|
|
index = 0;
|
|
}
|
|
|
|
selectedIndex = index;
|
|
},
|
|
});
|
|
|
|
afterUpdate(() => {
|
|
if (selectedIndex !== currentIndex) {
|
|
currentIndex = selectedIndex;
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<div
|
|
role="tablist"
|
|
class:bx--content-switcher="{true}"
|
|
class:bx--content-switcher--light="{light}"
|
|
class:bx--content-switcher--sm="{size === 'sm'}"
|
|
class:bx--content-switcher--xl="{size === 'xl'}"
|
|
{...$$restProps}
|
|
on:click
|
|
on:mouseover
|
|
on:mouseenter
|
|
on:mouseleave
|
|
>
|
|
<slot />
|
|
</div>
|