UNPKG

@nutui/nutui-react-taro

Version:

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

69 lines (68 loc) 2.98 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, { useRef } from "react"; import classNames from "classnames"; import { Loading as IconLoading, Loading1 as IconLoading1 } from "@nutui/icons-react-taro"; import { View } from "@tarojs/components"; import Lottie from "../lottie/index"; import { ComponentDefaults } from "../../utils/typings"; import { mergeProps } from "../../utils/merge-props"; // 方便以后扩展设置为键值对形式 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, lottieProps = _ref.lottieProps, rest = _object_without_properties(_ref, [ "className", "style", "children", "direction", "icon", "lottieProps" ]); // @ts-ignore var loadingLottieRef = useRef(); var mergedLottieProps = mergeProps(defaultLottieProps, lottieProps); React.useImperativeHandle(ref, function() { return loadingLottieRef; }); var classPrefix = 'nut-loading'; var getLoadingIcon = function() { if (rest.type === 'lottie' && rest.jsonData) { return /*#__PURE__*/ React.createElement(Lottie, _object_spread_props(_object_spread({}, mergedLottieProps), { // @ts-ignore ref: loadingLottieRef, source: rest.jsonData })); } var LoadingIcon = loadingMap[rest.type] || IconLoading1; return /*#__PURE__*/ React.createElement(LoadingIcon, { className: "".concat(classPrefix, "-icon") }); }; var iconboxClassName = function() { if (rest.type === 'lottie') return "".concat(classPrefix, "-lottie-box"); return "".concat(classPrefix, "-icon-box"); }; return /*#__PURE__*/ React.createElement(View, { className: classNames(classPrefix, direction === 'vertical' ? "".concat(classPrefix, "-vertical") : '', className), style: style }, /*#__PURE__*/ React.createElement(View, { className: iconboxClassName() }, icon || getLoadingIcon()), children ? /*#__PURE__*/ React.createElement(View, { className: "".concat(classPrefix, "-text") }, children) : null); }); Loading.displayName = 'NutLoading';