@easy-editor/materials-dashboard-scroll-list 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-scroll-list
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-scroll-list
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-scroll-list",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Scroll List 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 5023",
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,10 +1,10 @@
1
1
  /**
2
2
  * Scroll List Component
3
- * 滚动列表组件 - 用于展示排行榜、数据列表等
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, useDataSource, type MaterialComponet } from '@easy-editor/materials-shared'
8
8
  import styles from './component.module.css'
9
9
 
10
10
  export interface ScrollListItem {
@@ -13,10 +13,7 @@ export interface ScrollListItem {
13
13
  value: number
14
14
  }
15
15
 
16
- export interface ScrollListProps {
17
- ref?: Ref<HTMLDivElement>
18
- /** 列表数据 */
19
- data?: ScrollListItem[]
16
+ export interface ScrollListProps extends MaterialComponet {
20
17
  /** 最大显示条数 */
21
18
  maxItems?: number
22
19
  /** 是否显示排名 */
@@ -49,8 +46,16 @@ export interface ScrollListProps {
49
46
  itemBorderColor?: string
50
47
  /** 是否显示发光效果 */
51
48
  glowEnable?: boolean
52
- /** 外部样式 */
53
- style?: CSSProperties
49
+ /** 点击事件 */
50
+ onClick?: (e: React.MouseEvent) => void
51
+ /** 双击事件 */
52
+ onDoubleClick?: (e: React.MouseEvent) => void
53
+ /** 鼠标进入 */
54
+ onMouseEnter?: (e: React.MouseEvent) => void
55
+ /** 鼠标离开 */
56
+ onMouseLeave?: (e: React.MouseEvent) => void
57
+ /** 行点击事件 */
58
+ onItemClick?: (item: ScrollListItem, index: number) => void
54
59
  }
55
60
 
56
61
  const DEFAULT_DATA: ScrollListItem[] = [
@@ -97,7 +102,8 @@ const formatDisplayValue = (value: number, format: string, prefix: string, suffi
97
102
 
98
103
  export const ScrollList: React.FC<ScrollListProps> = ({
99
104
  ref,
100
- data = DEFAULT_DATA,
105
+ $data,
106
+ __dataSource,
101
107
  maxItems = 5,
102
108
  showRank = true,
103
109
  showMedal = true,
@@ -114,8 +120,24 @@ export const ScrollList: React.FC<ScrollListProps> = ({
114
120
  itemBackgroundColor = 'rgba(15, 15, 42, 0.9)',
115
121
  itemBorderColor = 'rgba(26, 26, 62, 0.6)',
116
122
  glowEnable = false,
123
+ rotation = 0,
124
+ opacity = 100,
117
125
  style: externalStyle,
126
+ onClick,
127
+ onDoubleClick,
128
+ onMouseEnter,
129
+ onMouseLeave,
130
+ onItemClick,
118
131
  }) => {
132
+ // 解析数据源
133
+ const dataSource = useDataSource($data, __dataSource)
134
+ const data = useMemo<ScrollListItem[]>(() => {
135
+ if (dataSource.length > 0) {
136
+ return dataSource as ScrollListItem[]
137
+ }
138
+ return DEFAULT_DATA
139
+ }, [dataSource])
140
+
119
141
  const displayData = data.slice(0, maxItems)
120
142
  const maxValue = Math.max(...displayData.map(item => item.value), 1)
121
143
 
@@ -131,9 +153,11 @@ export const ScrollList: React.FC<ScrollListProps> = ({
131
153
  }
132
154
 
133
155
  const containerStyle: CSSProperties = {
134
- ...externalStyle,
156
+ transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
157
+ opacity: opacity / 100,
135
158
  backgroundColor,
136
159
  borderColor,
160
+ ...externalStyle,
137
161
  }
138
162
 
139
163
  const itemStyle: CSSProperties = {
@@ -142,13 +166,21 @@ export const ScrollList: React.FC<ScrollListProps> = ({
142
166
  }
143
167
 
144
168
  return (
145
- <div className={styles.container} ref={ref} style={containerStyle}>
169
+ <div
170
+ className={styles.container}
171
+ onClick={onClick}
172
+ onDoubleClick={onDoubleClick}
173
+ onMouseEnter={onMouseEnter}
174
+ onMouseLeave={onMouseLeave}
175
+ ref={ref}
176
+ style={containerStyle}
177
+ >
146
178
  <div className={styles.list}>
147
- {displayData.map(item => {
179
+ {displayData.map((item, index) => {
148
180
  const isTopThree = item.rank <= 3
149
181
 
150
182
  return (
151
- <div className={styles.item} key={item.rank} style={itemStyle}>
183
+ <div className={styles.item} key={item.rank} onClick={() => onItemClick?.(item, index)} style={itemStyle}>
152
184
  {/* Rank Badge */}
153
185
  {showRank ? (
154
186
  <div