UNPKG

@nutui/nutui-react

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

51 lines (50 loc) 2.18 kB
import { _ as _object_spread } from "@swc/helpers/_/_object_spread"; import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props"; import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties"; import React from "react"; import classNames from "classnames"; import { Loading as IconLoading, Loading1 as IconLoading1 } from "@nutui/icons-react"; import { ComponentDefaults } from "../../utils/typings"; // 方便以后扩展设置为键值对形式 var loadingMap = { circular: IconLoading1, spinner: IconLoading }; var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), { // 对比一下,个人感觉还是Loading1比较好看一些,所以用它作为了默认的loading图标 type: 'circular', direction: 'horizontal', lottieProps: {} }); var defaultLottieProps = { loop: true, autoplay: true }; export var Loading = /*#__PURE__*/ React.forwardRef(function(props, ref) { var _ref = _object_spread({}, defaultProps, props), className = _ref.className, style = _ref.style, children = _ref.children, direction = _ref.direction, icon = _ref.icon, rest = _object_without_properties(_ref, [ "className", "style", "children", "direction", "icon" ]); var classPrefix = 'nut-loading'; var getLoadingIcon = function() { var LoadingIcon = loadingMap[rest.type] || IconLoading1; return /*#__PURE__*/ React.createElement(LoadingIcon, { className: "".concat(classPrefix, "-icon") }); }; var iconboxClassName = function() { return !icon ? "".concat(classPrefix, "-icon-box") : ''; }; return /*#__PURE__*/ React.createElement("div", { className: classNames(classPrefix, direction === 'vertical' ? "".concat(classPrefix, "-vertical") : '', className), style: style }, /*#__PURE__*/ React.createElement("div", { className: iconboxClassName() }, icon || getLoadingIcon()), children ? /*#__PURE__*/ React.createElement("div", { className: "".concat(classPrefix, "-text") }, children) : null); }); Loading.displayName = 'NutLoading';