Skip to content

Commit f14b997

Browse files
committed
infobanner extracted
1 parent 3d6b8ae commit f14b997

File tree

2 files changed

+70
-58
lines changed

2 files changed

+70
-58
lines changed

src/components/InfoBanner.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
3+
const InfoBanner = ({ visible, onHide }) => {
4+
if (!visible) return null;
5+
6+
const style = {
7+
padding: 10,
8+
borderStyle: 'solid',
9+
borderWidth: 2,
10+
marginLeft: 80,
11+
marginRight: 80,
12+
position: 'sticky',
13+
top: 100,
14+
left: 40,
15+
display: 'flex',
16+
flexWrap: 'wrap',
17+
flexDirection: 'row',
18+
alignContent: 'space-between',
19+
backgroundColor: '#E8E8E8',
20+
zIndex: 2147483647,
21+
};
22+
23+
const linkStyle = {
24+
color: 'grey',
25+
textDecoration: 'underline',
26+
};
27+
28+
const textStyle = {
29+
flex: 90,
30+
};
31+
32+
const buttonDiv = {
33+
flex: 10,
34+
textAlign: 'right',
35+
};
36+
37+
const buttonStyle = {
38+
outline: 'none',
39+
backgroundColor: 'transparent',
40+
border: 'none',
41+
};
42+
43+
return (
44+
<div style={style}>
45+
<div stule={textStyle}>
46+
Note that some libraries might not work with the new React version 18.
47+
If you run in trouble with library compatibility, read{' '}
48+
<a href="/en/part1/a_more_complex_state_debugging_react_apps#a-note-on-react-version">
49+
<span style={linkStyle}>this</span>
50+
</a>
51+
.
52+
</div>
53+
<div style={buttonDiv}>
54+
<button style={buttonStyle} onClick={onHide}>
55+
x
56+
</button>
57+
</div>
58+
</div>
59+
);
60+
};
61+
62+
export default InfoBanner;

src/components/layout.js

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import './index.scss';
44
import React, { Component } from 'react';
55

66
import Header from './Header/Header';
7+
import InfoBanner from './InfoBanner';
78
import PropTypes from 'prop-types';
89

910
class Layout extends Component {
@@ -20,14 +21,18 @@ class Layout extends Component {
2021
? 'zh'
2122
: 'fi';
2223

24+
const visible = !localStorage.getItem('r18_banner_seen');
25+
26+
console.log(visible);
27+
2328
this.setState({
2429
siteLanguage: siteLanguage,
25-
visible: true,
30+
visible,
2631
});
2732
}
2833

2934
hideNote() {
30-
console.log('yes');
35+
localStorage.setItem('r18_banner_seen', 'yes');
3136
this.setState({
3237
siteLanguage: this.state.siteLanguage,
3338
visible: false,
@@ -37,66 +42,11 @@ class Layout extends Component {
3742
render() {
3843
const { siteLanguage, visible } = this.state;
3944

40-
const style = {
41-
padding: 10,
42-
borderStyle: 'solid',
43-
borderWidth: 2,
44-
marginLeft: 80,
45-
marginRight: 80,
46-
position: 'sticky',
47-
top: 100,
48-
left: 40,
49-
display: 'flex',
50-
flexWrap: 'wrap',
51-
flexDirection: 'row',
52-
alignContent: 'space-between',
53-
backgroundColor: '#E8E8E8',
54-
zIndex: 2147483647,
55-
};
56-
57-
const linkStyle = {
58-
color: 'grey',
59-
textDecoration: 'underline',
60-
};
61-
62-
const textStyle = {
63-
flex: 90,
64-
};
65-
66-
const buttonDiv = {
67-
flex: 10,
68-
textAlign: 'right',
69-
};
70-
71-
const buttonStyle = {
72-
outline: 'none',
73-
backgroundColor: 'transparent',
74-
border: 'none',
75-
};
76-
77-
console.log(this.state);
78-
7945
return (
8046
<div className="main-wrapper">
8147
<Header lang={siteLanguage} />
8248

83-
{visible && (
84-
<div style={style}>
85-
<div stule={textStyle}>
86-
Note that some libraries might not work with the new React version
87-
18. If you run in trouble with library compatibility, read{' '}
88-
<a href="/en/part1/a_more_complex_state_debugging_react_apps#a-note-on-react-version">
89-
<span style={linkStyle}>this</span>
90-
</a>
91-
.
92-
</div>
93-
<div style={buttonDiv}>
94-
<button style={buttonStyle} onClick={() => this.hideNote()}>
95-
x
96-
</button>
97-
</div>
98-
</div>
99-
)}
49+
<InfoBanner onHide={() => this.hideNote()} visible={visible} />
10050

10151
{this.props.children}
10252
</div>

0 commit comments

Comments
 (0)