Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Commit 3050353

Browse files
authored
Merge pull request #3 from g86/feature/pictures_page
New page: Pictures
2 parents ddb2a3f + 35e51c0 commit 3050353

File tree

14 files changed

+180
-16
lines changed

14 files changed

+180
-16
lines changed

public/images/architecture.jpg

119 KB
Loading

public/images/night-shot.jpg

144 KB
Loading

public/images/shard-clouds.jpg

159 KB
Loading

public/images/tower-bridge.jpg

251 KB
Loading

src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import './App.css'
33
import Header from './layout/Header'
44
import Footer from './layout/Footer'
55
import Home from './pages/Home'
6+
import Pictures from './pages/Pictures'
7+
import Picture from './pages/Picture'
68
import Contact from './pages/Contact'
79
import { BrowserRouter as Router, Route} from 'react-router-dom'
810
// "npm install --save react-router-dom" - installs latest version of React Router
@@ -15,6 +17,8 @@ class App extends Component {
1517
<Header />
1618
<section className="app-body">
1719
<Route exact path="/" component={Home} />
20+
<Route path="/pictures" component={Pictures} />
21+
<Route path="/picture/:pictureIndex" component={Picture} />
1822
<Route path="/contact" component={Contact} />
1923
</section>
2024
<Footer />

src/layout/Header.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ import menuItems from '../sampleData/menuItems'
55

66
class Header extends Component {
77
renderMenuItems(menuItems) {
8-
return menuItems.map((menuItem, index) => {
9-
const addProps = {
10-
to: menuItem.to,
11-
exact: menuItem.exact
12-
}
13-
return (
14-
<li key={index}>
15-
<NavLink className="menu-item"
16-
activeClassName="menu-itm--current"
17-
{...addProps}>{menuItem.caption}</NavLink>
18-
</li>
19-
)
20-
})
8+
return menuItems.map(this.renderMenuItem)
9+
}
10+
11+
renderMenuItem(menuItem, index) {
12+
const addProps = {
13+
to: menuItem.to,
14+
exact: menuItem.exact || false
15+
}
16+
return (
17+
<li key={index}>
18+
<NavLink className="menu-item"
19+
activeClassName="menu-item--current"
20+
{...addProps}>{menuItem.caption}</NavLink>
21+
</li>
22+
)
2123
}
2224

2325
render() {

src/layout/Header.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ it('has h1 title', () => {
1313

1414
it('contains x2 NavLink (menu items)', () => {
1515
const component = shallow(<Header />)
16-
expect(component.find('li > NavLink').length).toEqual(2)
16+
expect(component.find('li > NavLink').length).toEqual(3)
1717
})
1818

1919
it('navigation has correct links', () => {
2020
const component = shallow(<Header />)
2121
expect(component.find('li > NavLink').at(0).props().children).toContain("Home")
2222
expect(component.find('li > NavLink').at(0).props().to).toEqual("/")
23-
expect(component.find('li > NavLink').at(1).props().children).toContain("Contact")
24-
expect(component.find('li > NavLink').at(1).props().to).toEqual("/contact")
23+
expect(component.find('li > NavLink').at(1).props().children).toContain("Pictures")
24+
expect(component.find('li > NavLink').at(1).props().to).toEqual("/pictures")
25+
expect(component.find('li > NavLink').at(2).props().children).toContain("Contact")
26+
expect(component.find('li > NavLink').at(2).props().to).toEqual("/contact")
2527
})

src/pages/Picture.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.Picture-full {
2+
max-width: 512px;
3+
}
4+
.Picture-full > img {
5+
display: block;
6+
width: 100%;
7+
height: auto;
8+
}

src/pages/Picture.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React, {Component} from 'react'
2+
import {Link} from 'react-router-dom'
3+
import pictures from '../sampleData/pictures'
4+
import './Picture.css'
5+
6+
class Picture extends Component {
7+
render() {
8+
const {pictureIndex} = this.props.match.params
9+
return (
10+
<div className="app-content-width">
11+
<article>
12+
<h2>{pictures[pictureIndex].name}</h2>
13+
<p>It is only about a single picture. Go back to <Link to="/pictures">gallery</Link></p>
14+
<div className="Picture-full">
15+
<img src={pictures[pictureIndex].url} alt="Nice one"/>
16+
</div>
17+
</article>
18+
</div>
19+
)
20+
}
21+
}
22+
23+
export default Picture

src/pages/Pictures.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.Pictures-gallery {
2+
display: flex;
3+
flex-wrap: wrap;
4+
padding: 15px 0 25px;
5+
justify-content: space-between;
6+
}
7+
8+
.Picture {
9+
box-shadow: 0 0 3px rgba(0, 0, 0, 0.25);
10+
box-sizing: border-box;
11+
margin-bottom: 10px;
12+
}
13+
14+
.Picture-name {
15+
text-align: center;
16+
padding: 3px 13px;
17+
background-color: rgba(0, 0, 0, 0.25);
18+
color: #ffffff;
19+
font-weight: 400;
20+
}
21+
22+
.Picture > a {
23+
display: block;
24+
}
25+
26+
.Picture > a > img {
27+
display: block;
28+
width: 100%;
29+
height: auto;
30+
}
31+
32+
/* large screens */
33+
@media all and (min-width: 1024px) {
34+
.Picture {
35+
/* 1/4 - 4 columns, 10px - spacing between columns */
36+
width: calc(1 / 4 * 100% - (1 - 1 / 4) * 10px);
37+
}
38+
}
39+
40+
/* medium screens, likely tablets, mostly in portrait mode */
41+
@media all and (min-width: 768px) and (max-width: 1023px) {
42+
.Picture {
43+
width: calc(1 / 3 * 100% - (1 - 1 / 3) * 10px);
44+
}
45+
}
46+
47+
/* small screens, mainly phones in landscape or small tablets */
48+
@media all and (min-width: 426px) and (max-width: 767px) {
49+
.Picture {
50+
width: calc(1 / 2 * 100% - (1 - 1 / 2) * 10px);
51+
}
52+
}
53+
54+
/* mobile screens */
55+
@media all and (max-width: 425px) {
56+
.Pictures-gallery {
57+
display: block;
58+
}
59+
}

0 commit comments

Comments
 (0)