# field.switch

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

Component: [`<Field>`](https://www.prongs.dev/docs/components/field.md) · Renders: `<input type="checkbox">` · Profile: [UI](https://www.prongs.dev/docs/intents/ui.md)

## Example

```tsx
<Field intent="field.switch" id="switch" name="switch" />
```

## Choosing between neighbours

Find the row that describes your element, and use the intent on the right.

| If it is for… | Use |
|---|---|
| A setting that turns on or off immediately: show images, compact mode. Pair with a text.label | `field.switch` (this page) |
| A choice that waits for a submit button | [`field.checkbox`](https://www.prongs.dev/docs/intents/field/checkbox.md) |
| A setting that takes effect immediately (rather than [`field.checkbox`](https://www.prongs.dev/docs/intents/field/checkbox.md)) | `field.switch` (this page) |

## Connections

Declared in the registry, both directions. Where an intent is used in your own code is something check and the gallery see; this site has no app code.

- Built from: [`input.toggle`](https://www.prongs.dev/docs/intents/ui.md#input-toggle)

## 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`](https://www.prongs.dev/docs/intents/ui.md#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` (this page) — 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',
    },
  ],
},
```
