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

37 lines
957 B
TypeScript
Raw Normal View History

2019-04-24 00:12:28 +09:00
import React, { useState } from "react";
import { withRouter } from "next/router";
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-07-09 15:46:11 +09:00
const TopAppBar = withRouter(({ router }) => {
2019-04-24 00:12:28 +09:00
const [value, setValue] = useState(
routes.findIndex(({ pathname }) => pathname === router.pathname)
);
router.events.on("routeChangeStart", (url: string) => {
2019-04-25 10:27:05 +09:00
setValue(
routes.findIndex(
({ pathname }) => pathname === url.replace(/(?<=.)\/$/, "")
)
);
2019-04-24 00:12:28 +09:00
});
2019-04-23 16:48:33 +09:00
return (
2019-07-09 15:46:11 +09:00
<AppBar color="default">
<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>
</AppBar>
2019-04-23 16:48:33 +09:00
);
2019-07-09 15:46:11 +09:00
});
export default TopAppBar;