import { Box, Text, SimpleGrid, TextInput } from "@mantine/core"; import classes from './InputChainWords.module.css' import { useState, useEffect } from "react"; interface InputChainWordsProps { words: number; onPassed: (words : string[]) => void; wordlist?: string[]; onNotPassed: () => void; placeholderFunc?: (inputNumber : number) => string; } export function InputChainWords(props : InputChainWordsProps) { const [inputValues, setInputValues] = useState(Array(props.words).fill("")); const [mounted, setMounted] = useState([]); useEffect(() => { setMounted(new Array(props.words).fill(false)); Array.from({ length: props.words }).forEach((_, index) => { setTimeout(() => { setMounted(prev => { const newMounted = [...prev]; newMounted[index] = true; return newMounted; }); }, index * 50); }); }, [props.words]); const handleInputChange = (value: string, index: number) => { const updatedValues = [...inputValues]; updatedValues[index] = value; setInputValues(updatedValues); const allFilled = updatedValues.every((word) => word.trim() !== ""); const allValid = props.wordlist ? updatedValues.every((word) => props.wordlist!.includes(word.trim())) : true; if (allFilled && allValid) { props.onPassed(updatedValues); } else { props.onNotPassed(); } } const handlePaste = (event: React.ClipboardEvent) => { event.preventDefault(); const pastedText = event.clipboardData.getData("text"); const pastedWords = pastedText.split(/\s+/).slice(0, props.words); const updatedValues = [...inputValues]; pastedWords.forEach((word, index) => { if (index < props.words) { updatedValues[index] = word; } }); setInputValues(updatedValues); const allFilled = updatedValues.every((word) => word.trim() !== ""); const allValid = props.wordlist ? updatedValues.every((word) => props.wordlist!.includes(word.trim())) : true; if (allFilled && allValid) { props.onPassed(updatedValues); } else { props.onNotPassed(); } }; return ( Enter your seed phrase: {Array.from({ length: props.words }, (_, i) => ( handleInputChange(e.target.value, i)} onPaste={(e) => handlePaste(e)} //placeholder={props.placeholderFunc ? props.placeholderFunc(i) : undefined} classNames={{ input: classes.wordInput }} leftSection={ {i + 1}. } size="sm" /> ))} ); }