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';
|
2017-05-18 21:21:33 +03:00
|
|
|
import { Grid, Col, Row } from 'react-styled-flexboxgrid';
|
|
|
|
import remcalc from 'remcalc';
|
|
|
|
import unitcalc from 'unitcalc';
|
2017-05-11 20:16:52 +03:00
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
import { H2 } from 'joyent-ui-toolkit';
|
2017-01-19 15:58:46 +02:00
|
|
|
|
|
|
|
const StyledDiv = styled.div`
|
2017-05-18 21:21:33 +03:00
|
|
|
border-bottom: solid ${remcalc(1)} ${props => props.theme.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-25 17:59:58 +03:00
|
|
|
const StyledH2 = H2.extend`
|
2017-05-18 21:21:33 +03:00
|
|
|
color: ${props => props.theme.primary};
|
2017-05-11 20:16:52 +03:00
|
|
|
margin: 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const BreadcrumbLink = styled(Link)`
|
2017-02-06 14:05:58 +02:00
|
|
|
text-decoration: none;
|
2017-05-18 21:21:33 +03:00
|
|
|
color: ${props => props.theme.primary};
|
2017-01-19 15:58:46 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const BreadcrumbSpan = styled.span`
|
2017-05-18 21:21:33 +03:00
|
|
|
color: ${props => props.theme.text};
|
2017-01-19 15:58:46 +02:00
|
|
|
`;
|
|
|
|
|
2017-05-11 20:16:52 +03:00
|
|
|
function getBreadcrumbLinks(links) {
|
2017-05-18 21:21:33 +03:00
|
|
|
if (links.length) {
|
2017-05-11 20:16:52 +03:00
|
|
|
return links.reduce((breadcrumb, link, index) => {
|
2017-05-18 21:21:33 +03:00
|
|
|
if (breadcrumb.length) {
|
2017-05-11 20:16:52 +03:00
|
|
|
breadcrumb.push(
|
|
|
|
<BreadcrumbSpan key={breadcrumb.length}> / </BreadcrumbSpan>
|
|
|
|
);
|
|
|
|
}
|
2017-05-22 20:13:24 +03:00
|
|
|
breadcrumb.push(
|
|
|
|
<BreadcrumbLink key={breadcrumb.length} to={link.pathname}>
|
|
|
|
{link.name}
|
|
|
|
</BreadcrumbLink>
|
|
|
|
);
|
2017-05-11 20:16:52 +03:00
|
|
|
return breadcrumb;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
return null;
|
2017-01-19 15:58:46 +02:00
|
|
|
}
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
const Breadcrumb = ({ links = [] }) => (
|
|
|
|
<Grid>
|
2017-02-20 18:15:36 +02:00
|
|
|
<Row>
|
2017-05-18 21:21:33 +03:00
|
|
|
<Col xs={12}>
|
2017-02-20 18:15:36 +02:00
|
|
|
<StyledDiv>
|
|
|
|
<StyledH2>
|
2017-05-18 21:21:33 +03:00
|
|
|
{getBreadcrumbLinks(links)}
|
2017-02-20 18:15:36 +02:00
|
|
|
</StyledH2>
|
|
|
|
</StyledDiv>
|
2017-05-18 21:21:33 +03:00
|
|
|
</Col>
|
2017-02-20 18:15:36 +02:00
|
|
|
</Row>
|
2017-05-18 21:21:33 +03:00
|
|
|
</Grid>
|
2017-02-20 18:15:36 +02:00
|
|
|
);
|
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-05-18 21:21:33 +03:00
|
|
|
})
|
|
|
|
)
|
2017-01-19 15:58:46 +02:00
|
|
|
};
|
|
|
|
|
2017-02-20 18:15:36 +02:00
|
|
|
export default Breadcrumb;
|