index.tsx
4.26 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React, { useState } from 'react';
import { Progress, Tooltip } from 'antd';
import './index.less';
import { EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons';
interface QxProgressProps {
/**
* @description 值
*/
value: number;
/**
* @description 进度条类型
* @default "circle"
*/
type?: 'bar' | 'circle';
/**
* @description 环状进度条规格
* @default "small"
*/
size?: 'small' | 'middle' | 'default' | string | undefined;
/**
* @description 是否开启隐私保护
* @default "false"
*/
privacy?: boolean;
/**
* @description 自定义显示的内容
*/
formatValue?: string | number;
/**
* @description 是否需要控制隐私保护的按钮
* @default "false"
*/
controlPrivacy?: boolean;
/**
* @description 位置
* @default "left"
*/
align?: string;
}
export const QxProgress: React.FC<QxProgressProps> = (props) => {
const { value, type, size, privacy, formatValue, controlPrivacy, align } = props;
const [privacyLocal, setPrivacyLocal] = useState<boolean>(privacy);
return (
<>
{value || typeof value === 'number' ? (
<>
{type === 'bar' ? (
<div
className={`qx-progress__horizontal ${
controlPrivacy && privacy ? 'qx-progress__horizontal--look' : ''
}`}
style={{ justifyContent: align || 'left' }}
>
<Progress
percent={
(!controlPrivacy && privacy) || (controlPrivacy && privacyLocal) ? 0 : value
}
format={() => (
<Tooltip
overlayClassName={'qx-ph-tooltip'}
title={
(!controlPrivacy && privacy) || (controlPrivacy && privacyLocal)
? '***%'
: formatValue || `${value}%`
}
color={'#fff'}
>
{(!controlPrivacy && privacy) || (controlPrivacy && privacyLocal)
? '***%'
: formatValue || `${value}%`}
</Tooltip>
)}
/>
{controlPrivacy && privacy ? (
<span
className={'qx-progress__look'}
onClick={() => {
setPrivacyLocal(!privacyLocal);
}}
>
{privacyLocal ? <EyeInvisibleOutlined /> : <EyeOutlined />}
</span>
) : null}
</div>
) : (
<div className={'qx-progress__annular'} style={{ justifyContent: align || 'left' }}>
<Progress
strokeWidth={10}
type="circle"
format={() => (
<Tooltip
overlayClassName={'qx-pa-tooltip'}
title={
(!controlPrivacy && privacy) || (controlPrivacy && privacyLocal)
? '***%'
: formatValue || `${value}%`
}
color={'#fff'}
>
{(!controlPrivacy && privacy) || (controlPrivacy && privacyLocal)
? '***%'
: formatValue || `${value}%`}
</Tooltip>
)}
percent={
(!controlPrivacy && privacy) || (controlPrivacy && privacyLocal) ? 0 : value
}
className={`qx-pa--main ${
size === 'default'
? 'qx-pa--default'
: size === 'middle'
? 'qx-pa--middle'
: 'qx-pa--small'
}`}
width={size === 'default' ? 40 : size === 'middle' ? 32 : 24}
/>
{controlPrivacy && privacy ? (
<span
className={'qx-progress__look'}
onClick={() => {
setPrivacyLocal(!privacyLocal);
}}
>
{privacyLocal ? <EyeInvisibleOutlined /> : <EyeOutlined />}
</span>
) : null}
</div>
)}
</>
) : null}
</>
);
};