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

74 lines
1.6 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 { Grid, Col, Row } from 'react-styled-flexboxgrid';
import remcalc from 'remcalc';
import unitcalc from 'unitcalc';
2017-05-11 20:16:52 +03:00
import { H2 } from 'joyent-ui-toolkit';
2017-01-19 15:58:46 +02:00
const StyledDiv = styled.div`
border-bottom: solid ${remcalc(1)} ${props => props.theme.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
`;
const StyledH2 = H2.extend`
color: ${props => props.theme.primary};
2017-05-11 20:16:52 +03:00
margin: 0;
`;
const BreadcrumbLink = styled(Link)`
text-decoration: none;
color: ${props => props.theme.primary};
2017-01-19 15:58:46 +02:00
`;
const BreadcrumbSpan = styled.span`
color: ${props => props.theme.text};
2017-01-19 15:58:46 +02:00
`;
2017-05-11 20:16:52 +03:00
function getBreadcrumbLinks(links) {
if (links.length) {
2017-05-11 20:16:52 +03:00
return links.reduce((breadcrumb, link, index) => {
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
}
const Breadcrumb = ({ links = [] }) => (
<Grid>
<Row>
<Col xs={12}>
<StyledDiv>
<StyledH2>
{getBreadcrumbLinks(links)}
</StyledH2>
</StyledDiv>
</Col>
</Row>
</Grid>
);
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;