Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { Link, useParams } from 'react-router-dom';
  3.  
  4. import List from '@material-ui/core/List';
  5. import ListItem from '@material-ui/core/ListItem';
  6. import ListItemText from '@material-ui/core/ListItemText';
  7. import { makeStyles, Theme, createStyles } from '@material-ui/core/styles';
  8.  
  9. import * as types from '../../common/types';
  10.  
  11. const useStyles = makeStyles((theme: Theme) =>
  12.   createStyles({
  13.     active: {
  14.       backgroundColor: theme.palette.primary.dark,
  15.       "&:hover": {
  16.         backgroundColor: theme.palette.primary.dark
  17.       }
  18.     },
  19.   }),
  20. );
  21.  
  22. interface IProps {
  23.   sections: types.ISection[];
  24. }
  25.  
  26. const MenuSection: React.FC<IProps> = (props: IProps) => {
  27.   const classes = useStyles();
  28.  
  29.   const { bookId, sectionId } = useParams();
  30.   let bookIdNumber: number = (bookId == null) ? 0 : ~~bookId;
  31.   let sectionIdNumber: number = (sectionId == null) ? 0 : ~~sectionId;
  32.  
  33.   return (
  34.     <List>
  35.       {
  36.         props.sections.map((s: types.ISection, index: number) => (
  37.           <Link key={index} to={'/editor/' + bookIdNumber + '/' + s.id}>
  38.             <ListItem button className={sectionIdNumber === s.id ? classes.active : ""}>
  39.               <ListItemText primary={s.name} />
  40.             </ListItem>
  41.           </Link>
  42.         ))
  43.       }
  44.     </List>
  45.   );
  46. }
  47.  
  48. export default MenuSection;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement