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