Skip to Content
ComponentsSwitch

Switch

Control to allow toggling between checked and not checked state.

Documentation

import { Switch } from "@optiaxiom/react"; export function App() { return <Switch>Label</Switch>; }

The children prop is used as the label of the switch control.

import { Group, Separator, Switch } from "@optiaxiom/react"; export function App() { return ( <Group gap="16"> <Switch>Label</Switch> <Separator orientation="vertical" /> <Switch /> </Group> ); }

Use the checked and defaultChecked props to toggle between controlled and uncontrolled usage. And combine it with onCheckedChange to listen for changes to the state.

"use client"; import { Button, Group, Switch } from "@optiaxiom/react"; import { useState } from "react"; export function App() { const [value, setValue] = useState(false); return ( <Group gap="16"> <Switch checked={value} onCheckedChange={setValue}> Label </Switch> <Button disabled={!value} onClick={() => setValue(false)}> Reset </Button> </Group> ); }

Use the size prop to control the size of the switch control.

"use client"; import type { ComponentPropsWithRef } from "react"; import { Switch } from "@optiaxiom/react"; export function App({ size, }: Pick<ComponentPropsWithRef<typeof Switch>, "size">) { return <Switch size={size}>Label</Switch>; }

Enable the disabled prop to toggle the disabled state of the input field.

import { Group, Switch } from "@optiaxiom/react"; export function App() { return ( <Group gap="16"> <Switch defaultChecked disabled> Label </Switch> <Switch disabled>Label</Switch> </Group> ); }

Checkbox

Basic control to allow selecting one or more items from a set.

RadioGroup

Basic control to allow selecting only one item from a set.

Props

Supports all Box props in addition to its own. Renders a <div> element but forwards all props to a hidden <input> element.

Prop

asChild

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read the Composition guide for more details.

false | true

children

ReactNode

className

string

description

Add secondary text after the label.

ReactNode

name

The name of the form control element.

string

onCheckedChange

Handler that is called when the checked state changes.

(checked: boolean) => void

size

Control the size of the switch.

"md" | "lg"

Default: md

Changelog

  • Added component
Last updated on