Added click SFX
This commit is contained in:
BIN
public/sounds/btn-click.mp3
Normal file
BIN
public/sounds/btn-click.mp3
Normal file
Binary file not shown.
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { useElementHover, useFocus } from '@vueuse/core'
|
import { useElementHover, useFocus } from '@vueuse/core'
|
||||||
|
|
||||||
const hoverSfx = new Audio('/sounds/btn-hover.mp3')
|
const hoverSfx = new Audio('/sounds/btn-hover.mp3')
|
||||||
|
const clickSfx = new Audio('/sounds/btn-click.mp3')
|
||||||
|
|
||||||
const btnRef = ref<HTMLElement | null>()
|
const btnRef = ref<HTMLElement | null>()
|
||||||
const isBtnHovered = useElementHover(btnRef)
|
const isBtnHovered = useElementHover(btnRef)
|
||||||
@@ -10,6 +11,15 @@ const { focused: isBtnFocused } = useFocus(btnRef)
|
|||||||
|
|
||||||
const shouldArrowDisplay = computed(() => isBtnFocused.value || isBtnHovered.value)
|
const shouldArrowDisplay = computed(() => isBtnFocused.value || isBtnHovered.value)
|
||||||
|
|
||||||
|
function handleClick() {
|
||||||
|
clickSfx.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMouseOver() {
|
||||||
|
isBtnFocused.value = true
|
||||||
|
hoverSfx.play()
|
||||||
|
}
|
||||||
|
|
||||||
function playHoverSfx() {
|
function playHoverSfx() {
|
||||||
hoverSfx.play()
|
hoverSfx.play()
|
||||||
}
|
}
|
||||||
@@ -36,17 +46,16 @@ const elementTag = computed(() => (props.href ? 'a' : 'button'))
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<component
|
<component
|
||||||
:ref="
|
ref="btnRef"
|
||||||
(el: HTMLElement) => {
|
|
||||||
btnRef = el
|
|
||||||
}
|
|
||||||
"
|
|
||||||
:is="elementTag"
|
:is="elementTag"
|
||||||
v-bind="attributes"
|
v-bind="attributes"
|
||||||
class="btn w-full p-1 px-2 text-left bg-y-beige-500 hover:shadow-md focus-visible:shadow-md"
|
class="btn w-full p-1 px-2 text-left bg-y-beige-500 hover:shadow-md focus-visible:shadow-md"
|
||||||
:class="{ active: isActive }"
|
:class="{ active: isActive }"
|
||||||
|
@mousedown="handleClick"
|
||||||
|
@keyup.enter="handleClick"
|
||||||
|
@keyup.space="handleClick"
|
||||||
@focusin="playHoverSfx"
|
@focusin="playHoverSfx"
|
||||||
@mouseover="playHoverSfx"
|
@mouseover="handleMouseOver"
|
||||||
>
|
>
|
||||||
<Transition name="fade" :duration="{ enter: 100, leave: 100 }">
|
<Transition name="fade" :duration="{ enter: 100, leave: 100 }">
|
||||||
<img
|
<img
|
||||||
|
|||||||
Reference in New Issue
Block a user