# Padlock toggle

> A privacy switch drawn as a polished steel padlock. Push the shackle down or tap it: the shackle snaps into the body, the body bounces, the keyhole lights up in the accent and the label rolls from Public to Private. Unlocking pops the shackle against its collar and swivels it open.

- Type: Component (special)
- Access: Arc Pro
- Page: https://uiarc.dev/components/padlock-toggle
- Markdown: https://uiarc.dev/components/padlock-toggle/markdown
- Source file: `registry/components/padlock-toggle/padlock-toggle.tsx`
- Keywords: special, toggle, switch, privacy, encryption, lock, metal, physics, new, padlock, private, public, visibility, secure, unlock, sharing

## When to use

- A share dialog or project header where Public and Private is the one decision that matters.
- Turning on end to end encryption for a vault, a chat or a folder.
- A product page that shows off how your app handles privacy.

## When not to use

- Use switch for ordinary settings in a list or a form.
- Use arming-switch for a destructive action that needs a guarded confirmation.
- Use a radio group or segmented control when there are more than two visibility levels, such as private, team and public.

## Installation

Padlock toggle is part of Arc Pro. The live preview is public; the source and install command need Pro.

### CLI with a Pro token

1. Create a token in your account and set it in the environment (or `.env.local`). Never commit it.

```bash
export ARC_PRO_TOKEN=arc_pro_...
```

2. Add the Pro registry to `components.json`:

```json
{
  "registries": {
    "@uiarc": "https://uiarc.dev/r/{name}.json",
    "@uiarc-pro": {
      "url": "https://uiarc.dev/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${ARC_PRO_TOKEN}"
      }
    }
  }
}
```

3. Install:

```bash
npx shadcn@latest add @uiarc-pro/padlock-toggle
```

### Manual

Signed-in Pro members can copy the source from the Manual tab on the docs page.

- Plans: https://uiarc.dev/pricing
- Create a Pro token: https://uiarc.dev/account#pro-access
- Setup guide: https://uiarc.dev/docs/ai#pro-access

## Usage

```tsx
import { PadlockToggle } from "@/components/arc/padlock-toggle/padlock-toggle";

export function VaultPrivacy({ vault }: { vault: { id: string; encrypted: boolean } }) {
  const [locked, setLocked] = useState(vault.encrypted);
  return (
    <PadlockToggle
      label="End to end encryption"
      checked={locked}
      onCheckedChange={async next => {
        setLocked(next);
        const ok = await api.setEncryption(vault.id, next);
        if (!ok) setLocked(!next);
      }}
      onLabel="Encrypted"
      offLabel="Not encrypted"
      onDescription="Only devices you approve can read these files"
      offDescription="Files are readable by workspace admins"
    />
  );
}
```

## API reference

### PadlockToggle

A privacy or encryption switch drawn as a polished steel padlock. Click it, press Space or Enter, or push the shackle down with a finger. Locking swings the open shackle back into line, the latch catches it and it slams into the body: the body dips and bounces, the keyhole ignites in the accent, a ring and a glint run out across the metal, and the label rolls from Public to Private. Unlocking lets the spring go: the shackle pops up against its collar and swivels open on its long leg. A streak of light follows the pointer across the brushed body.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `checked` | `boolean` | – | Controlled locked state. Leave it out for uncontrolled use. If the parent turns a request down, the shackle springs back. |
| `defaultChecked` | `boolean` | `false` | Initial locked state when uncontrolled. |
| `onCheckedChange` | `(locked: boolean) => void` | – | Called when a click, a key press, a push or a pull asks to lock or unlock. |
| `onSnap` | `(locked: boolean) => void` | – | Called at the physical moment: when the shackle lands in the body (true) or hits its collar on the way out (false). Use it to play a click sound. |
| `onLabel` | `string` | `"Private"` | State word shown while locked. |
| `offLabel` | `string` | `"Public"` | State word shown while unlocked. |
| `onDescription` | `string` | `"Only you and invited members can open it"` | Line under the state word while locked. Pass an empty string to hide it. |
| `offDescription` | `string` | `"Anyone with the link can view"` | Line under the state word while unlocked. Pass an empty string to hide it. |
| `label` | `string` | – | Accessible name of the switch. Defaults to onLabel, so it reads as Private, switch, on. |
| `size` | `number` | `132` | Width of the padlock in pixels. It shrinks to fit narrow containers. |
| `name` | `string` | – | Submits "on" with a form under this name while locked. |
| `haptics` | `boolean` | `true` | A short vibration on the snap and the pop, on devices that support it. |
| `disabled` | `boolean` | `false` | Locks the padlock in its current state and dims it. |
| `accent` | `string` | – | Any CSS color for the keyhole light. Defaults to the accent, or a clear blue when the accent is neutral. |
| `className` | `string` | – | Class on the root element. |
| `style` | `CSSProperties` | – | Inline styles on the root element. |

## Keyboard interactions

| Keys | Action |
| --- | --- |
| Tab | Moves focus to the padlock. Focus brings the light up across the metal instead of drawing a ring. |
| Space | Presses the padlock down while held and toggles it on release. |
| Enter | Toggles the padlock. |

## Accessibility

