-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from elite-se/feature/ui-foundation
Feature/ui foundation
- Loading branch information
Showing
13 changed files
with
211 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './general'; | ||
export * from './list'; | ||
export * from './navigation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './navigationBar.component'; |
75 changes: 75 additions & 0 deletions
75
packages/components/src/navigation/navigationBar.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as React from 'react'; | ||
import { AppBar, Toolbar, makeStyles, IconButton, Theme, createStyles, Typography, Button } from '@material-ui/core'; | ||
import MenuIcon from '@material-ui/icons/Menu'; | ||
import { RouteDrawer } from './routeDrawer.component'; | ||
import { AppRoute } from 'elite-types'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
root: { | ||
flexGrow: 1, | ||
}, | ||
menuButton: { | ||
marginRight: theme.spacing(2), | ||
}, | ||
title: { | ||
flexGrow: 1, | ||
}, | ||
}), | ||
); | ||
|
||
export interface NavigationBarProps { | ||
/** Title displayed by in navigation bar */ | ||
readonly title: string; | ||
|
||
/** Callback used by navigation bar to navigate to a route */ | ||
readonly onNavigateTo: (route: AppRoute) => void; | ||
|
||
/** Routes that the user may navigate to */ | ||
readonly routes: AppRoute[]; | ||
} | ||
|
||
/** | ||
* NavigationBar displays a material-ui AppBar in combination with a Drawer | ||
* component which the User can use to navigate the available routes | ||
* | ||
* @param props See NavigationBarProps | ||
*/ | ||
export const NavigationBar = (props: NavigationBarProps) => { | ||
const classes = useStyles(); | ||
const [routeDrawerOpen, setRouteDrawerOpen] = React.useState(false); | ||
|
||
const title = props.title; | ||
|
||
return ( | ||
<> | ||
<div className={classes.root}> | ||
<AppBar position={'static'}> | ||
<Toolbar> | ||
<IconButton | ||
edge={'start'} | ||
className={classes.menuButton} | ||
color={'inherit'} | ||
aria-label={'open drawer'} | ||
onClick={() => setRouteDrawerOpen(true)} | ||
> | ||
<MenuIcon /> | ||
</IconButton> | ||
<Typography className={classes.title} variant={'h6'} noWrap> | ||
{title} | ||
</Typography> | ||
<Button color={'inherit'}>Login</Button> | ||
</Toolbar> | ||
</AppBar> | ||
</div> | ||
|
||
<RouteDrawer | ||
routes={props.routes} | ||
onNavigateTo={props.onNavigateTo} | ||
isOpen={routeDrawerOpen} | ||
onOpen={() => setRouteDrawerOpen(true)} | ||
onClose={() => setRouteDrawerOpen(false)} | ||
/> | ||
</> | ||
); | ||
}; |
58 changes: 58 additions & 0 deletions
58
packages/components/src/navigation/routeDrawer.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
createStyles, | ||
List, | ||
ListItem, | ||
ListItemIcon, | ||
ListItemText, | ||
makeStyles, | ||
SwipeableDrawer, | ||
Theme, | ||
} from '@material-ui/core'; | ||
import { AppRoute, getDisplayNameForRoute, getLinkForRoute } from 'elite-types'; | ||
import * as React from 'react'; | ||
|
||
export interface RouteDrawerProps { | ||
/** Routes displayed as options in the drawer list */ | ||
readonly routes: AppRoute[]; | ||
|
||
/** Callback used by route drawer to navigate to a route */ | ||
readonly onNavigateTo: (route: AppRoute) => void; | ||
|
||
/** Whether or not the drawer is open */ | ||
readonly isOpen: boolean; | ||
|
||
/** Callback used by the drawer to signify it should open */ | ||
readonly onOpen: () => void; | ||
|
||
/** Callback used by the drawer to signify it should close */ | ||
readonly onClose: () => void; | ||
} | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
list: { | ||
width: 250, | ||
}, | ||
fullList: { | ||
width: 'auto', | ||
}, | ||
}), | ||
); | ||
|
||
export const RouteDrawer = (props: RouteDrawerProps) => { | ||
const classes = useStyles(); | ||
return ( | ||
<SwipeableDrawer anchor={'bottom'} open={props.isOpen} onClose={props.onClose} onOpen={props.onOpen}> | ||
<div className={classes.fullList} role={'presentation'} onClick={props.onClose} onKeyDown={props.onClose}> | ||
<List> | ||
{props.routes.map(route => ( | ||
<ListItem button={true} key={getLinkForRoute(route)} onClick={() => props.onNavigateTo(route)}> | ||
{route.icon && <ListItemIcon>{route.icon}</ListItemIcon>} | ||
<ListItemText primary={getDisplayNameForRoute(route)} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</div> | ||
</SwipeableDrawer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
import { LinkType } from './link.type'; | ||
import { AppPath } from './appPath.type'; | ||
import { RouteProps } from 'react-router'; | ||
import { RouteProps, RouteComponentProps } from 'react-router'; | ||
|
||
/** | ||
* Each Approute can have a specific link (i.e., path with filled parameter placeholders), | ||
* a display Name, i.e., text of the link and a nonoptional (!) path | ||
*/ | ||
export interface AppRoute extends RouteProps { | ||
// Use this if the link target differs from the path specification, | ||
// i.e., if the path url contains paramter specifications etc | ||
/** | ||
* Use this if the link target differs from the path specification, | ||
* i.e., if the path url contains paramter specifications etc | ||
*/ | ||
readonly link?: LinkType; | ||
|
||
// link text (Human readable!) | ||
/** link text (Human readable!) */ | ||
readonly displayName?: string; | ||
|
||
// AppRoutes must have a path - deoptionalize this property | ||
/** optional icon displayed next to the link name */ | ||
readonly icon?: JSX.Element; | ||
|
||
/** AppRoutes must have a path - deoptionalize this property */ | ||
readonly path: AppPath; | ||
|
||
render(props: any): any; | ||
/** render is required for AppRoutes */ | ||
readonly render: (props: RouteComponentProps<any>) => React.ReactNode; | ||
|
||
/** prevent usage of component/children props, i.e., AppRoutes must use render! */ | ||
readonly component?: never; | ||
readonly children?: never; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AppRoute } from './appRoute.type'; | ||
import { LinkType } from './link.type'; | ||
|
||
/** | ||
* Retrieves the url which other pages can use to link to a certain | ||
* app path | ||
* | ||
* @param route | ||
*/ | ||
export function getLinkForRoute(route: AppRoute): LinkType { | ||
return route.link || route.path; | ||
} | ||
|
||
/** | ||
* Retrieves the human readable link title/displayed name for | ||
* a given route | ||
* | ||
* @param route | ||
*/ | ||
export function getDisplayNameForRoute(route: AppRoute): string { | ||
return route.displayName || getLinkForRoute(route); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './appPath.type'; | ||
export * from './appRoute.type'; | ||
export * from './appRoute.util'; | ||
export * from './link.type'; |