feat: add FlashMessage component for displaying temporary messages
This commit is contained in:
parent
d1b828bba1
commit
8a19529230
37
app/components/ui/flash-massage.tsx
Normal file
37
app/components/ui/flash-massage.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
type FlashMessageProperties = {
|
||||
message: string
|
||||
type: 'success' | 'error' | 'info'
|
||||
}
|
||||
|
||||
export default function FlashMessage({
|
||||
message,
|
||||
type,
|
||||
}: FlashMessageProperties) {
|
||||
const [visible, setVisible] = useState<boolean>(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (message) {
|
||||
setVisible(true)
|
||||
const timer = setTimeout(() => setVisible(false), 3000)
|
||||
return () => clearTimeout(timer)
|
||||
}
|
||||
}, [message])
|
||||
|
||||
if (!visible) return
|
||||
|
||||
const messageStyles = {
|
||||
success: 'bg-green-100 text-green-800 border-green-300',
|
||||
error: 'bg-red-100 text-red-800 border-red-300',
|
||||
info: 'bg-blue-100 text-blue-800 border-blue-300',
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`fixed top-4 right-4 rounded-lg border p-4 shadow-lg ${messageStyles[type]}`}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user