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

56 lines
1.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import styled from 'styled-components';
import { Grid, Col } 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) => {
2017-07-26 17:28:14 +03:00
const item =
2017-08-28 22:21:08 +03:00
i + 1 >= links.length ? (
name
) : (
<BreadcrumbLink to={pathname}>{name}</BreadcrumbLink>
);
return <BreadcrumbItem key={name}>{item}</BreadcrumbItem>;
});
2017-08-28 22:21:08 +03:00
const NavBreadcrumb = ({ links = [] }) => (
<BreadcrumbContainer>
<Grid>
<Col xs={12}>
<Breadcrumb>{getBreadcrumbItems(...links)}</Breadcrumb>
</Col>
</Grid>
2017-08-28 22:21:08 +03:00
</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;