UNPKG

mobile-more

Version:

基于 antd-mobile v5 扩展移动端 UI 组件

52 lines (50 loc) 2.65 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["fieldNames", "valueEnum", "value", "type", "defaultLabel", "match", "component", "tagProps", "textProps"]; import React from 'react'; import { Tag } from 'antd-mobile'; import { omit } from 'ut2'; var BaseDictionary = function BaseDictionary(_ref) { var _ret$type; var fieldNames = _ref.fieldNames, valueEnum = _ref.valueEnum, value = _ref.value, _ref$type = _ref.type, type = _ref$type === void 0 ? 'text' : _ref$type, _ref$defaultLabel = _ref.defaultLabel, defaultLabel = _ref$defaultLabel === void 0 ? '-' : _ref$defaultLabel, match = _ref.match, component = _ref.component, tagProps = _ref.tagProps, textProps = _ref.textProps, restProps = _objectWithoutProperties(_ref, _excluded); var _label$value$props$fi = _objectSpread({ label: 'label', value: 'value', props: 'props' }, fieldNames), labelKey = _label$value$props$fi.label, valueKey = _label$value$props$fi.value, propsKey = _label$value$props$fi.props; var matchMethod = function matchMethod(itemValue, value) { return typeof match === 'function' ? match(itemValue, value) : itemValue === value; }; var ret = valueEnum.find(function (item) { return matchMethod(item[valueKey], value); }); var child = ret ? ((_ret$type = ret[type]) === null || _ret$type === void 0 ? void 0 : _ret$type.alias) || ret[labelKey] || defaultLabel : defaultLabel; if (type === 'tag') { return /*#__PURE__*/React.createElement(Tag, _extends({}, restProps, omit(ret === null || ret === void 0 ? void 0 : ret.tag, ['alias']), tagProps), child); } // html标签 if (typeof component === 'string') { return /*#__PURE__*/React.createElement(component, _objectSpread(_objectSpread({}, ret === null || ret === void 0 ? void 0 : ret[propsKey]), restProps), child); } // 自定义组件 if ( /*#__PURE__*/React.isValidElement(component)) { return /*#__PURE__*/React.cloneElement(component, _objectSpread(_objectSpread(_objectSpread({}, ret === null || ret === void 0 ? void 0 : ret[propsKey]), restProps), (component === null || component === void 0 ? void 0 : component.props) || {}), child); } return /*#__PURE__*/React.createElement("span", _extends({}, ret === null || ret === void 0 ? void 0 : ret[propsKey], restProps, omit(ret === null || ret === void 0 ? void 0 : ret.text, ['alias']), textProps), child); }; export default BaseDictionary;