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');
|
2017-02-03 14:35:33 +02:00
|
|
|
const Row = require('@ui/components/row');
|
|
|
|
const Column = require('@ui/components/column');
|
2017-02-06 14:05:58 +02:00
|
|
|
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');
|
2017-02-06 14:05:58 +02:00
|
|
|
const constants = require('@ui/shared/constants');
|
2017-01-19 15:58:46 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
remcalc
|
|
|
|
} = fns;
|
|
|
|
|
2017-02-06 14:05:58 +02:00
|
|
|
const {
|
|
|
|
colors,
|
|
|
|
} = constants;
|
|
|
|
|
|
|
|
const {
|
2017-02-15 18:57:27 +02:00
|
|
|
H2,
|
2017-02-06 14:05:58 +02:00
|
|
|
} = BaseElements;
|
|
|
|
|
2017-01-19 15:58:46 +02:00
|
|
|
const {
|
|
|
|
default: styled
|
|
|
|
} = Styled;
|
|
|
|
|
|
|
|
// Main Contonent Wrapper Styles
|
|
|
|
const StyledDiv = styled.div`
|
2017-02-07 00:44:50 +02:00
|
|
|
border-bottom: solid ${remcalc(1)} ${colors.base.greyDark};
|
2017-02-06 14:05:58 +02:00
|
|
|
padding: ${remcalc(30)} 0;
|
|
|
|
margin-bottom: ${remcalc(21)};
|
2017-01-19 15:58:46 +02:00
|
|
|
`;
|
|
|
|
|
2017-02-07 00:44:50 +02:00
|
|
|
const BreadcrumbA = styled(NavLink)`
|
2017-02-06 14:05:58 +02:00
|
|
|
text-decoration: none;
|
2017-01-19 15:58:46 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const BreadcrumbSpan = styled.span`
|
2017-02-06 14:05:58 +02:00
|
|
|
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
|
|
|
|
];
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2017-02-15 18:57:27 +02:00
|
|
|
const StyledH2 = styled(H2)`
|
|
|
|
color: ${colors.base.primary};
|
|
|
|
`;
|
|
|
|
|
2017-01-19 15:58:46 +02:00
|
|
|
const Breadcrumb = ({
|
|
|
|
children,
|
|
|
|
links = [],
|
|
|
|
name = []
|
|
|
|
}) => {
|
|
|
|
return (
|
|
|
|
<Container>
|
2017-02-03 14:35:33 +02:00
|
|
|
<Row>
|
|
|
|
<Column xs={12}>
|
|
|
|
<StyledDiv>
|
2017-02-15 18:57:27 +02:00
|
|
|
<StyledH2>
|
2017-02-03 14:35:33 +02:00
|
|
|
{getNameLink(name)}
|
2017-02-15 18:57:27 +02:00
|
|
|
</StyledH2>
|
2017-02-03 14:35:33 +02:00
|
|
|
</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;
|