Switch

A Switch component is a UI element that allows users to toggle between two states, typically representing an on/off or enabled/disabled choice. It is visually represented as a sliding toggle or checkbox and provides immediate feedback when the user interacts with it. Switch components are commonly used for settings, preferences, and feature activations in applications, enhancing user experience by simplifying the selection process.
# Demo
# Attributes
NameTypeDefaultDetails
classNamestring' 'You can customise by passing tailwind classes.
labelClassNamestring' 'You can customise by passing tailwind classes.
switchClassNamestring' 'You can customise by passing tailwind classes.
labelstring' 'You can pass label to switch.
enabledbooleanfalseYou can pass enabled to switch.
disabledbooleanfalseYou can pass disabled to switch.
onChange(enabled: boolean) => voidRequiredYou can get callback when switch changed.
# Usage
import { useState } from 'react'; import { NSwitch } from 'nayan'; const Switch = () => { const [enabled, setEnabled] = useState(false); return <NSwitch label="Is Dark Mode" enabled={enabled} onChange={setEnabled} />; }; export default Switch;