Switch
A control that indicates whether a setting is on or off.
Measured from the logged-in Linear app, light and dark.
import { Switch } from "@replicas/ui";
export default function SwitchDemo() {
return (
<label style={{ display: "flex", alignItems: "center", gap: 6, color: "var(--text-tertiary)" }}>
<Switch />
Auto-save
</label>
);
}Examples
Sizes
<Switch size="small" defaultChecked />
<Switch size="normal" defaultChecked />Prompt
Copy Prompt hands your agent everything it needs to build the Switch in the Linear style: the measured tokens, the CSS and the structure.
Show Prompt
# Linear Switch
A control that indicates whether a setting is on or off.
Build a Switch in this project that looks and behaves like Linear's. Measured from the running Linear app (linear.app). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or [Base UI](https://base-ui.com/react/components/switch) if it has none.
Fidelity: Measured from the logged-in Linear app, light and dark.
## Variants
- `size`: `small`, `normal`
## Tokens
| Token | Light | Dark |
| --- | --- | --- |
| `--accent` | `lch(53% 52.26 286.91)` | `lch(47.918% 59.303 288.421)` |
| `--switch-bg` | `lch(82.484% 0.054 281.837)` | `lch(47.575% 0.736 251.7)` |
| `--switch-thumb` | `lch(100% 5 286.91)` | `lch(100% 5 288.421)` |
| `--focus-ring` | `#5e69d1` | `#5e69d1` |
| `--radius-rounded` | `9999px` | `9999px` |
| `--speed-quick` | `0.1s` | `0.1s` |
| `--speed-highlight-fade-out` | `0.15s` | `0.15s` |
| `--duration-switch-stagger` | `50ms` | `50ms` |
## CSS
Scoped under `[data-style="linear"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.
```css
[data-style="linear"] {
.ui-switch {
--switch-inset: 3px;
--switch-thumb-size: 14px;
position: relative;
box-sizing: border-box;
flex-shrink: 0;
width: 30px;
height: 20px;
border: var(--switch-inset) solid transparent;
border-radius: var(--radius-rounded);
background-color: var(--switch-bg);
transition:
background-color var(--speed-highlight-fade-out) ease-out,
opacity var(--speed-highlight-fade-out) ease-out;
&:focus-visible {
outline: 1px solid var(--focus-ring);
outline-offset: 2px;
}
&[data-checked] {
background-color: var(--accent);
}
&[data-disabled] {
opacity: 0.5;
}
&[data-size="small"] {
--switch-inset: 2px;
--switch-thumb-size: 10px;
width: 22px;
height: 14px;
}
}
.ui-switch-thumb {
--switch-travel: calc(100% - var(--switch-thumb-size));
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: var(--switch-travel);
border-radius: var(--radius-rounded);
background-color: var(--switch-thumb);
transition:
left var(--speed-quick) ease-out,
right var(--speed-quick) ease-out var(--duration-switch-stagger);
&[data-checked] {
left: var(--switch-travel);
right: 0;
transition:
right var(--speed-quick) ease-out,
left var(--speed-quick) ease-out var(--duration-switch-stagger);
}
}
.ui-switch:not([data-disabled]):is(:hover, :active) .ui-switch-thumb {
right: calc(var(--switch-travel) - 2px);
&[data-checked] {
left: calc(var(--switch-travel) - 2px);
right: 0;
}
}
}
```
## Structure
How Replicas assembles it on Base UI.
```tsx
import { Switch as BaseSwitch } from "@base-ui/react/switch";
import { join } from "./utils";
export function Switch({
className,
size,
...props
}: Omit<BaseSwitch.Root.Props, "className"> & { className?: string; size?: string }) {
return (
<BaseSwitch.Root className={join("ui-switch", className)} data-size={size} {...props}>
<BaseSwitch.Thumb className="ui-switch-thumb" />
</BaseSwitch.Root>
);
}
```
## Example
```tsx
import { Switch } from "@replicas/ui";
export default function SwitchDemo() {
return (
<label style={{ display: "flex", alignItems: "center", gap: 6, color: "var(--text-tertiary)" }}>
<Switch />
Auto-save
</label>
);
}
```
## Foundations
The rest of the Linear style, as a skill: https://replicas.raphaelsalaja.com/skills/linear/SKILL.md