Skip to content

Commit bacb790

Browse files
committed
refactor: update Button component props to use TypeScript types and default values
1 parent 5a768e2 commit bacb790

File tree

2 files changed

+29
-64
lines changed

2 files changed

+29
-64
lines changed

packages/ui/src/components/button/Button.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
<script setup lang="ts">
1919
import { computed, ref } from 'vue'
20-
import { buttonProps, buttonEmits, ButtonSlots } from './meta'
20+
import { ButtonSlots, ButtonProps, ButtonEmits, buttonDefaultProps } from './meta'
2121
import { getCssVarColor } from '@/utils/colorAlgorithm'
2222
import { useThemeInject } from '../theme/hook'
2323
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'
2424
import { defaultColor } from '../theme/meta'
2525
import { Wave } from '../wave'
2626
27-
const props = defineProps(buttonProps)
27+
const props = withDefaults(defineProps<ButtonProps>(), buttonDefaultProps)
2828
const buttonRef = ref<HTMLButtonElement | null>(null)
29-
const emit = defineEmits(buttonEmits)
29+
const emit = defineEmits<ButtonEmits>()
3030
defineSlots<ButtonSlots>()
3131
3232
const theme = useThemeInject()
Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,75 @@
1-
import { PropType, ExtractPublicPropTypes } from 'vue'
2-
3-
// Button Props
4-
export const buttonProps = {
1+
export type ButtonProps = {
52
/**
63
* Specifies the visual style variant of the button
74
* @default 'primary'
85
*/
9-
variant: {
10-
type: String as PropType<'solid' | 'outlined' | 'text' | 'link' | 'dashed' | 'filled'>,
11-
default: 'solid',
12-
},
13-
6+
variant?: 'solid' | 'outlined' | 'text' | 'link' | 'dashed' | 'filled'
147
/**
158
* Specifies the size of the button
169
* @default 'md'
1710
*/
18-
size: {
19-
type: String as PropType<'sm' | 'md' | 'lg'>,
20-
default: 'md',
21-
},
22-
11+
size?: 'sm' | 'md' | 'lg'
2312
/**
2413
* Specifies the shape of the button
2514
* @default 'default'
2615
*/
27-
shape: {
28-
type: String as PropType<'default' | 'circle' | 'round'>,
29-
default: 'default',
30-
},
31-
16+
shape?: 'default' | 'circle' | 'round'
3217
/**
3318
* Specifies the loading state of the button
3419
* @default false
3520
*/
36-
loading: {
37-
type: Boolean,
38-
default: false,
39-
},
40-
21+
loading?: boolean
4122
/**
4223
* Specifies the disabled state of the button
4324
* @default false
4425
*/
45-
disabled: {
46-
type: Boolean,
47-
default: false,
48-
},
49-
26+
disabled?: boolean
5027
/**
5128
* Specifies the danger state of the button
5229
* @default false
5330
*/
54-
danger: {
55-
type: Boolean,
56-
default: false,
57-
},
58-
31+
danger?: boolean
5932
/**
6033
* Specifies the color of the button
6134
*/
62-
color: {
63-
type: String,
64-
},
65-
35+
color?: string
6636
/**
6737
* Specifies the href of the button
6838
*/
69-
href: {
70-
type: String,
71-
},
72-
39+
href?: string
7340
/**
7441
* Specifies the target of the button
7542
*/
76-
target: {
77-
type: String,
78-
},
79-
} as const
43+
target?: string
44+
}
8045

81-
export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>
46+
export const buttonDefaultProps = {
47+
variant: 'solid',
48+
size: 'md',
49+
shape: 'default',
50+
loading: false,
51+
disabled: false,
52+
} as const
8253

83-
// Button Emits
84-
export const buttonEmits = {
54+
export type ButtonEmits = {
8555
/**
8656
* Triggered when the button is clicked by the user
8757
* @param e - The native MouseEvent object
8858
*/
89-
click: (e: MouseEvent) => e instanceof MouseEvent,
90-
} as const
59+
(e: 'click', event: MouseEvent): void
60+
}
9161

92-
export type ButtonEmits = typeof buttonEmits
93-
94-
// Button Slots
95-
export const buttonSlots = {
62+
export type ButtonSlots = {
9663
/**
9764
* Main content slot for the button text or custom content
9865
*/
99-
default: (_: any) => null as any,
66+
default?: (_: any) => any
10067
/**
10168
* Slot for the button icon
10269
*/
103-
icon: (_: any) => null as any,
70+
icon?: (_: any) => any
10471
/**
10572
* Slot for the button loading indicator
10673
*/
107-
loading: (_: any) => null as any,
108-
} as const
109-
110-
export type ButtonSlots = Partial<typeof buttonSlots>
74+
loading?: (_: any) => any
75+
}

0 commit comments

Comments
 (0)