UNPKG

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