UNPKG

react-antd-admin-panel

Version:

Easy prototyping admin panel using React and Antd

42 lines 1.63 kB
import React, { useEffect } from "react"; import { Row, Col } from 'antd'; import Section from "../Section"; const Conditions = (props) => { var _a, _b; let model = props.model; const [state, setState] = React.useState({ key: 0, section: [], args: undefined, }); const [conditions, setConditions] = React.useState((_a = model === null || model === void 0 ? void 0 : model._fields) !== null && _a !== void 0 ? _a : []); model.clear = () => { setState({ key: state.key + 1, section: null, }); }; model.getValue = () => state.args; model.checkCondition = (args) => { let sections = []; conditions.forEach((r, i) => { if (r._condition(args)) { let temp = Math.floor((Math.random() * 10000)); sections.push(React.createElement(Section, { key: i + temp, form: props.form, main: props.main, parent: model, section: conditions[i]._content, args: args })); } }); setState({ key: state.key + 1, section: sections, args: args, }); }; useEffect(() => { model.checkCondition(typeof model._default === 'function' ? model._default() : model._default); }, []); return (React.createElement(React.Fragment, null, React.createElement(Row, null, React.createElement(Col, { key: state.key, span: 24 }, (_b = state.section) !== null && _b !== void 0 ? _b : null)))); }; export default Conditions; //# sourceMappingURL=Conditions.js.map