UNPKG

@alifd/meet-react

Version:

Fusion Mobile React UI System Component

55 lines 3.26 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import React, { createElement, useRef, useContext } from "react"; import classNames from 'classnames'; import { ItemContext } from '../../form'; import TagSelect from '../../tag-select'; import View from '../../view'; import Tag from '../../tag'; import { guid } from '../../utils/hooks'; var SelectValue = function SelectValue(props) { var items = props.items, prefix = props.prefix, displayType = props.displayType, sizeProp = props.size, disabled = props.disabled, type = props.type; var _useContext = useContext(ItemContext), isInsideForm = _useContext.isInsideForm, labelAlign = _useContext.labelAlign, contextSize = _useContext.size; var inlineMode = displayType === 'tag' && isInsideForm && labelAlign === 'inset'; var clsPrefix = "".concat(prefix, "select"); var isInverse = type === 'inverse'; var size = sizeProp || (isInsideForm ? contextSize : 'medium'); var ref = useRef(guid('select-val-')); switch (displayType) { case 'tag': return /*#__PURE__*/React.createElement(TagSelect, { disabled: disabled, isPreview: true, inlineMode: inlineMode, prefix: prefix, size: size, dataSource: items }); case 'tag-value': return /*#__PURE__*/React.createElement(View, { className: classNames("".concat(clsPrefix, "-tag-value"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(clsPrefix, "-value--inverse"), isInverse), "".concat(clsPrefix, "-value--disabled"), disabled), "".concat(clsPrefix, "-value--inverse-disabled"), disabled && isInverse)) }, items.map(function (val) { return /*#__PURE__*/React.createElement(Tag, { key: "".concat(ref.current, "-").concat(val), className: "".concat(clsPrefix, "-tag-item"), type: "primary", size: size }, "".concat(val)); })); default: return /*#__PURE__*/React.createElement(View, { className: classNames(_defineProperty(_defineProperty(_defineProperty({}, "".concat(clsPrefix, "-value--inverse"), isInverse), "".concat(clsPrefix, "-value--disabled"), disabled), "".concat(clsPrefix, "-value--inverse-disabled"), disabled && isInverse)) }, items.join(',')); } }; export default SelectValue;