Skip to content

Commit 0467571

Browse files
feat(mobile-header): add mobileOnly prop to Header (#433)
1 parent 9370c30 commit 0467571

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

src/components/Header/Header.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ const baseStyles = ({ theme }) => css`
2929
padding: ${theme.spacings.mega};
3030
z-index: ${theme.zIndex.header};
3131
position: sticky;
32-
top: 0;
33-
${theme.mq.giga} {
34-
display: none;
35-
}
3632
`;
3733

38-
const Container = styled('div')(baseStyles);
34+
const mobileOnlyStyles = ({ theme, mobileOnly }) =>
35+
mobileOnly &&
36+
css`
37+
${theme.mq.giga} {
38+
display: none;
39+
}
40+
`;
3941

40-
const Header = ({ title, children }) => (
41-
<Container>
42+
const Container = styled('div')(baseStyles, mobileOnlyStyles);
43+
44+
const Header = ({ title, mobileOnly, children }) => (
45+
<Container mobileOnly={mobileOnly}>
4246
{children}
4347
<Title>{title}</Title>
4448
</Container>
@@ -49,6 +53,11 @@ Header.propTypes = {
4953
* The page title for the Header.
5054
*/
5155
title: PropTypes.string,
56+
/**
57+
* If the Header should appear only on
58+
* mobile screens (useful for when using together with the Sidebar).
59+
*/
60+
mobileOnly: PropTypes.bool,
5261
/**
5362
* The child component of Header.
5463
*/

src/components/Header/Header.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ describe('Header', () => {
3030
expect(actual).toMatchSnapshot();
3131
});
3232

33+
it('should render and match snapshot for mobileOnly styles', () => {
34+
const mobileProps = { ...props, mobileOnly: true };
35+
const actual = create(<Header {...mobileProps} />);
36+
expect(actual).toMatchSnapshot();
37+
});
38+
3339
it('should render children', () => {
3440
const wrapper = shallow(
3541
<Header>

src/components/Header/Header.story.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import React from 'react';
1717
import styled from '@emotion/styled';
1818
import { storiesOf } from '@storybook/react';
1919
import { withInfo } from '@storybook/addon-info';
20+
import { boolean } from '@storybook/addon-knobs';
2021

2122
import { GROUPS } from '../../../.storybook/hierarchySeparators';
2223
import withTests from '../../util/withTests';
@@ -34,7 +35,7 @@ storiesOf(`${GROUPS.COMPONENTS}|Header`, module)
3435
'Header',
3536
withInfo()(() => (
3637
<HeaderContainer>
37-
<Header title="Title">
38+
<Header title="Title" mobileOnly={boolean('mobileOnly')}>
3839
<Hamburguer light />
3940
</Header>
4041
</HeaderContainer>

src/components/Header/__snapshots__/Header.spec.js.snap

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Header styles should render with default styles 1`] = `
3+
exports[`Header styles should render and match snapshot for mobileOnly styles 1`] = `
4+
.circuit-0 {
5+
font-size: 17px;
6+
line-height: 24px;
7+
font-weight: 700;
8+
color: #FAFBFC;
9+
margin-left: 16px;
10+
}
11+
412
.circuit-2 {
513
width: 100%;
614
display: -webkit-box;
@@ -17,7 +25,6 @@ exports[`Header styles should render with default styles 1`] = `
1725
z-index: 600;
1826
position: -webkit-sticky;
1927
position: sticky;
20-
top: 0;
2128
}
2229
2330
@media (min-width:960px) {
@@ -26,6 +33,37 @@ exports[`Header styles should render with default styles 1`] = `
2633
}
2734
}
2835
36+
<div
37+
className="circuit-2 circuit-3"
38+
>
39+
40+
<h1
41+
className="circuit-0 circuit-1"
42+
>
43+
Title
44+
</h1>
45+
</div>
46+
`;
47+
48+
exports[`Header styles should render with default styles 1`] = `
49+
.circuit-2 {
50+
width: 100%;
51+
display: -webkit-box;
52+
display: -webkit-flex;
53+
display: -ms-flexbox;
54+
display: flex;
55+
-webkit-align-items: center;
56+
-webkit-box-align: center;
57+
-ms-flex-align: center;
58+
align-items: center;
59+
min-height: 64px;
60+
background-color: #212933;
61+
padding: 16px;
62+
z-index: 600;
63+
position: -webkit-sticky;
64+
position: sticky;
65+
}
66+
2967
.circuit-0 {
3068
font-size: 17px;
3169
line-height: 24px;

0 commit comments

Comments
 (0)