Foundation
Main View
Components
Charts
Dialogs
Framer Animations
Forms
Grids
Typography
Tools
Package: @uireact/form
A switch component so user can toggle inputs
1. Make sure you install peer dependencies first:
2. Install package:
npm i -S @uireact/form
This is a controlled input so you need to control the state of the toggle. This is done through the onChange
and checked
props.
<SwitchExample />
SwitchExample:
export const SwitchExample: React.FC = () => { const [checked, setChecked] = useState(false); const onChangeCB = useCallback(() => { setChecked(!checked); }, [checked, setChecked]); return ( <> <UiSwitch checked={checked} onChange={onChangeCB} name="switch-example" /> <p>Checked: {`${checked}`}</p> </> ); };
<UiSwitch name="disabled-checkbox" label="Select option" disabled />
<UiSwitch name="disabled-checkbox" label="Select option" error="Please select this option" />
<UiSwitch name="start-label-checkbox" label="Select option" disabled labelPosition="start" />
<UiSwitch name="positive-checkbox" category="positive" checked />
<UiSwitch name="error-checkbox" category="error" checked />
<UiSwitch name="negative-checkbox" category="negative" checked />