- The padlock is a native button with role="switch" and aria-checked, named by label or the locked state word, so it reads as Private, switch, on or off.
- The line under the state word is linked with aria-describedby, and only the current line is exposed.
- The drawing is hidden from assistive technology; the state never relies on the keyhole color, because the word and the description change with it.
- Drag is an extra: every action is also a single tap, click or key press. Disabled uses the native disabled attribute.
- Pointer focus draws no ring; keyboard focus shows Arc's shared focus ring. Keyboard focus is shown by the light streak brightening across the body.

## Motion

- One requestAnimationFrame loop steps every part as a spring at 240 Hz and writes transforms and opacity straight to the DOM; React renders only when the locked state changes.
- Locking is choreographed by the physics, not by a timeline: the shackle hovers while its short leg swings back into line with the hole, then the latch pulls it in and it hits the floor of the body. That impact dips and squashes the body, nods the whole lock, ignites the keyhole past full, sends a ring out from the keyhole and runs a glint across the metal, then the label rolls down to Private.
- Unlocking releases the spring: the shackle jumps, clacks against its collar and bounces off it, and the swivel and lean follow a beat behind with a little wobble while the body kicks back against the release.
- Push the open shackle down and it follows the finger one to one, rests on the body until the leg lines up, and snaps shut once the latch catches it. Pull a locked shackle up and it gives a little against the latch, then pops free. A flick toward the body locks on release; every grab starts from where the shackle is, velocity included.
- Idle life: the open shackle sways on its leg, the lit keyhole breathes, the lock drifts a few tenths of a degree and the streak of light wanders slowly across the grain. On hover the streak glides in from the side the pointer came from and the lock tilts toward it.
- The loop pauses offscreen and in background tabs. With reduced motion the loop never runs: the shackle fades into its new place, the keyhole light fades in or out, and the label crossfades without travel.

## Responsive behavior

- The padlock is drawn in its own unit that follows the size prop and shrinks to 56% of the container width, so it keeps its proportions from a narrow card to a hero.
- Both state words and both descriptions share one grid cell, so the caption never changes size when the state changes; long descriptions wrap.
- Touch uses the same push and pull as the mouse; the padlock sets touch-action none so a drag on it does not scroll the page, while the rest of the page scrolls as usual.

## Performance

- About sixteen small composited layers; each frame writes a handful of transforms and opacities through a cache that skips unchanged values.
- No canvas, no layout reads in the loop: the button rectangle is read once per press or hover entry.
- The brushed grain is two tiny SVG noise tiles rasterized once. Nothing animates filters or gradients.

## Notes for AI

- Use it for one prominent privacy, sharing or encryption setting where the moment of locking deserves weight: project visibility, vault encryption, a private note, a locked channel.
- Keep onLabel and offLabel to one or two words and put the consequence in the descriptions, such as who can open the item.
- In controlled mode update checked optimistically and revert on failure; the shackle springs back when checked does not follow a request.
- Use onSnap, not onCheckedChange, to play sounds, so the click lands with the metal.
- It is a showpiece: use one per view. For lists of settings use switch.

## Related

- [Switch](https://uiarc.dev/components/switch/markdown): A tactile toggle for settings that take effect immediately.
- [Arming switch](https://uiarc.dev/components/arming-switch/markdown): An aircraft style guarded switch for dangerous actions such as a production deploy. Lift the translucent red cover on its hinge, throw the chrome bat toggle until it snaps over center and the lamp flickers on, then press and hold the lamp to run the action. Closing the cover throws an armed switch back to safe.
- [Theme switcher](https://uiarc.dev/components/theme-switch/markdown): Four smooth ways to move between light and dark appearance.

## Also in loaders

- [Stretch refresh](https://uiarc.dev/components/stretch-refresh/markdown): Pull a feed down and a line stretches to tell you when to let go.
- [Feedback morph](https://uiarc.dev/components/feedback-morph/markdown): A feedback button that becomes a form, then a thank-you, in one shape.
- [Morph loader](https://uiarc.dev/components/morph-loader/markdown): Tiny loaders that morph between shapes and fold into a check or a cross when done.
- [Skeleton morph](https://uiarc.dev/components/skeleton-morph/markdown): Loading skeletons that grow into the real content, block by block, instead of swapping.
- [Celebrate button](https://uiarc.dev/components/celebrate-button/markdown): A button that bursts confetti from its own edges on success while the label morphs to done.
- [Black hole](https://uiarc.dev/components/black-hole/markdown): A delete transition that pulls the chosen items into a tiny singularity while the rest of the list bends around it; undo spins them back out.
- [Slide to confirm](https://uiarc.dev/components/slide-to-confirm/markdown): A slide-to-confirm control. The thumb pulls a liquid fill behind it and makes the track swell. It snaps back on a spring if released early. Past the threshold, the track draws into the thumb and the chevron morphs into a success check, with pending and error states.
- [Charge session](https://uiarc.dev/components/charge-session/markdown): An EV or device charging card. Energy packets flow from a charger along the cable into the battery pack, which fills toward a draggable charge limit. The charge curve tapers near full, and power, energy, time to limit and cost update live. Stop charging drains the flow.

## Guidance for AI tools

Padlock toggle: A privacy switch drawn as a polished steel padlock. Push the shackle down or tap it: the shackle snaps into the body, the body bounces, the keyhole lights up in the accent and the label rolls from Public to Private. Unlocking pops the shackle against its collar and swivels it open. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://uiarc.dev/llms.txt
