-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathindex.ts
More file actions
60 lines (54 loc) · 1.43 KB
/
index.ts
File metadata and controls
60 lines (54 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { SetupContext } from 'vue';
import { buttonEmits, buttonProps } from 'element-plus';
export const elxButtonTypes = [
'clear',
'loading',
'send',
'speech',
'speechLoading',
''
] as const;
export const elxButtonProps = {
/**
* @description xButton type
*/
elxButtonType: {
type: String,
values: elxButtonTypes,
default: ''
},
...buttonProps
};
export const elxButtonEmits = {
clear: (evt: MouseEvent) => evt instanceof MouseEvent,
cancel: (evt: MouseEvent) => evt instanceof MouseEvent,
submit: (evt: MouseEvent) => evt instanceof MouseEvent,
...buttonEmits
};
export type ELXButtonProps = Partial<ExtractPropTypes<typeof elxButtonProps>>;
export type ELXButtonEmits = typeof elxButtonEmits;
export type ELXButtonType = ELXButtonProps['elxButtonType'];
export function useButton(
props: ELXButtonProps,
emit: SetupContext<ELXButtonEmits>['emit']
) {
const handleClick = (evt: MouseEvent) => {
if (props.disabled || props.loading) {
evt.stopPropagation();
return;
}
if (props.elxButtonType?.trim()?.length) {
if (props.elxButtonType === 'clear') {
return emit('clear', evt);
} else if (['loading', 'speechLoading'].includes(props.elxButtonType)) {
return emit('cancel', evt);
} else if (props.elxButtonType === 'send') {
return emit('submit', evt);
}
}
emit('click', evt);
};
return {
handleClick
};
}