|
9 | 9 | import RangeSlider from "svelte-range-slider-pips"; |
10 | 10 | import SmoothDiv from "../SmoothDiv.svelte"; |
11 | 11 | import "./VolumeControl.css"; |
| 12 | + import { toggleModes } from "$lib/binding_modes.svelte"; |
| 13 | + import { fly } from "svelte/transition"; |
| 14 | + import { config } from "$lib/config.svelte"; |
12 | 15 |
|
13 | 16 | let audio = $derived(providers.audio); |
14 | 17 | let device = $derived(audio?.defaultPlaybackDevice); |
|
30 | 33 | {#if device} |
31 | 34 | <div class="flex items-stretch h-full mr-1" onwheel={onMouseWheel}> |
32 | 35 | <div class="h-full overflow-hidden flex items-center"> |
33 | | - <SmoothDiv outerClass="flex justify-end"> |
| 36 | + <SmoothDiv outerClass="flex justify-end" innerClass="flex justify-end"> |
34 | 37 | {#if sliderOpen} |
| 38 | + {#if toggleModes.clickThrough} |
| 39 | + <div class="w-2"></div> |
| 40 | + {/if} |
35 | 41 | <RangeSlider |
36 | 42 | id="VolumeSlider" |
37 | | - class="w-24 mr-2" |
| 43 | + class="w-24" |
38 | 44 | float |
39 | 45 | min={0} |
40 | 46 | max={100} |
|
48 | 54 | {/if} |
49 | 55 | </SmoothDiv> |
50 | 56 | </div> |
51 | | - <button |
52 | | - class="transition px-1 text-lg hover:text-zb-accent hover:scale-125 {sliderOpen |
53 | | - ? 'rotate-180' |
54 | | - : ''}" |
55 | | - aria-label="Open volume slider" |
56 | | - onclick={() => (sliderOpen = !sliderOpen)}><ChevronLeft /></button |
| 57 | + <SmoothDiv |
| 58 | + height={false} |
| 59 | + outerClass="h-full flex justify-end" |
| 60 | + innerClass="flex justify-end" |
57 | 61 | > |
58 | | - <button |
59 | | - class="transition px-1 mr-1 text-lg stroke-2 hover:text-zb-accent hover:scale-125" |
60 | | - aria-label="Mute" |
61 | | - onclick={() => audio?.setMute(!muted)} |
| 62 | + {#if !toggleModes.clickThrough} |
| 63 | + <button |
| 64 | + class="h-full flex items-center justify-end transition text-lg hover:text-zb-accent hover:scale-125 relative" |
| 65 | + aria-label="Open volume slider" |
| 66 | + onclick={() => (sliderOpen = !sliderOpen)} |
| 67 | + transition:fly={{ y: 20, duration: config.transitionDuration }} |
| 68 | + > |
| 69 | + <ChevronLeft |
| 70 | + class="{toggleModes.clickThrough ? 'absolute' : ''} {sliderOpen |
| 71 | + ? 'rotate-180' |
| 72 | + : ''} transition mx-1" |
| 73 | + /> |
| 74 | + </button> |
| 75 | + {/if} |
| 76 | + </SmoothDiv> |
| 77 | + <SmoothDiv |
| 78 | + height={false} |
| 79 | + outerClass="h-full flex justify-end" |
| 80 | + innerClass="flex justify-end" |
62 | 81 | > |
63 | | - {#if device} |
64 | | - {#if muted || volume === 0} |
65 | | - <VolumeX /> |
66 | | - {:else if volume <= 33} |
67 | | - <Volume /> |
68 | | - {:else if volume > 33 && volume <= 66} |
69 | | - <Volume1 /> |
70 | | - {:else} |
71 | | - <Volume2 /> |
72 | | - {/if} |
73 | | - {:else} |
74 | | - <VolumeOff /> |
| 82 | + {@const visible = !sliderOpen || !toggleModes.clickThrough} |
| 83 | + {#if visible} |
| 84 | + <button |
| 85 | + class="h-full flex items-center justify-end transition text-lg stroke-2 hover:text-zb-accent hover:scale-125 relative" |
| 86 | + aria-label="Mute" |
| 87 | + onclick={() => audio?.setMute(!muted)} |
| 88 | + transition:fly={{ y: 20, duration: config.transitionDuration }} |
| 89 | + > |
| 90 | + <!-- |
| 91 | + One might ask: Why does this guy repeat the same class logic for each icon? |
| 92 | + For some reason, the conditional for 'absolute' doesn't work when I put it in a wrapper div, nor when I put |
| 93 | + it in the parent button. Might have something to do with svelte transitions? And why does it work just fine |
| 94 | + with the icon components? Go figure. I've spent way too long on this. |
| 95 | + --> |
| 96 | + {#if device} |
| 97 | + {#if muted || volume === 0} |
| 98 | + <VolumeX |
| 99 | + class="{!visible ? 'absolute' : ''} {toggleModes.clickThrough |
| 100 | + ? 'ml-2' |
| 101 | + : 'ml-1'} mr-2" |
| 102 | + /> |
| 103 | + {:else if volume <= 33} |
| 104 | + <Volume |
| 105 | + class="{!visible ? 'absolute' : ''} {toggleModes.clickThrough |
| 106 | + ? 'ml-2' |
| 107 | + : 'ml-1'} mr-2" |
| 108 | + /> |
| 109 | + {:else if volume > 33 && volume <= 66} |
| 110 | + <Volume1 |
| 111 | + class="{!visible ? 'absolute' : ''} {toggleModes.clickThrough |
| 112 | + ? 'ml-2' |
| 113 | + : 'ml-1'} mr-2" |
| 114 | + /> |
| 115 | + {:else} |
| 116 | + <Volume2 |
| 117 | + class="{!visible ? 'absolute' : ''} {toggleModes.clickThrough |
| 118 | + ? 'ml-2' |
| 119 | + : 'ml-1'} mr-2" |
| 120 | + /> |
| 121 | + {/if} |
| 122 | + {:else} |
| 123 | + <VolumeOff |
| 124 | + class="{!visible ? 'absolute' : ''} {toggleModes.clickThrough |
| 125 | + ? 'ml-2' |
| 126 | + : 'ml-1'} mr-2" |
| 127 | + /> |
| 128 | + {/if} |
| 129 | + </button> |
75 | 130 | {/if} |
76 | | - </button> |
| 131 | + </SmoothDiv> |
77 | 132 | </div> |
78 | 133 | {/if} |
0 commit comments