insomnia/packages/insomnia-components/components/breadcrumb.js

74 lines
1.4 KiB
JavaScript
Raw Normal View History

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`
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);
font-weight: 400 !important;
}
2020-04-26 20:33:39 +00:00
li {
a {
cursor: pointer;
2020-04-26 20:33:39 +00:00
}
&::before {
margin: 0 var(--padding-xs);
content: '/';
}
2020-04-26 20:33:39 +00:00
&:first-child::before {
content: '';
2020-04-26 20:33:39 +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;