2025-12-03 21:56:50 +00:00
|
|
|
/**
|
|
|
|
|
* Composant PlaybackSpeedControl
|
|
|
|
|
* Contrôle de la vitesse de lecture avec dropdown
|
|
|
|
|
*/
|
|
|
|
|
|
2025-12-22 21:56:37 +00:00
|
|
|
import { useState, useRef, useEffect } from 'react';
|
2025-12-03 21:56:50 +00:00
|
|
|
import { ChevronDown, Check } from 'lucide-react';
|
2025-12-22 21:56:37 +00:00
|
|
|
|
2025-12-03 21:56:50 +00:00
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
|
|
|
|
|
|
export type PlaybackSpeed = 0.5 | 0.75 | 1 | 1.25 | 1.5 | 1.75 | 2;
|
|
|
|
|
|
|
|
|
|
export interface PlaybackSpeedOption {
|
|
|
|
|
value: PlaybackSpeed;
|
|
|
|
|
label: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PlaybackSpeedControlProps {
|
|
|
|
|
currentSpeed: PlaybackSpeed;
|
|
|
|
|
onSpeedChange: (speed: PlaybackSpeed) => void;
|
|
|
|
|
className?: string;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
availableSpeeds?: PlaybackSpeed[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DEFAULT_SPEEDS: PlaybackSpeedOption[] = [
|
|
|
|
|
{ value: 0.5, label: '0.5x' },
|
|
|
|
|
{ value: 0.75, label: '0.75x' },
|
|
|
|
|
{ value: 1, label: '1x' },
|
|
|
|
|
{ value: 1.25, label: '1.25x' },
|
|
|
|
|
{ value: 1.5, label: '1.5x' },
|
|
|
|
|
{ value: 1.75, label: '1.75x' },
|
|
|
|
|
{ value: 2, label: '2x' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export function PlaybackSpeedControl({
|
|
|
|
|
currentSpeed,
|
|
|
|
|
onSpeedChange,
|
|
|
|
|
className,
|
|
|
|
|
disabled = false,
|
|
|
|
|
availableSpeeds,
|
|
|
|
|
}: PlaybackSpeedControlProps) {
|
|
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
// Filtrer les vitesses disponibles
|
|
|
|
|
const speeds = availableSpeeds
|
|
|
|
|
? DEFAULT_SPEEDS.filter((s) => availableSpeeds.includes(s.value))
|
|
|
|
|
: DEFAULT_SPEEDS;
|
|
|
|
|
|
2025-12-13 02:34:34 +00:00
|
|
|
const currentSpeedOption =
|
|
|
|
|
speeds.find((s) => s.value === currentSpeed) ||
|
|
|
|
|
speeds.find((s) => s.value === 1) ||
|
|
|
|
|
speeds[0];
|
2025-12-03 21:56:50 +00:00
|
|
|
|
|
|
|
|
// Fermer le dropdown quand on clique en dehors
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const handleClickOutside = (event: MouseEvent) => {
|
2025-12-13 02:34:34 +00:00
|
|
|
if (
|
|
|
|
|
dropdownRef.current &&
|
|
|
|
|
!dropdownRef.current.contains(event.target as Node)
|
|
|
|
|
) {
|
2025-12-03 21:56:50 +00:00
|
|
|
setIsOpen(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (isOpen) {
|
|
|
|
|
document.addEventListener('mousedown', handleClickOutside);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-12-27 17:40:36 +00:00
|
|
|
return undefined;
|
2025-12-03 21:56:50 +00:00
|
|
|
}, [isOpen]);
|
|
|
|
|
|
|
|
|
|
const handleSelect = (speed: PlaybackSpeed) => {
|
|
|
|
|
onSpeedChange(speed);
|
|
|
|
|
setIsOpen(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div ref={dropdownRef} className={cn('relative', className)}>
|
|
|
|
|
{/* Button */}
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => !disabled && setIsOpen(!isOpen)}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
className={cn(
|
aesthetic-improvements: align spacing to 8px grid (Action 11.2.1.3)
- Created automated script (scripts/align-8px-grid.py) to align all spacing to 8px grid
- Replaced non-8px-aligned spacing: gap-3/p-3/m-3 (12px) → gap-4/p-4/m-4 (16px), gap-5/p-5/m-5 (20px) → gap-6/p-6/m-6 (24px), gap-10/p-10/m-10 (40px) → gap-12/p-12/m-12 (48px), gap-20/p-20/m-20 (80px) → gap-24/p-24/m-24 (96px)
- Preserved: 4px values (gap-1, p-1, m-1) as they may be intentional fine-tuning, responsive breakpoints (sm:, md:, lg:), test files, documentation
- Modified files across all components to ensure consistent 8px grid alignment
- Action 11.2.1.3: Align all elements to 8px grid - COMPLETE
2026-01-16 10:50:46 +00:00
|
|
|
'flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg',
|
2026-01-16 00:56:54 +00:00
|
|
|
'bg-white dark:bg-kodo-graphite border border-kodo-steel dark:border-kodo-steel',
|
|
|
|
|
'text-kodo-text-main dark:text-kodo-text-main',
|
|
|
|
|
'hover:bg-kodo-void dark:hover:bg-kodo-steel',
|
2025-12-03 21:56:50 +00:00
|
|
|
'focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2',
|
|
|
|
|
'disabled:opacity-50 disabled:cursor-not-allowed',
|
2025-12-13 02:34:34 +00:00
|
|
|
'transition-colors',
|
2025-12-03 21:56:50 +00:00
|
|
|
)}
|
|
|
|
|
aria-label={`Vitesse de lecture: ${currentSpeedOption.label}`}
|
|
|
|
|
aria-expanded={isOpen}
|
|
|
|
|
aria-haspopup="listbox"
|
|
|
|
|
aria-disabled={disabled}
|
|
|
|
|
title={`Vitesse: ${currentSpeedOption.label}`}
|
|
|
|
|
>
|
|
|
|
|
<span>{currentSpeedOption.label}</span>
|
|
|
|
|
<ChevronDown
|
|
|
|
|
className={cn(
|
|
|
|
|
'h-4 w-4 transition-transform',
|
2025-12-13 02:34:34 +00:00
|
|
|
isOpen && 'transform rotate-180',
|
2025-12-03 21:56:50 +00:00
|
|
|
)}
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
/>
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{/* Dropdown */}
|
|
|
|
|
{isOpen && !disabled && (
|
|
|
|
|
<div
|
2026-01-16 00:56:54 +00:00
|
|
|
className="absolute z-50 mt-1 w-32 bg-white dark:bg-kodo-graphite border border-kodo-steel dark:border-kodo-steel rounded-lg shadow-lg"
|
2025-12-03 21:56:50 +00:00
|
|
|
role="listbox"
|
|
|
|
|
>
|
|
|
|
|
{speeds.map((speed) => (
|
|
|
|
|
<button
|
|
|
|
|
key={speed.value}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => handleSelect(speed.value)}
|
|
|
|
|
className={cn(
|
|
|
|
|
'w-full flex items-center justify-between px-4 py-2 text-sm text-left',
|
2026-01-16 00:56:54 +00:00
|
|
|
'hover:bg-kodo-void dark:hover:bg-kodo-steel',
|
|
|
|
|
'focus:outline-none focus:bg-kodo-void dark:focus:bg-kodo-steel',
|
2025-12-03 21:56:50 +00:00
|
|
|
'transition-colors',
|
2025-12-13 02:34:34 +00:00
|
|
|
currentSpeed === speed.value &&
|
2026-01-16 00:56:54 +00:00
|
|
|
'bg-kodo-cyan/10 dark:bg-kodo-cyan/20',
|
2025-12-03 21:56:50 +00:00
|
|
|
)}
|
|
|
|
|
role="option"
|
|
|
|
|
aria-selected={currentSpeed === speed.value}
|
|
|
|
|
>
|
2026-01-16 00:56:54 +00:00
|
|
|
<span className="font-medium text-kodo-text-main dark:text-white">
|
2025-12-03 21:56:50 +00:00
|
|
|
{speed.label}
|
|
|
|
|
</span>
|
|
|
|
|
{currentSpeed === speed.value && (
|
2025-12-13 02:34:34 +00:00
|
|
|
<Check
|
2026-01-16 10:40:13 +00:00
|
|
|
className="h-4 w-4 text-kodo-steel dark:text-kodo-steel"
|
2025-12-13 02:34:34 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
|
/>
|
2025-12-03 21:56:50 +00:00
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default PlaybackSpeedControl;
|