Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
New: Added breadcrumb for contents (fixes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit945 committed Sep 7, 2019
1 parent 038548a commit db877a8
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 250 deletions.
309 changes: 186 additions & 123 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
"react-router-dom": "^5.0.0"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/core": "^7.6.0",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-classes": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.6.0",
"@babel/polyfill": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.5.5",
"@babel/runtime": "^7.6.0",
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@semantic-release/git": "^7.0.16",
Expand Down Expand Up @@ -120,7 +120,7 @@
},
"scripts": {
"build": "webpack --config build/webpack/webpack.prod.js",
"start": "node ./build/webpack/webpack-dev-server.js",
"dev": "node ./build/webpack/webpack-dev-server.js",
"lint": "eslint src --color",
"lint:fix": "eslint src --color --fix",
"prepublishOnly": "npm run build",
Expand Down
8 changes: 4 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import ReactDOM from "react-dom";
import { ThemeProvider } from "@material-ui/styles";
import { HashRouter, Route, Switch } from "react-router-dom";
import CONSTANTS from "./helpers/constants";
import constants from "./helpers/constants";
import {
flatten,
validatePageObject,
Expand All @@ -19,11 +19,11 @@ import {
function AppRouter(props) {
const { pages, startLink, gitHubURL } = props;
return (
<ThemeProvider theme={CONSTANTS.THEME()}>
<ThemeProvider theme={constants.THEME()}>
<HashRouter basename={process.env.PUBLIC_URL}>
<div>
<Switch>
{flatten(pages, CONSTANTS.PATHNAME_PROPERTY).map(p => (
{flatten(pages, constants.PATHNAME_PROPERTY).map(p => (
<Route
exact
key={p}
Expand All @@ -48,7 +48,7 @@ function AppRouter(props) {
/>
<Route
exact
path={`/${CONSTANTS.VERSIONS_PATH}`}
path={`/${constants.VERSIONS_PATH}`}
render={() => (
<ReleasesPage gitHubURL={gitHubURL} />
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Content/HomePageBlurb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { withStyles } from "@material-ui/core/styles/index";
import Typography from "@material-ui/core/Typography/index";
import PropTypes from "prop-types";
import React from "react";
import CONSTANTS from "../../helpers/constants";
import constants from "../../helpers/constants";
import CarbonMainIcon from "../SvgIcons/CarbonMainIcon";

const styles = theme => ({
Expand Down Expand Up @@ -116,7 +116,7 @@ function HomePageBlurb(props) {
variant="contained"
color="primary"
>
{CONSTANTS.GETTING_STARTED}
{constants.GETTING_STARTED}
</Button>
</div>
</div>
Expand Down
53 changes: 53 additions & 0 deletions src/components/Drawer/ContentBreadcrumb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import PropTypes from "prop-types";
import Typography from "@material-ui/core/Typography";
import NavigateNextIcon from "@material-ui/icons/NavigateNextRounded";
import Breadcrumbs from "@material-ui/core/Breadcrumbs";
import Paper from "@material-ui/core/Paper";
import { makeSearchTitle } from "../../helpers/searchHelpers";

const useStyles = makeStyles(theme => ({
root: {
marginTop: theme.spacing(1),
marginBottom: theme.spacing(1),
padding: theme.spacing(2),
display: "flex",
background: theme.palette.background.default
}
}));

export default function ContentBreadcrumb(props) {
const classes = useStyles();
const { pathname } = props;
const pathPartitions = makeSearchTitle(pathname).split(">");
const isLastPath = (str, index) =>
str && index === pathPartitions.length - 1;
return (
<Paper className={classes.root}>
<Breadcrumbs
separator={<NavigateNextIcon fontSize="small" />}
aria-label="breadcrumb"
>
{pathPartitions.map((p, index) => {
if (isLastPath(p, index)) {
return (
<Typography variant="button" key={p} color="secondary">
{p.trim()}
</Typography>
);
}
return (
<Typography variant="button" key={p}>
{p.trim()}
</Typography>
);
})}
</Breadcrumbs>
</Paper>
);
}

ContentBreadcrumb.propTypes = {
pathname: PropTypes.string.isRequired
};
66 changes: 16 additions & 50 deletions src/components/Drawer/ResponsiveDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import CssBaseline from "@material-ui/core/CssBaseline/index";
import Divider from "@material-ui/core/Divider/index";
import Drawer from "@material-ui/core/Drawer/index";
import Hidden from "@material-ui/core/Hidden/index";
import Link from "@material-ui/core/Link/index";
import { withStyles } from "@material-ui/core/styles/index";
import PropTypes from "prop-types";
import React from "react";
import CONSTANTS from "../../helpers/constants";
import constants from "../../helpers/constants";
import renderNavItems from "../../helpers/navItemHelpers";
import {
getPageContent,
Expand All @@ -15,35 +14,16 @@ import {
} from "../../helpers/pageHelpers";
import { RouterContextConsumer } from "../Context/RouterContext";
import Header from "../Header/Header";
import CarbonMainIcon from "../SvgIcons/CarbonMainIcon";
import ToolbarIcon from "./ToolbarIcon";
import ContentBreadcrumb from "./ContentBreadcrumb";

const styles = theme => ({
root: {
display: "flex"
},
toolbarContainer: {
display: "flex"
},
title: {
color: theme.palette.text.primary,
display: "flex",
marginBottom: theme.spacing(0.5),
"&:hover": {
color: theme.palette.primary.main
}
},
titleIcon: {
margin: 0,
border: 0,
marginTop: theme.spacing(1 / 1.5),
marginRight: theme.spacing(1 / 1.5),
display: "flex",
height: 32,
width: 32
},
drawer: {
[theme.breakpoints.up("sm")]: {
width: CONSTANTS.DRAWER_WIDTH,
width: constants.DRAWER_WIDTH,
flexShrink: 0
}
},
Expand All @@ -53,28 +33,26 @@ const styles = theme => ({
display: "none"
}
},
toolbar: {
...theme.mixins.toolbar,
paddingLeft: theme.spacing(5),
display: "flex",
flexGrow: 1,
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "center"
},
drawerPaper: {
backgroundColor: theme.palette.background.paper,
width: CONSTANTS.DRAWER_WIDTH
width: constants.DRAWER_WIDTH
},
contentRoot: {
display: "flex",
background: theme.palette.background.paper,
flexDirection: "column",
height: "100vh",
paddingTop: theme.spacing(9),
paddingLeft: theme.spacing(1)
paddingLeft: theme.spacing(1),
paddingBottom: theme.spacing(1),
paddingRight: theme.spacing(1)
},
content: {
display: "flex",
flex: "1",
width: `calc(100vw - ${theme.spacing(2)}px)`, // The below width parameters are dependant on the paddingLeft of contentRoot
[theme.breakpoints.up("sm")]: {
width: `calc(100vw - ${CONSTANTS.DRAWER_WIDTH +
width: `calc(100vw - ${constants.DRAWER_WIDTH +
theme.spacing(2)}px)`
},
height: `calc(100vh - ${theme.spacing(9)}px)`,
Expand Down Expand Up @@ -138,20 +116,7 @@ class ResponsiveDrawer extends React.Component {
<RouterContextConsumer>
{context => (
<div>
<div className={classes.toolbarContainer}>
<div className={classes.toolbar}>
<Link
className={classes.title}
href={CONSTANTS.HEADER_ROOT_LINK}
variant="h4"
>
<CarbonMainIcon
className={classes.titleIcon}
/>
{CONSTANTS.HEADER_MAIN_TITLE}
</Link>
</div>
</div>
<ToolbarIcon />
<Divider />
{renderNavItems({
props,
Expand Down Expand Up @@ -199,6 +164,7 @@ class ResponsiveDrawer extends React.Component {
</Hidden>
</nav>
<main className={classes.contentRoot}>
<ContentBreadcrumb pathname={currentPage.pathname} />
<div
className={classes.content}
ref={this.setElementRef}
Expand Down
55 changes: 55 additions & 0 deletions src/components/Drawer/ToolbarIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Link from "@material-ui/core/Link/index";
import constants from "../../helpers/constants";
import CarbonMainIcon from "../SvgIcons/CarbonMainIcon";

const useStyles = makeStyles(theme => ({
toolbarContainer: {
display: "flex"
},
toolbar: {
...theme.mixins.toolbar,
paddingLeft: theme.spacing(5),
display: "flex",
flexGrow: 1,
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "center"
},
title: {
color: theme.palette.text.primary,
display: "flex",
marginBottom: theme.spacing(0.5),
"&:hover": {
color: theme.palette.primary.main
}
},
titleIcon: {
margin: 0,
border: 0,
marginTop: theme.spacing(1 / 1.5),
marginRight: theme.spacing(1 / 1.5),
display: "flex",
height: 32,
width: 32
}
}));

export default function ToolbarIcon() {
const classes = useStyles();
return (
<div className={classes.toolbarContainer}>
<div className={classes.toolbar}>
<Link
className={classes.title}
href={constants.HEADER_ROOT_LINK}
variant="h4"
>
<CarbonMainIcon className={classes.titleIcon} />
{constants.HEADER_MAIN_TITLE}
</Link>
</div>
</div>
);
}
Loading

0 comments on commit db877a8

Please sign in to comment.