mobile-more
Version:
基于 antd-mobile v5 扩展移动端 UI 组件
45 lines • 1.9 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["placeholder", "separator", "options", "value", "fieldNames", "renderCurrentValue"];
import { Input } from 'antd-mobile';
import * as React from 'react';
import BizCheckListPopup from '../../BizCheckListPopup';
var SuperCheckList = function SuperCheckList(_ref) {
var placeholder = _ref.placeholder,
_ref$separator = _ref.separator,
separator = _ref$separator === void 0 ? ', ' : _ref$separator,
_ref$options = _ref.options,
options = _ref$options === void 0 ? [] : _ref$options,
value = _ref.value,
fieldNames = _ref.fieldNames,
renderCurrentValue = _ref.renderCurrentValue,
restProps = _objectWithoutProperties(_ref, _excluded);
var _React$useMemo = React.useMemo(function () {
return _objectSpread({
label: 'label',
value: 'value'
}, fieldNames);
}, [fieldNames]),
labelKey = _React$useMemo.label,
valueKey = _React$useMemo.value;
var items = React.useMemo(function () {
return options.filter(function (item) {
return value === null || value === void 0 ? void 0 : value.includes(item[valueKey]);
});
}, [options, value, valueKey]);
var valueStr = typeof renderCurrentValue === 'function' ? renderCurrentValue(value, items) : items.filter(function (item) {
return !!item;
}).map(function (item) {
return item[labelKey];
}).join(separator);
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Input, {
readOnly: true,
value: valueStr,
placeholder: placeholder
}), /*#__PURE__*/React.createElement(BizCheckListPopup, _objectSpread({
value: value,
options: options,
fieldNames: fieldNames
}, restProps)));
};
export default SuperCheckList;