2025-12-03 21:56:50 +00:00
|
|
|
/**
|
|
|
|
|
* Composant QualitySelector
|
|
|
|
|
* Sélecteur de qualité audio 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';
|
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
|
|
|
|
|
|
export type AudioQuality = 'auto' | 'low' | 'medium' | 'high' | 'lossless';
|
|
|
|
|
|
|
|
|
|
export interface QualityOption {
|
|
|
|
|
value: AudioQuality;
|
|
|
|
|
label: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface QualitySelectorProps {
|
|
|
|
|
currentQuality: AudioQuality;
|
|
|
|
|
availableQualities?: AudioQuality[];
|
|
|
|
|
onQualityChange: (quality: AudioQuality) => void;
|
|
|
|
|
className?: string;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DEFAULT_QUALITIES: QualityOption[] = [
|
|
|
|
|
{ value: 'auto', label: 'Auto', description: 'Qualité automatique' },
|
|
|
|
|
{ value: 'low', label: 'Faible', description: '128 kbps' },
|
|
|
|
|
{ value: 'medium', label: 'Moyenne', description: '192 kbps' },
|
|
|
|
|
{ value: 'high', label: 'Haute', description: '320 kbps' },
|
|
|
|
|
{ value: 'lossless', label: 'Sans perte', description: 'FLAC / WAV' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export function QualitySelector({
|
|
|
|
|
currentQuality,
|
|
|
|
|
availableQualities,
|
|
|
|
|
onQualityChange,
|
|
|
|
|
className,
|
|
|
|
|
disabled = false,
|
|
|
|
|
}: QualitySelectorProps) {
|
|
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
// Filtrer les qualités disponibles
|
|
|
|
|
const qualities = availableQualities
|
|
|
|
|
? DEFAULT_QUALITIES.filter((q) => availableQualities.includes(q.value))
|
|
|
|
|
: DEFAULT_QUALITIES;
|
|
|
|
|
|
2025-12-13 02:34:34 +00:00
|
|
|
const currentQualityOption =
|
|
|
|
|
qualities.find((q) => q.value === currentQuality) || qualities[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 = (quality: AudioQuality) => {
|
|
|
|
|
onQualityChange(quality);
|
|
|
|
|
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-02-07 14:33:31 +00:00
|
|
|
'bg-card border border-border',
|
2026-02-07 15:01:56 +00:00
|
|
|
'text-foreground',
|
2026-02-07 14:33:31 +00:00
|
|
|
'hover:bg-muted',
|
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={`Qualité audio: ${currentQualityOption.label}`}
|
|
|
|
|
aria-expanded={isOpen}
|
|
|
|
|
aria-haspopup="listbox"
|
|
|
|
|
aria-disabled={disabled}
|
|
|
|
|
>
|
|
|
|
|
<span>{currentQualityOption.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-02-07 14:33:31 +00:00
|
|
|
className="absolute z-50 mt-1 w-48 bg-card border border-border rounded-lg shadow-lg"
|
2025-12-03 21:56:50 +00:00
|
|
|
role="listbox"
|
|
|
|
|
>
|
|
|
|
|
{qualities.map((quality) => (
|
|
|
|
|
<button
|
|
|
|
|
key={quality.value}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => handleSelect(quality.value)}
|
|
|
|
|
className={cn(
|
|
|
|
|
'w-full flex items-center justify-between px-4 py-2 text-sm text-left',
|
2026-02-07 14:33:31 +00:00
|
|
|
'hover:bg-muted',
|
|
|
|
|
'focus:outline-none focus:bg-muted',
|
2025-12-03 21:56:50 +00:00
|
|
|
'transition-colors',
|
2025-12-13 02:34:34 +00:00
|
|
|
currentQuality === quality.value &&
|
2026-02-07 15:01:56 +00:00
|
|
|
'bg-primary/10',
|
2025-12-03 21:56:50 +00:00
|
|
|
)}
|
|
|
|
|
role="option"
|
|
|
|
|
aria-selected={currentQuality === quality.value}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex flex-col">
|
2026-02-07 14:33:31 +00:00
|
|
|
<span className="font-medium text-foreground">
|
2025-12-03 21:56:50 +00:00
|
|
|
{quality.label}
|
|
|
|
|
</span>
|
|
|
|
|
{quality.description && (
|
2026-02-07 15:01:56 +00:00
|
|
|
<span className="text-xs text-muted-foreground">
|
2025-12-03 21:56:50 +00:00
|
|
|
{quality.description}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{currentQuality === quality.value && (
|
2025-12-13 02:34:34 +00:00
|
|
|
<Check
|
2026-02-07 14:33:31 +00:00
|
|
|
className="h-4 w-4 text-muted-foreground"
|
2025-12-13 02:34:34 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
|
/>
|
2025-12-03 21:56:50 +00:00
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default QualitySelector;
|