UNPKG

@sishuguojixuefu/react-native-form

Version:
58 lines 2.53 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const antd_mobile_rn_1 = require("@sishuguojixuefu/antd-mobile-rn"); const ErrorTip_1 = __importDefault(require("./helper/ErrorTip")); const Label_1 = __importDefault(require("./helper/Label")); const getFieldDecorator_1 = __importDefault(require("../utils/getFieldDecorator")); const { Item } = antd_mobile_rn_1.List; class SsSelect extends react_1.Component { constructor() { super(...arguments); this._onChange = (value) => { const { onChange } = this.props; onChange && onChange(value); }; this._getData = () => { const { options, cols } = this.props; if (cols === 1) { return options.map((item) => { return { label: item.label || item, value: item.value || item, }; }); } return options; }; } componentWillMount() { const { form, id, initialValue, rules } = this.props; this.fieldDecorator = getFieldDecorator_1.default(form, id, initialValue && [initialValue], rules); } render() { const { icon, placeholder, label, required, form, id, cols, last } = this.props; return (react_1.default.createElement(ErrorTip_1.default, { error: form.getFieldError(id), last: last }, this.fieldDecorator( // @ts-ignore react_1.default.createElement(antd_mobile_rn_1.Picker, Object.assign({}, this.props, { cols: cols, onChange: this._onChange, extra: placeholder, data: this._getData() }), react_1.default.createElement(Item, { arrow: "horizontal", style: { paddingLeft: 0 }, last: true, wrap: true }, react_1.default.createElement(Label_1.default, { required: required, label: label, icon: icon })))))); } } exports.default = SsSelect; SsSelect.defaultProps = { required: false, placeholder: '请输入', cols: 1, }; //# sourceMappingURL=SsSelect.js.map