Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit b18d235

Browse files
BeniCheniZYSzys
authored andcommitted
style: Adjust Header's padding below 380px (#162)
While checking out responsive styles, observed a style bug that below 380px, the header nav items would display in an odd layout, which would cause UX issue like the hamburger menu wouldn’t open. Tried out this PR to: * use `emotion` for styles in header's JSX so that it can support existing style code and hook into media query * use padding 0 up to 380px, where the original problemetcal breakpoint started to occur * update test snapshot. * ~~update code format with "format" script.~~ ##### Before Fix <img width="377" alt="screen shot 2019-03-02 at 9 33 39 pm" src="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3Ca+href%3D"https://user-images.githubusercontent.com/6441326/53690219-6db9d600-3d34-11e9-95c7-41077e4c211d.png" rel="nofollow">https://user-images.githubusercontent.com/6441326/53690219-6db9d600-3d34-11e9-95c7-41077e4c211d.png"> ##### With Fix @ 320px breakpoint (common like the legacy iPhone 5) <img width="326" alt="screen shot 2019-03-02 at 9 57 10 pm" src="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3Ca+href%3D"https://user-images.githubusercontent.com/6441326/53690323-27657680-3d36-11e9-9eec-cc81873125ae.png" rel="nofollow">https://user-images.githubusercontent.com/6441326/53690323-27657680-3d36-11e9-9eec-cc81873125ae.png">
1 parent 3a2abbc commit b18d235

3 files changed

Lines changed: 18 additions & 26 deletions

File tree

src/components/header.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import { Link } from 'gatsby'
2-
import React from 'react'
3-
import logo from '../images/logo.svg'
1+
import { Link } from 'gatsby';
2+
import React from 'react';
3+
import { css } from 'emotion';
4+
import logo from '../images/logo.svg';
45

56
const Header = () => (
67
<nav className="nav">
78
<ul
8-
style={{
9-
margin: '0 auto',
10-
padding: '0 4.8rem',
11-
display: 'flex',
12-
alignItems: 'center',
13-
listStyle: 'none',
14-
}}
9+
css={css`
10+
@media (max-width: 380px) {
11+
padding: 0;
12+
}
13+
margin: 0 auto;
14+
padding: 0 4.8rem;
15+
display: flex;
16+
align-items: center;
17+
list-style: none;
18+
`}
1519
>
1620
<li>
1721
<Link to="/" style={{ display: 'block' }}>
1822
<img src={logo} alt="Node.js" className="nav__logo" />
1923
</Link>
2024
</li>
21-
2225
<li className="nav__tabs">
2326
<a target="_blank" href="https://nodejs.org/en/download/">
2427
Download
2528
</a>
2629
</li>
27-
2830
<li className="nav__tabs">
2931
<a target="_blank" href="https://nodejs.org/en/docs/">
3032
API Docs
3133
</a>
3234
</li>
33-
3435
<li className="nav__tabs">
3536
<a target="_blank" href="https://github.com/nodejs/nodejs.dev">
3637
GitHub
3738
</a>
3839
</li>
39-
4040
</ul>
4141
</nav>
42-
)
42+
);
4343

44-
export default Header
44+
export default Header;

src/components/navigation-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Props = {
1111

1212
const NavigationItem = ({ isDone, isActive, slug, title, onClick }: Props) => {
1313
const element = useRef<HTMLAnchorElement | null>(null);
14-
14+
1515
const handleRef = (ref?: HTMLAnchorElement | null) => {
1616
if (ref && isActive) {
1717
element.current = ref;

test/components/__snapshots__/header.test.tsx.snap

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ exports[`Tests for Header component renders correctly 1`] = `
55
className="nav"
66
>
77
<ul
8-
style={
9-
Object {
10-
"alignItems": "center",
11-
"display": "flex",
12-
"listStyle": "none",
13-
"margin": "0 auto",
14-
"padding": "0 4.8rem",
15-
}
16-
}
8+
css="css-k9ksbg"
179
>
1810
<li>
1911
<a

0 commit comments

Comments
 (0)