prongs
GitHub

field.switch

A setting that turns on or off immediately: show images, compact mode. Pair with a text.label

Component

Renders

<input type="checkbox">

Profile

Comes from

starter
Read https://www.prongs.dev/docs/intents/field/switch.md and tell me whether field.switch fits what I am building.

Example

Preview
<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.switch
  • A choice that waits for a submit button

    field.checkbox
  • A setting that takes effect immediately

    rather than field.checkbox
    field.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.toggle

    Sliding 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.switch

    A setting that turns on or off immediately: show images, compact mode. Pair with a text.label

Final classes
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
Element behaviour
{ type: 'checkbox', role: 'switch' }
Definition
TS
'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',
},
],
},