x-ui-design 0.1.78 → 0.1.79
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.
|
@@ -1,7 +1,104 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { clsx } from '../../helpers';
|
|
1
3
|
import { ButtonProps } from '../../types/button';
|
|
2
|
-
import {
|
|
4
|
+
import { prefixClsButton } from '../../utils';
|
|
5
|
+
import './style.css';
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const Button = ({
|
|
8
|
+
type = 'default',
|
|
9
|
+
variant = 'solid',
|
|
10
|
+
color = 'default',
|
|
11
|
+
shape = 'default',
|
|
12
|
+
size = 'middle',
|
|
13
|
+
htmlType = 'button',
|
|
14
|
+
className,
|
|
15
|
+
rootClassName,
|
|
16
|
+
classNames: customClassNames = {},
|
|
17
|
+
styles = {},
|
|
18
|
+
prefixCls = prefixClsButton,
|
|
19
|
+
icon,
|
|
20
|
+
iconPosition = 'start',
|
|
21
|
+
loading = false,
|
|
22
|
+
disabled = false,
|
|
23
|
+
ghost = false,
|
|
24
|
+
danger = false,
|
|
25
|
+
block = false,
|
|
26
|
+
children,
|
|
27
|
+
href,
|
|
28
|
+
...restProps
|
|
29
|
+
}: ButtonProps): ReactElement => {
|
|
30
|
+
const innerLoading = typeof loading === 'object' ? !!loading : Boolean(loading);
|
|
31
|
+
|
|
32
|
+
const classes = clsx(
|
|
33
|
+
prefixCls,
|
|
34
|
+
rootClassName,
|
|
35
|
+
`${prefixCls}-${type}`,
|
|
36
|
+
`${prefixCls}-${variant}`,
|
|
37
|
+
`${prefixCls}-${color}`,
|
|
38
|
+
`${prefixCls}-${shape}`,
|
|
39
|
+
`${prefixCls}-size-${size}`,
|
|
40
|
+
{
|
|
41
|
+
[`${prefixCls}-block`]: block,
|
|
42
|
+
[`${prefixCls}-ghost`]: ghost,
|
|
43
|
+
[`${prefixCls}-danger`]: danger,
|
|
44
|
+
[`${prefixCls}-loading`]: innerLoading,
|
|
45
|
+
[`${prefixCls}-disabled`]: disabled
|
|
46
|
+
},
|
|
47
|
+
className
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const iconNode = innerLoading
|
|
51
|
+
? (typeof loading === 'object' && loading.icon) || (
|
|
52
|
+
<span className={`${prefixCls}-spinner`}></span>
|
|
53
|
+
)
|
|
54
|
+
: icon;
|
|
55
|
+
|
|
56
|
+
const content = (
|
|
57
|
+
<>
|
|
58
|
+
{iconNode && iconPosition === 'start' && (
|
|
59
|
+
<span
|
|
60
|
+
className={clsx(`${prefixCls}-icon`, customClassNames.icon)}
|
|
61
|
+
style={styles.icon}
|
|
62
|
+
>
|
|
63
|
+
{iconNode}
|
|
64
|
+
</span>
|
|
65
|
+
)}
|
|
66
|
+
<span className={`${prefixCls}-content`}>{children}</span>
|
|
67
|
+
{iconNode && iconPosition === 'end' && (
|
|
68
|
+
<span
|
|
69
|
+
className={clsx(`${prefixCls}-icon`, customClassNames.icon)}
|
|
70
|
+
style={styles.icon}
|
|
71
|
+
>
|
|
72
|
+
{iconNode}
|
|
73
|
+
</span>
|
|
74
|
+
)}
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const mergedDisabled = disabled || innerLoading;
|
|
79
|
+
|
|
80
|
+
if (href) {
|
|
81
|
+
return (
|
|
82
|
+
<a
|
|
83
|
+
className={classes}
|
|
84
|
+
href={mergedDisabled ? undefined : href}
|
|
85
|
+
aria-disabled={mergedDisabled}
|
|
86
|
+
>
|
|
87
|
+
{content}
|
|
88
|
+
</a>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<button
|
|
94
|
+
type={htmlType}
|
|
95
|
+
className={classes}
|
|
96
|
+
disabled={mergedDisabled}
|
|
97
|
+
{...restProps}
|
|
98
|
+
>
|
|
99
|
+
{content}
|
|
100
|
+
</button>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export default Button;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Button } from './Button'
|
|
1
|
+
export { default as Button } from './Button'
|
package/lib/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ import './styles/global.css';
|
|
|
27
27
|
// export { default as SkeletonButton } from "./components/Skeleton/Button/Button";
|
|
28
28
|
|
|
29
29
|
// export { default as Empty } from "./components/Empty/Empty";
|
|
30
|
-
export { Button } from "./components/Button/Button";
|
|
30
|
+
export { default as Button } from "./components/Button/Button";
|
|
31
31
|
// export { default as Upload } from "./components/Upload/Upload";
|
|
32
32
|
// export { default as Checkbox } from "./components/Checkbox/Checkbox";
|
|
33
33
|
|
package/package.json
CHANGED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { ReactElement, useEffect, useMemo, useState } from 'react';
|
|
4
|
-
import { clsx } from '../../helpers';
|
|
5
|
-
import { ButtonProps } from '../../types/button';
|
|
6
|
-
import { prefixClsButton } from '../../utils';
|
|
7
|
-
import './style.css';
|
|
8
|
-
|
|
9
|
-
export const ButtonClient = ({
|
|
10
|
-
type = 'default',
|
|
11
|
-
variant = 'solid',
|
|
12
|
-
color = 'default',
|
|
13
|
-
shape = 'default',
|
|
14
|
-
size = 'middle',
|
|
15
|
-
htmlType = 'button',
|
|
16
|
-
className,
|
|
17
|
-
rootClassName,
|
|
18
|
-
classNames: customClassNames = {},
|
|
19
|
-
styles = {},
|
|
20
|
-
prefixCls = prefixClsButton,
|
|
21
|
-
icon,
|
|
22
|
-
iconPosition = 'start',
|
|
23
|
-
loading = false,
|
|
24
|
-
disabled = false,
|
|
25
|
-
ghost = false,
|
|
26
|
-
danger = false,
|
|
27
|
-
block = false,
|
|
28
|
-
children,
|
|
29
|
-
href,
|
|
30
|
-
...restProps
|
|
31
|
-
}: ButtonProps): ReactElement => {
|
|
32
|
-
const [innerLoading, setInnerLoading] = useState(false);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (typeof loading === 'boolean') {
|
|
36
|
-
setInnerLoading(loading);
|
|
37
|
-
} else if (typeof loading === 'object' && loading.delay) {
|
|
38
|
-
const timeout = setTimeout(() => setInnerLoading(true), loading.delay);
|
|
39
|
-
return () => clearTimeout(timeout);
|
|
40
|
-
} else {
|
|
41
|
-
setInnerLoading(!!loading);
|
|
42
|
-
}
|
|
43
|
-
}, [loading]);
|
|
44
|
-
|
|
45
|
-
const classes = clsx(
|
|
46
|
-
prefixCls,
|
|
47
|
-
rootClassName,
|
|
48
|
-
`${prefixCls}-${type}`,
|
|
49
|
-
`${prefixCls}-${variant}`,
|
|
50
|
-
`${prefixCls}-${color}`,
|
|
51
|
-
`${prefixCls}-${shape}`,
|
|
52
|
-
`${prefixCls}-size-${size}`,
|
|
53
|
-
{
|
|
54
|
-
[`${prefixCls}-block`]: block,
|
|
55
|
-
[`${prefixCls}-ghost`]: ghost,
|
|
56
|
-
[`${prefixCls}-danger`]: danger,
|
|
57
|
-
[`${prefixCls}-loading`]: innerLoading,
|
|
58
|
-
[`${prefixCls}-disabled`]: disabled
|
|
59
|
-
},
|
|
60
|
-
className
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const iconNode = useMemo(() => {
|
|
64
|
-
return innerLoading
|
|
65
|
-
? (typeof loading === 'object' && loading.icon) || (
|
|
66
|
-
<span className={`${prefixCls}-spinner`}></span>
|
|
67
|
-
)
|
|
68
|
-
: icon;
|
|
69
|
-
}, [icon, innerLoading, loading, prefixCls]);
|
|
70
|
-
|
|
71
|
-
const content = useMemo(() => {
|
|
72
|
-
return (
|
|
73
|
-
<>
|
|
74
|
-
{iconNode && iconPosition === 'start' && (
|
|
75
|
-
<span
|
|
76
|
-
className={clsx(`${prefixCls}-icon`, customClassNames.icon)}
|
|
77
|
-
style={styles.icon}
|
|
78
|
-
>
|
|
79
|
-
{iconNode}
|
|
80
|
-
</span>
|
|
81
|
-
)}
|
|
82
|
-
<span className={`${prefixCls}-content`}>{children}</span>
|
|
83
|
-
{iconNode && iconPosition === 'end' && (
|
|
84
|
-
<span
|
|
85
|
-
className={clsx(`${prefixCls}-icon`, customClassNames.icon)}
|
|
86
|
-
style={styles.icon}
|
|
87
|
-
>
|
|
88
|
-
{iconNode}
|
|
89
|
-
</span>
|
|
90
|
-
)}
|
|
91
|
-
</>
|
|
92
|
-
);
|
|
93
|
-
}, [children, customClassNames.icon, iconNode, iconPosition, prefixCls, styles.icon]);
|
|
94
|
-
|
|
95
|
-
const mergedDisabled = disabled || innerLoading;
|
|
96
|
-
|
|
97
|
-
if (href) {
|
|
98
|
-
return (
|
|
99
|
-
<a
|
|
100
|
-
className={classes}
|
|
101
|
-
href={mergedDisabled ? undefined : href}
|
|
102
|
-
aria-disabled={mergedDisabled}
|
|
103
|
-
>
|
|
104
|
-
{content}
|
|
105
|
-
</a>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<button
|
|
111
|
-
type={htmlType}
|
|
112
|
-
className={classes}
|
|
113
|
-
disabled={mergedDisabled}
|
|
114
|
-
{...restProps}
|
|
115
|
-
>
|
|
116
|
-
{content}
|
|
117
|
-
</button>
|
|
118
|
-
);
|
|
119
|
-
};
|