Skip to content

Commit 75f6e10

Browse files
committed
fix(Button): Interactive effects are lost.
close #6
1 parent d7cc454 commit 75f6e10

File tree

1 file changed

+83
-85
lines changed

1 file changed

+83
-85
lines changed
Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,101 @@
11
<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'
55
66
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
6464
}
6565
66-
type ButtonState = "pressed" | "hover";
66+
type ButtonState = 'pressed' | 'hover'
6767
68-
type ButtonProps = Partial<Button>;
68+
type ButtonProps = Partial<Button>
6969
70-
const props = defineProps<ButtonProps>();
70+
const props = defineProps<ButtonProps>()
7171
72-
const buttonState = ref<ButtonState | undefined>();
72+
const buttonState = ref<ButtonState | undefined>()
7373
74-
const buttonRef = ref<HTMLButtonElement>();
75-
useRipple(buttonRef);
74+
const buttonRef = ref<HTMLButtonElement>()
75+
useRipple(buttonRef)
7676
7777
const className = computed(() => {
78-
return button({ ...props });
79-
});
78+
return button({ ...props })
79+
})
8080
81-
function setButtonState(): () => void;
82-
function setButtonState(state: ButtonState): () => void;
81+
function setButtonState(): void
82+
function setButtonState(state: ButtonState): void
8383
function setButtonState(state?: ButtonState) {
84-
return () => {
85-
buttonState.value = state;
86-
};
84+
buttonState.value = state
8785
}
8886
</script>
8987

9088
<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>
103101
</template>

0 commit comments

Comments
 (0)