Skip to content

Commit

Permalink
adding sidenav
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-commit committed Oct 16, 2019
1 parent be1209d commit 983fdb2
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config/react.go
Expand Up @@ -8,8 +8,14 @@ type reactHeader struct {
Enabled bool
}

type reactSidenavItem struct {
Path string
Label string
Icon string
}
type reactSidenav struct {
Enabled bool
Items []reactSidenavItem
}

type reactAccount struct {
Expand Down
7 changes: 7 additions & 0 deletions templates/commit0/commit0.tmpl
Expand Up @@ -28,6 +28,13 @@ react:
required: false
sidenav:
enabled: true
items:
- path: /
label: Home
icon: home
- path: /account
label: Account
icon: account_circle
views:
- path: /account
component: account
Expand Down
1 change: 1 addition & 0 deletions templates/react/public/index.html
Expand Up @@ -10,6 +10,7 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
1 change: 1 addition & 0 deletions templates/react/public/index.html.tmpl
Expand Up @@ -10,6 +10,7 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
4 changes: 2 additions & 2 deletions templates/react/src/components/layout/header/account.js
@@ -1,11 +1,11 @@
import React from 'react';
import React, { useState } from 'react';
import IconButton from '@material-ui/core/IconButton';
import AccountCircle from '@material-ui/icons/AccountCircle';
import MenuItem from '@material-ui/core/MenuItem';
import Menu from '@material-ui/core/Menu';

export default function MenuAppBar() {
const [anchorEl, setAnchorEl] = React.useState(null);
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);

const handleMenu = event => {
Expand Down
37 changes: 37 additions & 0 deletions templates/react/src/components/layout/header/sidenav/content.js
@@ -0,0 +1,37 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import Icon from '@material-ui/core/Icon';
import config from 'config';

const useStyles = makeStyles({
list: {
width: 250,
},
});

export default function Content() {
const classes = useStyles();
return (
<div
className={classes.list}
role="presentation"
>
<List>
{
config.sidenav && config.sidenav.items && config.sidenav.items.map((item, index) => (
<ListItem button component="a" href={item.path} key={index}>
<ListItemIcon>
<Icon>{item.icon}</Icon>
</ListItemIcon>
<ListItemText primary={item.label} />
</ListItem>
))
}
</List>
</div>
);
}
@@ -1,7 +1,9 @@
import React, { Fragment } from 'react';
import React, { Fragment, useState } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import Drawer from '@material-ui/core/Drawer';
import Content from 'components/layout/header/sidenav/content';

const useStyles = makeStyles(theme => ({
menuButton: {
Expand All @@ -11,16 +13,25 @@ const useStyles = makeStyles(theme => ({

export default function Sidenav() {
const classes = useStyles();
const [open, setOpen] = useState(false);

const onClose = () => setOpen(false);
const onOpen = () => setOpen(true);

return (
<Fragment>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="open drawer"
onClick={onOpen}
>
<MenuIcon />
</IconButton>
<Drawer open={open} onClose={onClose}>
<Content />
</Drawer>
</Fragment>
);
}
12 changes: 12 additions & 0 deletions templates/react/src/config/index.js
Expand Up @@ -11,6 +11,18 @@ export default {
},
sidenav: {
enabled: true,
items: [
{
path: '/',
label: 'Home',
icon: 'home',
},
{
path: '/account',
label: 'Account',
icon: 'account_circle',
},
],
},
views: [
{
Expand Down
9 changes: 9 additions & 0 deletions templates/react/src/config/index.js.tmpl
Expand Up @@ -11,6 +11,15 @@ export default {
},
sidenav: {
enabled: {{ .React.Sidenav.Enabled }},
items: [
{{ range .React.Sidenav.Items }}
{
path: '{{ .Path }}',
label: '{{ .Label }}',
icon: '{{ .Icon }}',
},
{{ end }}
]
},
views: [
{{ range .React.Views }}
Expand Down

0 comments on commit 983fdb2

Please sign in to comment.