Skip to main content

IconSwitch

A two-state sliding switch that shows a distinct icon in each of its "off" and "on" positions. Vajra UI ships no bundled icons: offIcon/onIcon accept any component matching TVajraIconComponent. The examples below use @devraj-labs/vajra-ui-icons, a small set of Lucide icons pre-adapted to that contract.

Basic usage

function ThemeSwitch() {
const [value, setValue] = useState(false);
return <IconSwitch value={value} onChange={setValue} offIcon={SunIcon} onIcon={MoonIcon} />;
}

Disabled

<IconSwitch value={false} onChange={() => {}} offIcon={SunIcon} onIcon={MoonIcon} isDisabled />

Custom sizing & colors

<IconSwitch
value={true}
onChange={() => {}}
offIcon={SunIcon}
onIcon={MoonIcon}
cellSize={32}
iconSize={14}
activeIconColor="primary"
inactiveIconColor="textMuted"
/>

Props

PropTypeDefaultDescription
valuebooleanRequired. Current state; false selects the off cell, true selects the on cell.
onChange(value: boolean) => voidRequired. Called with the toggled value on press.
offIconTVajraIconComponentRequired. Icon rendered in the off (left) cell.
onIconTVajraIconComponentRequired. Icon rendered in the on (right) cell.
trackBgTVajraColors'surfaceRaised'Background color of the track.
trackRoundedTRoundedToken'r-3'Corner radius of the track.
selectorBgTVajraColors'surface'Background color of the sliding selector box.
selectorRoundedTRoundedToken'r-2'Corner radius of the sliding selector box.
activeIconColorTVajraColors'text'Color of whichever icon is currently active.
inactiveIconColorTVajraColors'textMuted'Color of whichever icon is currently inactive.
isDisabledbooleanfalseDisables interaction and dims opacity.
cellSizenumber40Size of each icon cell (and the selector box).
iconSizenumber18Size passed to both icons.
testIDstringTest identifier forwarded to the root pressable.