veza/apps/web/src/components/player/PlayerControls.tsx
senke 39b2b642d2 feat(web): UI premium Discord/Spotify-like — tokens, shadows, focus, layout
Plan UI premium 6–8 semaines (design system, shell, Storybook, a11y):

- Design system: DESIGN_TOKENS.md, APP_SHELL.md, FULL_LAYOUT_PAGE.md. Single source
  for layout/shell (index.css), shadows (design-system.css), durations/easing.
- Tokens: shadow-cover-depth, shadow-gold-glow, shadow-fab-glow; layout max-height
  (max-h-layout-drawer, max-h-layout-panel, max-h-layout-list). All duration-200/300/500
  replaced by --duration-fast/normal/slow. Arbitrary shadows replaced by token classes.
- Shell & player: Sidebar, Header, GlobalPlayer, MiniPlayer, PlayerQueue, PlayerControls,
  AudioPlayer use tokens; focus-visible on Sidebar, PlayerQueue, DropdownMenuTrigger/Item,
  TabsTrigger. Typography: text-[10px]/[9px] → text-xs where applicable.
- ESLint: no-restricted-syntax (warn) for w-/h-/rounded-/shadow-/text-/spacing arbitrary.
- Scripts: report-arbitrary-values.mjs, capture/compare/generate visual; visual-complete.spec.ts.
- Stories full layout: Dashboard, Playlists, Library, Settings, Profile in DashboardLayout.stories.
- .cursorrules + README: DESIGN_TOKENS, APP_SHELL, visual commands, no arbitrary without justification.
- apps/web/.gitignore: e2e test artifacts (test-results-visual, playwright-report-visual).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 17:15:58 +01:00

184 lines
5.6 KiB
TypeScript

import React, { useState } from 'react';
import {
Play,
Pause,
SkipBack,
SkipForward,
Shuffle,
Repeat,
Volume2,
VolumeX,
Gauge,
SlidersHorizontal,
} from 'lucide-react';
import { useAudio } from '../../context/AudioContext';
import { PlaybackSpeedModal } from './PlaybackSpeedModal';
import { VisualizerSettingsModal } from './VisualizerSettingsModal';
interface PlayerControlsProps {
layout?: 'compact' | 'full';
}
export const PlayerControls: React.FC<PlayerControlsProps> = ({
layout = 'compact',
}) => {
const {
isPlaying,
togglePlay,
nextTrack,
prevTrack,
shuffle,
toggleShuffle,
repeatMode,
toggleRepeat,
volume,
setVolume,
isMuted,
toggleMute,
playbackRate: _playbackRate,
} = useAudio();
const [showSpeed, setShowSpeed] = useState(false);
const [showVisualizer, setShowVisualizer] = useState(false);
return (
<div
className={`flex items-center ${layout === 'full' ? 'justify-between w-full max-w-4xl' : 'justify-center gap-4'}`}
>
{/* 1. Playback Modifiers */}
<div className="flex items-center gap-4 relative">
<button
className={`transition-colors hover:text-foreground ${shuffle ? 'text-primary' : 'text-muted-foreground'}`}
onClick={toggleShuffle}
title="Shuffle"
>
<Shuffle className={layout === 'full' ? 'w-5 h-5' : 'w-4 h-4'} />
</button>
<button
className={`transition-colors hover:text-foreground relative ${repeatMode !== 'off' ? 'text-primary' : 'text-muted-foreground'}`}
onClick={toggleRepeat}
title="Repeat"
>
<Repeat className={layout === 'full' ? 'w-5 h-5' : 'w-4 h-4'} />
{repeatMode === 'one' && (
<span className="absolute -top-1 -right-1 text-[8px] font-bold">
1
</span>
)}
</button>
</div>
{/* 2. Main Transport */}
<div className="flex items-center gap-6">
<button
className="text-muted-foreground hover:text-foreground transition-colors"
onClick={prevTrack}
>
<SkipBack
className={
layout === 'full'
? 'w-8 h-8 fill-current'
: 'w-5 h-5 fill-current'
}
/>
</button>
<button
onClick={togglePlay}
className={`${layout === 'full' ? 'w-14 h-14' : 'w-9 h-9'} rounded-full bg-primary text-primary-foreground flex items-center justify-center transition-all duration-[var(--duration-immersive)] ease-in-out hover:opacity-90 shadow-button-primary-glow`}
>
{isPlaying ? (
<Pause
className={
layout === 'full'
? 'w-6 h-6 fill-current'
: 'w-4 h-4 fill-current'
}
/>
) : (
<Play
className={
layout === 'full'
? 'w-6 h-6 fill-current ml-1'
: 'w-4 h-4 fill-current ml-0.5'
}
/>
)}
</button>
<button
className="text-muted-foreground hover:text-foreground transition-colors"
onClick={nextTrack}
>
<SkipForward
className={
layout === 'full'
? 'w-8 h-8 fill-current'
: 'w-5 h-5 fill-current'
}
/>
</button>
</div>
{/* 3. Volume & Speed */}
<div className="flex items-center gap-4 relative">
{layout === 'full' && (
<>
<button
className={`text-muted-foreground hover:text-warning transition-colors ${showSpeed ? 'text-warning' : ''}`}
onClick={() => {
setShowSpeed(!showSpeed);
setShowVisualizer(false);
}}
title="Playback Speed"
>
<Gauge className="w-5 h-5" />
</button>
<button
className={`text-muted-foreground hover:text-foreground transition-colors ${showVisualizer ? 'text-primary' : ''}`}
onClick={() => {
setShowVisualizer(!showVisualizer);
setShowSpeed(false);
}}
title="Visualizer Settings"
>
<SlidersHorizontal className="w-5 h-5" />
</button>
</>
)}
{/* Volume */}
<div className="flex items-center gap-2 group w-24">
<button
onClick={toggleMute}
className="text-muted-foreground hover:text-foreground"
>
{isMuted || volume === 0 ? (
<VolumeX className="w-4 h-4" />
) : (
<Volume2 className="w-4 h-4" />
)}
</button>
<div
className="flex-1 h-1 bg-muted rounded-full cursor-pointer relative"
onClick={(e) => {
const rect = e.currentTarget.getBoundingClientRect();
setVolume(((e.clientX - rect.left) / rect.width) * 100);
}}
>
<div
className={`absolute top-0 left-0 h-full bg-white rounded-full ${isMuted ? 'opacity-50' : 'opacity-100'}`}
style={{ width: `${isMuted ? 0 : volume}%` }}
></div>
</div>
</div>
{/* Modals Positioned Relative */}
{showSpeed && (
<PlaybackSpeedModal onClose={() => setShowSpeed(false)} />
)}
{showVisualizer && (
<VisualizerSettingsModal onClose={() => setShowVisualizer(false)} />
)}
</div>
</div>
);
};