react-antd-admin-panel
Version:
Easy prototyping admin panel using React and Antd
53 lines • 2.54 kB
JavaScript
import React, { useState } from "react";
import { Checkbox as CheckboxAnt } from "antd";
import { Form } from 'antd';
import { Access } from "../../typescript";
const Checkbox = (props) => {
var _a, _b, _c, _d;
let model = props.model;
let [checked, setChecked] = useState((_a = model._default) !== null && _a !== void 0 ? _a : false);
const onChange = (value) => {
var _a;
let historyKey = model.history(value);
let finalize = (value) => {
model._data = value;
model._default = value;
if (model._formula)
model.value(value);
setChecked(value);
};
if (model._onChangeNext) {
model._onChangeNext(value, finalize);
}
else {
(_a = model._onChange) === null || _a === void 0 ? void 0 : _a.call(model, value, historyKey);
finalize(value);
}
};
const onClear = () => {
model._data = undefined;
if (model._formula)
model.value(undefined);
};
model._onError = () => onClear();
model._onComplete = () => onClear();
// Register the defaultValue to the formula.
if (model._default) {
model._data = model._default;
model._historyFirstKey = model.history(model._data);
if (model._formula) {
model.value(model._default);
}
}
return (React.createElement("div", { style: (_b = model._style) !== null && _b !== void 0 ? _b : {} },
React.createElement(Form.Item, { style: (_d = Object.assign(Object.assign({}, (_c = model._styleForm) !== null && _c !== void 0 ? _c : {}), { marginBottom: 0 })) !== null && _d !== void 0 ? _d : { marginBottom: 0 } },
React.createElement(CheckboxAnt.Group, { style: { marginBottom: 12 }, value: checked, disabled: model._disabled || new Access(props.main).simple(model), onChange: onChange, options: model._fields.map((r) => {
let item = r.getObject();
item['disabled'] = new Access(props.main).simple(r);
return item;
}) }, props.model._title),
model._required && model._data === undefined && React.createElement("div", { style: { color: '#ff4d4f', fontSize: 14, fontWeight: 300, paddingTop: 6, paddingBottom: 12 } }, "Required field")
|| React.createElement("div", { style: { paddingTop: 12 } }))));
};
export default Checkbox;
//# sourceMappingURL=Checkbox.js.map