mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
parent
e8be9280c7
commit
d4db64e2d1
3 changed files with 62 additions and 0 deletions
|
@ -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">
|
||||
|
|
31
docs/src/pages/framed/RadioTile/RadioTileReactive.svelte
Normal file
31
docs/src/pages/framed/RadioTile/RadioTileReactive.svelte
Normal 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>
|
|
@ -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>
|
Loading…
Add table
Add a link
Reference in a new issue