UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

70 lines (58 loc) 2.46 kB
import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import React, { createElement, memo, useContext } from 'react'; import classNames from 'classnames'; import { cloneElement } from '../_util/reactNode'; import SingleNumber from './SingleNumber'; import ConfigContext from '../config-provider/ConfigContext'; var ScrollNumber = function ScrollNumber(_ref) { var customizePrefixCls = _ref.prefixCls, count = _ref.count, className = _ref.className, motionClassName = _ref.motionClassName, style = _ref.style, title = _ref.title, show = _ref.show, _ref$component = _ref.component, component = _ref$component === void 0 ? 'sup' : _ref$component, children = _ref.children, restProps = _objectWithoutProperties(_ref, ["prefixCls", "count", "className", "motionClassName", "style", "title", "show", "component", "children"]); var _useContext = useContext(ConfigContext), getPrefixCls = _useContext.getPrefixCls; var prefixCls = getPrefixCls('scroll-number', customizePrefixCls); // ============================ Render ============================ var newProps = _objectSpread({}, restProps, { 'data-show': show, style: style, className: classNames(prefixCls, className, motionClassName), title: title }); // Only integer need motion var numberNodes = count; if (count && Number(count) % 1 === 0) { var numberList = String(count).split(''); numberNodes = numberList.map(function (num, i) { return React.createElement(SingleNumber, { prefixCls: prefixCls, count: Number(count), value: num, // eslint-disable-next-line react/no-array-index-key key: numberList.length - i }); }); } if (style && style.borderColor) { newProps.style = _objectSpread({}, style, { boxShadow: "0 0 0 1px ".concat(style.borderColor, " inset") }); } if (children) { return cloneElement(children, function (oriProps) { return { className: classNames("".concat(prefixCls, "-custom-component"), oriProps === null || oriProps === void 0 ? void 0 : oriProps.className, motionClassName) }; }); } return createElement(component, newProps, numberNodes); }; ScrollNumber.displayName = 'ScrollNumber'; export default memo(ScrollNumber); //# sourceMappingURL=ScrollNumber.js.map