Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 73de064

Browse files
feat: added Modal component
1 parent 2e1468b commit 73de064

File tree

5 files changed

+100
-16
lines changed

5 files changed

+100
-16
lines changed

‎src/App.tsx‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,28 @@
1-
import React,{useEffect} from 'react'
1+
import React from 'react'
22
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'
33

44
import './styles/app.scss'
55

66
import { NavBar } from './components/shared'
77
import { Home, Algorithms, About } from './pages'
8+
import Modal from './components/shared/Modal'
89

910
const App: React.FC = () => {
10-
useEffect(() => {
11-
alert(
12-
`Caution!\nThe application shows flashing colors.\n Please, use it in color mode 'off' if you are affected by it.`
13-
)
14-
}, [])
1511
return (
1612
<div className='app'>
1713
<Router>
1814
<NavBar>
1915
<Link to='/algorithms'>ALGORITHMS</Link>
2016
<Link to='/about'>ABOUT</Link>
2117
</NavBar>
18+
<Modal />
2219
<Switch>
23-
<Route path='/algorithms'>
24-
<Algorithms />
25-
</Route>
26-
<Route path='/about'>
27-
<About />
28-
</Route>
29-
<Route path='/'>
30-
<Home />
31-
</Route>
20+
<Route exact path='/algorithms' component={Algorithms} />
21+
<Route exact path='/about' component={About} />
22+
<Route exact path='/' component={Home} />
3223
</Switch>
3324
</Router>
34-
</div>
25+
</div>
3526
)
3627
}
3728

‎src/components/shared/Modal.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { FC, useEffect, useState } from 'react';
2+
3+
const localStorageKey = 'modal-has-been-shown'
4+
5+
const Modal: FC = () => {
6+
const [show, setShow] = useState<boolean>();
7+
8+
useEffect(() => {
9+
if (window) {
10+
const localStorageValue = localStorage.getItem(localStorageKey)
11+
if (!localStorageValue) {
12+
setShow(true)
13+
localStorage.setItem(localStorageKey, 'true')
14+
}
15+
}
16+
}, []);
17+
18+
const handleModalClose = (): void => {
19+
setShow(false)
20+
}
21+
22+
if (!show) {
23+
return null
24+
}
25+
26+
return <div className='modal'>
27+
<div className='modal__content'>
28+
<div className='modal__content__header'>
29+
<strong>Caution!</strong>
30+
</div>
31+
<div className='modal__content__content'>
32+
<p>The application shows flashing colors.</p>
33+
<p>Please, keep the color mode &quot;off&quot;, if you are affected by it.</p>
34+
</div>
35+
<div className='modal__content__footer'>
36+
<button type="button" onClick={handleModalClose}>Close</button>
37+
</div>
38+
</div>
39+
</div>
40+
}
41+
42+
export default Modal;

‎src/components/shared/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { default as Header } from './Header'
22
export { default as NavBar } from './NavBar'
33
export { default as Dropdown } from './Dropdown'
4+
export { default as Modal } from './Modal'

‎src/styles/common/index.scss‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import './navbar.scss';
22
@import './dropdown.scss';
3+
@import './modal.scss';
34

45
a {
56
text-decoration: none;

‎src/styles/common/modal.scss‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.modal {
2+
position: fixed;
3+
top: 0;
4+
left: 0;
5+
width: 100%;
6+
height: 100%;
7+
background: rgba(0, 0, 0, 0.5);
8+
z-index: 9999;
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
13+
&__content {
14+
width: 50rem;
15+
height: 20rem;
16+
background: rgb(243, 243, 243);
17+
border-radius: 0.5rem;
18+
padding: 2rem;
19+
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5);
20+
display: flex;
21+
flex-direction: column;
22+
justify-content: center;
23+
align-items: center;
24+
text-align: center;
25+
26+
&__header {
27+
font-style: normal;
28+
font-weight: bold;
29+
font-size: 2rem;
30+
line-height: 1.6rem;
31+
margin-bottom: 2rem;
32+
color: rgb(215, 98, 98);
33+
}
34+
35+
&__content {
36+
font-size: 1.5rem;
37+
}
38+
39+
&__footer {
40+
& button {
41+
margin-top: 2rem;
42+
padding: 0.5rem 1rem;
43+
color: white;
44+
background-color: orange;
45+
cursor: pointer;
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /