Toggle
A two-state button that can be either on or off.
import * as stylex from '@stylexjs/stylex';
import { Bold } from 'lucide-react';
import { Toggle } from '@/components/ui/toggle';
import { icon } from '@/lib/stylex-utils';
export default function ToggleDemo() {
return (
<Toggle aria-label="Toggle bold">
<Bold {...stylex.props(icon.md)} />
</Toggle>
);
}
Install
npx @madeui/cli add toggleUsage
import { Toggle } from '@/components/ui/toggle';Outline
import { Toggle } from '@/components/ui/toggle';
export default function ToggleOutline() {
return (
<Toggle variant="outline" aria-label="Toggle italic">
Italic
</Toggle>
);
}
With text
import * as stylex from '@stylexjs/stylex';
import { Italic } from 'lucide-react';
import { Toggle } from '@/components/ui/toggle';
import { icon } from '@/lib/stylex-utils';
export default function ToggleText() {
return (
<Toggle aria-label="Toggle italic">
<Italic {...stylex.props(icon.md)} />
Italic
</Toggle>
);
}
Sizes
import * as stylex from '@stylexjs/stylex';
import { Toggle } from '@/components/ui/toggle';
import { space } from '@/lib/constants.stylex';
export default function ToggleSizes() {
return (
<div {...stylex.props(styles.row)}>
<Toggle size="sm" aria-label="Toggle bold">
Small
</Toggle>
<Toggle size="md" aria-label="Toggle bold">
Medium
</Toggle>
<Toggle size="lg" aria-label="Toggle bold">
Large
</Toggle>
</div>
);
}
const styles = stylex.create({
row: {
alignItems: 'center',
display: 'flex',
gap: space.s2,
},
});
Disabled
import { Toggle } from '@/components/ui/toggle';
export default function ToggleDisabled() {
return (
<Toggle disabled aria-label="Toggle bold">
Bold
</Toggle>
);
}
API reference
Built on Base UI Toggle. The table below covers the props this library adds — every other prop (pressed, defaultPressed, onPressedChange, disabled, …) is forwarded; see the Base UI Toggle API reference.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'outline' | 'default' | |
size | 'sm' | 'md' | 'lg' | 'md' | |
style | StyleXStyles | — | StyleX styles merged last — always win over the component’s own styles. |