Settings toggles
A notification settings list with squishy switches: the knob stretches as it slides, and a master switch turns the whole group on or off.
"use client";
import { useState } from "react";
import "./settings-toggles.css";
const ITEMS = [
{
id: "mentions",
title: "Mentions and replies",
hint: "When someone tags you or answers your comment.",
},
{
id: "digest",
title: "Weekly digest",
hint: "A Monday summary of what changed in your projects.",
},
{
id: "launch",
title: "Product news",
hint: "New features, at most twice a month.",
},
{
id: "sound",
title: "Sound",
hint: "A soft chime for messages while the app is open.",
},
];
/**
* SettingsToggles
* - Each row is a <label> wrapping a checkbox with role="switch", so the whole row toggles.
* - The knob stretches while it travels (a CSS keyframe), which reads as "springy" without JS.
* - The master switch disables the group visually and for assistive tech.
*/
export function SettingsToggles({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [all, setAll] = useState(true);
const [on, setOn] = useState<Record<string, boolean>>({
mentions: true,
digest: true,
launch: false,
sound: false,
});
return (
<section
className="gu-toggles"
data-theme={theme}
aria-labelledby="gu-toggles-title"
>
<label className="gu-toggles__row gu-toggles__row--master">
<span>
<strong id="gu-toggles-title">Email notifications</strong>
<small>
{all
? `${Object.values(on).filter(Boolean).length} of ${ITEMS.length} on`
: "Paused"}
</small>
</span>
<input
type="checkbox"
role="switch"
checked={all}
onChange={(e) => setAll(e.target.checked)}
/>
<i className="gu-switch" aria-hidden="true" />
</label>
<fieldset className="gu-toggles__group" disabled={!all}>
<legend className="gu-sr">Notification types</legend>
{ITEMS.map((it) => (
<label key={it.id} className="gu-toggles__row">
<span>
<strong>{it.title}</strong>
<small>{it.hint}</small>
</span>
<input
type="checkbox"
role="switch"
checked={on[it.id]}
onChange={(e) =>
setOn((o) => ({ ...o, [it.id]: e.target.checked }))
}
/>
<i className="gu-switch" aria-hidden="true" />
</label>
))}
</fieldset>
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Settings toggles
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A notification settings panel: a master "Email notifications" switch above four setting rows. Each switch's knob stretches as it slides. Turning the master off dims and disables the group.
## Layout and look
- Card 440px, padding 8px, radius 24px. Rows 64px+, padding 12px 14px, title (weight 700) plus a muted hint; hairline dividers.
- Master row has a faint tinted background and a bigger title with "2 of 4 on" or "Paused".
- Switch: 52×32 pill, off gray, on orange #ff5a1f; knob 24px white with a soft shadow.
## Behavior and motion
1. Each row is a <label> around an invisible checkbox (role="switch") and a decorative switch, so the whole row toggles.
2. Knob slides with left (350ms cubic-bezier(0.16, 1, 0.3, 1)) and a keyframe widens it to 34px halfway for a squishy feel.
3. Master off: fieldset disabled, opacity 0.45, not-allowed cursor.
## Touch
Full-row targets of 64px.
## Accessibility
- Native checkboxes with role="switch" keep keyboard (Space) and announcements; the group is a fieldset with a hidden legend.
- Focus ring on the visual switch (#2b35ff, dark #d7ff3a).
- prefers-reduced-motion: no slide or stretch.
## Props
theme. Edit the ITEMS array.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### SettingsToggles.tsx
```tsx
"use client";
import { useState } from "react";
import "./settings-toggles.css";
const ITEMS = [
{
id: "mentions",
title: "Mentions and replies",
hint: "When someone tags you or answers your comment.",
},
{
id: "digest",
title: "Weekly digest",
hint: "A Monday summary of what changed in your projects.",
},
{
id: "launch",
title: "Product news",
hint: "New features, at most twice a month.",
},
{
id: "sound",
title: "Sound",
hint: "A soft chime for messages while the app is open.",
},
];
/**
* SettingsToggles
* - Each row is a <label> wrapping a checkbox with role="switch", so the whole row toggles.
* - The knob stretches while it travels (a CSS keyframe), which reads as "springy" without JS.
* - The master switch disables the group visually and for assistive tech.
*/
export function SettingsToggles({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [all, setAll] = useState(true);
const [on, setOn] = useState<Record<string, boolean>>({
mentions: true,
digest: true,
launch: false,
sound: false,
});
return (
<section
className="gu-toggles"
data-theme={theme}
aria-labelledby="gu-toggles-title"
>
<label className="gu-toggles__row gu-toggles__row--master">
<span>
<strong id="gu-toggles-title">Email notifications</strong>
<small>
{all
? `${Object.values(on).filter(Boolean).length} of ${ITEMS.length} on`
: "Paused"}
</small>
</span>
<input
type="checkbox"
role="switch"
checked={all}
onChange={(e) => setAll(e.target.checked)}
/>
<i className="gu-switch" aria-hidden="true" />
</label>
<fieldset className="gu-toggles__group" disabled={!all}>
<legend className="gu-sr">Notification types</legend>
{ITEMS.map((it) => (
<label key={it.id} className="gu-toggles__row">
<span>
<strong>{it.title}</strong>
<small>{it.hint}</small>
</span>
<input
type="checkbox"
role="switch"
checked={on[it.id]}
onChange={(e) =>
setOn((o) => ({ ...o, [it.id]: e.target.checked }))
}
/>
<i className="gu-switch" aria-hidden="true" />
</label>
))}
</fieldset>
</section>
);
}
```
### settings-toggles.css
```css
/* SettingsToggles: change these colors to match your brand. */
.gu-toggles {
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.12);
--off: rgb(14 14 16 / 0.2);
--on: #ff5a1f;
--knob: #ffffff;
--focus: #2b35ff;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
width: min(100%, 440px);
padding: 8px;
border: 1px solid var(--line);
border-radius: 24px;
background: var(--card);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-toggles[data-theme="dark"] {
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.12);
--off: rgb(243 238 227 / 0.22);
--knob: #f3eee3;
--focus: #d7ff3a;
}
.gu-toggles__row {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
min-height: 64px;
padding: 12px 14px;
border-radius: 16px;
cursor: pointer;
transition: background-color 0.2s;
}
.gu-toggles__row:hover {
background: color-mix(in srgb, var(--text) 5%, transparent);
}
.gu-toggles__row span {
display: grid;
gap: 2px;
}
.gu-toggles__row strong {
font-weight: 700;
}
.gu-toggles__row small {
color: var(--muted);
font-size: 0.82rem;
line-height: 1.35;
}
.gu-toggles__row--master {
margin-bottom: 4px;
background: color-mix(in srgb, var(--text) 5%, transparent);
}
.gu-toggles__row--master strong {
font-size: 1.05rem;
font-weight: 900;
}
.gu-toggles__group {
margin: 0;
padding: 0;
border: 0;
transition: opacity 0.3s;
}
.gu-toggles__group:disabled {
opacity: 0.45;
}
.gu-toggles__group:disabled .gu-toggles__row {
cursor: not-allowed;
}
.gu-toggles__row + .gu-toggles__row {
border-top: 1px solid var(--line);
border-radius: 0 0 16px 16px;
}
/* The real checkbox stays in place but invisible, so it still gets focus and clicks */
.gu-toggles input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.gu-switch {
position: relative;
flex: none;
width: 52px;
height: 32px;
border-radius: 99px;
background: var(--off);
transition: background-color 0.3s var(--ease);
}
.gu-switch::after {
content: "";
position: absolute;
top: 4px;
left: 4px;
width: 24px;
height: 24px;
border-radius: 99px;
background: var(--knob);
box-shadow: 0 2px 6px rgb(0 0 0 / 0.25);
transition: left 0.35s var(--ease);
animation: gu-switch-off 0.35s var(--ease);
}
.gu-toggles input:checked + .gu-switch {
background: var(--on);
}
.gu-toggles input:checked + .gu-switch::after {
left: 24px;
animation-name: gu-switch-on;
}
/* The knob grows wide mid-travel, then settles: a squishy feel */
@keyframes gu-switch-on {
0% {
width: 24px;
}
45% {
width: 34px;
margin-left: -10px;
}
100% {
width: 24px;
}
}
@keyframes gu-switch-off {
0% {
width: 24px;
}
45% {
width: 34px;
}
100% {
width: 24px;
}
}
.gu-toggles input:focus-visible + .gu-switch {
outline: 3px solid var(--focus);
outline-offset: 3px;
}
.gu-toggles input:disabled + .gu-switch {
filter: grayscale(1);
}
.gu-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-switch,
.gu-switch::after {
transition: none;
animation: none !important;
}
}
```
You might also want
Next piece: Skeleton to contentDate range picker
Components, advanced
Floating label form
Components, beginner
Multi-step form
Components, advanced