2020-04-26 20:33:39 +00:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
type Props = {|
|
|
|
|
crumbs: Array<Object>,
|
|
|
|
onClick: (index: number) => any,
|
|
|
|
|};
|
|
|
|
|
|
|
|
const StyledBreadcrumb: React.ComponentType<{}> = styled.ul`
|
2020-05-14 22:54:07 +00:00
|
|
|
font-size: var(--font-size-md);
|
|
|
|
font-weight: 600;
|
|
|
|
color: var(--color-font);
|
|
|
|
grid-area: breadcrumbs;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
a,
|
|
|
|
a::before,
|
|
|
|
li > ::before {
|
2020-04-26 20:33:39 +00:00
|
|
|
color: var(--color-font);
|
2020-05-14 22:54:07 +00:00
|
|
|
font-weight: 400 !important;
|
|
|
|
}
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2020-05-14 22:54:07 +00:00
|
|
|
li {
|
|
|
|
a {
|
|
|
|
cursor: pointer;
|
2020-04-26 20:33:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 22:54:07 +00:00
|
|
|
&::before {
|
|
|
|
margin: 0 var(--padding-xs);
|
|
|
|
content: '/';
|
|
|
|
}
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2020-05-14 22:54:07 +00:00
|
|
|
&:first-child::before {
|
|
|
|
content: '';
|
2020-04-26 20:33:39 +00:00
|
|
|
}
|
2020-05-14 22:54:07 +00:00
|
|
|
}
|
2020-04-26 20:33:39 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
class Breadcrumb extends React.PureComponent<Props> {
|
|
|
|
_handleClick(index: number, e: SyntheticEvent<HTMLAnchorElement>) {
|
|
|
|
e.preventDefault();
|
|
|
|
const { onClick } = this.props;
|
|
|
|
if (typeof onClick === 'function') {
|
|
|
|
onClick(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { crumbs, onClick } = this.props;
|
|
|
|
return (
|
|
|
|
<StyledBreadcrumb>
|
|
|
|
{crumbs.map((crumb, i, arr) => {
|
|
|
|
if (arr.length - 1 === i) {
|
|
|
|
return <li key={crumb}>{crumb}</li>;
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<li key={crumb}>
|
|
|
|
<a href="#" onClick={onClick}>
|
|
|
|
{crumb}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</StyledBreadcrumb>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Breadcrumb;
|