ToggleSwitch
A switch component for toggling between on/off states.
Installation
npm install @cleartrip/ct-design-toggle-switch
# or
pnpm add @cleartrip/ct-design-toggle-switch
Peer dependencies
# Required for all targets
npm install react
# Web only
npm install react-dom
# React Native only
npm install react-native
Usage
Basic
import { ToggleSwitch } from '@cleartrip/ct-design-toggle-switch';
function Example() {
return (
<ToggleSwitch>
{/* Basic usage */}
</ToggleSwitch>
);
}
Props
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
checked | boolean | — | No | checked property |
disabled | boolean | — | No | disabled property |
onChange | (checked: boolean) => void | — | No | onChange property |
prefix | `string | ReactElement` | — | No |
suffix | `string | ReactElement` | — | No |
size | ToggleSwitchSizeType | — | No | size property |
styleConfig | { | — | No | styleConfig property |
root | Styles[] | — | No | root property |
switch | Styles[] | — | No | switch property |
switchContainer | Styles[] | — | No | switchContainer property |
switchWrapper | Styles[] | — | No | switchWrapper property |
labelStylesConfig | TextStyle[] | — | No | labelStylesConfig property |
ToggleSwitchSize
SMALL— smLARGE— lg
Accessibility
- The component follows accessibility best practices
- Ensure proper ARIA attributes are provided where needed
- Test with screen readers to ensure usability
Migration
If migrating from a previous version:
- import { ToggleSwitch } from 'yagami/core/components';
+ import { ToggleSwitch } from '@cleartrip/ct-design-toggle-switch';