Enhance Checkbox to use bind:group

This commit is contained in:
Gregor Wassmann 2021-12-27 23:31:56 +01:00
commit ede294d553
6 changed files with 54 additions and 5 deletions

View file

@ -712,7 +712,7 @@
"name": "value",
"kind": "let",
"description": "Specify the value of the checkbox",
"type": "string",
"type": "string | any",
"value": "\"\"",
"isFunction": false,
"isFunctionDeclaration": false,
@ -730,6 +730,17 @@
"constant": false,
"reactive": true
},
{
"name": "group",
"kind": "let",
"description": "Specify the bound group",
"type": "any[]",
"value": "[]",
"isFunction": false,
"isFunctionDeclaration": false,
"constant": false,
"reactive": true
},
{
"name": "indeterminate",
"kind": "let",

View file

@ -25,4 +25,10 @@
### Skeleton
<Checkbox skeleton />
<Checkbox skeleton />
### Multiple
Bind a selection list to multiple checkboxes.
<FileSource src="/framed/Checkbox/MultipleCheckboxes" />

View file

@ -0,0 +1,15 @@
<script>
import { Checkbox } from "carbon-components-svelte";
let options = ["Apple", "Banana", "Coconut"];
let selection = options.slice(0, 2);
</script>
{#each options as option}
<Checkbox bind:group="{selection}" labelText="{option}" value="{option}" />
{/each}
<div style="margin: var(--cds-layout-01) 0">
Selected options:
<strong>{selection.join(", ")}</strong>
</div>