import React, { useEffect, useMemo, useState } from 'react'; import { Button } from '../Button'; import { Input } from '../Input'; import { Tag } from '../Tag'; import styles from './Todo.styles'; import { ColorProps, TodoProps } from './types'; const { DivStyled, DivStyledContent, SectionStyled } = styles; const colors: ColorProps[] = [ 'green', 'red', 'grey', 'yellow', 'blue', 'blueLight', 'purple', 'pink', ]; const Todo: React.FC = ({ buttonText = 'Add', fullWidth = false, label, onChange, pattern, todos = [], ...props }) => { const key = useMemo(() => Math.random(), []); const [inputValue, setInputValue] = useState(''); const [lists, setLists] = useState(todos); useEffect(() => onChange && onChange(lists), [lists]); useEffect(() => setLists(todos), [todos]); const removeTodo = (id: number) => { const updatedList = lists.filter((item) => item !== lists[id]); setLists([...updatedList]); }; const addTodo = (e: any) => { e.preventDefault(); setLists((prevTodo) => [...prevTodo, inputValue]); setInputValue(''); const input: HTMLInputElement | null = document.querySelector( `input[key="${key}"]`, ); input?.focus(); }; return (
setInputValue(e.target.value)} size="large" validation={{ regExp: pattern, required: true, }} key={key} value={inputValue} />