-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathScrollNumber.tsx
85 lines (77 loc) · 2.57 KB
/
ScrollNumber.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import classNames from '../_util/classNames';
import PropTypes from '../_util/vue-types';
import { cloneElement } from '../_util/vnode';
import type { ExtractPropTypes, CSSProperties, DefineComponent, HTMLAttributes } from 'vue';
import { defineComponent } from 'vue';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import SingleNumber from './SingleNumber';
import { filterEmpty } from '../_util/props-util';
const scrollNumberProps = {
prefixCls: String,
count: PropTypes.any,
component: String,
title: PropTypes.any,
show: Boolean,
};
export type ScrollNumberProps = Partial<ExtractPropTypes<typeof scrollNumberProps>>;
export default defineComponent({
name: 'ScrollNumber',
inheritAttrs: false,
props: scrollNumberProps,
setup(props, { attrs, slots }) {
const { prefixCls } = useConfigInject('scroll-number', props);
return () => {
const {
prefixCls: customizePrefixCls,
count,
title,
show,
component: Tag = 'sup' as unknown as DefineComponent,
class: className,
style,
...restProps
} = { ...props, ...attrs } as ScrollNumberProps & HTMLAttributes & { style: CSSProperties };
// ============================ Render ============================
const newProps = {
...restProps,
style,
'data-show': props.show,
class: classNames(prefixCls.value, className),
title: title as string,
};
// Only integer need motion
let numberNodes: any = count;
if (count && Number(count) % 1 === 0) {
const numberList = String(count).split('');
numberNodes = numberList.map((num, i) => (
<SingleNumber
prefixCls={prefixCls.value}
count={Number(count)}
value={num}
key={numberList.length - i}
/>
));
}
// allow specify the border
// mock border-color by box-shadow for compatible with old usage:
// <Badge count={4} style={{ backgroundColor: '#fff', color: '#999', borderColor: '#d9d9d9' }} />
if (style && style.borderColor) {
newProps.style = {
...(style as CSSProperties),
boxShadow: `0 0 0 1px ${style.borderColor} inset`,
};
}
const children = filterEmpty(slots.default?.());
if (children && children.length) {
return cloneElement(
children,
{
class: classNames(`${prefixCls.value}-custom-component`),
},
false,
);
}
return <Tag {...newProps}>{numberNodes}</Tag>;
};
},
});