Skip to content

Commit 3083172

Browse files
committed
changing color of banner and adding close icon
1 parent 13ee6e1 commit 3083172

3 files changed

Lines changed: 59 additions & 12 deletions

File tree

content/sitewide/banner.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"visible": false,
2+
"visible": true,
33
"text": "This is some text",
44
"url": "https://designsystems.international"
55
}

src/components/Banner.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
1-
import React, { memo } from 'react';
1+
import React, { memo, useEffect, useState } from 'react';
2+
import { slugify } from '../utils';
23
import * as css from './Banner.module.css';
34

45
export const Banner = ({ text, url }) => {
5-
return (
6-
<a href={url} target="_blank" className={css.root}>
7-
{text}
8-
</a>
9-
);
6+
const [visible, setVisible] = useState(false);
7+
const key = slugify(text);
8+
9+
const hide = () => {
10+
if (window.localStorage) {
11+
window.localStorage.setItem(
12+
`banner-${key}`,
13+
JSON.stringify({
14+
visible: false
15+
})
16+
);
17+
}
18+
setVisible(false);
19+
};
20+
21+
// Only show the banner if this text has not been dismissed yet
22+
useEffect(() => {
23+
if (window.localStorage) {
24+
const savedState = window.localStorage.getItem(`banner-${key}`);
25+
if (savedState) {
26+
setVisible(JSON.parse(savedState).visible);
27+
} else {
28+
setVisible(true);
29+
}
30+
}
31+
}, [key]);
32+
33+
return visible ? (
34+
<div className={css.root}>
35+
<a className={css.link} href={url} target="_blank" rel="noreferrer">
36+
{text}
37+
</a>
38+
<button className={css.close} onClick={hide}>
39+
x
40+
</button>
41+
</div>
42+
) : null;
1043
};
1144

1245
export default memo(Banner);

src/components/Banner.module.css

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
.root {
2-
display: block;
32
text-align: center;
4-
background-color: var(--processing-blue-gradient);
5-
padding: var(--margin-quarter);
6-
font-size: var(--text-small);
7-
color: var(--processing-blue-dark);
3+
background-color: var(--processing-blue-deep);
4+
color: white;
5+
font-size: var(--text-normal);
86
margin-top: -2px;
7+
display: flex;
8+
}
9+
10+
.link {
11+
display: block;
12+
padding: var(--margin-quarter);
13+
flex: 1;
14+
}
15+
16+
.close {
17+
flex: 0 0 60px;
18+
cursor: pointer;
19+
background: none;
20+
color: white;
21+
border: none;
22+
font-size: var(--text-large);
923
}

0 commit comments

Comments
 (0)