Enhance Checkbox to use bind:group (#947)

* Enhance Checkbox to use bind:group

* Use custom logic

* Move multiple checkboxes above skeleton

* Incorprate PR feedback

* Any instead of string
This commit is contained in:
Gregor Wassmann 2021-12-30 22:31:33 +01:00 committed by GitHub
commit f0cf4e7ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 7 deletions

View file

@ -23,6 +23,12 @@
<Checkbox labelText="Label text" disabled />
### Multiple
Bind a selection [group](https://svelte.dev/tutorial/group-inputs) to multiple checkboxes.
<FileSource src="/framed/Checkbox/MultipleCheckboxes" />
### Skeleton
<Checkbox skeleton />
<Checkbox skeleton />

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>