Skip to content

Commit

Permalink
feat(project): add header component
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed Apr 29, 2021
1 parent 7177e9a commit b793979
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/components/Header/Header.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
@use '../../styles/variables';
@use '../../styles/theme';
@use '../../styles/mixins/responsive';
@use '../../styles/mixins/utils';

//
// Header
// --------------------------------

.header {
height: variables.$header-height;
padding: 10px 56px;
}

//
// Make header fixed
//
.fixed {
position: fixed;
z-index: variables.$header-z-index;
width: 100%;
}

//
// Make header static
//
.static {
position: static;
width: 100%;
}

//
// Header container
//
.container {
position: relative;
display: flex;
flex-direction: row;
height: 100%;
}

//
// Header menu
//
.menu {
display: none;
}

//
// Header navigation
//
.nav {
display: inherit;
flex: 1;
}

//
// mediaQueries
// --------------------------------

@include responsive.mobile-and-tablet() {
.header {
height: variables.$header-height-mobile;
padding: 10px variables.$base-spacing * 2;
}

.menu {
display: block;
}

.nav {
display: none;
}
}

@include responsive.mobile-only() {
.header {
padding: 10px variables.$base-spacing-mobile;
}

.menu {
width: 90px;
transition: opacity 0.2s ease;
}
}

@include responsive.tablet-only() {
.menu {
width: 180px;
}
}

@include responsive.desktop-only() {
.nav {
text-align: center;
}
}
13 changes: 13 additions & 0 deletions src/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';

import { render } from '../../testUtils';

import Header from './Header';

describe('<Header />', () => {
test('renders headers', () => {
const { container } = render(<Header />);

expect(container).toMatchSnapshot();
});
});
35 changes: 35 additions & 0 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import classNames from 'classnames';

import ButtonLink from '../ButtonLink/ButtonLink';
import Logo from '../Logo/Logo';

import styles from './Header.module.scss';

type TypeHeader = 'static' | 'fixed';

type HeaderProps = {
headerType?: TypeHeader;
};

const Header: React.FC<HeaderProps> = ({ headerType = 'static' }) => {
return (
<header className={classNames(styles.header, styles[headerType])}>
<div className={styles.container}>
<div className={styles.menu}>
<span>Placeholder</span>
</div>
<Logo src="https://cdn.jwplayer.com/images/HXyBCU5N.png" />
<nav className={styles.nav}>
<ButtonLink label="Home" to="/" />
{/* mock */}
<ButtonLink label="Playlist" to="/p/:id" />
<ButtonLink label="Settings" to="/u" />
{/* mock */}
</nav>
</div>
</header>
);
};

export default Header;
48 changes: 48 additions & 0 deletions src/components/Header/__snapshots__/Header.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Header /> renders headers 1`] = `
<div>
<header
class=""
>
<div>
<div>
<span>
menu
</span>
</div>
<div>
<img
alt="logo"
src="https://cdn.jwplayer.com/images/HXyBCU5N.png"
/>
</div>
<nav>
<a
aria-current="page"
class="function link() { [native code] } active"
href="/"
>
<span>
Home
</span>
</a>
<a
href="/one"
>
<span>
One
</span>
</a>
<a
href="/two"
>
<span>
Two
</span>
</a>
</nav>
</div>
</header>
</div>
`;

0 comments on commit b793979

Please sign in to comment.