From 59a0dec8f33844b397dd2d4554b970059ab7c4d0 Mon Sep 17 00:00:00 2001 From: Marco Kruppa Date: Fri, 25 Sep 2026 00:31:35 +0200 Subject: [PATCH] feat: slide the highlight when switching modes --- src/components/PlaylistPicker.tsx | 13 +++++++++++-- src/styles.css | 10 +++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/PlaylistPicker.tsx b/src/components/PlaylistPicker.tsx index 120268f..50fdf60 100644 --- a/src/components/PlaylistPicker.tsx +++ b/src/components/PlaylistPicker.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { editablePlaylists, LIKED_SONGS_ID, type PlaylistSummary } from '../core/playlists'; import type { SpotifyApi } from '../spotify/api'; import { AuthError, describeError } from '../spotify/errors'; @@ -24,6 +24,14 @@ export function PlaylistPicker({ api, mode, onModeChange, onPick, onAuthLost, on const [likedTotal, setLikedTotal] = useState(null); const [error, setError] = useState(null); const [attempt, setAttempt] = useState(0); + const segRef = useRef(null); + const [pill, setPill] = useState<{ left: number; width: number } | null>(null); + + // Slide the highlight under the active mode. It first renders already in place, so it only animates on a switch. + useLayoutEffect(() => { + const active = segRef.current?.querySelector('button.on'); + if (active) setPill({ left: active.offsetLeft, width: active.offsetWidth }); + }, [mode]); useEffect(() => { let cancelled = false; @@ -65,7 +73,8 @@ export function PlaylistPicker({ api, mode, onModeChange, onPick, onAuthLost, on

Pick a playlist

-
+
+ {pill &&