Toggle

A switch for a boolean setting.

onChange receives the next state, value, and the event. Use it for settings that take effect immediately. description adds text below the label.

Live example

Example controls

Usage

'use client';

import { Toggle } from '@prosazhin/pbcomponents';
import { useState } from 'react';

function Example() {
  const [checked, setChecked] = useState(false);
  return (
    <Toggle
      value='one'
      checked={checked}
      onChange={setChecked}
    >
      Label
    </Toggle>
  );
}

Component API

PropType / variantsPurposeDefault
childrenstringComponent content.—
size's' | 'm's · mComponent size.m
labelPlace'left' | 'right'left · rightLabel position relative to the control.right
checkedbooleanCurrent selected state.false
disabledbooleanDisables interaction.false
descriptionReactNodeSecondary text below the label.—
valuestringForm item value.—
onChange(checked: boolean, value: string, event: InputEvent) => voidReports the new checked state and item value.—
classNamestringClass of the root element.—
wrapperClassNamestringClass of the outer wrapper.—
textClassNamestringClass of the text part.—

Native HTML attributes are accepted where the component renders the corresponding element. className props only affect styling.