UNPKG

react-antd-admin-panel

Version:

Easy prototyping admin panel using React and Antd

28 lines 1.2 kB
import React, { useState } from "react"; import { Switch as SwitchAnt } from "antd"; const Switch = (props) => { var _a; let model = props.model; const [value, setValue] = useState((_a = model._default) !== null && _a !== void 0 ? _a : ''); const onChange = (checked) => { var _a; model._data = checked; setValue(model._data); if (model._formula) model.value(model._data); (_a = model._onChange) === null || _a === void 0 ? void 0 : _a.call(model, model._data, model._index); }; // Register the defaultValue to the formula. if (model._default) { if (model._formula) model.value(model._default); } let addProps = {}; if (model._checkedChildren) addProps['checkedChildren'] = model._checkedChildren; if (model._unCheckedChildren) addProps['unCheckedChildren'] = model._unCheckedChildren; return (React.createElement(SwitchAnt, Object.assign({ style: model._style, checked: value, defaultChecked: value !== null && value !== void 0 ? value : true, onChange: onChange }, addProps))); }; export default Switch; //# sourceMappingURL=Switch.js.map