2017-02-20 18:15:36 +02:00
|
|
|
import React from 'react';
|
2017-05-11 20:16:52 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-02-20 18:15:36 +02:00
|
|
|
import styled from 'styled-components';
|
2017-05-11 20:16:52 +03:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
|
|
|
import { remcalc, unitcalc } from '@ui/shared/functions';
|
|
|
|
import { colors } from '@ui/shared/constants';
|
|
|
|
|
2017-02-20 18:15:36 +02:00
|
|
|
import Container from '@ui/components/container';
|
|
|
|
import Row from '@ui/components/row';
|
|
|
|
import Column from '@ui/components/column';
|
|
|
|
import { H2 } from '@ui/components/base-elements';
|
2017-01-19 15:58:46 +02:00
|
|
|
|
|
|
|
const StyledDiv = styled.div`
|
2017-02-20 15:14:44 +02:00
|
|
|
border-bottom: solid ${remcalc(1)} ${colors.base.grey};
|
2017-02-22 17:11:22 +02:00
|
|
|
padding: ${unitcalc(4.5)} 0 ${unitcalc(4.5)} 0;
|
2017-02-22 19:31:25 +02:00
|
|
|
margin-bottom: ${remcalc(18)};
|
2017-01-19 15:58:46 +02:00
|
|
|
`;
|
|
|
|
|
2017-05-11 20:16:52 +03:00
|
|
|
const StyledH2 = styled(H2)`
|
|
|
|
color: ${colors.base.primary};
|
|
|
|
margin: 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const BreadcrumbLink = styled(Link)`
|
2017-02-06 14:05:58 +02:00
|
|
|
text-decoration: none;
|
2017-03-20 19:43:26 +02:00
|
|
|
color: ${colors.base.primary};
|
2017-01-19 15:58:46 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const BreadcrumbSpan = styled.span`
|
2017-02-22 17:18:18 +02:00
|
|
|
color: ${colors.base.text};
|
2017-01-19 15:58:46 +02:00
|
|
|
`;
|
|
|
|
|
2017-05-11 20:16:52 +03:00
|
|
|
function getBreadcrumbLinks(links) {
|
|
|
|
if(links.length) {
|
|
|
|
return links.reduce((breadcrumb, link, index) => {
|
|
|
|
if(breadcrumb.length) {
|
|
|
|
breadcrumb.push(
|
|
|
|
<BreadcrumbSpan key={breadcrumb.length}> / </BreadcrumbSpan>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if(index < links.length - 1) {
|
|
|
|
breadcrumb.push(
|
|
|
|
<BreadcrumbLink key={breadcrumb.length} to={link.pathname}>
|
|
|
|
{link.name}
|
|
|
|
</BreadcrumbLink>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
breadcrumb.push(
|
2017-05-16 16:46:04 +03:00
|
|
|
<span key={breadcrumb.length}>
|
2017-05-11 20:16:52 +03:00
|
|
|
{link.name}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return breadcrumb;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
return null;
|
2017-01-19 15:58:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const Breadcrumb = ({
|
2017-05-11 20:16:52 +03:00
|
|
|
links = []
|
2017-02-20 18:15:36 +02:00
|
|
|
}) => (
|
|
|
|
<Container>
|
|
|
|
<Row>
|
|
|
|
<Column xs={12}>
|
|
|
|
<StyledDiv>
|
|
|
|
<StyledH2>
|
2017-05-11 20:16:52 +03:00
|
|
|
{ getBreadcrumbLinks(links) }
|
2017-02-20 18:15:36 +02:00
|
|
|
</StyledH2>
|
|
|
|
</StyledDiv>
|
|
|
|
</Column>
|
|
|
|
</Row>
|
|
|
|
</Container>
|
|
|
|
);
|
2017-01-19 15:58:46 +02:00
|
|
|
|
|
|
|
Breadcrumb.propTypes = {
|
2017-05-11 20:16:52 +03:00
|
|
|
links: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
pathname: PropTypes.string
|
|
|
|
}))
|
2017-01-19 15:58:46 +02:00
|
|
|
};
|
|
|
|
|
2017-02-20 18:15:36 +02:00
|
|
|
export default Breadcrumb;
|