x-ui-design 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src/app/globals.css +1 -0
- package/src/app/page.tsx +143 -11
- package/src/xUiDesign/components/Button/index.tsx +114 -0
- package/src/xUiDesign/components/Button/style.css +197 -0
- package/src/xUiDesign/components/Checkbox/index.tsx +90 -85
- package/src/xUiDesign/components/DatePicker/RangePicker/index.tsx +7 -4
- package/src/xUiDesign/components/DatePicker/RangePicker/style.css +4 -4
- package/src/xUiDesign/components/DatePicker/TimePicker/index.tsx +1 -2
- package/src/xUiDesign/components/DatePicker/index.tsx +3 -3
- package/src/xUiDesign/components/DatePicker/style.css +0 -5
- package/src/xUiDesign/components/Form/Item/index.tsx +2 -2
- package/src/xUiDesign/components/Form/index.tsx +1 -1
- package/src/xUiDesign/components/Input/Textarea/index.tsx +2 -2
- package/src/xUiDesign/components/Input/index.tsx +1 -1
- package/src/xUiDesign/components/Radio/Button/index.tsx +4 -4
- package/src/xUiDesign/components/Radio/Group/index.tsx +5 -5
- package/src/xUiDesign/components/Radio/index.tsx +2 -2
- package/src/xUiDesign/components/Select/Option/index.tsx +4 -2
- package/src/xUiDesign/components/Select/index.tsx +565 -542
- package/src/xUiDesign/components/Skeleton/Avatar/index.tsx +59 -0
- package/src/xUiDesign/components/Skeleton/Avatar/style.css +27 -0
- package/src/xUiDesign/components/Skeleton/Button/index.tsx +42 -0
- package/src/xUiDesign/components/Skeleton/Button/style.css +50 -0
- package/src/xUiDesign/components/Skeleton/Image/index.tsx +43 -0
- package/src/xUiDesign/components/Skeleton/Image/style.css +21 -0
- package/src/xUiDesign/components/Skeleton/Input/index.tsx +40 -0
- package/src/xUiDesign/components/Skeleton/Input/style.css +56 -0
- package/src/xUiDesign/components/Skeleton/index.tsx +92 -0
- package/src/xUiDesign/components/Skeleton/style.css +84 -0
- package/src/xUiDesign/components/Upload/index.tsx +1 -1
- package/src/xUiDesign/helpers/index.ts +4 -0
- package/src/xUiDesign/hooks/useForm.ts +11 -6
- package/src/xUiDesign/types/button.ts +81 -0
- package/src/xUiDesign/types/form.ts +14 -15
- package/src/xUiDesign/types/input.ts +6 -2
- package/src/xUiDesign/types/select.ts +6 -2
- package/src/xUiDesign/types/skeleton.ts +62 -0
- package/src/xUiDesign/utils/index.ts +2 -0
package/package.json
CHANGED
package/src/app/globals.css
CHANGED
package/src/app/page.tsx
CHANGED
|
@@ -1,18 +1,150 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import Button from "@/xUiDesign/components/Button"
|
|
4
|
+
import { Button as AntButton, Flex } from "antd"
|
|
4
5
|
|
|
5
6
|
export default function Home() {
|
|
6
7
|
return (
|
|
7
|
-
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
<div style={{ display: 'flex', gap: '100px' }}>
|
|
9
|
+
<div>
|
|
10
|
+
<h2>xUiDesign Button</h2>
|
|
11
|
+
<Flex gap="small" align="flex-start" vertical>
|
|
12
|
+
<Flex gap="small">
|
|
13
|
+
<Button type="primary">Primary</Button>
|
|
14
|
+
<Button type="primary" disabled>
|
|
15
|
+
Primary(disabled)
|
|
16
|
+
</Button>
|
|
17
|
+
</Flex>
|
|
18
|
+
<Flex gap="small">
|
|
19
|
+
<Button>Default</Button>
|
|
20
|
+
<Button disabled>Default(disabled)</Button>
|
|
21
|
+
</Flex>
|
|
22
|
+
<Flex gap="small">
|
|
23
|
+
<Button type="dashed">Dashed</Button>
|
|
24
|
+
<Button type="dashed" disabled>
|
|
25
|
+
Dashed(disabled)
|
|
26
|
+
</Button>
|
|
27
|
+
</Flex>
|
|
28
|
+
<Flex gap="small">
|
|
29
|
+
<Button type="text">Text</Button>
|
|
30
|
+
<Button type="text" disabled>
|
|
31
|
+
Text(disabled)
|
|
32
|
+
</Button>
|
|
33
|
+
</Flex>
|
|
34
|
+
<Flex gap="small">
|
|
35
|
+
<Button href="https://vran.am" type="link">Link</Button>
|
|
36
|
+
<Button href="https://vran.am" type="link" disabled>
|
|
37
|
+
Link(disabled)
|
|
38
|
+
</Button>
|
|
39
|
+
</Flex>
|
|
40
|
+
<Flex gap="small">
|
|
41
|
+
<Button type="primary" href="https://ant.design/index-cn">
|
|
42
|
+
Href Primary
|
|
43
|
+
</Button>
|
|
44
|
+
<Button type="primary" href="https://ant.design/index-cn" disabled>
|
|
45
|
+
Href Primary(disabled)
|
|
46
|
+
</Button>
|
|
47
|
+
</Flex>
|
|
48
|
+
<Flex gap="small">
|
|
49
|
+
<Button danger>Danger Default</Button>
|
|
50
|
+
<Button danger disabled>
|
|
51
|
+
Danger Default(disabled)
|
|
52
|
+
</Button>
|
|
53
|
+
</Flex>
|
|
54
|
+
<Flex gap="small">
|
|
55
|
+
<Button danger type="text">
|
|
56
|
+
Danger Text
|
|
57
|
+
</Button>
|
|
58
|
+
<Button danger type="text" disabled>
|
|
59
|
+
Danger Text(disabled)
|
|
60
|
+
</Button>
|
|
61
|
+
</Flex>
|
|
62
|
+
<Flex gap="small">
|
|
63
|
+
<Button href="https://vran.am" type="link" danger>
|
|
64
|
+
Danger Link
|
|
65
|
+
</Button>
|
|
66
|
+
<Button href="https://vran.am" type="link" danger disabled>
|
|
67
|
+
Danger Link(disabled)
|
|
68
|
+
</Button>
|
|
69
|
+
</Flex>
|
|
70
|
+
<Flex gap="small" className="site-button-ghost-wrapper">
|
|
71
|
+
<Button ghost>Ghost</Button>
|
|
72
|
+
<Button ghost disabled>
|
|
73
|
+
Ghost(disabled)
|
|
74
|
+
</Button>
|
|
75
|
+
</Flex>
|
|
76
|
+
</Flex>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
<div>
|
|
80
|
+
<h2>Ant Design Button</h2>
|
|
81
|
+
<Flex gap="small" align="flex-start" vertical>
|
|
82
|
+
<Flex gap="small">
|
|
83
|
+
<AntButton type="primary">Primary</AntButton>
|
|
84
|
+
<AntButton type="primary" disabled>
|
|
85
|
+
Primary(disabled)
|
|
86
|
+
</AntButton>
|
|
87
|
+
</Flex>
|
|
88
|
+
<Flex gap="small">
|
|
89
|
+
<AntButton>Default</AntButton>
|
|
90
|
+
<AntButton disabled>Default(disabled)</AntButton>
|
|
91
|
+
</Flex>
|
|
92
|
+
<Flex gap="small">
|
|
93
|
+
<AntButton type="dashed">Dashed</AntButton>
|
|
94
|
+
<AntButton type="dashed" disabled>
|
|
95
|
+
Dashed(disabled)
|
|
96
|
+
</AntButton>
|
|
97
|
+
</Flex>
|
|
98
|
+
<Flex gap="small">
|
|
99
|
+
<AntButton type="text">Text</AntButton>
|
|
100
|
+
<AntButton type="text" disabled>
|
|
101
|
+
Text(disabled)
|
|
102
|
+
</AntButton>
|
|
103
|
+
</Flex>
|
|
104
|
+
<Flex gap="small">
|
|
105
|
+
<AntButton href="https://vran.am" type="link">Link</AntButton>
|
|
106
|
+
<AntButton href="https://vran.am" type="link" disabled>
|
|
107
|
+
Link(disabled)
|
|
108
|
+
</AntButton>
|
|
109
|
+
</Flex>
|
|
110
|
+
<Flex gap="small">
|
|
111
|
+
<AntButton type="primary" href="https://ant.design/index-cn">
|
|
112
|
+
Href Primary
|
|
113
|
+
</AntButton>
|
|
114
|
+
<AntButton type="primary" href="https://ant.design/index-cn" disabled>
|
|
115
|
+
Href Primary(disabled)
|
|
116
|
+
</AntButton>
|
|
117
|
+
</Flex>
|
|
118
|
+
<Flex gap="small">
|
|
119
|
+
<AntButton danger>Danger Default</AntButton>
|
|
120
|
+
<AntButton danger disabled>
|
|
121
|
+
Danger Default(disabled)
|
|
122
|
+
</AntButton>
|
|
123
|
+
</Flex>
|
|
124
|
+
<Flex gap="small">
|
|
125
|
+
<AntButton danger type="text">
|
|
126
|
+
Danger Text
|
|
127
|
+
</AntButton>
|
|
128
|
+
<AntButton danger type="text" disabled>
|
|
129
|
+
Danger Text(disabled)
|
|
130
|
+
</AntButton>
|
|
131
|
+
</Flex>
|
|
132
|
+
<Flex gap="small">
|
|
133
|
+
<AntButton href="https://vran.am" type="link" danger>
|
|
134
|
+
Danger Link
|
|
135
|
+
</AntButton>
|
|
136
|
+
<AntButton href="https://vran.am" type="link" danger disabled>
|
|
137
|
+
Danger Link(disabled)
|
|
138
|
+
</AntButton>
|
|
139
|
+
</Flex>
|
|
140
|
+
<Flex gap="small" className="site-Antbutton-ghost-wrapper">
|
|
141
|
+
<AntButton ghost>Ghost</AntButton>
|
|
142
|
+
<AntButton ghost disabled>
|
|
143
|
+
Ghost(disabled)
|
|
144
|
+
</AntButton>
|
|
145
|
+
</Flex>
|
|
146
|
+
</Flex>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
17
149
|
)
|
|
18
150
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ReactElement, useEffect, useState } from 'react';
|
|
2
|
+
import { clsx } from '@/xUiDesign/helpers';
|
|
3
|
+
import { ButtonProps } from '@/xUiDesign/types/button';
|
|
4
|
+
import { prefixClsButton } from '@/xUiDesign/utils';
|
|
5
|
+
import './style.css';
|
|
6
|
+
|
|
7
|
+
export const ButtonComponent = ({
|
|
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, setInnerLoading] = useState(false);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (typeof loading === 'boolean') {
|
|
34
|
+
setInnerLoading(loading);
|
|
35
|
+
} else if (typeof loading === 'object' && loading.delay) {
|
|
36
|
+
const timeout = setTimeout(() => setInnerLoading(true), loading.delay);
|
|
37
|
+
|
|
38
|
+
return () => clearTimeout(timeout);
|
|
39
|
+
} else {
|
|
40
|
+
setInnerLoading(!!loading);
|
|
41
|
+
}
|
|
42
|
+
}, [loading]);
|
|
43
|
+
|
|
44
|
+
const classes = clsx(
|
|
45
|
+
prefixCls,
|
|
46
|
+
rootClassName,
|
|
47
|
+
`${prefixCls}-${type}`,
|
|
48
|
+
`${prefixCls}-${variant}`,
|
|
49
|
+
`${prefixCls}-${color}`,
|
|
50
|
+
`${prefixCls}-${shape}`,
|
|
51
|
+
`${prefixCls}-size-${size}`,
|
|
52
|
+
{
|
|
53
|
+
[`${prefixCls}-block`]: block,
|
|
54
|
+
[`${prefixCls}-ghost`]: ghost,
|
|
55
|
+
[`${prefixCls}-danger`]: danger,
|
|
56
|
+
[`${prefixCls}-loading`]: innerLoading,
|
|
57
|
+
[`${prefixCls}-disabled`]: disabled
|
|
58
|
+
},
|
|
59
|
+
className
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const iconNode = innerLoading
|
|
63
|
+
? (typeof loading === 'object' && loading.icon) || (
|
|
64
|
+
<span className={`${prefixCls}-spinner`} />
|
|
65
|
+
)
|
|
66
|
+
: icon;
|
|
67
|
+
|
|
68
|
+
const content = (
|
|
69
|
+
<>
|
|
70
|
+
{iconNode && iconPosition === 'start' && (
|
|
71
|
+
<span
|
|
72
|
+
className={clsx(`${prefixCls}-icon`, customClassNames.icon)}
|
|
73
|
+
style={styles.icon}
|
|
74
|
+
>
|
|
75
|
+
{iconNode}
|
|
76
|
+
</span>
|
|
77
|
+
)}
|
|
78
|
+
<span className={`${prefixCls}-content`}>{children}</span>
|
|
79
|
+
{iconNode && iconPosition === 'end' && (
|
|
80
|
+
<span
|
|
81
|
+
className={clsx(`${prefixCls}-icon`, customClassNames.icon)}
|
|
82
|
+
style={styles.icon}
|
|
83
|
+
>
|
|
84
|
+
{iconNode}
|
|
85
|
+
</span>
|
|
86
|
+
)}
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const mergedDisabled = disabled || innerLoading;
|
|
91
|
+
|
|
92
|
+
if (href) {
|
|
93
|
+
return (
|
|
94
|
+
<a
|
|
95
|
+
className={classes}
|
|
96
|
+
href={mergedDisabled ? undefined : href}
|
|
97
|
+
aria-disabled={mergedDisabled}
|
|
98
|
+
>
|
|
99
|
+
{content}
|
|
100
|
+
</a>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<button
|
|
106
|
+
type={htmlType}
|
|
107
|
+
className={classes}
|
|
108
|
+
disabled={mergedDisabled}
|
|
109
|
+
{...restProps}
|
|
110
|
+
>
|
|
111
|
+
{content}
|
|
112
|
+
</button>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
.xUi-button {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
font-weight: 400;
|
|
6
|
+
white-space: nowrap;
|
|
7
|
+
vertical-align: middle;
|
|
8
|
+
user-select: none;
|
|
9
|
+
border: 1px solid transparent;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
transition: all 0.3s ease;
|
|
12
|
+
border-radius: 6px;
|
|
13
|
+
line-height: 1.5715;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.xUi-button-content {
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.xUi-button-icon {
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
line-height: 0;
|
|
27
|
+
margin-right: 0.5em;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.xUi-button-icon:last-child {
|
|
31
|
+
margin-right: 0;
|
|
32
|
+
margin-left: 0.5em;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.xUi-button-spinner {
|
|
36
|
+
width: 1em;
|
|
37
|
+
height: 1em;
|
|
38
|
+
border: 1px solid transparent;
|
|
39
|
+
border-top-color: var(--xui-text-color);
|
|
40
|
+
border-radius: 50%;
|
|
41
|
+
animation: xUi-spin 1s linear infinite;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@keyframes xUi-spin {
|
|
45
|
+
0% {
|
|
46
|
+
transform: rotate(0deg);
|
|
47
|
+
}
|
|
48
|
+
100% {
|
|
49
|
+
transform: rotate(360deg);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.xUi-button-size-small {
|
|
54
|
+
padding: 4px 12px;
|
|
55
|
+
font-size: 12px;
|
|
56
|
+
height: 24px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.xUi-button-size-middle {
|
|
60
|
+
padding: 0 16px;
|
|
61
|
+
font-size: 14px;
|
|
62
|
+
height: 32px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.xUi-button-size-large {
|
|
66
|
+
padding: 8px 20px;
|
|
67
|
+
font-size: 16px;
|
|
68
|
+
height: 40px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.xUi-button-circle {
|
|
72
|
+
padding: 0;
|
|
73
|
+
border-radius: 50%;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.xUi-button-circle.xUi-button-size-small {
|
|
78
|
+
width: 24px;
|
|
79
|
+
height: 24px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.xUi-button-circle.xUi-button-size-large {
|
|
83
|
+
width: 40px;
|
|
84
|
+
height: 40px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.xUi-button-round {
|
|
88
|
+
border-radius: 9999px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.xUi-button-default {
|
|
92
|
+
background-color: #fff;
|
|
93
|
+
border-color: var(--xui-border-color);
|
|
94
|
+
color: rgba(0, 0, 0, 0.85);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.xUi-button-default:hover {
|
|
98
|
+
border-color: var(--xui-primary-color);
|
|
99
|
+
color: var(--xui-primary-color);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.xUi-button-primary {
|
|
103
|
+
background-color: var(--xui-primary-color);
|
|
104
|
+
border-color: var(--xui-primary-color);
|
|
105
|
+
color: #fff;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.xUi-button-primary:hover {
|
|
109
|
+
background-color: var(--xui-primary-color-light);
|
|
110
|
+
border-color: var(--xui-primary-color-light);
|
|
111
|
+
color: #fff;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.xUi-button-dashed {
|
|
115
|
+
border-style: dashed;
|
|
116
|
+
background-color: #fff;
|
|
117
|
+
color: rgba(0, 0, 0, 0.85);
|
|
118
|
+
border-color: var(--xui-border-color);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.xUi-button-dashed:hover {
|
|
122
|
+
border-color: var(--xui-primary-color);
|
|
123
|
+
color: var(--xui-primary-color);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.xUi-button-text {
|
|
127
|
+
background-color: transparent;
|
|
128
|
+
border-color: transparent !important;
|
|
129
|
+
color: rgba(0, 0, 0, 0.88);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.xUi-button-text:hover {
|
|
133
|
+
color: rgba(0, 0, 0, 0.88);
|
|
134
|
+
border-color: transparent;
|
|
135
|
+
background-color: rgba(0, 0, 0, 0.04);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.xUi-button-link {
|
|
139
|
+
background-color: transparent;
|
|
140
|
+
border-color: transparent !important;
|
|
141
|
+
color: var(--xui-primary-color);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.xUi-button-link:hover {
|
|
145
|
+
border-color: transparent;
|
|
146
|
+
color: var(--xui-primary-color-light);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.xUi-button-outlined {
|
|
150
|
+
background-color: transparent;
|
|
151
|
+
border-color: var(--xui-border-color);
|
|
152
|
+
color: #fff;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.xUi-button-filled {
|
|
156
|
+
background-color: transparent;
|
|
157
|
+
color: var(--xui-text-color);
|
|
158
|
+
border-color: var(--xui-border-color);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.xUi-button-danger {
|
|
162
|
+
background-color: transparent;
|
|
163
|
+
border-color: var(--xui-error-color);
|
|
164
|
+
color: var(--xui-error-color);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.xUi-button-danger:hover {
|
|
168
|
+
color: var(--xui-error-color-light);
|
|
169
|
+
border-color: var(--xui-error-color-light);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.xUi-button-ghost {
|
|
173
|
+
opacity: 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.xUi-button-ghost:hover {
|
|
177
|
+
opacity: 1;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.xUi-button-block {
|
|
181
|
+
display: flex;
|
|
182
|
+
width: 100%;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.xUi-button-disabled,
|
|
186
|
+
.xUi-button-loading {
|
|
187
|
+
cursor: not-allowed;
|
|
188
|
+
opacity: 0.5;
|
|
189
|
+
color: var(--xui-text-color);
|
|
190
|
+
border-color: var(--xui-border-color);
|
|
191
|
+
background-color: var(--xui-color-disabled);
|
|
192
|
+
pointer-events: none;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.xUi-button-loading {
|
|
196
|
+
background-color: transparent
|
|
197
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
ForwardedRef,
|
|
@@ -8,103 +8,108 @@ import {
|
|
|
8
8
|
useEffect,
|
|
9
9
|
useState
|
|
10
10
|
} from 'react';
|
|
11
|
+
import { clsx } from '@/xUiDesign/helpers';
|
|
11
12
|
import { SyntheticBaseEvent } from '@/xUiDesign/types';
|
|
12
13
|
import { CheckboxProps } from '@/xUiDesign/types/checkbox';
|
|
13
14
|
import { prefixClsCheckbox } from '@/xUiDesign/utils';
|
|
14
15
|
import './style.css';
|
|
15
|
-
import { clsx } from '@/xUiDesign/helpers';
|
|
16
16
|
|
|
17
|
-
const Checkbox = forwardRef<HTMLDivElement, CheckboxProps>(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
17
|
+
const Checkbox = forwardRef<HTMLDivElement, CheckboxProps>(
|
|
18
|
+
(
|
|
19
|
+
{
|
|
20
|
+
prefixCls = prefixClsCheckbox,
|
|
21
|
+
className = '',
|
|
22
|
+
defaultChecked = false,
|
|
23
|
+
checked,
|
|
24
|
+
style,
|
|
25
|
+
disabled = false,
|
|
26
|
+
onChange,
|
|
27
|
+
onClick,
|
|
28
|
+
onMouseEnter,
|
|
29
|
+
onMouseLeave,
|
|
30
|
+
onKeyPress,
|
|
31
|
+
onKeyDown,
|
|
32
|
+
tabIndex,
|
|
33
|
+
name,
|
|
34
|
+
children,
|
|
35
|
+
id,
|
|
36
|
+
autoFocus,
|
|
37
|
+
type = 'checkbox',
|
|
38
|
+
value = false,
|
|
39
|
+
required = false,
|
|
40
|
+
noStyle
|
|
41
|
+
},
|
|
42
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
43
|
+
): ReactElement => {
|
|
44
|
+
const isChecked = checked !== undefined ? checked : defaultChecked || value;
|
|
45
|
+
const [internalChecked, setInternalChecked] = useState(isChecked);
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
const handleClick = (
|
|
48
|
+
e: MouseEvent<HTMLInputElement> & SyntheticBaseEvent
|
|
49
|
+
) => {
|
|
50
|
+
e.stopPropagation();
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
if (disabled) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
setInternalChecked(!internalChecked);
|
|
57
|
+
e.target.value = !internalChecked;
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
onClick?.(e);
|
|
60
|
+
onChange?.(e);
|
|
61
|
+
};
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (checked !== undefined) {
|
|
65
|
+
setInternalChecked(checked);
|
|
66
|
+
}
|
|
67
|
+
}, [checked]);
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
return (
|
|
70
|
+
<div className={`${prefixCls}-wrapper`}>
|
|
71
|
+
<div
|
|
72
|
+
ref={ref}
|
|
73
|
+
style={style}
|
|
74
|
+
onClick={handleClick}
|
|
75
|
+
className={clsx([
|
|
76
|
+
prefixCls,
|
|
77
|
+
className,
|
|
78
|
+
{
|
|
79
|
+
noStyle: noStyle,
|
|
80
|
+
[`${prefixCls}-disabled`]: disabled,
|
|
81
|
+
[`${prefixCls}-checked`]: internalChecked
|
|
82
|
+
}
|
|
83
|
+
])}
|
|
84
|
+
>
|
|
85
|
+
<input
|
|
86
|
+
id={id}
|
|
87
|
+
type={type}
|
|
88
|
+
name={name}
|
|
89
|
+
disabled={disabled}
|
|
90
|
+
tabIndex={tabIndex}
|
|
91
|
+
required={required}
|
|
92
|
+
autoFocus={autoFocus}
|
|
93
|
+
onKeyDown={onKeyDown}
|
|
94
|
+
onKeyPress={onKeyPress}
|
|
95
|
+
onMouseEnter={onMouseEnter}
|
|
96
|
+
onMouseLeave={onMouseLeave}
|
|
97
|
+
/>
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
<span className={`${prefixCls}-box`}>
|
|
100
|
+
<span
|
|
101
|
+
className={`${prefixCls}-check`}
|
|
102
|
+
style={{ opacity: Number(internalChecked) }}
|
|
103
|
+
/>
|
|
104
|
+
</span>
|
|
105
|
+
</div>
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
+
{children && <span className={`${prefixCls}-label`}>{children}</span>}
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
);
|
|
107
112
|
|
|
108
|
-
Checkbox.displayName =
|
|
113
|
+
Checkbox.displayName = 'Checkbox';
|
|
109
114
|
|
|
110
115
|
export { Checkbox };
|