From 966fe5d74b004964517030edb9eb0f44469ce7e5 Mon Sep 17 00:00:00 2001 From: Afonso Delgado Date: Mon, 15 Jul 2019 09:28:27 -0300 Subject: [PATCH] feat(mobile-header): add mobileOnly prop to Header (#433) --- src/components/Header/Header.js | 23 ++++++---- src/components/Header/Header.spec.js | 6 +++ src/components/Header/Header.story.js | 3 +- .../Header/__snapshots__/Header.spec.js.snap | 42 ++++++++++++++++++- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/components/Header/Header.js b/src/components/Header/Header.js index ff6a56ba45..10f76c5706 100644 --- a/src/components/Header/Header.js +++ b/src/components/Header/Header.js @@ -29,16 +29,20 @@ const baseStyles = ({ theme }) => css` padding: ${theme.spacings.mega}; z-index: ${theme.zIndex.header}; position: sticky; - top: 0; - ${theme.mq.giga} { - display: none; - } `; -const Container = styled('div')(baseStyles); +const mobileOnlyStyles = ({ theme, mobileOnly }) => + mobileOnly && + css` + ${theme.mq.giga} { + display: none; + } + `; -const Header = ({ title, children }) => ( - +const Container = styled('div')(baseStyles, mobileOnlyStyles); + +const Header = ({ title, mobileOnly, children }) => ( + {children} {title} @@ -49,6 +53,11 @@ Header.propTypes = { * The page title for the Header. */ title: PropTypes.string, + /** + * If the Header should appear only on + * mobile screens (useful for when using together with the Sidebar). + */ + mobileOnly: PropTypes.bool, /** * The child component of Header. */ diff --git a/src/components/Header/Header.spec.js b/src/components/Header/Header.spec.js index e266acdfe1..2166e831be 100644 --- a/src/components/Header/Header.spec.js +++ b/src/components/Header/Header.spec.js @@ -30,6 +30,12 @@ describe('Header', () => { expect(actual).toMatchSnapshot(); }); + it('should render and match snapshot for mobileOnly styles', () => { + const mobileProps = { ...props, mobileOnly: true }; + const actual = create(
); + expect(actual).toMatchSnapshot(); + }); + it('should render children', () => { const wrapper = shallow(
diff --git a/src/components/Header/Header.story.js b/src/components/Header/Header.story.js index 4885eb32f4..b7564191b3 100644 --- a/src/components/Header/Header.story.js +++ b/src/components/Header/Header.story.js @@ -17,6 +17,7 @@ import React from 'react'; import styled from '@emotion/styled'; import { storiesOf } from '@storybook/react'; import { withInfo } from '@storybook/addon-info'; +import { boolean } from '@storybook/addon-knobs'; import { GROUPS } from '../../../.storybook/hierarchySeparators'; import withTests from '../../util/withTests'; @@ -34,7 +35,7 @@ storiesOf(`${GROUPS.COMPONENTS}|Header`, module) 'Header', withInfo()(() => ( -
+
diff --git a/src/components/Header/__snapshots__/Header.spec.js.snap b/src/components/Header/__snapshots__/Header.spec.js.snap index be52e291f1..b2dd618210 100644 --- a/src/components/Header/__snapshots__/Header.spec.js.snap +++ b/src/components/Header/__snapshots__/Header.spec.js.snap @@ -1,6 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Header styles should render with default styles 1`] = ` +exports[`Header styles should render and match snapshot for mobileOnly styles 1`] = ` +.circuit-0 { + font-size: 17px; + line-height: 24px; + font-weight: 700; + color: #FAFBFC; + margin-left: 16px; +} + .circuit-2 { width: 100%; display: -webkit-box; @@ -17,7 +25,6 @@ exports[`Header styles should render with default styles 1`] = ` z-index: 600; position: -webkit-sticky; position: sticky; - top: 0; } @media (min-width:960px) { @@ -26,6 +33,37 @@ exports[`Header styles should render with default styles 1`] = ` } } +
+ +

+ Title +

+
+`; + +exports[`Header styles should render with default styles 1`] = ` +.circuit-2 { + width: 100%; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + min-height: 64px; + background-color: #212933; + padding: 16px; + z-index: 600; + position: -webkit-sticky; + position: sticky; +} + .circuit-0 { font-size: 17px; line-height: 24px;