import React, { FormEventHandler } from "react"; import Palette, { palettes } from "./Palette"; interface Props { onImageSubmit: (image: Blob, palette: Palette) => void; } function ImageInput({ onImageSubmit }: Props) { const fileInputRef = React.useRef(null); const [paletteIndex, setPaletteIndex] = React.useState(0); const handleSubmit: FormEventHandler = (e) => { e.preventDefault(); if ( !fileInputRef.current || !fileInputRef.current.files || fileInputRef.current.files.length === 0 ) { return; } onImageSubmit(fileInputRef.current.files[0], palettes[paletteIndex]); }; const handlePaletteChange = (event: React.ChangeEvent) => { setPaletteIndex(parseInt(event.target.value)); }; return (
); } export default ImageInput;