Add ticker animation for long device names in badge tooltip
Adds scrolling animation when device names overflow tooltip width, borrowed from AlbumCard component pattern. Also fixes accessibility warning by adding role and aria-label to badge container.
This commit is contained in:
1 parent
6166b7c206
commit
5f3b4631e6
1 file changed
+56
-1
@@ -45,6 +45,14 @@
|
|||||||
let hardwareStatus = $state<HardwareAudioStatus | null>(null);
|
let hardwareStatus = $state<HardwareAudioStatus | null>(null);
|
||||||
let isHovering = $state(false);
|
let isHovering = $state(false);
|
||||||
|
|
||||||
|
// Ticker animation for long device names
|
||||||
|
let deviceNameRef: HTMLDivElement | null = $state(null);
|
||||||
|
let deviceNameTextRef: HTMLSpanElement | null = $state(null);
|
||||||
|
let deviceNameOverflow = $state(0);
|
||||||
|
const deviceNameOffset = $derived(deviceNameOverflow > 0 ? `-${deviceNameOverflow + 16}px` : '0px');
|
||||||
|
const tickerSpeed = 80; // pixels per second
|
||||||
|
const deviceNameDuration = $derived(deviceNameOverflow > 0 ? `${(deviceNameOverflow + 16) / tickerSpeed}s` : '0s');
|
||||||
|
|
||||||
// Derived state
|
// Derived state
|
||||||
const currentDevice = $derived(outputStatus?.device_name ?? null);
|
const currentDevice = $derived(outputStatus?.device_name ?? null);
|
||||||
|
|
||||||
@@ -147,6 +155,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update outputStatus when hovering to get fresh device name
|
||||||
|
$effect(() => {
|
||||||
|
if (isHovering && !outputStatus) {
|
||||||
|
invoke<AudioOutputStatus>('get_audio_output_status')
|
||||||
|
.then(status => outputStatus = status)
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Calculate overflow for ticker animation when tooltip is visible
|
||||||
|
$effect(() => {
|
||||||
|
if (isHovering && deviceNameRef && deviceNameTextRef) {
|
||||||
|
const overflow = deviceNameTextRef.scrollWidth - deviceNameRef.clientWidth;
|
||||||
|
deviceNameOverflow = overflow > 0 ? overflow : 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
loadStatus();
|
loadStatus();
|
||||||
|
|
||||||
@@ -170,6 +195,8 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="audio-badges"
|
class="audio-badges"
|
||||||
|
role="group"
|
||||||
|
aria-label="Audio output indicators"
|
||||||
onmouseenter={() => isHovering = true}
|
onmouseenter={() => isHovering = true}
|
||||||
onmouseleave={() => isHovering = false}
|
onmouseleave={() => isHovering = false}
|
||||||
>
|
>
|
||||||
@@ -205,7 +232,16 @@
|
|||||||
<!-- Output Device -->
|
<!-- Output Device -->
|
||||||
<div class="tooltip-section">
|
<div class="tooltip-section">
|
||||||
<div class="tooltip-label">Output Device</div>
|
<div class="tooltip-label">Output Device</div>
|
||||||
<div class="tooltip-device">{prettyDeviceName}</div>
|
<div
|
||||||
|
class="tooltip-device"
|
||||||
|
class:scrollable={deviceNameOverflow > 0}
|
||||||
|
style="--ticker-offset: {deviceNameOffset}; --ticker-duration: {deviceNameDuration};"
|
||||||
|
bind:this={deviceNameRef}
|
||||||
|
>
|
||||||
|
<span class="device-name-text" bind:this={deviceNameTextRef}>
|
||||||
|
{prettyDeviceName}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
{#if currentDevice && currentDevice !== prettyDeviceName}
|
{#if currentDevice && currentDevice !== prettyDeviceName}
|
||||||
<div class="tooltip-raw">{currentDevice}</div>
|
<div class="tooltip-raw">{currentDevice}</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -367,6 +403,25 @@
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tooltip-device.scrollable {
|
||||||
|
text-overflow: clip;
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-name-text {
|
||||||
|
display: inline-block;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-tooltip:hover .tooltip-device.scrollable .device-name-text {
|
||||||
|
animation: device-name-ticker var(--ticker-duration) linear infinite;
|
||||||
|
will-change: transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes device-name-ticker {
|
||||||
|
from { transform: translateX(0); }
|
||||||
|
to { transform: translateX(var(--ticker-offset)); }
|
||||||
|
}
|
||||||
|
|
||||||
.tooltip-raw {
|
.tooltip-raw {
|
||||||
font-size: 9px;
|
font-size: 9px;
|
||||||
color: rgba(255, 255, 255, 0.3);
|
color: rgba(255, 255, 255, 0.3);
|
||||||
|
|||||||
Reference in new issue
Block a user