field.switch
A setting that turns on or off immediately: show images, compact mode. Pair with a text.label
Read https://www.prongs.dev/docs/intents/field/switch.md and tell me whether field.switch fits what I am building.Field intents
Example
<Layout intent="layout.headline">
<Text intent="text.label" as="label" htmlFor="notify">Email me about new comments</Text>
<Field intent="field.switch" id="notify" checked={notify} onChange={toggleNotify} />
</Layout>Connections
Choosing between neighbours
If it is
Use
A setting that turns on or off immediately: show images, compact mode. Pair with a text.label
field.switchA choice that waits for a submit button
field.checkboxA setting that takes effect immediately
rather thanfield.checkboxfield.switch
For registry authors
Starter intents. These are the intents prongs add puts in your registry, shown in this site’s theme. Yours are your own registry.ts: rename, restyle and add to them, and see them with prongs add gallery.
What this intent is built from and its entry in components/prongs/registry.ts. You only need this to change how it looks or to add an intent like it.
How field.switch resolves, and its definition
Each layer adds to the one before it; a later class wins over an earlier one that sets the same thing.
input.toggleSliding on/off track
relative h-5 w-9 shrink-0 cursor-pointer appearance-none rounded-full bg-input transition-colors checked:bg-primary before:absolute before:left-0.5 before:top-0.5 before:h-4 before:w-4 before:rounded-full before:bg-background before:transition-transform checked:before:translate-x-4
field.switchA setting that turns on or off immediately: show images, compact mode. Pair with a text.label
relative h-5 w-9 shrink-0 cursor-pointer appearance-none rounded-full bg-input transition-colors checked:bg-primary before:absolute before:left-0.5 before:top-0.5 before:h-4 before:w-4 before:rounded-full before:bg-background before:transition-transform checked:before:translate-x-4
{ type: 'checkbox', role: 'switch' }'field.switch': {
kind: 'semantic',
description: 'A setting that turns on or off immediately: show images, compact mode. Pair with a text.label',
refs: ['input.toggle'],
binding: { behavior: { type: 'checkbox', role: 'switch' } },
notFor: [
{
context: 'a choice that waits for a submit button',
instead: 'field.checkbox',
},
],
},