1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-31 06:18:07 +00:00
_/styles/TopAppBar.tsx

41 lines
1.1 KiB
TypeScript
Raw Normal View History

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";
2019-04-24 00:29:07 +09:00
import routes from "../routes";
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);