import React, { useState, useEffect } from 'react'; interface ButtonProps { variant?: 'primary' | 'secondary'; disabled?: boolean; onClick?: () => void; children: React.ReactNode; } /** * A reusable button component with Tailwind CSS styling */ export const Button: React.FC = ({ variant = 'primary', disabled = false, onClick, children }) => { const baseClasses = 'font-bold py-2 px-4 rounded transition-colors duration-200'; const variantClasses = { primary: 'bg-blue-500 hover:bg-blue-700 text-white', secondary: 'bg-gray-500 hover:bg-gray-700 text-white' }; return ( ); }; interface TodoItem { id: number; text: string; completed: boolean; } /** * Todo list component demonstrating React hooks and Tailwind */ export const TodoList: React.FC = () => { const [todos, setTodos] = useState([ { id: 1, text: 'Learn React', completed: true }, { id: 2, text: 'Learn TypeScript', completed: true }, { id: 3, text: 'Build amazing apps', completed: false } ]); const [inputValue, setInputValue] = useState(''); useEffect(() => { console.log('Todos updated:', todos); }, [todos]); const addTodo = () => { if (inputValue.trim()) { const newTodo: TodoItem = { id: Date.now(), text: inputValue, completed: false }; setTodos([...todos, newTodo]); setInputValue(''); } }; const toggleTodo = (id: number) => { setTodos(todos.map(todo => todo.id === id ? { ...todo, completed: !todo.completed } : todo )); }; const deleteTodo = (id: number) => { setTodos(todos.filter(todo => todo.id !== id)); }; return (

My Todo List

setInputValue(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && addTodo()} placeholder="Add a new todo..." className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" />
    {todos.map(todo => (
  • toggleTodo(todo.id)} className="w-5 h-5 text-blue-600 rounded focus:ring-2 focus:ring-blue-500" /> {todo.text}
  • ))}
{todos.length === 0 && (
No todos yet. Add one above!
)}
); };