mobile-more
Version:
基于 antd-mobile v5 扩展移动端 UI 组件
93 lines • 3.63 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["placeholder", "title", "loading", "options", "fieldNames", "checkListProps", "searchBarProps", "emptyProps", "checkListPopupProps", "renderCurrentValue", "multiple", "radioMode", "separator", "showSearch", "actionRef", "readOnly", "disabled", "onClick", "required"];
import React from 'react';
import { isArray, isUndefined } from 'ut2';
import BizFormItem from "../FormItem";
import SuperCheckList from "./SuperCheckList";
import { useConfig } from "../../BizConfigProvider";
import getDefaultPopupTitle from "../utils/getDefaultPopupTitle";
var BizFormItemCheckList = function BizFormItemCheckList(props) {
var _useConfig = useConfig(),
locale = _useConfig.locale;
var _props$placeholder = props.placeholder,
placeholder = _props$placeholder === void 0 ? locale.form.common.selectPlaceholder : _props$placeholder,
_props$title = props.title,
title = _props$title === void 0 ? getDefaultPopupTitle(props, locale) : _props$title,
loading = props.loading,
options = props.options,
fieldNames = props.fieldNames,
checkListProps = props.checkListProps,
searchBarProps = props.searchBarProps,
emptyProps = props.emptyProps,
checkListPopupProps = props.checkListPopupProps,
renderCurrentValue = props.renderCurrentValue,
multiple = props.multiple,
radioMode = props.radioMode,
separator = props.separator,
showSearch = props.showSearch,
actionRef = props.actionRef,
readOnly = props.readOnly,
disabled = props.disabled,
onClick = props.onClick,
required = props.required,
restProps = _objectWithoutProperties(props, _excluded);
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
visible = _React$useState2[0],
setVisible = _React$useState2[1];
var handleClick = React.useCallback(function (e, widgetRef) {
if (!disabled && !readOnly) {
setVisible(true);
}
onClick === null || onClick === void 0 || onClick(e, widgetRef);
}, [disabled, onClick, readOnly]);
React.useImperativeHandle(actionRef, function () {
return {
hidePopup: function hidePopup() {
setVisible(false);
},
showPopup: function showPopup() {
setVisible(true);
},
togglePopup: function togglePopup() {
setVisible(function (v) {
return !v;
});
}
};
});
return /*#__PURE__*/React.createElement(BizFormItem, _extends({
onClick: handleClick,
disabled: disabled,
required: required,
rules: [{
validator: function validator(rule, value) {
if (required) {
if (isUndefined(value) || isArray(value) && value.length <= 0) {
return Promise.reject(locale.form.common.selectRequired);
}
}
return Promise.resolve();
}
}]
}, restProps), /*#__PURE__*/React.createElement(SuperCheckList, _extends({
title: title,
visible: visible,
onVisibleChange: setVisible,
loading: loading,
options: options,
fieldNames: fieldNames,
renderCurrentValue: renderCurrentValue,
checkListProps: checkListProps,
searchBarProps: searchBarProps,
emptyProps: emptyProps,
placeholder: placeholder,
multiple: multiple,
radioMode: radioMode,
separator: separator,
showSearch: showSearch
}, checkListPopupProps)));
};
export default BizFormItemCheckList;