Skip to content

Commit 891a997

Browse files
committed
feat: Add tooltips to PlayerWidget buttons for improved UX
1 parent 71c6f86 commit 891a997

File tree

2 files changed

+112
-94
lines changed

2 files changed

+112
-94
lines changed

src/components/ListenToPlayer/PlayerWidget/index.tsx

Lines changed: 111 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
PauseCircleIcon,
1010
PlayCircleIcon,
1111
} from "@/components/icons/listen-to"
12+
import Tooltip from "@/components/Tooltip"
1213

1314
import { cn } from "@/lib/utils/cn"
1415
import { trackCustomEvent } from "@/lib/utils/matomo"
@@ -120,21 +121,22 @@ const PlayerWidget = ({
120121
>
121122
<div className="flex justify-between">
122123
<p className="text-sm font-bold leading-base">{title}</p>
123-
<button
124-
className="cursor-pointer text-body-medium hover:text-body"
125-
aria-label={"Collapse"}
126-
title={"Collapse"}
127-
onClick={() => {
128-
setIsExpanded(!isExpanded)
129-
trackCustomEvent({
130-
eventCategory: "Audio",
131-
eventAction: "click",
132-
eventName: "minimize",
133-
})
134-
}}
135-
>
136-
<CollapseIcon />
137-
</button>
124+
<Tooltip content={"Collapse"}>
125+
<button
126+
className="cursor-pointer text-body-medium hover:text-body"
127+
aria-label={"Collapse"}
128+
onClick={() => {
129+
setIsExpanded(!isExpanded)
130+
trackCustomEvent({
131+
eventCategory: "Audio",
132+
eventAction: "click",
133+
eventName: "minimize",
134+
})
135+
}}
136+
>
137+
<CollapseIcon />
138+
</button>
139+
</Tooltip>
138140
</div>
139141
<div className="flex items-center justify-between">
140142
<div
@@ -161,14 +163,16 @@ const PlayerWidget = ({
161163
</div>
162164
<div className="flex items-center justify-between gap-10">
163165
<div className="relative">
164-
<button
165-
className="w-[24px] cursor-pointer text-right text-xs font-bold leading-base text-body-medium hover:text-body"
166-
onClick={() => setShowSpeedMenu(!showSpeedMenu)}
167-
title={`Playback speed`}
168-
aria-label={"Playback speed"}
169-
>
170-
{playbackSpeed}x
171-
</button>
166+
<Tooltip content={"Playback speed"}>
167+
<button
168+
className="w-[24px] cursor-pointer text-right text-xs font-bold leading-base text-body-medium hover:text-body"
169+
onClick={() => setShowSpeedMenu(!showSpeedMenu)}
170+
title={`Playback speed`}
171+
aria-label={"Playback speed"}
172+
>
173+
{playbackSpeed}x
174+
</button>
175+
</Tooltip>
172176
{showSpeedMenu && (
173177
<div
174178
ref={speedMenuRef}
@@ -189,42 +193,50 @@ const PlayerWidget = ({
189193
</div>
190194
)}
191195
</div>
192-
<button
193-
className="cursor-pointer text-2xl text-disabled hover:text-body"
194-
onClick={handlePrevious}
195-
title="Previous"
196-
aria-label={"Previous"}
197-
>
198-
<ArrowIcon />
199-
</button>
200-
<button
201-
className="cursor-pointer text-[32px] text-primary hover:text-primary-hover"
202-
onClick={handlePlayPause}
203-
title={isPlaying ? "Pause" : "Play"}
204-
aria-label={isPlaying ? "Pause" : "Play"}
205-
>
206-
{isPlaying ? <PauseCircleIcon /> : <PlayCircleIcon />}
207-
</button>
208-
<button
209-
className="cursor-pointer text-2xl text-disabled hover:text-body"
210-
onClick={handleNext}
211-
title="Next"
212-
aria-label={"Next"}
213-
>
214-
<ArrowIcon className="rotate-180" />
215-
</button>
216-
<button
217-
className={cn(
218-
"cursor-pointer text-base",
219-
autoplay ? "text-primary" : "text-disabled",
220-
"hover:text-primary-hover"
221-
)}
222-
onClick={() => setAutoplay(!autoplay)}
223-
title={autoplay ? "Disable autoplay" : "Enable autoplay"}
224-
aria-label={autoplay ? "Disable autoplay" : "Enable autoplay"}
225-
>
226-
<AutoplayIcon />
227-
</button>
196+
<Tooltip content={"Previous"}>
197+
<button
198+
className="cursor-pointer text-2xl text-disabled hover:text-body"
199+
onClick={handlePrevious}
200+
title="Previous"
201+
aria-label={"Previous"}
202+
>
203+
<ArrowIcon />
204+
</button>
205+
</Tooltip>
206+
<Tooltip content={isPlaying ? "Pause" : "Play"}>
207+
<button
208+
className="cursor-pointer text-[32px] text-primary hover:text-primary-hover"
209+
onClick={handlePlayPause}
210+
title={isPlaying ? "Pause" : "Play"}
211+
aria-label={isPlaying ? "Pause" : "Play"}
212+
>
213+
{isPlaying ? <PauseCircleIcon /> : <PlayCircleIcon />}
214+
</button>
215+
</Tooltip>
216+
<Tooltip content={"Next"}>
217+
<button
218+
className="cursor-pointer text-2xl text-disabled hover:text-body"
219+
onClick={handleNext}
220+
title="Next"
221+
aria-label={"Next"}
222+
>
223+
<ArrowIcon className="rotate-180" />
224+
</button>
225+
</Tooltip>
226+
<Tooltip content={autoplay ? "Disable autoplay" : "Enable autoplay"}>
227+
<button
228+
className={cn(
229+
"cursor-pointer text-base",
230+
autoplay ? "text-primary" : "text-disabled",
231+
"hover:text-primary-hover"
232+
)}
233+
onClick={() => setAutoplay(!autoplay)}
234+
title={autoplay ? "Disable autoplay" : "Enable autoplay"}
235+
aria-label={autoplay ? "Disable autoplay" : "Enable autoplay"}
236+
>
237+
<AutoplayIcon />
238+
</button>
239+
</Tooltip>
228240
</div>
229241
</div>
230242

@@ -235,45 +247,51 @@ const PlayerWidget = ({
235247
)}
236248
>
237249
<div className="flex flex-row items-center gap-2">
238-
<button
239-
className="cursor-pointer text-[32px] text-primary hover:text-primary-hover"
240-
onClick={handlePlayPause}
241-
title={isPlaying ? "Pause" : "Play"}
242-
aria-label={isPlaying ? "Pause" : "Play"}
243-
>
244-
{isPlaying ? <PauseCircleIcon /> : <PlayCircleIcon />}
245-
</button>
250+
<Tooltip content={isPlaying ? "Pause" : "Play"}>
251+
<button
252+
className="cursor-pointer text-[32px] text-primary hover:text-primary-hover"
253+
onClick={handlePlayPause}
254+
title={isPlaying ? "Pause" : "Play"}
255+
aria-label={isPlaying ? "Pause" : "Play"}
256+
>
257+
{isPlaying ? <PauseCircleIcon /> : <PlayCircleIcon />}
258+
</button>
259+
</Tooltip>
246260
<div className="text-sm text-body-medium">
247261
{`${Math.floor(timeRemaining / 60)}:${String(Math.floor(timeRemaining % 60)).padStart(2, "0")}`}
248262
</div>
249263
</div>
250264
<div className="flex flex-row gap-6">
251-
<button
252-
className="cursor-pointer text-disabled hover:text-body"
253-
title={"Expand"}
254-
aria-label={"Expand"}
255-
onClick={() => {
256-
setIsExpanded(!isExpanded)
257-
trackCustomEvent({
258-
eventCategory: "Audio",
259-
eventAction: "click",
260-
eventName: "expand",
261-
})
262-
}}
263-
>
264-
<ExpandIcon />
265-
</button>
266-
<button
267-
className="cursor-pointer text-disabled hover:text-body"
268-
title={"Close"}
269-
aria-label={"Close"}
270-
onClick={() => {
271-
setIsExpanded(!isExpanded)
272-
handleCloseWidget()
273-
}}
274-
>
275-
<IoClose />
276-
</button>
265+
<Tooltip content={"Expand"}>
266+
<button
267+
className="cursor-pointer text-disabled hover:text-body"
268+
title={"Expand"}
269+
aria-label={"Expand"}
270+
onClick={() => {
271+
setIsExpanded(!isExpanded)
272+
trackCustomEvent({
273+
eventCategory: "Audio",
274+
eventAction: "click",
275+
eventName: "expand",
276+
})
277+
}}
278+
>
279+
<ExpandIcon />
280+
</button>
281+
</Tooltip>
282+
<Tooltip content={"Close"}>
283+
<button
284+
className="cursor-pointer text-disabled hover:text-body"
285+
title={"Close"}
286+
aria-label={"Close"}
287+
onClick={() => {
288+
setIsExpanded(!isExpanded)
289+
handleCloseWidget()
290+
}}
291+
>
292+
<IoClose />
293+
</button>
294+
</Tooltip>
277295
</div>
278296
</div>
279297
</div>

src/components/Tooltip/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const Tooltip = ({
105105
<Content
106106
side="top"
107107
sideOffset={2}
108-
className="max-w-80 px-5 text-sm"
108+
className="z-[10000] max-w-80 px-5 text-sm"
109109
data-testid="tooltip-popover"
110110
>
111111
{content}

0 commit comments

Comments
 (0)