@easy-editor/materials-dashboard-progress 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/component.min.js +1 -2
- package/dist/index.min.js +1 -2
- package/dist/meta.min.js +1 -2
- package/easypack.config.ts +10 -0
- package/package.json +4 -8
- package/src/component.tsx +304 -262
- package/src/configure.ts +168 -265
- package/src/index.tsx +7 -7
- package/src/meta.ts +26 -28
- package/src/snippets.ts +69 -60
- package/tsconfig.json +20 -9
- package/.vite/plugins/vite-plugin-external-deps.ts +0 -224
- package/.vite/plugins/vite-plugin-material-dev.ts +0 -218
- package/dist/component.esm.js +0 -257
- package/dist/component.esm.js.map +0 -1
- package/dist/component.js +0 -265
- package/dist/component.js.map +0 -1
- package/dist/component.min.js.map +0 -1
- package/dist/index.cjs +0 -560
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.js +0 -557
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -564
- package/dist/index.js.map +0 -1
- package/dist/index.min.js.map +0 -1
- package/dist/meta.esm.js +0 -304
- package/dist/meta.esm.js.map +0 -1
- package/dist/meta.js +0 -315
- package/dist/meta.js.map +0 -1
- package/dist/meta.min.js.map +0 -1
- package/dist/src/component.d.ts +0 -36
- package/dist/src/configure.d.ts +0 -7
- package/dist/src/constants.d.ts +0 -36
- package/dist/src/index.d.ts +0 -6
- package/dist/src/meta.d.ts +0 -7
- package/dist/src/snippets.d.ts +0 -7
- package/rollup.config.js +0 -212
- package/tsconfig.build.json +0 -12
- package/tsconfig.test.json +0 -7
- package/vite.config.ts +0 -54
package/src/component.tsx
CHANGED
|
@@ -1,262 +1,304 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Progress Component
|
|
3
|
-
* 进度组件 -
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useId, useRef, useEffect, useState,
|
|
7
|
-
import
|
|
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
|
-
const
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Progress Component
|
|
3
|
+
* 进度组件 - 支持数据源绑定和事件交互
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useId, useRef, useEffect, useState, useMemo, type CSSProperties } from 'react'
|
|
7
|
+
import { type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
|
|
8
|
+
import styles from './component.module.css'
|
|
9
|
+
|
|
10
|
+
export interface ProgressProps extends MaterialComponet {
|
|
11
|
+
/** 最大值 */
|
|
12
|
+
maxValue?: number
|
|
13
|
+
/** 进度条类型 */
|
|
14
|
+
type?: 'ring' | 'bar'
|
|
15
|
+
/** 是否显示数值 */
|
|
16
|
+
showValue?: boolean
|
|
17
|
+
/** 是否显示标签 */
|
|
18
|
+
showLabel?: boolean
|
|
19
|
+
/** 标签文本 */
|
|
20
|
+
label?: string
|
|
21
|
+
/** 数值格式 */
|
|
22
|
+
valueFormat?: 'percent' | 'number'
|
|
23
|
+
/** 线条宽度比例(相对于尺寸的百分比) */
|
|
24
|
+
strokeWidthRatio?: number
|
|
25
|
+
/** 轨道颜色 */
|
|
26
|
+
trackColor?: string
|
|
27
|
+
/** 进度颜色 */
|
|
28
|
+
progressColor?: string
|
|
29
|
+
/** 是否启用渐变 */
|
|
30
|
+
gradientEnable?: boolean
|
|
31
|
+
/** 渐变颜色 [起始色, 结束色] */
|
|
32
|
+
gradientColors?: [string, string]
|
|
33
|
+
/** 点击事件 */
|
|
34
|
+
onClick?: (e: React.MouseEvent) => void
|
|
35
|
+
/** 双击事件 */
|
|
36
|
+
onDoubleClick?: (e: React.MouseEvent) => void
|
|
37
|
+
/** 鼠标进入 */
|
|
38
|
+
onMouseEnter?: (e: React.MouseEvent) => void
|
|
39
|
+
/** 鼠标离开 */
|
|
40
|
+
onMouseLeave?: (e: React.MouseEvent) => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 格式化数值
|
|
44
|
+
const formatValue = (value: number, percentage: number, valueFormat: string): string => {
|
|
45
|
+
if (valueFormat === 'percent') {
|
|
46
|
+
return `${Math.round(percentage)}%`
|
|
47
|
+
}
|
|
48
|
+
return `${value}`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 环形进度条组件
|
|
52
|
+
const RingProgress = ({
|
|
53
|
+
percentage,
|
|
54
|
+
strokeWidthRatio,
|
|
55
|
+
trackColor,
|
|
56
|
+
progressColor,
|
|
57
|
+
gradientEnable,
|
|
58
|
+
gradientColors,
|
|
59
|
+
showValue,
|
|
60
|
+
showLabel,
|
|
61
|
+
label,
|
|
62
|
+
valueFormat,
|
|
63
|
+
displayColor,
|
|
64
|
+
gradientId,
|
|
65
|
+
}: {
|
|
66
|
+
percentage: number
|
|
67
|
+
strokeWidthRatio: number
|
|
68
|
+
trackColor: string
|
|
69
|
+
progressColor: string
|
|
70
|
+
gradientEnable: boolean
|
|
71
|
+
gradientColors: [string, string]
|
|
72
|
+
showValue: boolean
|
|
73
|
+
showLabel: boolean
|
|
74
|
+
label: string
|
|
75
|
+
valueFormat: string
|
|
76
|
+
displayColor: string
|
|
77
|
+
gradientId: string
|
|
78
|
+
}) => {
|
|
79
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
80
|
+
const [size, setSize] = useState(100)
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const container = containerRef.current
|
|
84
|
+
if (!container) {
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const updateSize = () => {
|
|
89
|
+
const { width, height } = container.getBoundingClientRect()
|
|
90
|
+
const minSize = Math.min(width, height)
|
|
91
|
+
if (minSize > 0) {
|
|
92
|
+
setSize(minSize)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
updateSize()
|
|
97
|
+
|
|
98
|
+
const resizeObserver = new ResizeObserver(updateSize)
|
|
99
|
+
resizeObserver.observe(container)
|
|
100
|
+
|
|
101
|
+
return () => resizeObserver.disconnect()
|
|
102
|
+
}, [])
|
|
103
|
+
|
|
104
|
+
const strokeWidth = Math.max(2, size * strokeWidthRatio)
|
|
105
|
+
const radius = (size - strokeWidth) / 2
|
|
106
|
+
const circumference = 2 * Math.PI * radius
|
|
107
|
+
const strokeDashoffset = circumference - (percentage / 100) * circumference
|
|
108
|
+
const center = size / 2
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div className={styles.container} ref={containerRef}>
|
|
112
|
+
<svg aria-label='Progress ring' className={styles.ring} height={size} role='img' width={size}>
|
|
113
|
+
<title>Progress indicator</title>
|
|
114
|
+
{gradientEnable ? (
|
|
115
|
+
<defs>
|
|
116
|
+
<linearGradient id={gradientId} x1='0%' x2='100%' y1='0%' y2='0%'>
|
|
117
|
+
<stop offset='0%' stopColor={gradientColors[0]} />
|
|
118
|
+
<stop offset='100%' stopColor={gradientColors[1]} />
|
|
119
|
+
</linearGradient>
|
|
120
|
+
</defs>
|
|
121
|
+
) : null}
|
|
122
|
+
{/* 轨道 */}
|
|
123
|
+
<circle cx={center} cy={center} fill='none' r={radius} stroke={trackColor} strokeWidth={strokeWidth} />
|
|
124
|
+
{/* 进度 */}
|
|
125
|
+
<circle
|
|
126
|
+
cx={center}
|
|
127
|
+
cy={center}
|
|
128
|
+
fill='none'
|
|
129
|
+
r={radius}
|
|
130
|
+
stroke={gradientEnable ? `url(#${gradientId})` : progressColor}
|
|
131
|
+
strokeDasharray={circumference}
|
|
132
|
+
strokeDashoffset={strokeDashoffset}
|
|
133
|
+
strokeLinecap='round'
|
|
134
|
+
strokeWidth={strokeWidth}
|
|
135
|
+
style={{
|
|
136
|
+
transition: 'stroke-dashoffset 0.5s ease',
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
</svg>
|
|
140
|
+
<div className={styles.centerContent}>
|
|
141
|
+
{showValue ? (
|
|
142
|
+
<span className={styles.value} style={{ fontSize: size * 0.2, color: displayColor }}>
|
|
143
|
+
{formatValue(Math.round(percentage), percentage, valueFormat)}
|
|
144
|
+
</span>
|
|
145
|
+
) : null}
|
|
146
|
+
{showLabel && label ? (
|
|
147
|
+
<span className={styles.label} style={{ fontSize: size * 0.1 }}>
|
|
148
|
+
{label}
|
|
149
|
+
</span>
|
|
150
|
+
) : null}
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 线性进度条组件
|
|
157
|
+
const BarProgress = ({
|
|
158
|
+
percentage,
|
|
159
|
+
trackColor,
|
|
160
|
+
progressColor,
|
|
161
|
+
gradientEnable,
|
|
162
|
+
gradientColors,
|
|
163
|
+
showValue,
|
|
164
|
+
showLabel,
|
|
165
|
+
label,
|
|
166
|
+
valueFormat,
|
|
167
|
+
displayColor,
|
|
168
|
+
}: {
|
|
169
|
+
percentage: number
|
|
170
|
+
trackColor: string
|
|
171
|
+
progressColor: string
|
|
172
|
+
gradientEnable: boolean
|
|
173
|
+
gradientColors: [string, string]
|
|
174
|
+
showValue: boolean
|
|
175
|
+
showLabel: boolean
|
|
176
|
+
label: string
|
|
177
|
+
valueFormat: string
|
|
178
|
+
displayColor: string
|
|
179
|
+
}) => (
|
|
180
|
+
<div className={styles.barContainer}>
|
|
181
|
+
{showLabel || showValue ? (
|
|
182
|
+
<div className={styles.barLabels}>
|
|
183
|
+
{showLabel ? <span className={styles.barLabel}>{label}</span> : null}
|
|
184
|
+
{showValue ? (
|
|
185
|
+
<span className={styles.barValue} style={{ color: displayColor }}>
|
|
186
|
+
{formatValue(Math.round(percentage), percentage, valueFormat)}
|
|
187
|
+
</span>
|
|
188
|
+
) : null}
|
|
189
|
+
</div>
|
|
190
|
+
) : null}
|
|
191
|
+
<div className={styles.barWrapper} style={{ background: trackColor }}>
|
|
192
|
+
<div
|
|
193
|
+
className={styles.barFill}
|
|
194
|
+
style={{
|
|
195
|
+
width: `${percentage}%`,
|
|
196
|
+
background: gradientEnable
|
|
197
|
+
? `linear-gradient(90deg, ${gradientColors[0]}, ${gradientColors[1]})`
|
|
198
|
+
: progressColor,
|
|
199
|
+
}}
|
|
200
|
+
/>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
export const Progress: React.FC<ProgressProps> = ({
|
|
206
|
+
ref,
|
|
207
|
+
$data,
|
|
208
|
+
__dataSource,
|
|
209
|
+
rotation = 0,
|
|
210
|
+
opacity = 100,
|
|
211
|
+
background = 'transparent',
|
|
212
|
+
style: externalStyle,
|
|
213
|
+
maxValue = 100,
|
|
214
|
+
type = 'ring',
|
|
215
|
+
showValue = true,
|
|
216
|
+
showLabel = false,
|
|
217
|
+
label = '',
|
|
218
|
+
valueFormat = 'percent',
|
|
219
|
+
strokeWidthRatio = 0.07,
|
|
220
|
+
trackColor = 'rgba(26, 26, 62, 0.8)',
|
|
221
|
+
progressColor = '#00d4ff',
|
|
222
|
+
gradientEnable = false,
|
|
223
|
+
gradientColors = ['#00d4ff', '#9b59b6'],
|
|
224
|
+
onClick,
|
|
225
|
+
onDoubleClick,
|
|
226
|
+
onMouseEnter,
|
|
227
|
+
onMouseLeave,
|
|
228
|
+
}) => {
|
|
229
|
+
const gradientId = useId()
|
|
230
|
+
|
|
231
|
+
// 解析数据源
|
|
232
|
+
const dataSource = useDataSource($data, __dataSource)
|
|
233
|
+
const value = useMemo<number>(() => {
|
|
234
|
+
if (dataSource.length > 0 && typeof dataSource[0]?.value === 'number') {
|
|
235
|
+
return dataSource[0].value
|
|
236
|
+
}
|
|
237
|
+
return 0
|
|
238
|
+
}, [dataSource])
|
|
239
|
+
|
|
240
|
+
const normalizedValue = Math.min(Math.max(value, 0), maxValue)
|
|
241
|
+
const percentage = (normalizedValue / maxValue) * 100
|
|
242
|
+
const displayColor = gradientEnable ? gradientColors[0] : progressColor
|
|
243
|
+
|
|
244
|
+
const wrapperStyle: CSSProperties = {
|
|
245
|
+
transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
|
|
246
|
+
opacity: opacity / 100,
|
|
247
|
+
backgroundColor: background,
|
|
248
|
+
...externalStyle,
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (type === 'ring') {
|
|
252
|
+
return (
|
|
253
|
+
<div
|
|
254
|
+
className={styles.wrapper}
|
|
255
|
+
onClick={onClick}
|
|
256
|
+
onDoubleClick={onDoubleClick}
|
|
257
|
+
onMouseEnter={onMouseEnter}
|
|
258
|
+
onMouseLeave={onMouseLeave}
|
|
259
|
+
ref={ref}
|
|
260
|
+
style={wrapperStyle}
|
|
261
|
+
>
|
|
262
|
+
<RingProgress
|
|
263
|
+
displayColor={displayColor}
|
|
264
|
+
gradientColors={gradientColors}
|
|
265
|
+
gradientEnable={gradientEnable}
|
|
266
|
+
gradientId={gradientId}
|
|
267
|
+
label={label}
|
|
268
|
+
percentage={percentage}
|
|
269
|
+
progressColor={progressColor}
|
|
270
|
+
showLabel={showLabel}
|
|
271
|
+
showValue={showValue}
|
|
272
|
+
strokeWidthRatio={strokeWidthRatio}
|
|
273
|
+
trackColor={trackColor}
|
|
274
|
+
valueFormat={valueFormat}
|
|
275
|
+
/>
|
|
276
|
+
</div>
|
|
277
|
+
)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div
|
|
282
|
+
className={styles.wrapper}
|
|
283
|
+
onClick={onClick}
|
|
284
|
+
onDoubleClick={onDoubleClick}
|
|
285
|
+
onMouseEnter={onMouseEnter}
|
|
286
|
+
onMouseLeave={onMouseLeave}
|
|
287
|
+
ref={ref}
|
|
288
|
+
style={wrapperStyle}
|
|
289
|
+
>
|
|
290
|
+
<BarProgress
|
|
291
|
+
displayColor={displayColor}
|
|
292
|
+
gradientColors={gradientColors}
|
|
293
|
+
gradientEnable={gradientEnable}
|
|
294
|
+
label={label}
|
|
295
|
+
percentage={percentage}
|
|
296
|
+
progressColor={progressColor}
|
|
297
|
+
showLabel={showLabel}
|
|
298
|
+
showValue={showValue}
|
|
299
|
+
trackColor={trackColor}
|
|
300
|
+
valueFormat={valueFormat}
|
|
301
|
+
/>
|
|
302
|
+
</div>
|
|
303
|
+
)
|
|
304
|
+
}
|