import { Reorder, useDragControls } from "motion/react"; import { INGREDIENT_UNITS, type RecipeIngredient } from "../../types/recipe"; import DeleteIconSmall from "../icons/DeleteIconSmall"; import DragIconSmall from "../icons/DragIconSmall"; interface IngredientItemProps { classes: string; ingredient: RecipeIngredient; onChange: (id: string, name: "Amount" | "Unit" | "Name", value: string) => void; removeIngredientHandler: (id: string) => void; allowDelete: boolean; valid: boolean; dirty: boolean; markDirty: (id: string) => void; } export default function IngredientItem({ classes, ingredient, onChange, removeIngredientHandler, allowDelete, valid, dirty, markDirty }: IngredientItemProps) { const controls = useDragControls(); const changeHandler = (name: "Amount" | "Unit" | "Name", value: string) => { if (!dirty) markDirty(ingredient.Id); onChange(ingredient.Id, name, value); } return (
changeHandler("Amount", e.target.value)} className={`w-1/2 md:w-28 ${classes} ${dirty && ingredient.Amount <= 0 ? "border-red-500" : ""}`} />
changeHandler("Name", e.target.value)} className={`flex-grow ${classes} ${dirty && ingredient.Name.trim() === "" ? "border-red-500" : ""}`} />
{ e.preventDefault(); controls.start(e); }} className="p-1 md:p-0 cursor-pointer touch-none" >
{(dirty && !valid) && (

Please fill out all fields.

)}
); }