Documentation
Form Components
Switch

Switch

The Switch component is designed for toggling between two states, such as "on" and "off," with a user-friendly sliding interface. It provides a clear and intuitive way for users to make binary choices, with support for custom labels, colors, and sizes to fit your application's design.

Installation

Install the package

npm i @start-base/react-form-elements

Add the styles

To use the React form elements styles in a Next.js project, import the styles in your layout.tsx file.

app/layout.tsx
import "@start-base/react-form-elements/styles.css";

Import the component

import Switch from '@start-base/react-form-elements/Switch';

Usages

Switch Component Checked

Switch Component Disabled

Switch Component Error

API

A toggle switch component.

NameTypeDefaultDescription
namestringName of the input
labelstringnullLabel of the input
onChangefunctionCallback function that is fired when the value changes.
inputClassNamestringnullClassname for input element
labelClassNamestringnullClassname for label element
errorClassNamestringnullClassname for error element
disabledbooleanfalseDisable the input
errorstring or boolean or objectnullError message to display below the input. if value is a boolean input border will be change. Also you can pass schema validator error objects.
checkedbooleanfalseChecked state of the switch

Styling