UNPKG

react-antd-admin-panel

Version:

Easy prototyping admin panel using React and Antd

45 lines 2.25 kB
import React, { useState } from "react"; import { Input as InputAnt } from "antd"; import { Form } from 'antd'; import Section from "../Section"; const Input = (props) => { var _a, _b, _c; let model = props.model; let access = props.main.$access(model._access); let addProps = {}; const [value, setValue] = useState((_a = model._default) !== null && _a !== void 0 ? _a : ''); if (model._onPressEnter) addProps['onPressEnter'] = model._onPressEnter; if (model._suffix) addProps['suffix'] = React.createElement(Section, { main: props.main, section: model._suffix }); const onChange = (e) => { var _a; let value = e.target.value; model._data = value; model._default = value; if (model._formula) model.value(value); (_a = model._onChange) === null || _a === void 0 ? void 0 : _a.call(model, value, model._index); setValue(value); }; const onClear = () => { if (model._formula) model.value(undefined); model._data = undefined; setValue(undefined); }; model.tsxClear = () => onClear(); // Register the defaultValue to the formula. if (model._default) { model._data = model._default; if (model._formula) { model.value(model._default); } } return (React.createElement(Form.Item, { style: { marginBottom: 0, width: '100%' }, wrapperCol: { sm: 24 } }, React.createElement(InputAnt, Object.assign({ value: value, style: { width: '100%', marginBottom: 4 }, disabled: model._disabled || !access.access, placeholder: (_b = props.model._label) !== null && _b !== void 0 ? _b : '', size: (_c = props.size) !== null && _c !== void 0 ? _c : 'large', onChange: onChange, autoFocus: model._autofocus, readOnly: model._readOnly, allowClear: true }, addProps)), 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 Input; //# sourceMappingURL=Input.js.map