refactor: update Button component props to use TypeScript types and default values
parent
5a768e2ae4
commit
bacb790bfb
|
@ -17,16 +17,16 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { buttonProps, buttonEmits, ButtonSlots } from './meta'
|
import { ButtonSlots, ButtonProps, ButtonEmits, buttonDefaultProps } from './meta'
|
||||||
import { getCssVarColor } from '@/utils/colorAlgorithm'
|
import { getCssVarColor } from '@/utils/colorAlgorithm'
|
||||||
import { useThemeInject } from '../theme/hook'
|
import { useThemeInject } from '../theme/hook'
|
||||||
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'
|
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'
|
||||||
import { defaultColor } from '../theme/meta'
|
import { defaultColor } from '../theme/meta'
|
||||||
import { Wave } from '../wave'
|
import { Wave } from '../wave'
|
||||||
|
|
||||||
const props = defineProps(buttonProps)
|
const props = withDefaults(defineProps<ButtonProps>(), buttonDefaultProps)
|
||||||
const buttonRef = ref<HTMLButtonElement | null>(null)
|
const buttonRef = ref<HTMLButtonElement | null>(null)
|
||||||
const emit = defineEmits(buttonEmits)
|
const emit = defineEmits<ButtonEmits>()
|
||||||
defineSlots<ButtonSlots>()
|
defineSlots<ButtonSlots>()
|
||||||
|
|
||||||
const theme = useThemeInject()
|
const theme = useThemeInject()
|
||||||
|
|
|
@ -1,110 +1,75 @@
|
||||||
import { PropType, ExtractPublicPropTypes } from 'vue'
|
export type ButtonProps = {
|
||||||
|
|
||||||
// Button Props
|
|
||||||
export const buttonProps = {
|
|
||||||
/**
|
/**
|
||||||
* Specifies the visual style variant of the button
|
* Specifies the visual style variant of the button
|
||||||
* @default 'primary'
|
* @default 'primary'
|
||||||
*/
|
*/
|
||||||
variant: {
|
variant?: 'solid' | 'outlined' | 'text' | 'link' | 'dashed' | 'filled'
|
||||||
type: String as PropType<'solid' | 'outlined' | 'text' | 'link' | 'dashed' | 'filled'>,
|
|
||||||
default: 'solid',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the size of the button
|
* Specifies the size of the button
|
||||||
* @default 'md'
|
* @default 'md'
|
||||||
*/
|
*/
|
||||||
size: {
|
size?: 'sm' | 'md' | 'lg'
|
||||||
type: String as PropType<'sm' | 'md' | 'lg'>,
|
|
||||||
default: 'md',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the shape of the button
|
* Specifies the shape of the button
|
||||||
* @default 'default'
|
* @default 'default'
|
||||||
*/
|
*/
|
||||||
shape: {
|
shape?: 'default' | 'circle' | 'round'
|
||||||
type: String as PropType<'default' | 'circle' | 'round'>,
|
|
||||||
default: 'default',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the loading state of the button
|
* Specifies the loading state of the button
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
loading: {
|
loading?: boolean
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the disabled state of the button
|
* Specifies the disabled state of the button
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
disabled: {
|
disabled?: boolean
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the danger state of the button
|
* Specifies the danger state of the button
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
danger: {
|
danger?: boolean
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the color of the button
|
* Specifies the color of the button
|
||||||
*/
|
*/
|
||||||
color: {
|
color?: string
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the href of the button
|
* Specifies the href of the button
|
||||||
*/
|
*/
|
||||||
href: {
|
href?: string
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the target of the button
|
* Specifies the target of the button
|
||||||
*/
|
*/
|
||||||
target: {
|
target?: string
|
||||||
type: String,
|
}
|
||||||
},
|
|
||||||
|
export const buttonDefaultProps = {
|
||||||
|
variant: 'solid',
|
||||||
|
size: 'md',
|
||||||
|
shape: 'default',
|
||||||
|
loading: false,
|
||||||
|
disabled: false,
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>
|
export type ButtonEmits = {
|
||||||
|
|
||||||
// Button Emits
|
|
||||||
export const buttonEmits = {
|
|
||||||
/**
|
/**
|
||||||
* Triggered when the button is clicked by the user
|
* Triggered when the button is clicked by the user
|
||||||
* @param e - The native MouseEvent object
|
* @param e - The native MouseEvent object
|
||||||
*/
|
*/
|
||||||
click: (e: MouseEvent) => e instanceof MouseEvent,
|
(e: 'click', event: MouseEvent): void
|
||||||
} as const
|
}
|
||||||
|
|
||||||
export type ButtonEmits = typeof buttonEmits
|
export type ButtonSlots = {
|
||||||
|
|
||||||
// Button Slots
|
|
||||||
export const buttonSlots = {
|
|
||||||
/**
|
/**
|
||||||
* Main content slot for the button text or custom content
|
* Main content slot for the button text or custom content
|
||||||
*/
|
*/
|
||||||
default: (_: any) => null as any,
|
default?: (_: any) => any
|
||||||
/**
|
/**
|
||||||
* Slot for the button icon
|
* Slot for the button icon
|
||||||
*/
|
*/
|
||||||
icon: (_: any) => null as any,
|
icon?: (_: any) => any
|
||||||
/**
|
/**
|
||||||
* Slot for the button loading indicator
|
* Slot for the button loading indicator
|
||||||
*/
|
*/
|
||||||
loading: (_: any) => null as any,
|
loading?: (_: any) => any
|
||||||
} as const
|
}
|
||||||
|
|
||||||
export type ButtonSlots = Partial<typeof buttonSlots>
|
|
||||||
|
|
Loading…
Reference in New Issue