-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e47cec2
commit 73cc79d
Showing
7 changed files
with
287 additions
and
77 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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from "react"; | ||
import styled from "@emotion/styled"; | ||
import { | ||
Box, | ||
ClickAwayListener, | ||
Grow as MuiGrow, | ||
IconButton, | ||
MenuList, | ||
Paper, | ||
Popper, | ||
} from "@material-ui/core"; | ||
import NotificationsIcon from "@material-ui/icons/Notifications"; | ||
|
||
const StyledNotificationsIcon = styled(IconButton)({ | ||
color: "#ffffff", | ||
margin: "8px", | ||
padding: "12px", | ||
"&:hover": { | ||
background: "#2d3db4", | ||
}, | ||
"&:active": { | ||
background: "#2938a5", | ||
}, | ||
}); | ||
|
||
const Grow = styled(MuiGrow)((props: { placement: string }) => ({ | ||
transformOrigin: props.placement, | ||
})); | ||
|
||
// TODO (sperry): add interface to render menu items | ||
const Notifications: React.FC = () => { | ||
const [open, setOpen] = React.useState(false); | ||
const anchorRef = React.useRef(null); | ||
|
||
const handleToggle = () => { | ||
setOpen(!open); | ||
}; | ||
|
||
const handleClose = event => { | ||
if (anchorRef.current && anchorRef.current.contains(event.target)) { | ||
return; | ||
} | ||
setOpen(false); | ||
}; | ||
|
||
function handleListKeyDown(event) { | ||
if (event.key === "Tab") { | ||
event.preventDefault(); | ||
setOpen(false); | ||
} | ||
} | ||
|
||
return ( | ||
<Box> | ||
<StyledNotificationsIcon | ||
ref={anchorRef} | ||
edge="end" | ||
aria-controls={open ? "notification-options" : undefined} | ||
aria-haspopup="true" | ||
onClick={handleToggle} | ||
> | ||
<NotificationsIcon /> | ||
</StyledNotificationsIcon> | ||
<Popper open={open} anchorEl={anchorRef.current} role={undefined} transition> | ||
{({ TransitionProps, placement }) => ( | ||
<Grow | ||
{...TransitionProps} | ||
placement={placement === "bottom" ? "center top" : "center bottom"} | ||
> | ||
<Paper> | ||
<ClickAwayListener onClickAway={handleClose}> | ||
<MenuList | ||
autoFocusItem={open} | ||
id="notification-options" | ||
onKeyDown={handleListKeyDown} | ||
/> | ||
</ClickAwayListener> | ||
</Paper> | ||
</Grow> | ||
)} | ||
</Popper> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default Notifications; |
27 changes: 27 additions & 0 deletions
27
frontend/packages/core/src/AppLayout/stories/header.stories.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,27 @@ | ||
import * as React from "react"; | ||
import { MemoryRouter } from "react-router"; | ||
import type { Meta } from "@storybook/react"; | ||
|
||
import { ApplicationContext } from "../../Contexts/app-context"; | ||
import Header from "../header"; | ||
|
||
export default { | ||
title: "Core/AppLayout/Header", | ||
component: Header, | ||
decorators: [ | ||
() => ( | ||
<MemoryRouter> | ||
<Header /> | ||
</MemoryRouter> | ||
), | ||
StoryFn => { | ||
return ( | ||
<ApplicationContext.Provider value={{ workflows: [] }}> | ||
<StoryFn /> | ||
</ApplicationContext.Provider> | ||
); | ||
}, | ||
], | ||
} as Meta; | ||
|
||
export const Primary: React.FC<{}> = () => <Header />; |
17 changes: 17 additions & 0 deletions
17
frontend/packages/core/src/AppLayout/stories/notifications.stories.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,17 @@ | ||
import * as React from "react"; | ||
import type { Meta } from "@storybook/react"; | ||
|
||
import Notifications from "../notifications"; | ||
|
||
export default { | ||
title: "Core/AppLayout/Notifications", | ||
component: Notifications, | ||
parameters: { | ||
backgrounds: { | ||
default: "header blue", | ||
values: [{ name: "header blue", value: "#131C5F" }], | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
export const Primary: React.FC<{}> = () => <Notifications />; |
23 changes: 23 additions & 0 deletions
23
frontend/packages/core/src/AppLayout/stories/user-information.stories.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,23 @@ | ||
import * as React from "react"; | ||
import { Grid } from "@material-ui/core"; | ||
import type { Meta } from "@storybook/react"; | ||
|
||
import { UserInformation } from "../user"; | ||
|
||
export default { | ||
title: "Core/AppLayout/User Information", | ||
component: UserInformation, | ||
parameters: { | ||
backgrounds: { | ||
default: "header blue", | ||
values: [{ name: "header blue", value: "#131C5F" }], | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const Template = () => ( | ||
<Grid container alignItems="center" justify="flex-end"> | ||
<UserInformation /> | ||
</Grid> | ||
); | ||
export const Primary = Template.bind({}); |
Oops, something went wrong.