docs(radio-tile): add reactive examples (#979)

Enabled by #971
This commit is contained in:
Eric Liu 2022-01-08 09:37:53 -08:00 committed by GitHub
commit d4db64e2d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 0 deletions

View file

@ -22,6 +22,16 @@ source: Tile/RadioTile.svelte
</RadioTile>
</TileGroup>
### Reactive (one-way binding)
<FileSource src="/framed/RadioTile/RadioTileReactiveOneWay" />
### Reactive (two-way binding)
Binding to the `selected` prop is a more concise approach to managing state.
<FileSource src="/framed/RadioTile/RadioTileReactive" />
### Light variant
<TileGroup legend="Service pricing tiers">

View file

@ -0,0 +1,31 @@
<script>
import { TileGroup, RadioTile, Button } from "carbon-components-svelte";
const values = ["Lite plan", "Standard plan", "Plus plan"];
let selected = values[0];
</script>
<TileGroup legend="Service pricing tiers" bind:selected>
{#each values as value}
<RadioTile value="{value}">{value}</RadioTile>
{/each}
</TileGroup>
<div>
Selected: <strong>{selected}</strong>
</div>
<Button
size="small"
disabled="{selected === values[1]}"
on:click="{() => (selected = values[1])}"
>
Set to "{values[1]}"
</Button>
<style>
div {
margin: var(--cds-spacing-05) 0;
}
</style>

View file

@ -0,0 +1,21 @@
<script>
import { TileGroup, RadioTile } from "carbon-components-svelte";
const values = ["Lite plan", "Standard plan", "Plus plan"];
let selected = values[0];
</script>
<TileGroup
legend="Service pricing tiers"
on:select="{({ detail }) => (selected = detail)}"
>
{#each values as value}
<RadioTile value="{value}" checked="{selected === value}">{value}</RadioTile
>
{/each}
</TileGroup>
<br />
Selected: <strong>{selected}</strong>