UNPKG

2.85 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2var __rest = this && this.__rest || function (s, e) {
3 var t = {};
4 for (var p in s) {
5 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6 }
7 if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
9 }
10 return t;
11};
12import classNames from 'classnames';
13import * as React from 'react';
14import { ConfigContext } from '../config-provider';
15import { cloneElement } from '../_util/reactNode';
16import SingleNumber from './SingleNumber';
17var ScrollNumber = function ScrollNumber(_a) {
18 var customizePrefixCls = _a.prefixCls,
19 count = _a.count,
20 className = _a.className,
21 motionClassName = _a.motionClassName,
22 style = _a.style,
23 title = _a.title,
24 show = _a.show,
25 _a$component = _a.component,
26 component = _a$component === void 0 ? 'sup' : _a$component,
27 children = _a.children,
28 restProps = __rest(_a, ["prefixCls", "count", "className", "motionClassName", "style", "title", "show", "component", "children"]);
29 var _React$useContext = React.useContext(ConfigContext),
30 getPrefixCls = _React$useContext.getPrefixCls;
31 var prefixCls = getPrefixCls('scroll-number', customizePrefixCls);
32 // ============================ Render ============================
33 var newProps = _extends(_extends({}, restProps), {
34 'data-show': show,
35 style: style,
36 className: classNames(prefixCls, className, motionClassName),
37 title: title
38 });
39 // Only integer need motion
40 var numberNodes = count;
41 if (count && Number(count) % 1 === 0) {
42 var numberList = String(count).split('');
43 numberNodes = numberList.map(function (num, i) {
44 return /*#__PURE__*/React.createElement(SingleNumber, {
45 prefixCls: prefixCls,
46 count: Number(count),
47 value: num,
48 // eslint-disable-next-line react/no-array-index-key
49 key: numberList.length - i
50 });
51 });
52 }
53 // allow specify the border
54 // mock border-color by box-shadow for compatible with old usage:
55 // <Badge count={4} style={{ backgroundColor: '#fff', color: '#999', borderColor: '#d9d9d9' }} />
56 if (style && style.borderColor) {
57 newProps.style = _extends(_extends({}, style), {
58 boxShadow: "0 0 0 1px " + style.borderColor + " inset"
59 });
60 }
61 if (children) {
62 return cloneElement(children, function (oriProps) {
63 return {
64 className: classNames(prefixCls + "-custom-component", oriProps === null || oriProps === void 0 ? void 0 : oriProps.className, motionClassName)
65 };
66 });
67 }
68 return /*#__PURE__*/React.createElement(component, newProps, numberNodes);
69};
70export default ScrollNumber;
\No newline at end of file