UNPKG

loners-form

Version:

为工作而生,基于 antd 而生的可配置化表单

92 lines (79 loc) 5.6 kB
import "antd/es/tooltip/style"; import _Tooltip from "antd/es/tooltip"; import "antd/es/select/style"; import _Select from "antd/es/select"; var _excluded = ["mode", "showQA", "fixedWidth", "tooltip", "style", "valueEnum", "options", "allowClear", "placeholder"]; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import cx from 'classnames'; import QA from '../QA'; import Multi from './Multi'; import { WIDTH_SIZE_ENUM } from '../constants'; import { fromValueEnum } from './utils'; import { FORM_ITEM_CLASS_NAME } from '../constants'; import '../index.less'; var Option = _Select.Option; var SelectGo = function SelectGo(props) { var mode = props.mode, showQA = props.showQA, _props$fixedWidth = props.fixedWidth, fixedWidth = _props$fixedWidth === void 0 ? false : _props$fixedWidth, _props$tooltip = props.tooltip, tooltip = _props$tooltip === void 0 ? false : _props$tooltip, style = props.style, valueEnum = props.valueEnum, options = props.options, _props$allowClear = props.allowClear, allowClear = _props$allowClear === void 0 ? true : _props$allowClear, _props$placeholder = props.placeholder, placeholder = _props$placeholder === void 0 ? '请选择' : _props$placeholder, rawProps = _objectWithoutProperties(props, _excluded); var ownStyle = fixedWidth ? { width: WIDTH_SIZE_ENUM.s } : style; var opts = valueEnum ? fromValueEnum(valueEnum) : options; var ownProps = _objectSpread({ placeholder: placeholder, allowClear: allowClear, optionFilterProp: 'label', style: ownStyle }, rawProps); var competent = tooltip ? /*#__PURE__*/React.createElement(_Select, _extends({ mode: mode, filterOption: function filterOption(inputValue, option) { var _option$children, _option$children$prop, _option$children$prop2; return option === null || option === void 0 ? void 0 : (_option$children = option.children) === null || _option$children === void 0 ? void 0 : (_option$children$prop = _option$children.props) === null || _option$children$prop === void 0 ? void 0 : (_option$children$prop2 = _option$children$prop.title) === null || _option$children$prop2 === void 0 ? void 0 : _option$children$prop2.includes(inputValue); } }, ownProps), opts === null || opts === void 0 ? void 0 : opts.map(function (_ref) { var label = _ref.label, value = _ref.value; return /*#__PURE__*/React.createElement(Option, { key: value, value: value }, /*#__PURE__*/React.createElement(_Tooltip, _extends({ title: label, placement: "left" }, tooltip), /*#__PURE__*/React.createElement("div", { className: "text-ellipsis" }, label))); })) : /*#__PURE__*/React.createElement(_Select, _extends({ mode: mode, options: opts }, ownProps)); var formItemClassName = FORM_ITEM_CLASS_NAME; return /*#__PURE__*/React.createElement("div", { className: cx("".concat(formItemClassName, "-box"), _defineProperty({}, "".concat(formItemClassName, "-mg-r"), showQA && fixedWidth)) }, mode === 'multiple' ? /*#__PURE__*/React.createElement(Multi, _extends({ options: opts, tooltip: tooltip }, ownProps)) : competent, showQA && /*#__PURE__*/React.createElement(QA, { className: "".concat(formItemClassName, "-qa"), title: typeof showQA === 'boolean' ? '' : showQA.title })); }; export default SelectGo;