docs(radio-button): simplify reactive radio button example

This commit is contained in:
Eric Liu 2022-01-16 15:00:25 -08:00
commit f52c217cb7

View file

@ -1,35 +1,32 @@
<script> <script>
import { import {
ButtonSet,
Button, Button,
RadioButtonGroup, RadioButtonGroup,
RadioButton, RadioButton,
} from "carbon-components-svelte"; } from "carbon-components-svelte";
let plan = "standard"; const plans = ["Free (1 GB)", "Standard (10 GB)", "Pro (128 GB)"];
let plan = plans[1];
</script> </script>
<RadioButtonGroup legendText="Storage tier (disk)" bind:selected="{plan}"> <RadioButtonGroup legendText="Storage tier (disk)" bind:selected="{plan}">
<RadioButton labelText="Free (1 GB)" value="free" /> {#each plans as value}
<RadioButton labelText="Standard (10 GB)" value="standard" /> <RadioButton labelText="{value}" value="{value}" />
<RadioButton labelText="Pro (128 GB)" value="pro" /> {/each}
</RadioButtonGroup> </RadioButtonGroup>
<ButtonSet style="margin-top: var(--cds-layout-03)"> <div style="margin: var(--cds-layout-01) 0">
{#each ["free", "standard", "pro"] as value} {#each plans as value}
<Button <Button
disabled="{plan === value}"
kind="secondary" kind="secondary"
on:click="{() => { disabled="{plan === value}"
plan = value; on:click="{() => (plan = value)}"
}}"
> >
Select "{value}" Select "{value}"
</Button> </Button>
{/each} {/each}
</ButtonSet> </div>
<div style="margin: var(--cds-layout-01) 0">
Selected plan: Selected plan:
<strong>{plan}</strong> <strong>{plan}</strong>
</div>