/
minimus
/
simplelib-ui-kit
Обзор
Документация
Войти
/
minimus
/
simplelib-ui-kit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/inputs/SwitchInput.tsx
32 строки
919 B
minimus
fix: react 19 2
27 фев 2026, 15:51
27 фев 2026, 15:51
f49d0a7
Код
Авторство
О чём код?
import React, { ChangeEvent, FC } from 'react'; import FormControlLabel from '@mui/material/FormControlLabel'; import Switch from '@mui/material/Switch'; import { Root } from '../styles'; import { ISwitchInput } from '../types'; const SwitchInput: FC<ISwitchInput> = (props) => { const { id, caption, value, size = 'small', disabled = false, onChange = undefined } = props; const onValueChange = (e: ChangeEvent<HTMLInputElement>): void => { if (onChange) { const val = e?.target?.checked; if (Number.isInteger(value)) { onChange(val ? 1 : 0); } else { onChange(val); } } }; return ( <Root size={size} style={{ margin: '0 5px' }}> <FormControlLabel control={<Switch checked={!!value} onChange={onValueChange} name={id} color="primary" disabled={disabled} />} label={caption} /> </Root> ); }; export default SwitchInput;