You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.6 KiB

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; }
import React from 'react';
import { DownOutlined, CloseOutlined } from '@ant-design/icons';
import classNames from 'classnames';
import './index.less';
var LightFilterLabel = function LightFilterLabel(props) {
var _classNames;
var label = props.label,
_props$prefixCls = props.prefixCls,
customizePrefixCls = _props$prefixCls === void 0 ? 'ant-pro-form' : _props$prefixCls,
onClear = props.onClear,
value = props.value,
_props$size = props.size,
size = _props$size === void 0 ? 'default' : _props$size,
disabled = props.disabled,
ellipsis = props.ellipsis,
placeholder = props.placeholder,
className = props.className,
style = props.style;
var prefixCls = "".concat(customizePrefixCls, "-light-filter-label"); // TODO 国际化
var locale = {
itemUnit: '项'
};
var getTextByValue = function getTextByValue(aLabel, aValue) {
if (aValue && (!Array.isArray(aValue) || aValue.length)) {
var str = Array.isArray(aValue) ? aValue.join(',') : aValue;
var prefix = aLabel ? "".concat(aLabel, ": ") : '';
if (!ellipsis) {
return /*#__PURE__*/React.createElement("span", null, "".concat(prefix).concat(str));
}
var tail = str.length > 16 ? "...".concat(Array.isArray(aValue) && aValue.length > 1 ? "".concat(aValue.length).concat(locale.itemUnit) : '') : '';
return /*#__PURE__*/React.createElement("span", {
title: str
}, "".concat(prefix).concat(str.substr(0, 16)).concat(tail));
}
return placeholder || aLabel;
};
return /*#__PURE__*/React.createElement("span", {
className: classNames(prefixCls, "".concat(prefixCls, "-").concat(size), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-active"), !!value), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), disabled), _classNames), className),
style: style
}, getTextByValue(label, value), value && /*#__PURE__*/React.createElement(CloseOutlined, {
className: classNames("".concat(prefixCls, "-icon"), "".concat(prefixCls, "-close")),
onClick: function onClick(e) {
if (onClear && !disabled) {
onClear();
}
e.stopPropagation();
}
}), /*#__PURE__*/React.createElement(DownOutlined, {
className: classNames("".concat(prefixCls, "-icon"), "".concat(prefixCls, "-arrow"))
}));
};
export default LightFilterLabel;