1 | "use client";
|
2 |
|
3 | var __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 | };
|
11 | import * as React from 'react';
|
12 | import classNames from 'classnames';
|
13 | import { cloneElement } from '../_util/reactNode';
|
14 | import { ConfigContext } from '../config-provider';
|
15 | import SingleNumber from './SingleNumber';
|
16 | const ScrollNumber = 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 |
|
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 |
|
41 | let numberNodes = count;
|
42 | if (count && Number(count) % 1 === 0) {
|
43 | const numberList = String(count).split('');
|
44 | numberNodes = React.createElement("bdi", null, numberList.map((num, i) => (React.createElement(SingleNumber, {
|
45 | prefixCls: prefixCls,
|
46 | count: Number(count),
|
47 | value: num,
|
48 |
|
49 | key: numberList.length - i
|
50 | }))));
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 | if (style === null || style === void 0 ? void 0 : 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 React.createElement(Component, Object.assign({}, newProps, {
|
66 | ref: ref
|
67 | }), numberNodes);
|
68 | });
|
69 | export default ScrollNumber; |
\ | No newline at end of file |