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

101 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-02-07 00:44:50 +02:00
const React = require('react');
const Styled = require('styled-components');
const flatten = require('lodash.flatten');
2017-01-19 15:58:46 +02:00
const Container = require('@ui/components/container');
const Row = require('@ui/components/row');
const Column = require('@ui/components/column');
const BaseElements = require('@ui/components/base-elements');
2017-02-07 00:44:50 +02:00
const NavLink = require('@ui/components/nav-link');
2017-01-19 15:58:46 +02:00
const PropTypes = require('@root/prop-types');
const fns = require('@ui/shared/functions');
const constants = require('@ui/shared/constants');
2017-01-19 15:58:46 +02:00
const {
remcalc,
unitcalc
2017-01-19 15:58:46 +02:00
} = fns;
const {
2017-02-20 16:51:54 +02:00
colors
} = constants;
const {
2017-02-20 16:51:54 +02:00
H2
} = BaseElements;
2017-01-19 15:58:46 +02:00
const {
default: styled
} = Styled;
// Main Contonent Wrapper Styles
const StyledDiv = styled.div`
border-bottom: solid ${remcalc(1)} ${colors.base.grey};
padding: ${unitcalc(4.5)} 0 ${unitcalc(4.5)} 0;
2017-01-19 15:58:46 +02:00
`;
2017-02-07 00:44:50 +02:00
const BreadcrumbA = styled(NavLink)`
text-decoration: none;
2017-01-19 15:58:46 +02:00
`;
const BreadcrumbSpan = styled.span`
color: ${colors.base.secondaryDark};
2017-01-19 15:58:46 +02:00
`;
function getNameLink(name) {
return flatten(name.map((part, i) => {
if (!part.name) {
return null;
}
const link = (
2017-02-07 00:44:50 +02:00
<BreadcrumbA key={part.pathname} to={part.pathname}>
{part.name}
</BreadcrumbA>
2017-01-19 15:58:46 +02:00
);
const key = `${part.pathname}${i}`;
const slash = (
<BreadcrumbSpan key={key}> / </BreadcrumbSpan>
);
return (i === 0) ? link : [
slash,
link
];
}));
}
const StyledH2 = styled(H2)`
color: ${colors.base.primary};
2017-02-20 17:18:41 +02:00
margin: 0;
`;
2017-01-19 15:58:46 +02:00
const Breadcrumb = ({
children,
links = [],
name = []
}) => {
return (
<Container>
<Row>
<Column xs={12}>
<StyledDiv>
<StyledH2>
{getNameLink(name)}
</StyledH2>
</StyledDiv>
</Column>
</Row>
2017-01-19 15:58:46 +02:00
</Container>
);
};
Breadcrumb.propTypes = {
children: React.PropTypes.node,
links: React.PropTypes.arrayOf(PropTypes.link),
name: React.PropTypes.arrayOf(PropTypes.link)
};
module.exports = Breadcrumb;