Skip to content

Commit 1e61b80

Browse files
author
Francois Laubscher
authored
feat(header): header with breadcrumbs
1 parent f4096dc commit 1e61b80

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed

src/colors.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ export default {
2222
disabled: '#a9a9bb',
2323
grey: '#d2d2e4',
2424
lightgrey: '#fafafa',
25-
darkbg: '#f0f0f8'
25+
darkbg: '#f0f0f8',
26+
27+
monteCarlo: '#87ccd4',
28+
paradiso: '#398891'
2629
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { StyledHeader as Header, Step, Crumbs } from './style';
5+
6+
const HeaderWithBreadcrumbs = ({ className, crumbs, activeIndex }) => {
7+
console.log(activeIndex);
8+
return (
9+
<Header className={className}>
10+
<Crumbs>
11+
{crumbs.map((crumb, index) => (
12+
<Step
13+
key={crumb}
14+
completed={index < activeIndex}
15+
active={index === activeIndex}
16+
>
17+
{crumb}
18+
</Step>
19+
))}
20+
</Crumbs>
21+
</Header>
22+
);
23+
};
24+
25+
HeaderWithBreadcrumbs.defaultProps = {
26+
className: null,
27+
activeIndex: 0
28+
};
29+
30+
HeaderWithBreadcrumbs.propTypes = {
31+
className: PropTypes.string,
32+
crumbs: PropTypes.arrayOf(PropTypes.string).isRequired,
33+
activeIndex: PropTypes.number
34+
};
35+
36+
export default HeaderWithBreadcrumbs;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import styled from 'styled-components';
2+
import Header from '../header';
3+
4+
import Colors from '../colors';
5+
6+
export const StyledHeader = styled(Header)`
7+
padding: 0.5rem;
8+
`;
9+
10+
const getStepBackground = (completed, active) => {
11+
const background = (completed && Colors.monteCarlo) || Colors.darkerStorm;
12+
return (active && Colors.ocean) || background;
13+
};
14+
15+
const getStepColor = (completed, active) => {
16+
const color = (completed && Colors.paradiso) || Colors.lighterStorm;
17+
return (active && Colors.white) || color;
18+
};
19+
20+
export const Crumbs = styled.div`
21+
margin-left: 1rem;
22+
display: flex;
23+
align-items: center;
24+
height: 25px;
25+
width: 100%;
26+
max-width: 860px;
27+
28+
@media (min-width: 768px) {
29+
margin: 0 auto;
30+
}
31+
`;
32+
33+
export const Step = styled.div`
34+
line-height: 25px;
35+
font-size: 10px;
36+
text-align: center;
37+
background-color: ${({ completed, active }) =>
38+
getStepBackground(completed, active)};
39+
color: ${({ completed, active }) => getStepColor(completed, active)};
40+
width: 100%;
41+
margin-right: 1px;
42+
font-weight: 600;
43+
transition: background-color 0.2s ease-in;
44+
45+
:first-child {
46+
border-top-left-radius: 15px;
47+
border-bottom-left-radius: 15px;
48+
}
49+
50+
:last-child {
51+
margin-right: 0;
52+
border-top-right-radius: 15px;
53+
border-bottom-right-radius: 15px;
54+
}
55+
`;

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Colors from './colors';
33
import Input, { Currency as InputCurrency } from './input';
44
import Dropdown from './dropdown';
55
import Header from './header';
6+
import HeaderWithBreadcrumbs from './header-with-breadcrumbs';
67
import Footer from './footer';
78
import AutoComplete from './autocomplete';
89
import Toast from './toast';
@@ -19,6 +20,7 @@ export {
1920
InputCurrency,
2021
Dropdown,
2122
Header,
23+
HeaderWithBreadcrumbs,
2224
Footer,
2325
AutoComplete,
2426
Toast,

stories/header-with-breadcrumbs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
import { number } from '@storybook/addon-knobs';
4+
import HeaderWithBreadcrumbs from '../src/header-with-breadcrumbs';
5+
6+
const crumbs = ['Address', 'Time', 'Details'];
7+
8+
storiesOf('HeaderWithBreadcrumbs', module).add('Default', () => {
9+
return <HeaderWithBreadcrumbs crumbs={crumbs} />;
10+
});
11+
12+
storiesOf('HeaderWithBreadcrumbs', module).add('WithActiveIndex', () => (
13+
<HeaderWithBreadcrumbs crumbs={crumbs} activeIndex={number('activeIndex')} />
14+
));

0 commit comments

Comments
 (0)