1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-15 15:50:06 +02:00
copilot/frontend/src/components/navigation/breadcrumb.js

78 lines
1.7 KiB
JavaScript
Raw Normal View History

import React from 'react';
2017-05-11 20:16:52 +03:00
import PropTypes from 'prop-types';
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';
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`
border-bottom: solid ${remcalc(1)} ${colors.base.grey};
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)`
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>
);
}
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
}
const Breadcrumb = ({
2017-05-11 20:16:52 +03:00
links = []
}) => (
<Container>
<Row>
<Column xs={12}>
<StyledDiv>
<StyledH2>
2017-05-11 20:16:52 +03:00
{ getBreadcrumbLinks(links) }
</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
};
export default Breadcrumb;