Skip to content

Commit f70d71a

Browse files
authored
fix: 优化Button组件API,抽离逻辑,更新其他组件demo中Button的用法 (#230)
1 parent 658c990 commit f70d71a

File tree

17 files changed

+484
-610
lines changed

17 files changed

+484
-610
lines changed
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import type { App } from 'vue'
2-
import Button from './src/button'
3-
import { Loading } from '../loading/index'
1+
import type { App } from 'vue';
2+
import Button from './src/button';
43

5-
Button.install = function (app: App) {
6-
app.directive('dLoading', Loading)
7-
app.component(Button.name, Button)
8-
}
4+
export * from './src/button-types';
95

10-
export * from './src/button-types'
11-
12-
export { Button }
6+
export { Button };
137

148
export default {
159
title: 'Button 按钮',
1610
category: '通用',
1711
status: '100%',
1812
install(app: App): void {
19-
app.use(Button as any)
20-
}
21-
}
13+
app.component(Button.name, Button);
14+
},
15+
};
Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,40 @@
1-
import { ExtractPropTypes, PropType } from 'vue';
1+
import type { ComputedRef, ExtractPropTypes, PropType } from 'vue';
22

3-
export type IButtonType = 'button' | 'submit' | 'reset';
4-
export type IButtonVariant = 'common' | 'primary' | 'text' | 'text-dark' | 'danger' | 'success' | 'warning';
5-
export type IButtonPosition = 'left' | 'right' | 'default';
3+
export type IButtonVariant = 'solid' | 'outline' | 'text';
4+
export type IButtonColor = 'secondary' | 'primary' | 'danger';
65
export type IButtonSize = 'lg' | 'md' | 'sm' | 'xs';
76

87
export const buttonProps = {
9-
type: {
10-
type: String as PropType<IButtonType>,
11-
default: 'button'
12-
},
138
variant: {
149
type: String as PropType<IButtonVariant>,
15-
default: 'primary'
10+
default: 'outline',
1611
},
1712
size: {
1813
type: String as PropType<IButtonSize>,
19-
default: 'md'
20-
},
21-
position: {
22-
type: String as PropType<IButtonPosition>,
23-
default: 'default'
14+
default: 'md',
2415
},
25-
bordered: {
26-
type: Boolean,
27-
default: false
16+
color: {
17+
type: String as PropType<IButtonColor>,
2818
},
2919
icon: {
3020
type: String,
31-
default: ''
21+
default: '',
3222
},
33-
showLoading: {
23+
loading: {
3424
type: Boolean,
35-
default: false
36-
},
37-
width: {
38-
type: String,
25+
default: false,
3926
},
4027
disabled: {
4128
type: Boolean,
42-
default: false
43-
},
44-
autofocus: {
45-
type: Boolean,
46-
default: false
29+
default: false,
4730
},
48-
onClick: {
49-
type: Function as PropType<(event: MouseEvent) => void>
50-
}
5131
} as const;
5232

33+
export type ButtonProps = ExtractPropTypes<typeof buttonProps>;
5334

54-
export type ButtonProps = ExtractPropTypes<typeof buttonProps>;
35+
export interface UseButtonReturnType {
36+
classes: ComputedRef<{
37+
[key: string]: string | boolean;
38+
}>;
39+
iconClass: ComputedRef<string>;
40+
}

0 commit comments

Comments
 (0)