import React, {ChangeEvent, KeyboardEvent, useRef, useState} from "react"; import AddActionButton from "@/components/form/AddActionButton"; interface InlineAddInputProps { value: string; setValue: (value: string) => void; numericalValue?: number; setNumericalValue?: (value: number) => void; placeholder: string; onAdd: () => Promise; showNumericalInput?: boolean; } export default function InlineAddInput( { value, setValue, numericalValue, setNumericalValue, placeholder, onAdd, showNumericalInput = false }: InlineAddInputProps) { const [isAdding, setIsAdding] = useState(false); const listItemRef = useRef(null); async function handleAdd(): Promise { await onAdd(); setIsAdding(false); } return (
  • ): void => { if (!listItemRef.current?.contains(e.relatedTarget)) { setIsAdding(false); } }} className="relative flex items-center gap-1 h-[44px] px-3 bg-secondary/30 rounded-xl border-2 border-dashed border-secondary/50 hover:border-primary/60 hover:bg-secondary/50 cursor-pointer transition-colors duration-200" > {showNumericalInput && numericalValue !== undefined && setNumericalValue && ( ) => setNumericalValue(parseInt(e.target.value))} tabIndex={isAdding ? 0 : -1} /> )} setIsAdding(true)} onKeyUp={async (e: KeyboardEvent) => { if (e.key === 'Enter') { await handleAdd(); } }} className="flex-1 min-w-0 bg-transparent text-text-primary text-sm px-1 py-0.5 cursor-pointer focus:cursor-text placeholder:text-muted/60 transition-all duration-200 !outline-none !ring-0 !shadow-none focus-visible:!outline-none focus-visible:!ring-0 focus-visible:!shadow-none" type="text" onChange={(e: ChangeEvent) => setValue(e.target.value)} value={value} placeholder={placeholder} /> {isAdding && (
    )}
  • ); }