@easy-editor/materials-dashboard-button 0.0.2 → 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 +21 -7
- package/easypack.config.ts +10 -0
- package/package.json +4 -8
- package/src/component.tsx +139 -80
- package/src/configure.ts +136 -258
- package/src/index.tsx +7 -7
- package/src/meta.ts +2 -2
- package/src/snippets.ts +54 -49
- 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 -97
- package/dist/component.esm.js.map +0 -1
- package/dist/component.js +0 -106
- package/dist/component.js.map +0 -1
- package/dist/component.min.js +0 -2
- package/dist/component.min.js.map +0 -1
- package/dist/index.cjs +0 -394
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.js +0 -391
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -399
- package/dist/index.js.map +0 -1
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -1
- package/dist/meta.esm.js +0 -298
- package/dist/meta.esm.js.map +0 -1
- package/dist/meta.js +0 -309
- package/dist/meta.js.map +0 -1
- package/dist/meta.min.js +0 -2
- package/dist/meta.min.js.map +0 -1
- package/dist/src/component.d.ts +0 -26
- package/dist/src/configure.d.ts +0 -7
- package/dist/src/constants.d.ts +0 -16
- 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 -222
- package/tsconfig.build.json +0 -12
- package/tsconfig.test.json +0 -7
- package/vite.config.ts +0 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
# @easy-editor/materials-dashboard-button
|
|
2
|
-
|
|
3
|
-
## 0.0.
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
-
|
|
1
|
+
# @easy-editor/materials-dashboard-button
|
|
2
|
+
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: component export error
|
|
8
|
+
|
|
9
|
+
## 0.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- perf: configure & datasource
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @easy-editor/materials-shared@0.0.1
|
|
16
|
+
|
|
17
|
+
## 0.0.2
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- feat: new setters
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-editor/materials-dashboard-button",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Button component for EasyEditor dashboard",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,19 +45,15 @@
|
|
|
45
45
|
"@types/react-dom": "^18 || ^19"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@easy-editor/materials-shared": "0.0.
|
|
48
|
+
"@easy-editor/materials-shared": "0.0.1"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
|
-
"dev": "
|
|
51
|
+
"dev": "easypack dev",
|
|
52
52
|
"format": "biome format --write .",
|
|
53
53
|
"lint": "biome check .",
|
|
54
54
|
"build": "npm-run-all -nl build:*",
|
|
55
55
|
"build:clean": "rimraf dist/",
|
|
56
|
-
"build:js": "
|
|
57
|
-
"build:types": "pnpm types",
|
|
58
|
-
"types": "npm-run-all -nl types:*",
|
|
59
|
-
"types:src": "tsc --project tsconfig.build.json",
|
|
60
|
-
"test-types": "tsc --project tsconfig.test.json"
|
|
56
|
+
"build:js": "easypack build"
|
|
61
57
|
},
|
|
62
58
|
"module": "dist/index.esm.js",
|
|
63
59
|
"unpkg": "dist/index.min.js"
|
package/src/component.tsx
CHANGED
|
@@ -1,80 +1,139 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Button Component
|
|
3
|
-
* 按钮组件
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import { cn } from '@easy-editor/materials-shared'
|
|
8
|
-
import styles from './component.module.css'
|
|
9
|
-
|
|
10
|
-
export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger'
|
|
11
|
-
export type ButtonSize = 'small' | 'medium' | 'large'
|
|
12
|
-
|
|
13
|
-
export interface ButtonProps {
|
|
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
|
-
case '
|
|
47
|
-
return styles.
|
|
48
|
-
|
|
49
|
-
return styles.
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Button Component
|
|
3
|
+
* 按钮组件 - 支持数据源绑定和事件交互
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useMemo, type CSSProperties, type MouseEvent } from 'react'
|
|
7
|
+
import { cn, type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
|
|
8
|
+
import styles from './component.module.css'
|
|
9
|
+
|
|
10
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger'
|
|
11
|
+
export type ButtonSize = 'small' | 'medium' | 'large'
|
|
12
|
+
|
|
13
|
+
export interface ButtonProps extends MaterialComponet<HTMLButtonElement> {
|
|
14
|
+
/** 按钮变体 */
|
|
15
|
+
variant?: ButtonVariant
|
|
16
|
+
/** 按钮尺寸 */
|
|
17
|
+
size?: ButtonSize
|
|
18
|
+
/** 是否禁用 */
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
/** 是否显示发光效果 */
|
|
21
|
+
glowEnable?: boolean
|
|
22
|
+
/** 链接地址 */
|
|
23
|
+
href?: string
|
|
24
|
+
/** 链接打开方式 */
|
|
25
|
+
target?: '_blank' | '_self'
|
|
26
|
+
/** 是否加载中 */
|
|
27
|
+
loading?: boolean
|
|
28
|
+
/** 加载文本 */
|
|
29
|
+
loadingText?: string
|
|
30
|
+
/** 点击事件 */
|
|
31
|
+
onClick?: (e: MouseEvent<HTMLButtonElement>) => void
|
|
32
|
+
/** 双击事件 */
|
|
33
|
+
onDoubleClick?: (e: MouseEvent<HTMLButtonElement>) => void
|
|
34
|
+
/** 鼠标进入 */
|
|
35
|
+
onMouseEnter?: (e: MouseEvent<HTMLButtonElement>) => void
|
|
36
|
+
/** 鼠标离开 */
|
|
37
|
+
onMouseLeave?: (e: MouseEvent<HTMLButtonElement>) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getSizeClass = (size: ButtonSize): string => {
|
|
41
|
+
switch (size) {
|
|
42
|
+
case 'small':
|
|
43
|
+
return styles.sizeSmall
|
|
44
|
+
case 'medium':
|
|
45
|
+
return styles.sizeMedium
|
|
46
|
+
case 'large':
|
|
47
|
+
return styles.sizeLarge
|
|
48
|
+
default:
|
|
49
|
+
return styles.sizeMedium
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const getVariantClass = (variant: ButtonVariant): string => {
|
|
54
|
+
switch (variant) {
|
|
55
|
+
case 'primary':
|
|
56
|
+
return styles.variantPrimary
|
|
57
|
+
case 'secondary':
|
|
58
|
+
return styles.variantSecondary
|
|
59
|
+
case 'outline':
|
|
60
|
+
return styles.variantOutline
|
|
61
|
+
case 'ghost':
|
|
62
|
+
return styles.variantGhost
|
|
63
|
+
case 'danger':
|
|
64
|
+
return styles.variantDanger
|
|
65
|
+
default:
|
|
66
|
+
return styles.variantPrimary
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const Button: React.FC<ButtonProps> = ({
|
|
71
|
+
ref,
|
|
72
|
+
$data,
|
|
73
|
+
__dataSource,
|
|
74
|
+
variant = 'primary',
|
|
75
|
+
size = 'medium',
|
|
76
|
+
disabled = false,
|
|
77
|
+
glowEnable = false,
|
|
78
|
+
href,
|
|
79
|
+
target = '_blank',
|
|
80
|
+
loading = false,
|
|
81
|
+
loadingText = '加载中...',
|
|
82
|
+
rotation = 0,
|
|
83
|
+
opacity = 100,
|
|
84
|
+
background,
|
|
85
|
+
onClick,
|
|
86
|
+
onDoubleClick,
|
|
87
|
+
onMouseEnter,
|
|
88
|
+
onMouseLeave,
|
|
89
|
+
style: externalStyle,
|
|
90
|
+
}) => {
|
|
91
|
+
const dataSource = useDataSource($data, __dataSource)
|
|
92
|
+
const data = useMemo<string>(() => {
|
|
93
|
+
if (dataSource.length > 0 && dataSource[0]?.text) {
|
|
94
|
+
return String(dataSource[0].text)
|
|
95
|
+
}
|
|
96
|
+
return ''
|
|
97
|
+
}, [dataSource])
|
|
98
|
+
|
|
99
|
+
const buttonClass = cn(styles.button, getSizeClass(size), getVariantClass(variant), glowEnable && styles.glow)
|
|
100
|
+
|
|
101
|
+
const displayText = loading ? loadingText : data
|
|
102
|
+
|
|
103
|
+
const buttonStyle: CSSProperties = {
|
|
104
|
+
transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
|
|
105
|
+
opacity: opacity / 100,
|
|
106
|
+
backgroundColor: background,
|
|
107
|
+
...externalStyle,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const handleClick = (e: MouseEvent<HTMLButtonElement>) => {
|
|
111
|
+
if (disabled || loading) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (href) {
|
|
116
|
+
window.open(href, target)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
onClick?.(e)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<button
|
|
124
|
+
className={buttonClass}
|
|
125
|
+
disabled={disabled || loading}
|
|
126
|
+
onClick={handleClick}
|
|
127
|
+
onDoubleClick={onDoubleClick}
|
|
128
|
+
onMouseEnter={onMouseEnter}
|
|
129
|
+
onMouseLeave={onMouseLeave}
|
|
130
|
+
ref={ref}
|
|
131
|
+
style={buttonStyle}
|
|
132
|
+
type='button'
|
|
133
|
+
>
|
|
134
|
+
{displayText ? <span>{displayText}</span> : null}
|
|
135
|
+
</button>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export default Button
|