RadioGrid
A grid of radio buttons.
Integrates the Radio Grid control from Tweakpane-creator Hiroki Kokubun's Essentials plugin.
See <ButtonGrid> for a button-flavored variation.
Unlike the vanilla Tweakpane API, Svelte Tweakpane UI provides a unique groupname for each instance of RadioGrid by default for consistency with expectations around component isolation. You may still assign the groupname prop manually to create cross-component groups that share selection exclusivity.
Svelte Tweakpane UI also includes some additional logic to manage default grid dimensions:
If no
rowsorcolumnsprops are provided, it will create a grid with the squarest possible aspect ratio for the given quantity ofvalues.If a single
rowsorcolumnsprop is provided, it lets the undefined axis grow / shrink as needed to accommodate the quantity ofvalues.If both
rowsandcolumnsprops area provided, then buttons may be clipped ifrows * columns < values.length.
Usage outside of a <Pane> component will implicitly wrap the radio grid in <Pane position="inline">.
Note that Svelte Tweakpane UI embeds a functionally identical fork of the plugin with build optimizations. The fork also changes the package name from @tweakpane/plugin-essentials to @kitschpatrol/tweakpane-plugin-essentials for consistency with other plugins.
<script lang="ts"> import { RadioGrid } from 'svelte-tweakpane-ui'
// Svelte transition works around CSS gradient // transition limitations import { fade } from 'svelte/transition'
const radioValues = [ ['magenta', 'orange'], ['yellow', 'red'], ['violet', 'gold'], ['red', 'rebeccapurple'], ]
let value = 1
$: [start, end] = radioValues[value - 1]</script>
<RadioGrid bind:value prefix="Color Scheme " values={[1, 2, 3, 4]} />
<div class="demo"> {#key value} <div class="swatch" style:--e={end} style:--s={start} transition:fade ></div> {/key}</div>
<style> div.demo { position: relative; aspect-ratio: 1; width: 100%; background: white; }
div.swatch { position: absolute; width: 100%; height: 100%; background: linear-gradient(45deg, var(--s), var(--e)); }</style>| bindablerequired | |
| Description | Value of selected radio button. Bind to this prop to receive updates when the user clicks a radio button. The value to control. |
|---|---|
| Type | string | number | boolean |
| optional | |
| Description | Number of columns to arrange the radio buttons into. |
|---|---|
| Type | number |
| Default | undefined |
| optional | |
| Description | Name allowing multiple radio groups to share mutually exclusive selection state. Allows spanning exclusive selection state across multiple independent |
|---|---|
| Type | string |
| Default | undefinedUses a dynamically generated globally unique id internally. |
| optional | |
| Description | Text to show in the radio button label before the value. |
|---|---|
| Type | string |
| Default | undefined |
| optional | |
| Description | Number of rows to arrange the radio buttons into. |
|---|---|
| Type | number |
| Default | undefined |
| optional | |
| Description | Text to show in the radio button label after the value. |
|---|---|
| Type | string |
| Default | undefined |
| required | |
| Description | Array of |
|---|---|
| Type | (string | number | boolean)[] |
| optional | |
| Description | Prevent interactivity and gray out the control. |
|---|---|
| Type | boolean |
| Default | false |
| optional | |
| Description | Text displayed next to control. |
|---|---|
| Type | string |
| Default | undefined |
| optional | |
| Description | Custom color scheme. |
|---|---|
| Type | Theme |
| Default | undefinedInherits default Tweakpane theme equivalent to ThemeUtils.presets.standard, or the theme set with setGlobalDefaultTheme(). |
| Description | Fires when This event is provided for advanced use cases. It's usually preferred to bind to the The |
|---|---|
| Extends | ValueChangeEvent |
| Type | RadioGridChangeEvent |