joyent-portal/packages/cp-frontend/src/components/navigation/breadcrumb.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import styled from 'styled-components';
import { Grid } from 'react-styled-flexboxgrid';
2017-05-11 20:16:52 +03:00
import { Link } from 'react-router-dom';
import forceArray from 'force-array';
import PropTypes from 'prop-types';
import remcalc from 'remcalc';
2017-05-11 20:16:52 +03:00
import { Breadcrumb, BreadcrumbItem } from 'joyent-ui-toolkit';
2017-05-11 20:16:52 +03:00
const BreadcrumbLink = styled(Link)`
text-decoration: none;
cursor: pointer;
2017-01-19 15:58:46 +02:00
&:visited {
color: inherit;
2017-05-11 20:16:52 +03:00
}
`;
2017-01-19 15:58:46 +02:00
const BreadcrumbContainer = styled.div`
border-bottom: solid ${remcalc(1)} ${props => props.theme.grey};
`;
2017-01-19 15:58:46 +02:00
const getBreadcrumbItems = (...links) =>
forceArray(links).map(({ pathname, name }, i) => {
const item = i + 1 >= links.length
? name
: <BreadcrumbLink to={pathname}>{name}</BreadcrumbLink>;
return <BreadcrumbItem key={name}>{item}</BreadcrumbItem>;
});
const NavBreadcrumb = ({ links = [] }) =>
<BreadcrumbContainer>
<Grid>
<Breadcrumb>
{getBreadcrumbItems(...links)}
</Breadcrumb>
</Grid>
</BreadcrumbContainer>;
NavBreadcrumb.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 NavBreadcrumb;