|
1 | 1 | <script lang="ts" setup>
|
2 |
| -import { computed, ref } from "vue"; |
3 |
| -import { button } from "@heroui/theme"; |
4 |
| -import { useRipple } from "@vue-nextui/shared"; |
| 2 | +import { computed, ref } from 'vue' |
| 3 | +import { button } from '@heroui/theme' |
| 4 | +import { useRipple } from '@vue-nextui/shared' |
5 | 5 |
|
6 | 6 | interface Button {
|
7 |
| - /** |
8 |
| - * 按钮的变体样式 |
9 |
| - */ |
10 |
| - variant: |
11 |
| - | "solid" |
12 |
| - | "bordered" |
13 |
| - | "light" |
14 |
| - | "flat" |
15 |
| - | "faded" |
16 |
| - | "shadow" |
17 |
| - | "ghost"; |
18 |
| -
|
19 |
| - /** |
20 |
| - * 按钮的尺寸 |
21 |
| - */ |
22 |
| - size: "sm" | "md" | "lg"; |
23 |
| -
|
24 |
| - /** |
25 |
| - * 按钮的颜色 |
26 |
| - */ |
27 |
| - color: |
28 |
| - | "default" |
29 |
| - | "primary" |
30 |
| - | "secondary" |
31 |
| - | "success" |
32 |
| - | "warning" |
33 |
| - | "danger"; |
34 |
| -
|
35 |
| - /** |
36 |
| - * 按钮的圆角样式 |
37 |
| - */ |
38 |
| - radius: "none" | "sm" | "md" | "lg" | "full"; |
39 |
| -
|
40 |
| - /** |
41 |
| - * 是否占满父容器宽度 |
42 |
| - */ |
43 |
| - fullWidth: boolean; |
44 |
| -
|
45 |
| - /** |
46 |
| - * 是否禁用按钮 |
47 |
| - */ |
48 |
| - isDisabled: boolean; |
49 |
| -
|
50 |
| - /** |
51 |
| - * 是否在按钮组中 |
52 |
| - */ |
53 |
| - isInGroup: boolean; |
54 |
| -
|
55 |
| - /** |
56 |
| - * 是否仅为图标按钮 |
57 |
| - */ |
58 |
| - isIconOnly: boolean; |
59 |
| -
|
60 |
| - /** |
61 |
| - * 是否禁用动画效果 |
62 |
| - */ |
63 |
| - disableAnimation: boolean; |
| 7 | + /** |
| 8 | + * 按钮的变体样式 |
| 9 | + */ |
| 10 | + variant: |
| 11 | + | 'solid' |
| 12 | + | 'bordered' |
| 13 | + | 'light' |
| 14 | + | 'flat' |
| 15 | + | 'faded' |
| 16 | + | 'shadow' |
| 17 | + | 'ghost' |
| 18 | +
|
| 19 | + /** |
| 20 | + * 按钮的尺寸 |
| 21 | + */ |
| 22 | + size: 'sm' | 'md' | 'lg' |
| 23 | +
|
| 24 | + /** |
| 25 | + * 按钮的颜色 |
| 26 | + */ |
| 27 | + color: |
| 28 | + | 'default' |
| 29 | + | 'primary' |
| 30 | + | 'secondary' |
| 31 | + | 'success' |
| 32 | + | 'warning' |
| 33 | + | 'danger' |
| 34 | +
|
| 35 | + /** |
| 36 | + * 按钮的圆角样式 |
| 37 | + */ |
| 38 | + radius: 'none' | 'sm' | 'md' | 'lg' | 'full' |
| 39 | +
|
| 40 | + /** |
| 41 | + * 是否占满父容器宽度 |
| 42 | + */ |
| 43 | + fullWidth: boolean |
| 44 | +
|
| 45 | + /** |
| 46 | + * 是否禁用按钮 |
| 47 | + */ |
| 48 | + isDisabled: boolean |
| 49 | +
|
| 50 | + /** |
| 51 | + * 是否在按钮组中 |
| 52 | + */ |
| 53 | + isInGroup: boolean |
| 54 | +
|
| 55 | + /** |
| 56 | + * 是否仅为图标按钮 |
| 57 | + */ |
| 58 | + isIconOnly: boolean |
| 59 | +
|
| 60 | + /** |
| 61 | + * 是否禁用动画效果 |
| 62 | + */ |
| 63 | + disableAnimation: boolean |
64 | 64 | }
|
65 | 65 |
|
66 |
| -type ButtonState = "pressed" | "hover"; |
| 66 | +type ButtonState = 'pressed' | 'hover' |
67 | 67 |
|
68 |
| -type ButtonProps = Partial<Button>; |
| 68 | +type ButtonProps = Partial<Button> |
69 | 69 |
|
70 |
| -const props = defineProps<ButtonProps>(); |
| 70 | +const props = defineProps<ButtonProps>() |
71 | 71 |
|
72 |
| -const buttonState = ref<ButtonState | undefined>(); |
| 72 | +const buttonState = ref<ButtonState | undefined>() |
73 | 73 |
|
74 |
| -const buttonRef = ref<HTMLButtonElement>(); |
75 |
| -useRipple(buttonRef); |
| 74 | +const buttonRef = ref<HTMLButtonElement>() |
| 75 | +useRipple(buttonRef) |
76 | 76 |
|
77 | 77 | const className = computed(() => {
|
78 |
| - return button({ ...props }); |
79 |
| -}); |
| 78 | + return button({ ...props }) |
| 79 | +}) |
80 | 80 |
|
81 |
| -function setButtonState(): () => void; |
82 |
| -function setButtonState(state: ButtonState): () => void; |
| 81 | +function setButtonState(): void |
| 82 | +function setButtonState(state: ButtonState): void |
83 | 83 | function setButtonState(state?: ButtonState) {
|
84 |
| - return () => { |
85 |
| - buttonState.value = state; |
86 |
| - }; |
| 84 | + buttonState.value = state |
87 | 85 | }
|
88 | 86 | </script>
|
89 | 87 |
|
90 | 88 | <template>
|
91 |
| - <button |
92 |
| - ref="buttonRef" |
93 |
| - :data-pressed="buttonState === 'pressed'" |
94 |
| - :data-hover="buttonState === 'hover'" |
95 |
| - :class="className" |
96 |
| - @mouseup="setButtonState()" |
97 |
| - @mousedown="setButtonState('pressed')" |
98 |
| - @mouseenter="setButtonState('hover')" |
99 |
| - @mouseleave="setButtonState()" |
100 |
| - > |
101 |
| - <slot /> |
102 |
| - </button> |
| 89 | + <button |
| 90 | + ref="buttonRef" |
| 91 | + :data-pressed="buttonState === 'pressed'" |
| 92 | + :data-hover="buttonState === 'hover'" |
| 93 | + :class="className" |
| 94 | + @mouseup="setButtonState()" |
| 95 | + @mousedown="setButtonState('pressed')" |
| 96 | + @mouseenter="setButtonState('hover')" |
| 97 | + @mouseleave="setButtonState()" |
| 98 | + > |
| 99 | + <slot /> |
| 100 | + </button> |
103 | 101 | </template>
|
0 commit comments