-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
42 lines (37 loc) · 1.53 KB
/
App.jsx
File metadata and controls
42 lines (37 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useEffect, useState, useMemo } from 'react';
import './App.css';
function App() {
const [txStatus, setTxStatus] = useState({ type: '', message: '' });
const [showTxStatus, setShowTxStatus] = useState(false);
// Demo: Show popup on mount
useEffect(() => {
setTxStatus({ type: 'success', message: 'Token info refreshed' });
}, []);
// Auto-hide popup after 3 seconds
useEffect(() => {
if (txStatus.message) {
setShowTxStatus(true);
const timer = setTimeout(() => setShowTxStatus(false), 3000);
return () => clearTimeout(timer);
}
}, [txStatus]);
return (
<main style={{ padding: '2em' }}>
{txStatus.message && (
<div className={`tx-status-popup ${txStatus.type}${!showTxStatus ? ' hide' : ''}`}
role="alert"
aria-live="polite">
<span className="tx-status-popup__icon">
{txStatus.type === 'success' ? '✅' : txStatus.type === 'error' ? '❌' : 'ℹ️'}
</span>
<span>{txStatus.message}</span>
<button className="tx-status-popup__close" onClick={() => setShowTxStatus(false)} title="Close notification">×</button>
</div>
)}
<h1>Styled Popup Demo</h1>
<button onClick={() => setTxStatus({ type: 'success', message: 'Token info refreshed' })}>Show Success</button>
<button onClick={() => setTxStatus({ type: 'error', message: 'Something went wrong' })} style={{ marginLeft: '1em' }}>Show Error</button>
</main>
);
}
export default App;