diff --git a/src/components/PeriodSelector.tsx b/src/components/PeriodSelector.tsx index f043cc0..91169cb 100644 --- a/src/components/PeriodSelector.tsx +++ b/src/components/PeriodSelector.tsx @@ -1,3 +1,5 @@ +import { useState, useRef, useEffect } from 'react'; + interface PeriodSelectorProps { value: number; onChange: (days: number) => void; @@ -11,16 +13,40 @@ const PERIODS = [ { label: '30 jours', days: 30 }, ]; +const PRESET_DAYS = new Set([1, 7, 30]); + export function PeriodSelector({ value, onChange, animationActive, onAnimate }: PeriodSelectorProps) { + const [customOpen, setCustomOpen] = useState(false); + const [inputVal, setInputVal] = useState(''); + const inputRef = useRef(null); + + // Ouvre le champ custom avec la valeur courante pré-remplie + const openCustom = () => { + setInputVal(PRESET_DAYS.has(value) ? '' : String(value)); + setCustomOpen(true); + }; + + useEffect(() => { + if (customOpen) inputRef.current?.focus(); + }, [customOpen]); + + const commit = () => { + const n = parseInt(inputVal, 10); + if (n >= 1 && n <= 365) onChange(n); + setCustomOpen(false); + }; + + const isCustomActive = !PRESET_DAYS.has(value); + return ( -
+
{PERIODS.map(({ label, days }) => ( ))} +
+ + {/* Bouton Personnaliser + champ inline */} + {customOpen ? ( +
+ setInputVal(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') commit(); + if (e.key === 'Escape') setCustomOpen(false); + }} + onBlur={commit} + placeholder="jours" + className="w-16 px-2 py-1 text-sm bg-[#1a1b23] border border-[#d4a843] rounded-md text-[#d4a843] text-center focus:outline-none tabular-nums [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none" + /> + j +
+ ) : ( + + )} + +
+