Files
SCM-Manager/scm-ui-components/packages/ui-components/src/Breadcrumb.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-06-26 15:06:59 +02:00
//@flow
import React from "react";
import { Link } from "react-router-dom";
2019-06-26 15:17:16 +02:00
import injectSheet from "react-jss";
import classNames from "classnames";
2019-06-26 15:06:59 +02:00
type Props = {
2019-06-27 13:54:04 +02:00
revision: string,
2019-06-26 15:06:59 +02:00
path: string,
2019-06-26 15:17:16 +02:00
baseUrl: string,
classes: any
};
const styles = {
margin: {
margin: "1rem 1.25rem 0rem"
}
2019-06-26 15:06:59 +02:00
};
class Breadcrumb extends React.Component<Props> {
render() {
2019-06-27 13:54:04 +02:00
const { revision, path, baseUrl, classes } = this.props;
2019-06-26 15:06:59 +02:00
if (path) {
const paths = path.split("/");
return (
2019-06-26 15:17:16 +02:00
<>
<nav
className={classNames("breadcrumb", classes.margin)}
aria-label="breadcrumbs"
>
<ul>
{paths.map((path, index) => {
2019-06-27 13:54:04 +02:00
const currPath = paths.slice(0, index + 1).join("/");
2019-06-26 15:17:16 +02:00
if (paths.length - 1 === index) {
return (
<li className="is-active" key={index}>
<Link to={"#"} aria-current="page">
{path}
</Link>
</li>
);
}
2019-06-26 15:06:59 +02:00
return (
2019-06-26 15:17:16 +02:00
<li key={index}>
2019-06-27 13:54:04 +02:00
<Link to={baseUrl + "/" + revision + "/" + currPath}>
{path}
</Link>
2019-06-26 15:06:59 +02:00
</li>
);
2019-06-26 15:17:16 +02:00
})}
</ul>
</nav>
<hr />
</>
2019-06-26 15:06:59 +02:00
);
}
return null;
}
}
2019-06-26 15:17:16 +02:00
export default injectSheet(styles)(Breadcrumb);