@easy-editor/materials-dashboard-progress 0.0.2

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.
Files changed (44) hide show
  1. package/.vite/plugins/vite-plugin-external-deps.ts +224 -0
  2. package/.vite/plugins/vite-plugin-material-dev.ts +218 -0
  3. package/CHANGELOG.md +7 -0
  4. package/LICENSE +9 -0
  5. package/dist/component.esm.js +257 -0
  6. package/dist/component.esm.js.map +1 -0
  7. package/dist/component.js +265 -0
  8. package/dist/component.js.map +1 -0
  9. package/dist/component.min.js +2 -0
  10. package/dist/component.min.js.map +1 -0
  11. package/dist/index.cjs +560 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.esm.js +557 -0
  14. package/dist/index.esm.js.map +1 -0
  15. package/dist/index.js +564 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/index.min.js +2 -0
  18. package/dist/index.min.js.map +1 -0
  19. package/dist/meta.esm.js +304 -0
  20. package/dist/meta.esm.js.map +1 -0
  21. package/dist/meta.js +315 -0
  22. package/dist/meta.js.map +1 -0
  23. package/dist/meta.min.js +2 -0
  24. package/dist/meta.min.js.map +1 -0
  25. package/dist/src/component.d.ts +36 -0
  26. package/dist/src/configure.d.ts +7 -0
  27. package/dist/src/constants.d.ts +36 -0
  28. package/dist/src/index.d.ts +6 -0
  29. package/dist/src/meta.d.ts +7 -0
  30. package/dist/src/snippets.d.ts +7 -0
  31. package/package.json +66 -0
  32. package/rollup.config.js +212 -0
  33. package/src/component.module.css +89 -0
  34. package/src/component.tsx +262 -0
  35. package/src/configure.ts +265 -0
  36. package/src/constants.ts +43 -0
  37. package/src/index.tsx +7 -0
  38. package/src/meta.ts +28 -0
  39. package/src/snippets.ts +60 -0
  40. package/src/type.d.ts +8 -0
  41. package/tsconfig.build.json +12 -0
  42. package/tsconfig.json +9 -0
  43. package/tsconfig.test.json +7 -0
  44. package/vite.config.ts +54 -0
