mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
docs(radio-button): simplify reactive example (#1012)
* docs(radio-button): simplify reactive radio button example * docs(radio-button): rename to "Reactive example"
This commit is contained in:
parent
e5f77aa614
commit
58de79d66b
3 changed files with 35 additions and 38 deletions
|
@ -41,11 +41,11 @@ Use the named "legendText" slot to customize the legend text.
|
||||||
<RadioButton labelText="Pro (128 GB)" value="pro" />
|
<RadioButton labelText="Pro (128 GB)" value="pro" />
|
||||||
</RadioButtonGroup>
|
</RadioButtonGroup>
|
||||||
|
|
||||||
### Programmatic usage
|
### Reactive example
|
||||||
|
|
||||||
Bind the selected value using the `selected` prop.
|
Use the `selected` prop to bind and update the selected value.
|
||||||
|
|
||||||
<FileSource src="/framed/RadioButton/ProgrammaticRadioButton" />
|
<FileSource src="/framed/RadioButton/RadioButtonReactive" />
|
||||||
|
|
||||||
### Left-aligned label text
|
### Left-aligned label text
|
||||||
|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<script>
|
|
||||||
import {
|
|
||||||
ButtonSet,
|
|
||||||
Button,
|
|
||||||
RadioButtonGroup,
|
|
||||||
RadioButton,
|
|
||||||
} from "carbon-components-svelte";
|
|
||||||
|
|
||||||
let plan = "standard";
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<RadioButtonGroup legendText="Storage tier (disk)" bind:selected="{plan}">
|
|
||||||
<RadioButton labelText="Free (1 GB)" value="free" />
|
|
||||||
<RadioButton labelText="Standard (10 GB)" value="standard" />
|
|
||||||
<RadioButton labelText="Pro (128 GB)" value="pro" />
|
|
||||||
</RadioButtonGroup>
|
|
||||||
|
|
||||||
<ButtonSet style="margin-top: var(--cds-layout-03)">
|
|
||||||
{#each ["free", "standard", "pro"] as value}
|
|
||||||
<Button
|
|
||||||
disabled="{plan === value}"
|
|
||||||
kind="secondary"
|
|
||||||
on:click="{() => {
|
|
||||||
plan = value;
|
|
||||||
}}"
|
|
||||||
>
|
|
||||||
Select "{value}"
|
|
||||||
</Button>
|
|
||||||
{/each}
|
|
||||||
</ButtonSet>
|
|
||||||
|
|
||||||
<div style="margin: var(--cds-layout-01) 0">
|
|
||||||
Selected plan:
|
|
||||||
<strong>{plan}</strong>
|
|
||||||
</div>
|
|
32
docs/src/pages/framed/RadioButton/RadioButtonReactive.svelte
Normal file
32
docs/src/pages/framed/RadioButton/RadioButtonReactive.svelte
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
RadioButtonGroup,
|
||||||
|
RadioButton,
|
||||||
|
} from "carbon-components-svelte";
|
||||||
|
|
||||||
|
const plans = ["Free (1 GB)", "Standard (10 GB)", "Pro (128 GB)"];
|
||||||
|
|
||||||
|
let plan = plans[1];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<RadioButtonGroup legendText="Storage tier (disk)" bind:selected="{plan}">
|
||||||
|
{#each plans as value}
|
||||||
|
<RadioButton labelText="{value}" value="{value}" />
|
||||||
|
{/each}
|
||||||
|
</RadioButtonGroup>
|
||||||
|
|
||||||
|
<div style="margin: var(--cds-layout-01) 0">
|
||||||
|
{#each plans as value}
|
||||||
|
<Button
|
||||||
|
kind="secondary"
|
||||||
|
disabled="{plan === value}"
|
||||||
|
on:click="{() => (plan = value)}"
|
||||||
|
>
|
||||||
|
Select "{value}"
|
||||||
|
</Button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Selected plan:
|
||||||
|
<strong>{plan}</strong>
|
Loading…
Add table
Add a link
Reference in a new issue