Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styling for mobile devices #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43,859 changes: 43,859 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions src/components/molecules/BrowserMenu/BrowserMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { makeStyles, useTheme } from '@material-ui/core/styles';
import useMediaQuery from "@material-ui/core/useMediaQuery";
import MenuIcon from "@material-ui/icons/Menu";
import { Button, IconButton } from '@material-ui/core';
import Link from '@material-ui/core/Link';
import { IMenuProps } from '../../../types/IMenuProps';


const useStyles = makeStyles((theme) => ({
toolbar: {
borderBottom: `1px solid ${theme.palette.divider}`,
},
toolbarTitle: {
flex: 1,
},
toolbarSecondary: {
justifyContent: 'space-between',
overflowX: 'auto',
},
toolbarLink: {
padding: theme.spacing(1),
flexShrink: 0,
},
menuButton: {
marginRight: theme.spacing(2)
},
}));


export default function MobileMenu(props: IMenuProps): JSX.Element {
const classes = useStyles();
const theme = useTheme();

return (<>{
props.sections.map(section => <>
<Button href={section.url}>{section.title}</Button>
</>)
}</>)
}
2 changes: 2 additions & 0 deletions src/components/molecules/Header/Header.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { makeStyles } from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
appbar: {
backgroundColor: "rgba(0,20,43,0.0)",
paddingTop: theme.spacing(2),
paddingBottom: theme.spacing(2),
// marginLeft: -theme.spacing(4),
// marginRight: -theme.spacing(4),
Comment on lines 8 to 9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these can be removed?

},
Expand Down
38 changes: 2 additions & 36 deletions src/components/molecules/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Toolbar, Typography, Link, AppBar } from "@material-ui/core";
import useStyles from "./Header.styles";
import Section from "../../../types/section";
import { StaticImage } from "gatsby-plugin-image";
import MainMenu from "../../organisms/MainMenu/MainMenu";

// TODO add storybook

Expand Down Expand Up @@ -31,43 +32,8 @@ const Header: FC<HeaderProps> = ({ sections, title }) => {
src="../../../images/codestar_logo_dark.svg"
/>
</Typography>
{/* <IconButton>
<SearchIcon />
</IconButton>
<Button variant="outlined" size="small">
Sign up
</Button> */}
{sections.map((section) => (
<Link
color="inherit"
noWrap
key={section.title}
variant="body2"
href={section.url}
className={classes.toolbarLink}
>
{section.title}
</Link>
))}
<MainMenu sections={sections}></MainMenu>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have this extracted! 👍🏻

</Toolbar>
{/* <Toolbar
component="nav"
variant="dense"
className={classes.toolbarSecondary}
>
{sections.map((section) => (
<Link
color="inherit"
noWrap
key={section.title}
variant="body2"
href={section.url}
className={classes.toolbarLink}
>
{section.title}
</Link>
))}
</Toolbar> */}
</AppBar>
);
};
Expand Down
34 changes: 34 additions & 0 deletions src/components/molecules/Menu/Mobile/MobileMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import MenuIcon from "@material-ui/icons/Menu";
import { IconButton } from '@material-ui/core';

//interfaces
import { IMenuProps } from '../../../../types/IMenuProps';


const useStyles = makeStyles((theme) => ({
menuButton: {
marginRight: theme.spacing(2)
},
}));

export interface IMobileMenuProps {
sections: IMenuProps[];
}

export default function MobileMenu(props: IMobileMenuProps): JSX.Element {
const classes = useStyles();

return (<>{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to wrap it with <></> if you're returning only one component IconButton

<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
//onClick={handleMenu}
>
<MenuIcon />
</IconButton>
}</>)
}
76 changes: 76 additions & 0 deletions src/components/molecules/MobileMenu/MobileMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import MenuIcon from "@material-ui/icons/Menu";
import { Button, IconButton, List, ListItem, Typography } from '@material-ui/core';
import { StaticImage } from "gatsby-plugin-image";

//interfaces
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this comment adds much 😜

import Section from '../../../types/section';
import { Drawer } from '@material-ui/core';
import { ListItemText } from '@material-ui/core';
import useStyles from '../Header/Header.styles';

export interface IMobileMenuProps {
sections: Section[];
}

export default function MobileMenu(props: IMobileMenuProps): JSX.Element {

const [state, setState] = React.useState(false);

const toggleDrawer = (open: boolean) => (
event: React.KeyboardEvent | React.MouseEvent,
) => {
if (
event.type === 'keydown' &&
((event as React.KeyboardEvent).key === 'Tab' ||
(event as React.KeyboardEvent).key === 'Shift')
) {
return;
}

setState(open);
};

const classes = useStyles();

return (
<div>
<Drawer anchor="top" open={state} onClose={() => setState(false)}>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<Typography
component="h2"
variant="h5"
color="inherit"
style={{ padding: '10px' }}
noWrap
className={classes.toolbarTitle}
>
<StaticImage
alt={`Mobile menu Logo`}
src="../../../images/codestar_logo_dark.svg"
/>
</Typography>
<List component="nav" aria-label="secondary mailbox folders" >
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for <> here 😊

<>{
props.sections.map(section => <>
<ListItem button>
<Button href={section.url}>{section.title}</Button>
</ListItem>
</>)
}</>

</List>
</div>
</Drawer>
<IconButton
key="iconButton"
edge="start"
color="inherit"
aria-label="menu"
onClick={toggleDrawer(true)}
>
<MenuIcon key="menuIButton" />
</IconButton>
</div>
)
}
24 changes: 24 additions & 0 deletions src/components/organisms/MainMenu/MainMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { useTheme } from '@material-ui/core/styles';
import useMediaQuery from "@material-ui/core/useMediaQuery";

// local imports
import BrowserMenu from '../../molecules/BrowserMenu/BrowserMenu';
import MobileMenu from '../../molecules/MobileMenu/MobileMenu';

//interfaces
import { IMenuProps } from '../../../types/IMenuProps';

export default function MainMenu(props: IMenuProps): JSX.Element {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("xs"));

return (<>
{
isMobile ?
<MobileMenu sections={props.sections} />
:
<BrowserMenu sections={props.sections} />
}
</>)
Comment on lines +16 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think

return isMobile ? <MobileMenu sections={props.sections} /> : <BrowserMenu sections={props.sections} />

should also work!

}
6 changes: 6 additions & 0 deletions src/types/IMenuProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Section from './section';


export interface IMenuProps {
sections: Section[];
}
Loading