-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactor/decoupling
- Loading branch information
Showing
8 changed files
with
127 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,66 @@ | ||
import { createSignal } from "solid-js" | ||
|
||
type VolumeButtonProps = { | ||
type VolumeControlProps = { | ||
mute: (isMuted: boolean) => void | ||
setVolume: (newVolume: number) => void | ||
} | ||
|
||
export const VolumeButton = (props: VolumeButtonProps) => { | ||
export const VolumeControl = (props: VolumeControlProps) => { | ||
const [isMuted, setIsMuted] = createSignal(false) | ||
const [currentVolume, setCurrentVolume] = createSignal(1) | ||
const [previousVolume, setPreviousVolume] = createSignal(1) | ||
|
||
const toggleMute = () => { | ||
const newIsMuted = !isMuted() | ||
setIsMuted(newIsMuted) | ||
props?.mute(newIsMuted) | ||
props.mute(newIsMuted) | ||
|
||
if (newIsMuted) { | ||
setPreviousVolume(currentVolume()) | ||
props.setVolume(0) | ||
setCurrentVolume(0) | ||
} else { | ||
const restoredVolume = previousVolume() | ||
setCurrentVolume(restoredVolume) | ||
props.setVolume(restoredVolume) | ||
} | ||
} | ||
|
||
const handleVolumeChange = (e: InputEvent & { currentTarget: HTMLInputElement }) => { | ||
const volume = parseFloat(e.currentTarget.value) | ||
if (volume == 0) { | ||
setIsMuted(true) | ||
} else { | ||
setIsMuted(false) | ||
} | ||
setCurrentVolume(volume) | ||
props.setVolume(volume) | ||
} | ||
|
||
return ( | ||
<button | ||
class=" | ||
flex h-4 w-0 items-center justify-center rounded bg-transparent | ||
p-4 text-white hover:bg-black/80 | ||
focus:bg-black/80 focus:outline-none | ||
" | ||
onClick={toggleMute} | ||
aria-label={isMuted() ? "Unmute" : "Mute"} | ||
> | ||
{isMuted() ? "🔇" : "🔊"} | ||
</button> | ||
<div class="flex items-center gap-2"> | ||
<button | ||
class=" | ||
flex h-4 w-0 items-center justify-center rounded bg-transparent | ||
p-4 text-white hover:bg-black/80 | ||
focus:bg-black/80 focus:outline-none | ||
" | ||
onClick={toggleMute} | ||
aria-label={isMuted() ? "Unmute" : "Mute"} | ||
> | ||
{isMuted() ? "🔇" : "🔊"} | ||
</button> | ||
|
||
<input | ||
type="range" | ||
min="0" | ||
max="1" | ||
step="0.1" | ||
style={{ padding: "0" }} | ||
value={currentVolume()} | ||
onInput={handleVolumeChange} | ||
class="h-1 w-24 cursor-pointer" | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters