Skip to content

Commit 3856de1

Browse files
authored
feat: Add dismissable notification with configurable content (#1503)
1 parent a5f28b1 commit 3856de1

4 files changed

Lines changed: 155 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, { useState, useEffect } from 'react';
2+
import styles from './styles.module.css';
3+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4+
import { faArrowUpRightFromSquare, faTimes } from "@fortawesome/free-solid-svg-icons";
5+
import notificationConfig from '../../config/notification.json';
6+
7+
const GlobalNotification = () => {
8+
const [isVisible, setIsVisible] = useState(false);
9+
const [isAnimating, setIsAnimating] = useState(false);
10+
11+
// Don't render if notification is disabled in config
12+
if (!notificationConfig.enabled) return null;
13+
14+
useEffect(() => {
15+
const dismissed = localStorage.getItem('eks-workshop-notification-dismissed');
16+
if (!dismissed) {
17+
setIsVisible(true);
18+
setTimeout(() => setIsAnimating(true), 100);
19+
}
20+
}, []);
21+
22+
const handleDismiss = () => {
23+
setIsAnimating(false);
24+
setTimeout(() => {
25+
setIsVisible(false);
26+
localStorage.setItem('eks-workshop-notification-dismissed', 'true');
27+
}, 300);
28+
};
29+
30+
if (!isVisible) return null;
31+
32+
return (
33+
<div className={`${styles.notification} ${isAnimating ? styles.notificationVisible : ''}`}>
34+
<span className={styles.notificationText}>
35+
<b>{notificationConfig.prefix}</b> {notificationConfig.text}{" "}
36+
<a
37+
href={notificationConfig.linkUrl}
38+
target="_blank"
39+
rel="noopener noreferrer"
40+
>
41+
{notificationConfig.linkText} <FontAwesomeIcon
42+
icon={faArrowUpRightFromSquare}
43+
className={styles.linkIcon}
44+
/>
45+
</a>
46+
</span>
47+
<button
48+
className={styles.dismissButton}
49+
onClick={handleDismiss}
50+
aria-label="Dismiss notification"
51+
>
52+
<FontAwesomeIcon icon={faTimes} />
53+
</button>
54+
</div>
55+
);
56+
};
57+
58+
export default GlobalNotification;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.notification {
2+
background-color: #1a1a1a;
3+
padding: 12px 16px;
4+
text-align: left;
5+
display: flex;
6+
align-items: center;
7+
justify-content: space-between;
8+
position: fixed;
9+
top: 80px;
10+
right: 20px;
11+
z-index: 1000;
12+
border-radius: 8px;
13+
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
14+
max-width: 400px;
15+
min-width: 300px;
16+
transform: translateX(100%);
17+
opacity: 0;
18+
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
19+
}
20+
21+
.notificationVisible {
22+
transform: translateX(0);
23+
opacity: 1;
24+
}
25+
26+
.notificationText {
27+
color: #ffffff;
28+
font-size: 13px;
29+
font-weight: 400;
30+
flex: 1;
31+
margin-right: 12px;
32+
}
33+
34+
.notificationText b {
35+
color: #ffffff;
36+
}
37+
38+
.notificationText a {
39+
color: #ff9900;
40+
text-decoration: none;
41+
font-weight: 500;
42+
transition: color 0.2s ease;
43+
}
44+
45+
.notificationText a:hover {
46+
color: #ffb84d;
47+
text-decoration: underline;
48+
}
49+
50+
.linkIcon {
51+
font-size: 12px;
52+
width: 12px;
53+
height: 12px;
54+
margin-left: 4px;
55+
vertical-align: middle;
56+
display: inline-block;
57+
}
58+
59+
.dismissButton {
60+
background: none;
61+
border: none;
62+
color: #ffffff;
63+
cursor: pointer;
64+
font-size: 12px;
65+
padding: 4px;
66+
display: flex;
67+
align-items: center;
68+
justify-content: center;
69+
border-radius: 4px;
70+
transition: all 0.2s ease;
71+
opacity: 0.7;
72+
flex-shrink: 0;
73+
}
74+
75+
.dismissButton:hover {
76+
background-color: rgba(255,255,255,0.1);
77+
opacity: 1;
78+
}
79+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"enabled": false,
3+
"prefix": "Live:",
4+
"text": "Hands-on EKS Workshop Series -",
5+
"linkText": "Register",
6+
"linkUrl": "https://aws-experience.com/emea/smb/events/series/get-hands-on-with-amazon-eks?trk=d42ffbaa-d60a-4513-8a79-0bf36b9f33ce&sc_channel=el"
7+
}

website/src/theme/Root/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import GlobalNotification from '../../components/GlobalNotification';
3+
4+
export default function Root({children}) {
5+
return (
6+
<>
7+
<GlobalNotification />
8+
{children}
9+
</>
10+
);
11+
}

0 commit comments

Comments
 (0)