@easy-editor/materials-dashboard-number-flip 0.0.3 → 0.0.5

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 CHANGED
@@ -1,13 +1,27 @@
1
- # @easy-editor/materials-dashboard-number-flip
2
-
3
- ## 0.0.3
4
-
5
- ### Patch Changes
6
-
7
- - fix: build error
8
-
9
- ## 0.0.2
10
-
11
- ### Patch Changes
12
-
13
- - feat: new setters
1
+ # @easy-editor/materials-dashboard-number-flip
2
+
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: component export error
8
+
9
+ ## 0.0.4
10
+
11
+ ### Patch Changes
12
+
13
+ - perf: configure & datasource
14
+ - Updated dependencies
15
+ - @easy-editor/materials-shared@0.0.1
16
+
17
+ ## 0.0.3
18
+
19
+ ### Patch Changes
20
+
21
+ - fix: build error
22
+
23
+ ## 0.0.2
24
+
25
+ ### Patch Changes
26
+
27
+ - feat: new setters
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @easy-editor/easypack configuration
3
+ * @type {import('@easy-editor/easypack').EasypackConfig}
4
+ */
5
+ export default {
6
+ preset: 'material',
7
+ dev: {
8
+ port: 5001,
9
+ },
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-editor/materials-dashboard-number-flip",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Number Flip component for EasyEditor dashboard",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -45,20 +45,16 @@
45
45
  "@types/react-dom": "^18 || ^19"
46
46
  },
47
47
  "dependencies": {
48
- "@easy-editor/materials-shared": "0.0.0"
48
+ "@easy-editor/materials-shared": "0.0.1"
49
49
  },
50
50
  "scripts": {
51
- "dev": "vite",
51
+ "dev": "easypack dev",
52
52
  "dev:debug": "vite --port 5024",
53
53
  "format": "biome format --write .",
54
54
  "lint": "biome check .",
55
55
  "build": "npm-run-all -nl build:*",
56
56
  "build:clean": "rimraf dist/",
57
- "build:js": "rollup -c",
58
- "build:types": "pnpm types",
59
- "types": "npm-run-all -nl types:*",
60
- "types:src": "tsc --project tsconfig.build.json",
61
- "test-types": "tsc --project tsconfig.test.json"
57
+ "build:js": "easypack build"
62
58
  },
63
59
  "module": "dist/index.esm.js",
64
60
  "unpkg": "dist/index.min.js"
package/src/component.tsx CHANGED
@@ -1,18 +1,15 @@
1
1
  /**
2
2
  * Number Flip Component
3
- * 数字翻牌组件 - 用于展示 KPI、统计数字等
3
+ * 数字翻牌组件 - 支持数据源绑定和事件交互
4
4
  */
5
5
 
6
- import type { CSSProperties, Ref } from 'react'
7
- import { cn } from '@easy-editor/materials-shared'
6
+ import { useMemo, type CSSProperties } from 'react'
7
+ import { cn, type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
8
8
  import styles from './component.module.css'
9
9
 
10
10
  export type TrendType = 'up' | 'down' | 'flat'
11
11
 
12
- export interface NumberFlipProps {
13
- ref?: Ref<HTMLDivElement>
14
- /** 数值 */
15
- value?: number
12
+ export interface NumberFlipProps extends MaterialComponet {
16
13
  /** 小数位数 */
17
14
  decimals?: number
18
15
  /** 是否显示千分位分隔符 */
@@ -41,8 +38,14 @@ export interface NumberFlipProps {
41
38
  trendUpColor?: string
42
39
  /** 趋势下降颜色 */
43
40
  trendDownColor?: string
44
- /** 外部样式 */
45
- style?: CSSProperties
41
+ /** 点击事件 */
42
+ onClick?: (e: React.MouseEvent) => void
43
+ /** 双击事件 */
44
+ onDoubleClick?: (e: React.MouseEvent) => void
45
+ /** 鼠标进入 */
46
+ onMouseEnter?: (e: React.MouseEvent) => void
47
+ /** 鼠标离开 */
48
+ onMouseLeave?: (e: React.MouseEvent) => void
46
49
  }
47
50
 
48
51
  const formatNumber = (value: number, decimals: number, separator: boolean): string => {
@@ -100,7 +103,8 @@ const TrendIndicator: React.FC<{
100
103
 
101
104
  export const NumberFlip: React.FC<NumberFlipProps> = ({
102
105
  ref,
103
- value = 0,
106
+ $data,
107
+ __dataSource,
104
108
  decimals = 0,
105
109
  separator = true,
106
110
  prefix = '',
@@ -115,8 +119,24 @@ export const NumberFlip: React.FC<NumberFlipProps> = ({
115
119
  trendSuffix = '%',
116
120
  trendUpColor = '#52c41a',
117
121
  trendDownColor = '#ff4d4f',
122
+ rotation = 0,
123
+ opacity = 100,
124
+ background = 'transparent',
118
125
  style: externalStyle,
126
+ onClick,
127
+ onDoubleClick,
128
+ onMouseEnter,
129
+ onMouseLeave,
119
130
  }) => {
131
+ // 解析数据源
132
+ const dataSource = useDataSource($data, __dataSource)
133
+ const value = useMemo<number>(() => {
134
+ if (dataSource.length > 0 && typeof dataSource[0]?.value === 'number') {
135
+ return dataSource[0].value
136
+ }
137
+ return 0
138
+ }, [dataSource])
139
+
120
140
  const isDigital = fontFamily === 'digital'
121
141
  const formattedValue = formatNumber(value, decimals, separator)
122
142
 
@@ -126,8 +146,23 @@ export const NumberFlip: React.FC<NumberFlipProps> = ({
126
146
  ? `0 0 ${10 * glowIntensity}px ${color}, 0 0 ${20 * glowIntensity}px ${color}40, 0 0 ${30 * glowIntensity}px ${color}20`
127
147
  : 'none'
128
148
 
149
+ const containerStyle: CSSProperties = {
150
+ transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
151
+ opacity: opacity / 100,
152
+ backgroundColor: background,
153
+ ...externalStyle,
154
+ }
155
+
129
156
  return (
130
- <div className={styles.container} ref={ref} style={externalStyle}>
157
+ <div
158
+ className={styles.container}
159
+ onClick={onClick}
160
+ onDoubleClick={onDoubleClick}
161
+ onMouseEnter={onMouseEnter}
162
+ onMouseLeave={onMouseLeave}
163
+ ref={ref}
164
+ style={containerStyle}
165
+ >
131
166
  <div className={styles.content}>
132
167
  {prefix ? (
133
168
  <span