File tree 4 files changed +64
-10
lines changed
4 files changed +64
-10
lines changed Original file line number Diff line number Diff line change @@ -29,16 +29,20 @@ const baseStyles = ({ theme }) => css`
29
29
padding : ${ theme . spacings . mega } ;
30
30
z-index : ${ theme . zIndex . header } ;
31
31
position : sticky;
32
- top : 0 ;
33
- ${ theme . mq . giga } {
34
- display : none;
35
- }
36
32
` ;
37
33
38
- const Container = styled ( 'div' ) ( baseStyles ) ;
34
+ const mobileOnlyStyles = ( { theme, mobileOnly } ) =>
35
+ mobileOnly &&
36
+ css `
37
+ ${ theme . mq . giga } {
38
+ display : none;
39
+ }
40
+ ` ;
39
41
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 } >
42
46
{ children }
43
47
< Title > { title } </ Title >
44
48
</ Container >
@@ -49,6 +53,11 @@ Header.propTypes = {
49
53
* The page title for the Header.
50
54
*/
51
55
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 ,
52
61
/**
53
62
* The child component of Header.
54
63
*/
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ describe('Header', () => {
30
30
expect ( actual ) . toMatchSnapshot ( ) ;
31
31
} ) ;
32
32
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
+
33
39
it ( 'should render children' , ( ) => {
34
40
const wrapper = shallow (
35
41
< Header >
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import React from 'react';
17
17
import styled from '@emotion/styled' ;
18
18
import { storiesOf } from '@storybook/react' ;
19
19
import { withInfo } from '@storybook/addon-info' ;
20
+ import { boolean } from '@storybook/addon-knobs' ;
20
21
21
22
import { GROUPS } from '../../../.storybook/hierarchySeparators' ;
22
23
import withTests from '../../util/withTests' ;
@@ -34,7 +35,7 @@ storiesOf(`${GROUPS.COMPONENTS}|Header`, module)
34
35
'Header' ,
35
36
withInfo ( ) ( ( ) => (
36
37
< HeaderContainer >
37
- < Header title = "Title" >
38
+ < Header title = "Title" mobileOnly = { boolean ( 'mobileOnly' ) } >
38
39
< Hamburguer light />
39
40
</ Header >
40
41
</ HeaderContainer >
Original file line number Diff line number Diff line change 1
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
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
+
4
12
.circuit-2 {
5
13
width : 100 % ;
6
14
display : - webkit - box ;
@@ -17,7 +25,6 @@ exports[`Header styles should render with default styles 1`] = `
17
25
z - index : 600 ;
18
26
position : - webkit - sticky ;
19
27
position : sticky ;
20
- top : 0 ;
21
28
}
22
29
23
30
@media (min-width:960px) {
@@ -26,6 +33,37 @@ exports[`Header styles should render with default styles 1`] = `
26
33
}
27
34
}
28
35
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
+
29
67
.circuit-0 {
30
68
font - size : 17px ;
31
69
line - height : 24px ;
You can’t perform that action at this time.
0 commit comments