mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
43 lines
957 B
Svelte
43 lines
957 B
Svelte
<script>
|
|
/**
|
|
* Specify the selected tile value
|
|
* @type {string}
|
|
*/
|
|
export let selected = undefined;
|
|
|
|
/** Set to `true` to disable the tile group */
|
|
export let disabled = false;
|
|
|
|
/** Specify the legend text */
|
|
export let legend = "";
|
|
|
|
import { createEventDispatcher, setContext } from "svelte";
|
|
import { writable } from "svelte/store";
|
|
|
|
const dispatch = createEventDispatcher();
|
|
const selectedValue = writable(selected);
|
|
|
|
setContext("TileGroup", {
|
|
selectedValue,
|
|
add: ({ checked, value }) => {
|
|
if (checked) {
|
|
selectedValue.set(value);
|
|
}
|
|
},
|
|
update: (value) => {
|
|
selectedValue.set(value);
|
|
},
|
|
});
|
|
|
|
$: selected = $selectedValue;
|
|
$: dispatch("select", $selectedValue);
|
|
</script>
|
|
|
|
<fieldset disabled="{disabled}" class:bx--tile-group="{true}" {...$$restProps}>
|
|
{#if legend}
|
|
<legend class:bx--label="{true}">{legend}</legend>
|
|
{/if}
|
|
<div>
|
|
<slot />
|
|
</div>
|
|
</fieldset>
|