mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 03:26:36 +00:00
implement change requests
This commit is contained in:
parent
5ef181d693
commit
746ce9278b
3 changed files with 36 additions and 17 deletions
|
@ -26,3 +26,17 @@ components: ["RadioTileGroup", "RadioTile"]
|
||||||
Plus plan
|
Plus plan
|
||||||
</RadioTile>
|
</RadioTile>
|
||||||
</RadioTileGroup>
|
</RadioTileGroup>
|
||||||
|
|
||||||
|
### Light variant
|
||||||
|
|
||||||
|
<RadioTileGroup legend="Service pricing tiers">
|
||||||
|
<RadioTile light value="0" checked>
|
||||||
|
Lite plan
|
||||||
|
</RadioTile>
|
||||||
|
<RadioTile light value="1">
|
||||||
|
Standard plan
|
||||||
|
</RadioTile>
|
||||||
|
<RadioTile light value="2">
|
||||||
|
Plus plan
|
||||||
|
</RadioTile>
|
||||||
|
</RadioTileGroup>
|
||||||
|
|
|
@ -7,7 +7,7 @@ components: ["SelectableTile", "SelectableTileGroup"]
|
||||||
import Preview from "../../components/Preview.svelte";
|
import Preview from "../../components/Preview.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
### Multi-selectable tiles
|
### Default
|
||||||
|
|
||||||
<SelectableTileGroup legend="Select the options you require">
|
<SelectableTileGroup legend="Select the options you require">
|
||||||
<SelectableTile title="Option 1" value="option1" selected>
|
<SelectableTile title="Option 1" value="option1" selected>
|
||||||
|
@ -20,3 +20,17 @@ components: ["SelectableTile", "SelectableTileGroup"]
|
||||||
Option 3
|
Option 3
|
||||||
</SelectableTile>
|
</SelectableTile>
|
||||||
</SelectableTileGroup>
|
</SelectableTileGroup>
|
||||||
|
|
||||||
|
### Light variant
|
||||||
|
|
||||||
|
<SelectableTileGroup legend="Select the options you require">
|
||||||
|
<SelectableTile light title="Option 1" value="option1" selected>
|
||||||
|
Option 1
|
||||||
|
</SelectableTile>
|
||||||
|
<SelectableTile light title="Option 2" value="2" selected>
|
||||||
|
Option 2
|
||||||
|
</SelectableTile>
|
||||||
|
<SelectableTile light title="Option 3" value="3">
|
||||||
|
Option 3
|
||||||
|
</SelectableTile>
|
||||||
|
</SelectableTileGroup>
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
*/
|
*/
|
||||||
export let selectedValues = [];
|
export let selectedValues = [];
|
||||||
|
|
||||||
/** Set to `true` to disable the tile group */
|
|
||||||
export let disabled = false;
|
|
||||||
|
|
||||||
/** Specify the legend text */
|
/** Specify the legend text */
|
||||||
export let legend = "";
|
export let legend = "";
|
||||||
|
|
||||||
|
@ -17,28 +14,22 @@
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
const _selectedValues = writable(selectedValues);
|
const _selectedValues = writable(selectedValues);
|
||||||
|
|
||||||
function newArray(value, selected) {
|
|
||||||
let a = [...$_selectedValues];
|
|
||||||
const i = a.indexOf(value);
|
|
||||||
if (selected && i === -1) {
|
|
||||||
a.push(value);
|
|
||||||
} else if (!selected && i > -1) {
|
|
||||||
a.splice(i, 1);
|
|
||||||
}
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
setContext("SelectableTileGroup", {
|
setContext("SelectableTileGroup", {
|
||||||
selectedValues: _selectedValues,
|
selectedValues: _selectedValues,
|
||||||
update: ({ selected, value }) =>
|
update: ({ selected, value }) =>
|
||||||
_selectedValues.set(newArray(value, selected)),
|
_selectedValues.update((_) => {
|
||||||
|
if (_.includes(value)) {
|
||||||
|
return _.filter((i) => i !== value);
|
||||||
|
}
|
||||||
|
return [..._, value];
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
$: selectedValues = $_selectedValues;
|
$: selectedValues = $_selectedValues;
|
||||||
$: dispatch("select", $_selectedValues);
|
$: dispatch("select", $_selectedValues);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<fieldset disabled="{disabled}" class:bx--tile-group="{true}" {...$$restProps}>
|
<fieldset class:bx--tile-group="{true}" {...$$restProps}>
|
||||||
{#if legend}
|
{#if legend}
|
||||||
<legend class:bx--label="{true}">{legend}</legend>
|
<legend class:bx--label="{true}">{legend}</legend>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue