2019-04-24 00:12:28 +09:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { withRouter } from "next/router";
|
2019-04-23 16:48:33 +09:00
|
|
|
import { makeStyles } from "@material-ui/styles";
|
2019-04-24 00:12:28 +09:00
|
|
|
import { AppBar, Tabs, Tab } from "@material-ui/core";
|
|
|
|
import { Home, Info } from "@material-ui/icons";
|
2019-04-23 16:48:33 +09:00
|
|
|
|
2019-04-24 00:12:28 +09:00
|
|
|
export const routes = [
|
|
|
|
{ pathname: "/", icon: <Home /> },
|
|
|
|
{ pathname: "/about", icon: <Info /> }
|
|
|
|
];
|
2019-04-23 16:48:33 +09:00
|
|
|
|
2019-04-24 00:12:28 +09:00
|
|
|
const TopAppBar: React.FC<{ router: any }> = ({ router }) => {
|
|
|
|
const classes = makeStyles({
|
|
|
|
root: {
|
|
|
|
flexGrow: 1
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
const [value, setValue] = useState(
|
|
|
|
routes.findIndex(({ pathname }) => pathname === router.pathname)
|
|
|
|
);
|
|
|
|
router.events.on("routeChangeStart", (url: string) => {
|
|
|
|
setValue(routes.findIndex(({ pathname }) => pathname === url));
|
|
|
|
});
|
2019-04-23 16:48:33 +09:00
|
|
|
return (
|
|
|
|
<div className={classes.root}>
|
2019-04-23 22:31:38 +09:00
|
|
|
<AppBar color="default">
|
2019-04-24 00:12:28 +09:00
|
|
|
<Tabs
|
|
|
|
value={value}
|
|
|
|
onChange={(_, value) => {
|
|
|
|
router.push(routes[value].pathname);
|
|
|
|
setValue(value);
|
|
|
|
}}
|
|
|
|
variant="fullWidth"
|
|
|
|
indicatorColor="primary"
|
|
|
|
textColor="primary"
|
|
|
|
>
|
|
|
|
{routes.map(({ icon }, i) => (
|
|
|
|
<Tab key={i} icon={icon} />
|
|
|
|
))}
|
|
|
|
</Tabs>
|
2019-04-23 16:48:33 +09:00
|
|
|
</AppBar>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2019-04-24 00:12:28 +09:00
|
|
|
export default withRouter(TopAppBar);
|