Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 2x 2x 3x 2x 3x 3x 90x | // @flow strict
import React, { useState, useCallback } from 'react';
import { withRouter } from 'react-router-dom'; // eslint-disable-line
import type { Location } from 'react-router-dom';
import Link from './Link';
import List from './material-toolbox/list';
import ListItem from './material-toolbox/list/Item';
type Props = {
className?: string,
location: Location,
};
const navs = [
{ to: '/', label: 'Home' },
{ to: '/animation', label: 'Animation' },
{ to: '/buttons', label: 'Buttons' },
{ to: '/cards', label: 'Cards' },
{ to: '/checkboxes', label: 'Checkboxes' },
{ to: '/chips', label: 'Chips' },
{ to: '/data-tables', label: 'Data Tables' },
{ to: '/dialogs', label: 'Dialogs' },
{ to: '/drawers', label: 'Drawers' },
{ to: '/elevations', label: 'Elevations' },
{ to: '/fabs', label: 'FABs' },
{ to: '/form-fields', label: 'Form Field' },
{ to: '/icon-buttons', label: 'Icon Buttons' },
{ to: '/image-lists', label: 'Image Lists' },
{ to: '/layout-grids', label: 'Layout Grid' },
{ to: '/linear-progress-indicators', label: 'Liner Progress Indicators' },
{ to: '/lists', label: 'Lists' },
{ to: '/menus', label: 'Menus' },
{ to: '/radio-buttons', label: 'Radio Buttons' },
{ to: '/ripple', label: 'Ripple' },
{ to: '/rtl', label: 'RTL' },
{ to: '/selects', label: 'Selects' },
{ to: '/sliders', label: 'Sliders' },
{ to: '/snackbars', label: 'Snackbars' },
{ to: '/switches', label: 'Switches' },
{ to: '/tabs', label: 'Tab Bars' },
{ to: '/text-fields', label: 'Text Fields' },
{ to: '/theme', label: 'Theme' },
{ to: '/top-app-bars', label: 'Top App Bars' },
{ to: '/typography', label: 'Typography' },
];
const MainNav = withRouter(({ className, location }: Props) => {
const [selected, setSelected] = useState(() => {
return navs.findIndex(nav => nav.to === location.pathname);
});
const handleSelected = useCallback(index => {
setSelected(index);
}, []);
return (
<List
wrapFocus
asActived
onSelect={handleSelected}
selected={selected}
role="listbox"
className={className}
as="nav"
>
{navs.map(nav => (
<Link key={nav.to} component={ListItem} to={nav.to} as="a">
{nav.label}
</Link>
))}
</List>
);
});
export default MainNav;
|