@@ -0,0 +1,212 @@
1
+ import babel from '@rollup/plugin-babel'
2
+ import commonjs from '@rollup/plugin-commonjs'
3
+ import nodeResolve from '@rollup/plugin-node-resolve'
4
+ import json from '@rollup/plugin-json'
5
+ import { terser } from 'rollup-plugin-terser'
6
+ import cleanup from 'rollup-plugin-cleanup'
7
+ import postcss from 'rollup-plugin-postcss'
8
+ import pkg from './package.json' with { type: 'json' }
9
+
10
+ const GLOBAL_NAME = 'EasyEditorMaterialsProgressRing'
11
+
12
+ // 外部依赖(不打包进组件)
13
+ const external = ['react', 'react-dom', 'react/jsx-runtime', '@easy-editor/core']
14
+
15
+ const globals = {
16
+ react: 'React',
17
+ 'react-dom': 'ReactDOM',
18
+ 'react/jsx-runtime': 'jsxRuntime',
19
+ '@easy-editor/core': 'EasyEditorCore',
20
+ }
21
+
22
+ const plugins = [
23
+ nodeResolve({
24
+ extensions: ['.js', '.ts', '.jsx', '.tsx'],
25
+ }),
26
+ commonjs(),
27
+ json(),
28
+ postcss({
29
+ modules: {
30
+ generateScopedName: '[name]__[local]___[hash:base64:5]',
31
+ },
32
+ autoModules: true,
33
+ minimize: true,
34
+ inject: true,
35
+ }),
36
+ babel({
37
+ extensions: ['.js', '.ts', '.jsx', '.tsx'],
38
+ exclude: 'node_modules/**',
39
+ babelrc: false,
40
+ babelHelpers: 'bundled',
41
+ presets: [
42
+ ['@babel/preset-react', { runtime: 'automatic' }],
43
+ [
44
+ '@babel/preset-typescript',
45
+ {
46
+ allowDeclareFields: true,
47
+ },
48
+ ],
49
+ ],
50
+ }),
51
+ cleanup({
52
+ comments: ['some', /PURE/],
53
+ extensions: ['.js', '.ts'],
54
+ }),
55
+ ]
56
+
57
+ export default [
58
+ /* ---------------------------------- 元数据构建 --------------------------------- */
59
+ {
60
+ input: 'src/meta.ts',
61
+ output: [
62
+ {
63
+ file: 'dist/meta.esm.js',
64
+ format: 'esm',
65
+ sourcemap: true,
66
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} (meta, esm) */`,
67
+ exports: 'named',
68
+ },
69
+ ],
70
+ plugins,
71
+ external,
72
+ },
73
+ {
74
+ input: 'src/meta.ts',
75
+ output: [
76
+ {
77
+ file: 'dist/meta.js',
78
+ format: 'umd',
79
+ name: `${GLOBAL_NAME}Meta`,
80
+ globals,
81
+ sourcemap: true,
82
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} (meta) */`,
83
+ exports: 'named',
84
+ },
85
+ ],
86
+ plugins,
87
+ external,
88
+ },
89
+ {
90
+ input: 'src/meta.ts',
91
+ output: [
92
+ {
93
+ file: 'dist/meta.min.js',
94
+ format: 'umd',
95
+ name: `${GLOBAL_NAME}Meta`,
96
+ globals,
97
+ sourcemap: true,
98
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} (meta, minified) */`,
99
+ exports: 'named',
100
+ },
101
+ ],
102
+ plugins: [...plugins, terser()],
103
+ external,
104
+ },
105
+
106
+ /* ---------------------------------- 组件构建 ---------------------------------- */
107
+ {
108
+ input: 'src/component.tsx',
109
+ output: [
110
+ {
111
+ file: 'dist/component.esm.js',
112
+ format: 'esm',
113
+ sourcemap: true,
114
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} (component, esm) */`,
115
+ exports: 'named',
116
+ },
117
+ ],
118
+ plugins,
119
+ external,
120
+ },
121
+ {
122
+ input: 'src/component.tsx',
123
+ output: [
124
+ {
125
+ file: 'dist/component.js',
126
+ format: 'umd',
127
+ name: `${GLOBAL_NAME}Component`,
128
+ globals,
129
+ sourcemap: true,
130
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} (component) */`,
131
+ exports: 'named',
132
+ },
133
+ ],
134
+ plugins,
135
+ external,
136
+ },
137
+ {
138
+ input: 'src/component.tsx',
139
+ output: [
140
+ {
141
+ file: 'dist/component.min.js',
142
+ format: 'umd',
143
+ name: `${GLOBAL_NAME}Component`,
144
+ globals,
145
+ sourcemap: true,
146
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} (component, minified) */`,
147
+ exports: 'named',
148
+ },
149
+ ],
150
+ plugins: [...plugins, terser()],
151
+ external,
152
+ },
153
+
154
+ /* ---------------------------------- 完整构建 ---------------------------------- */
155
+ {
156
+ input: 'src/index.tsx',
157
+ output: [
158
+ {
159
+ file: 'dist/index.js',
160
+ format: 'umd',
161
+ name: GLOBAL_NAME,
162
+ globals,
163
+ sourcemap: true,
164
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} */`,
165
+ exports: 'named',
166
+ },
167
+ ],
168
+ plugins,
169
+ external,
170
+ },
171
+ {
172
+ input: 'src/index.tsx',
173
+ output: [
174
+ {
175
+ file: 'dist/index.esm.js',
176
+ format: 'esm',
177
+ sourcemap: true,
178
+ },
179
+ ],
180
+ plugins,
181
+ external,
182
+ },
183
+ {
184
+ input: 'src/index.tsx',
185
+ output: [
186
+ {
187
+ file: 'dist/index.cjs',
188
+ format: 'cjs',
189
+ sourcemap: true,
190
+ exports: 'named',
191
+ },
192
+ ],
193
+ plugins,
194
+ external,
195
+ },
196
+ {
197
+ input: 'src/index.tsx',
198
+ output: [
199
+ {
200
+ file: 'dist/index.min.js',
201
+ format: 'umd',
202
+ name: GLOBAL_NAME,
203
+ globals,
204
+ sourcemap: true,
205
+ banner: `/* @easy-editor/materials-dashboard-progress-ring v${pkg.version} (minified) */`,
206
+ exports: 'named',
207
+ },
208
+ ],
209
+ plugins: [...plugins, terser()],
210
+ external,
211
+ },
212
+ ]
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Progress Component Styles
3
+ * 进度组件样式
4
+ */
5
+
6
+ .wrapper {
7
+ width: 100%;
8
+ height: 100%;
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ }
13
+
14
+ .container {
15
+ position: relative;
16
+ display: flex;
17
+ align-items: center;
18
+ justify-content: center;
19
+ width: 100%;
20
+ height: 100%;
21
+ }
22
+
23
+ .ring {
24
+ transform: rotate(-90deg);
25
+ }
26
+
27
+ .centerContent {
28
+ position: absolute;
29
+ top: 50%;
30
+ left: 50%;
31
+ transform: translate(-50%, -50%);
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: center;
35
+ justify-content: center;
36
+ text-align: center;
37
+ }
38
+
39
+ .value {
40
+ font-weight: 700;
41
+ line-height: 1.1;
42
+ }
43
+
44
+ .label {
45
+ margin-top: 4px;
46
+ opacity: 0.7;
47
+ color: #fff;
48
+ }
49
+
50
+ /* 线性进度条样式 */
51
+ .barContainer {
52
+ width: 100%;
53
+ height: 100%;
54
+ display: flex;
55
+ flex-direction: column;
56
+ justify-content: center;
57
+ gap: 4px;
58
+ }
59
+
60
+ .barWrapper {
61
+ width: 100%;
62
+ flex: 1;
63
+ min-height: 8px;
64
+ max-height: 8px;
65
+ border-radius: 4px;
66
+ overflow: hidden;
67
+ }
68
+
69
+ .barFill {
70
+ height: 100%;
71
+ border-radius: 4px;
72
+ transition: width 0.5s ease;
73
+ }
74
+
75
+ .barLabels {
76
+ display: flex;
77
+ justify-content: space-between;
78
+ align-items: center;
79
+ }
80
+
81
+ .barLabel {
82
+ font-size: 12px;
83
+ color: rgba(255, 255, 255, 0.7);
84
+ }
85
+
86
+ .barValue {
87
+ font-size: 14px;
88
+ font-weight: 600;
89
+ }
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Progress Component
3
+ * 进度组件 - 支持环形和线性进度条
4
+ */
5
+
6
+ import { useId, useRef, useEffect, useState, type CSSProperties, type Ref } from 'react'
7
+ import styles from './component.module.css'
8
+
9
+ export interface ProgressProps {
10
+ ref?: Ref<HTMLDivElement>
11
+ /** 当前值 */
12
+ value?: number
13
+ /** 最大值 */
14
+ maxValue?: number
15
+ /** 进度条类型 */
16
+ type?: 'ring' | 'bar'
17
+ /** 是否显示数值 */
18
+ showValue?: boolean
19
+ /** 是否显示标签 */
20
+ showLabel?: boolean
21
+ /** 标签文本 */
22
+ label?: string
23
+ /** 数值格式 */
24
+ valueFormat?: 'percent' | 'number'
25
+ /** 线条宽度比例(相对于尺寸的百分比) */
26
+ strokeWidthRatio?: number
27
+ /** 轨道颜色 */
28
+ trackColor?: string
29
+ /** 进度颜色 */
30
+ progressColor?: string
31
+ /** 是否启用渐变 */
32
+ gradientEnable?: boolean
33
+ /** 渐变颜色 [起始色, 结束色] */
34
+ gradientColors?: [string, string]
35
+ /** 外部样式 */
36
+ style?: CSSProperties
37
+ }
38
+
39
+ // 格式化数值
40
+ const formatValue = (value: number, percentage: number, valueFormat: string): string => {
41
+ if (valueFormat === 'percent') {
42
+ return `${Math.round(percentage)}%`
43
+ }
44
+ return `${value}`
45
+ }
46
+
47
+ // 环形进度条组件
48
+ const RingProgress = ({
49
+ percentage,
50
+ strokeWidthRatio,
51
+ trackColor,
52
+ progressColor,
53
+ gradientEnable,
54
+ gradientColors,
55
+ showValue,
56
+ showLabel,
57
+ label,
58
+ valueFormat,
59
+ displayColor,
60
+ gradientId,
61
+ }: {
62
+ percentage: number
63
+ strokeWidthRatio: number
64
+ trackColor: string
65
+ progressColor: string
66
+ gradientEnable: boolean
67
+ gradientColors: [string, string]
68
+ showValue: boolean
69
+ showLabel: boolean
70
+ label: string
71
+ valueFormat: string
72
+ displayColor: string
73
+ gradientId: string
74
+ }) => {
75
+ const containerRef = useRef<HTMLDivElement>(null)
76
+ const [size, setSize] = useState(100)
77
+
78
+ useEffect(() => {
79
+ const container = containerRef.current
80
+ if (!container) {
81
+ return
82
+ }
83
+
84
+ const updateSize = () => {
85
+ const { width, height } = container.getBoundingClientRect()
86
+ const minSize = Math.min(width, height)
87
+ if (minSize > 0) {
88
+ setSize(minSize)
89
+ }
90
+ }
91
+
92
+ updateSize()
93
+
94
+ const resizeObserver = new ResizeObserver(updateSize)
95
+ resizeObserver.observe(container)
96
+
97
+ return () => resizeObserver.disconnect()
98
+ }, [])
99
+
100
+ const strokeWidth = Math.max(2, size * strokeWidthRatio)
101
+ const radius = (size - strokeWidth) / 2
102
+ const circumference = 2 * Math.PI * radius
103
+ const strokeDashoffset = circumference - (percentage / 100) * circumference
104
+ const center = size / 2
105
+
106
+ return (
107
+ <div className={styles.container} ref={containerRef}>
108
+ <svg aria-label='Progress ring' className={styles.ring} height={size} role='img' width={size}>
109
+ <title>Progress indicator</title>
110
+ {gradientEnable ? (
111
+ <defs>
112
+ <linearGradient id={gradientId} x1='0%' x2='100%' y1='0%' y2='0%'>
113
+ <stop offset='0%' stopColor={gradientColors[0]} />
114
+ <stop offset='100%' stopColor={gradientColors[1]} />
115
+ </linearGradient>
116
+ </defs>
117
+ ) : null}
118
+ {/* 轨道 */}
119
+ <circle cx={center} cy={center} fill='none' r={radius} stroke={trackColor} strokeWidth={strokeWidth} />
120
+ {/* 进度 */}
121
+ <circle
122
+ cx={center}
123
+ cy={center}
124
+ fill='none'
125
+ r={radius}
126
+ stroke={gradientEnable ? `url(#${gradientId})` : progressColor}
127
+ strokeDasharray={circumference}
128
+ strokeDashoffset={strokeDashoffset}
129
+ strokeLinecap='round'
130
+ strokeWidth={strokeWidth}
131
+ style={{
132
+ transition: 'stroke-dashoffset 0.5s ease',
133
+ }}
134
+ />
135
+ </svg>
136
+ <div className={styles.centerContent}>
137
+ {showValue ? (
138
+ <span className={styles.value} style={{ fontSize: size * 0.2, color: displayColor }}>
139
+ {formatValue(Math.round(percentage), percentage, valueFormat)}
140
+ </span>
141
+ ) : null}
142
+ {showLabel && label ? (
143
+ <span className={styles.label} style={{ fontSize: size * 0.1 }}>
144
+ {label}
145
+ </span>
146
+ ) : null}
147
+ </div>
148
+ </div>
149
+ )
150
+ }
151
+
152
+ // 线性进度条组件
153
+ const BarProgress = ({
154
+ percentage,
155
+ trackColor,
156
+ progressColor,
157
+ gradientEnable,
158
+ gradientColors,
159
+ showValue,
160
+ showLabel,
161
+ label,
162
+ valueFormat,
163
+ displayColor,
164
+ }: {
165
+ percentage: number
166
+ trackColor: string
167
+ progressColor: string
168
+ gradientEnable: boolean
169
+ gradientColors: [string, string]
170
+ showValue: boolean
171
+ showLabel: boolean
172
+ label: string
173
+ valueFormat: string
174
+ displayColor: string
175
+ }) => (
176
+ <div className={styles.barContainer}>
177
+ {showLabel || showValue ? (
178
+ <div className={styles.barLabels}>
179
+ {showLabel ? <span className={styles.barLabel}>{label}</span> : null}
180
+ {showValue ? (
181
+ <span className={styles.barValue} style={{ color: displayColor }}>
182
+ {formatValue(Math.round(percentage), percentage, valueFormat)}
183
+ </span>
184
+ ) : null}
185
+ </div>
186
+ ) : null}
187
+ <div className={styles.barWrapper} style={{ background: trackColor }}>
188
+ <div
189
+ className={styles.barFill}
190
+ style={{
191
+ width: `${percentage}%`,
192
+ background: gradientEnable
193
+ ? `linear-gradient(90deg, ${gradientColors[0]}, ${gradientColors[1]})`
194
+ : progressColor,
195
+ }}
196
+ />
197
+ </div>
198
+ </div>
199
+ )
200
+
201
+ export const Progress: React.FC<ProgressProps> = ({
202
+ ref,
203
+ value = 0,
204
+ maxValue = 100,
205
+ type = 'ring',
206
+ showValue = true,
207
+ showLabel = false,
208
+ label = '',
209
+ valueFormat = 'percent',
210
+ strokeWidthRatio = 0.07,
211
+ trackColor = 'rgba(26, 26, 62, 0.8)',
212
+ progressColor = '#00d4ff',
213
+ gradientEnable = false,
214
+ gradientColors = ['#00d4ff', '#9b59b6'],
215
+ style: externalStyle,
216
+ }) => {
217
+ const gradientId = useId()
218
+
219
+ const normalizedValue = Math.min(Math.max(value, 0), maxValue)
220
+ const percentage = (normalizedValue / maxValue) * 100
221
+ const displayColor = gradientEnable ? gradientColors[0] : progressColor
222
+
223
+ if (type === 'ring') {
224
+ return (
225
+ <div className={styles.wrapper} ref={ref} style={externalStyle}>
226
+ <RingProgress
227
+ displayColor={displayColor}
228
+ gradientColors={gradientColors}
229
+ gradientEnable={gradientEnable}
230
+ gradientId={gradientId}
231
+ label={label}
232
+ percentage={percentage}
233
+ progressColor={progressColor}
234
+ showLabel={showLabel}
235
+ showValue={showValue}
236
+ strokeWidthRatio={strokeWidthRatio}
237
+ trackColor={trackColor}
238
+ valueFormat={valueFormat}
239
+ />
240
+ </div>
241
+ )
242
+ }
243
+
244
+ return (
245
+ <div className={styles.wrapper} ref={ref} style={externalStyle}>
246
+ <BarProgress
247
+ displayColor={displayColor}
248
+ gradientColors={gradientColors}
249
+ gradientEnable={gradientEnable}
250
+ label={label}
251
+ percentage={percentage}
252
+ progressColor={progressColor}
253
+ showLabel={showLabel}
254
+ showValue={showValue}
255
+ trackColor={trackColor}
256
+ valueFormat={valueFormat}
257
+ />
258
+ </div>
259
+ )
260
+ }
261
+
262
+ export default Progress