UNPKG

linkmore-design

Version:

🌈 🚀lm组件库。🚀

77 lines 4.37 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["className", "prefixCls", "image", "description", "title", "children", "imageStyle"]; import classNames from 'classnames'; import React, { useMemo } from 'react'; import { ConfigContext } from "../config-provider"; import LocaleReceiver from "../locale-provider/LocaleReceiver"; import DefaultEmptyImg from "./empty"; import defaultLocale from "../locale/zh_CN"; import SimpleEmptyImg from "./simple"; var defaultEmptyImg = /*#__PURE__*/React.createElement(DefaultEmptyImg, null); var simpleEmptyImg = /*#__PURE__*/React.createElement(SimpleEmptyImg, null); var Empty = function Empty(_ref) { var _locale$Empty, _locale$Empty2, _locale$Empty3, _locale$Empty4, _locale$Empty5; var className = _ref.className, customizePrefixCls = _ref.prefixCls, _ref$image = _ref.image, image = _ref$image === void 0 ? defaultEmptyImg : _ref$image, description = _ref.description, title = _ref.title, children = _ref.children, imageStyle = _ref.imageStyle, restProps = _objectWithoutProperties(_ref, _excluded); var _React$useContext = React.useContext(ConfigContext), getPrefixCls = _React$useContext.getPrefixCls, direction = _React$useContext.direction, _React$useContext$loc = _React$useContext.locale, locale = _React$useContext$loc === void 0 ? defaultLocale : _React$useContext$loc; var isCustomEmpty = useMemo(function () { if (typeof image === 'string' && ['notfound', 'nopermissions', 'loaderror', 'networkerror', 'nodata'].includes(image)) { return true; } return false; }, [image]); var TitleMap = { notfound: ((_locale$Empty = locale.Empty) === null || _locale$Empty === void 0 ? void 0 : _locale$Empty.networkerror) || '抱歉,系统服务发生异常,请稍后再试', nopermissions: ((_locale$Empty2 = locale.Empty) === null || _locale$Empty2 === void 0 ? void 0 : _locale$Empty2.networkerror) || '抱歉,系统服务发生异常,请稍后再试', loaderror: ((_locale$Empty3 = locale.Empty) === null || _locale$Empty3 === void 0 ? void 0 : _locale$Empty3.networkerror) || '抱歉,系统服务发生异常,请稍后再试', networkerror: ((_locale$Empty4 = locale.Empty) === null || _locale$Empty4 === void 0 ? void 0 : _locale$Empty4.networkerror) || '抱歉,系统服务发生异常,请稍后再试', nodata: ((_locale$Empty5 = locale.Empty) === null || _locale$Empty5 === void 0 ? void 0 : _locale$Empty5.description) || '暂无数据' }; return /*#__PURE__*/React.createElement(LocaleReceiver, { componentName: "Empty" }, function (contextLocale) { var _classNames; var prefixCls = getPrefixCls('empty', customizePrefixCls); var des = typeof description !== 'undefined' ? description : contextLocale.description; var alt = typeof des === 'string' ? des : 'empty'; var imageNode = null; if (isCustomEmpty) { imageNode = /*#__PURE__*/React.createElement("div", { className: classNames('lm_custom_empty_img', "".concat(image)) }); } else if (typeof image === 'string') { imageNode = /*#__PURE__*/React.createElement("img", { alt: alt, src: image }); } else { imageNode = image; } return /*#__PURE__*/React.createElement("div", _extends({ className: classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-normal"), image === simpleEmptyImg), _defineProperty(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _classNames), className, 'lm_empty') }, restProps), /*#__PURE__*/React.createElement("div", { className: classNames("".concat(prefixCls, "-image"), isCustomEmpty && 'lm_custom_empty'), style: imageStyle }, imageNode), (title || isCustomEmpty) && /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-title") }, title || TitleMap["".concat(image)]), children && /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-footer") }, children)); }); }; Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg; Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg; export default Empty;