Inputs
Setting Switch
A setting toggle as a row: label and description on the left, the switch pinned to the edge. A native checkbox inside keeps keyboard and form behaviour free.
- switch
- toggle
- settings
- form
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/switch-001?lang=en
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "switch-001" (Setting Switch) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/switch-001.json
Registry item: https://vibeui.ru/r/switch-001.json
Installs to: components/vibeui/switch-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A setting toggle as a row: label and description on the left, the switch pinned to the edge. A native checkbox inside keeps keyboard and form behaviour free.
A setting toggle rather than a form field: a full-width row with the label and description on the left and the switch at the edge. The track is a native checkbox with appearance:none and the thumb rides on transform. The whole row is the target, state and keyboard stay native, and the role is declared with role="switch". Zero dependencies, one file, its own palette.
## 3. How to use it
import { Switch001 } from "@/components/vibeui/switch-001"
<Switch001
name="twofa"
defaultChecked
label="Two-factor protection"
description="Ask for a code when signing in from a new device."
/>
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-switch-001-* palette — do not swap it for your theme tokens (bg-primary, bg-muted and the like)
- the <label> root and the full-width row: that is what makes it read as a settings row
- the native input[type=checkbox] with role="switch": the role announces the behaviour while the state stays real
- moving the thumb with transform rather than left: transform does not trigger layout
- the focus-visible outline on the track — the switch is toggled with the space key
- the shadow under the thumb: without it a white thumb disappears on a light track
- the :has(input:disabled) rules that dim the entire row
- the <style> block inside the component — it holds the palette, the geometry and the thumb animation
## 6. You may change
- the label and description copy; without description the row becomes single-line
- align: end puts the switch on the right, start on the left for a narrow column
- the accent through the accent prop — it colours the on-state track and the focus ring
- any native input props: name, checked, defaultChecked, onChange, disabled, value
- outer spacing and width through className
## 7. Rules
- A switch applies its setting immediately. If the change only takes effect on a Save button, that is a checkbox, not a switch.
- Do not wrap the component in your own <label> — there is one inside, and nested labels break clicking.
- Do not put On/Off wording inside the track: the room in there is sized for the thumb, not for text.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/switch-001.jsonhttps://vibeui.ru/r/switch-001.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-switch-001-*. Корень — <label>, поэтому мишень это вся строка. Внутри нативный input[type=checkbox] с role="switch" и appearance:none: дорожка — сам input, кружок — соседний span, который сдвигается по :checked. Пропом align тумблер переносится в начало строки для настроек в узкой колонке.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Switch001Props = Omit<
ComponentPropsWithoutRef<"input">,
"type" | "size"
> & {
label?: string
/** Пояснение под подписью: чем включённое состояние отличается от выключенного. */
description?: string
/** Сторона, с которой стоит тумблер. По умолчанию справа, как в настройках. */
align?: "start" | "end"
accent?: string
}
// Идея компонента: переключатель настройки, а не поле формы. Строка занимает
// всю ширину, подпись слева, тумблер прижат к краю — так он читается рядом с
// соседними настройками. Внутри нативный checkbox: состояние, клавиатура и
// форма достаются даром.
const STYLES = `
:where([data-vibeui-block="switch-001"]){
--vibeui-switch-001-surface:oklch(1 0 0);
--vibeui-switch-001-surface-border:oklch(0.91 0.006 265);
--vibeui-switch-001-fg:oklch(0.24 0.016 265);
--vibeui-switch-001-muted:oklch(0.54 0.014 265);
--vibeui-switch-001-track:oklch(0.88 0.008 265);
--vibeui-switch-001-thumb:oklch(1 0 0);
--vibeui-switch-001-accent:oklch(0.55 0.2 262);
--vibeui-switch-001-hover:oklch(0.55 0.02 265 / 7%);
--vibeui-switch-001-radius:0.625rem;
--vibeui-switch-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Собственная подложка: подпись поля — это текст, и на тёмной странице
он обязан читаться без правки палитры проекта. */
[data-vibeui-block="switch-001"]{
box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-switch-001-surface);
border:1px solid var(--vibeui-switch-001-surface-border);border-radius:0.875rem;
display:flex;align-items:center;gap:1rem;width:100%;box-sizing:border-box;
padding:0.625rem 0.75rem;margin:-0.625rem -0.75rem;
border-radius:var(--vibeui-switch-001-radius);cursor:pointer;
font-family:var(--vibeui-switch-001-font);color:var(--vibeui-switch-001-fg);
transition:background-color .16s ease;
}
[data-vibeui-block="switch-001"][data-align="start"]{flex-direction:row-reverse;justify-content:flex-end}
[data-vibeui-block="switch-001"]:hover:not(:has(input:disabled)){background:var(--vibeui-switch-001-hover)}
[data-vibeui-block="switch-001"]:has(input:disabled){cursor:not-allowed;opacity:.55}
[data-vibeui-block="switch-001"] [data-part="text"]{display:flex;flex-direction:column;gap:0.125rem;flex:1 1 auto;min-width:0}
[data-vibeui-block="switch-001"] [data-part="title"]{font-size:0.9375rem;line-height:1.35}
[data-vibeui-block="switch-001"] [data-part="description"]{font-size:0.8125rem;line-height:1.4;color:var(--vibeui-switch-001-muted)}
[data-vibeui-block="switch-001"] [data-part="track"]{position:relative;display:flex;flex:none}
[data-vibeui-block="switch-001"] input{
appearance:none;-webkit-appearance:none;margin:0;
width:2.75rem;height:1.5rem;border-radius:9999px;
background:var(--vibeui-switch-001-track);cursor:inherit;
transition:background-color .18s ease;
}
[data-vibeui-block="switch-001"] input:checked{background:var(--vibeui-switch-001-accent)}
[data-vibeui-block="switch-001"] input:focus-visible{outline:2px solid var(--vibeui-switch-001-accent);outline-offset:2px}
[data-vibeui-block="switch-001"] [data-part="thumb"]{
position:absolute;left:0.1875rem;top:0.1875rem;
width:1.125rem;height:1.125rem;border-radius:9999px;pointer-events:none;
background:var(--vibeui-switch-001-thumb);
box-shadow:0 1px 2px oklch(0.2 0.02 265 / 25%);
transition:transform .18s cubic-bezier(.32,.72,0,1);
}
[data-vibeui-block="switch-001"] input:checked + [data-part="thumb"]{transform:translateX(1.25rem)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="switch-001"] *{animation:none!important;transition:none!important}}
`
/**
* Переключатель настройки: строка целиком, тумблер у края.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Switch001({
label = "Двухфакторная защита",
description = "Запрашивать код из приложения при входе с нового устройства.",
align = "end",
accent,
className,
style,
...props
}: Switch001Props) {
const palette = {
...(accent ? { "--vibeui-switch-001-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-switch-001" precedence="medium">
{STYLES}
</style>
<label
data-vibeui-block="switch-001"
data-align={align}
className={className}
style={palette}
>
<span data-part="text">
<span data-part="title">{label}</span>
{description ? (
<span data-part="description">{description}</span>
) : null}
</span>
<span data-part="track">
<input {...props} type="checkbox" role="switch" />
<span data-part="thumb" aria-hidden="true" />
</span>
</label>
</>
)
}