-
Notifications
You must be signed in to change notification settings - Fork 117
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
ui v2: update UserInformation component #782
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a717854
update styling, add interface
scarlettperry 27e652e
cleanup, add more styling
scarlettperry f1176e2
remove typography component, simplify conditional logic
scarlettperry f7730f6
clean up css, fix popper alignment
scarlettperry 2cdf30e
add more comments
scarlettperry dcd413d
change email, keep padding the same
scarlettperry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 14 additions & 9 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 |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import * as React from "react"; | ||
import { Grid } from "@material-ui/core"; | ||
import styled from "@emotion/styled"; | ||
import { Grid as MuiGrid } from "@material-ui/core"; | ||
import type { Meta } from "@storybook/react"; | ||
|
||
import type { UserInformationProps } from "../user"; | ||
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 = () => ( | ||
const Grid = styled(MuiGrid)({ | ||
height: "64px", | ||
backgroundColor: "#131C5F", | ||
}); | ||
|
||
const Template = (props: UserInformationProps) => ( | ||
<Grid container alignItems="center" justify="center"> | ||
<UserInformation /> | ||
<UserInformation {...props} /> | ||
</Grid> | ||
); | ||
export const Primary = Template.bind({}); | ||
Primary.args = { | ||
data: [{ value: "Dashboard" }, { value: "Settings" }], | ||
user: "fooBar@gmail.com", | ||
}; |
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 |
---|---|---|
|
@@ -2,17 +2,16 @@ import React from "react"; | |
import styled from "@emotion/styled"; | ||
import { | ||
Avatar as MuiAvatar, | ||
Box, | ||
ClickAwayListener, | ||
Divider as MuiDivider, | ||
Grow as MuiGrow, | ||
IconButton, | ||
ListItemIcon, | ||
ListItemText, | ||
ListItemText as MuiListItemText, | ||
MenuItem as MuiMenuItem, | ||
MenuList, | ||
MenuList as MuiMenuList, | ||
Paper as MuiPaper, | ||
Popper as MuiPopper, | ||
Typography, | ||
} from "@material-ui/core"; | ||
import Cookies from "js-cookie"; | ||
import jwtDecode from "jwt-decode"; | ||
|
@@ -25,51 +24,93 @@ const UserPhoto = styled(IconButton)({ | |
"&:active": { | ||
background: "#2938a5", | ||
}, | ||
// avatar on header | ||
".MuiAvatar-root": { | ||
height: "32px", | ||
width: "32px", | ||
fontSize: "14px", | ||
lineHeight: "18px", | ||
}, | ||
}); | ||
|
||
// header and menu avatar | ||
const Avatar = styled(MuiAvatar)({ | ||
backgroundColor: "#dce7f4", | ||
height: "28px", | ||
width: "28px", | ||
border: "2px solid #f6faff", | ||
borderRadius: "50%", | ||
}); | ||
|
||
const Initials = styled(Typography)({ | ||
color: "#0d1030", | ||
opacity: 0.6, | ||
fontSize: "14px", | ||
backgroundColor: "#727FE1", | ||
color: "#FFFFFF", | ||
fontWeight: 500, | ||
}); | ||
|
||
const Paper = styled(MuiPaper)({ | ||
width: "266px", | ||
border: "1px solid #e2e2e6", | ||
width: "242px", | ||
border: "1px solid #E7E7EA", | ||
boxShadow: "0px 5px 15px rgba(53, 72, 212, 0.2)", | ||
}); | ||
|
||
const Popper = styled(MuiPopper)({ | ||
padding: "0 12px", | ||
marginLeft: "12px", | ||
padding: "0 6px", | ||
marginLeft: "6px", | ||
zIndex: 1101, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this commit https://github.com/lyft/clutch/pull/760/files, the avatar popper has been hidden behind the appbar. so added the appbar zindex + 1 |
||
}); | ||
|
||
const UserProfileMenuItem = styled(MuiMenuItem)({ | ||
"&:focus": { | ||
background: "transparent", | ||
}, | ||
"&:hover": { | ||
background: "transparent", | ||
const MenuList = styled(MuiMenuList)({ | ||
padding: "0px", | ||
borderRadius: "4px", | ||
".MuiMenuItem-root": { | ||
"&:hover": { | ||
backgroundColor: "#E7E7EA", | ||
}, | ||
"&:active": { | ||
backgroundColor: "#EBEDFB", | ||
}, | ||
}, | ||
}); | ||
|
||
// user details menu item | ||
const AvatarMenuItem = styled(MuiMenuItem)({ | ||
height: "52px", | ||
margin: "16px 0 16px 0", | ||
padding: "0 16px 0 16px", | ||
}); | ||
|
||
const AvatarListItemIcon = styled(ListItemIcon)({ | ||
marginLeft: "8px", | ||
minWidth: "inherit", | ||
width: "48px", | ||
// avatar on menu | ||
".MuiAvatar-root": { | ||
height: "48px", | ||
width: "48px", | ||
fontSize: "20px", | ||
lineHeight: "24px", | ||
}, | ||
}); | ||
|
||
const AvatarListItemText = styled(MuiListItemText)({ | ||
paddingLeft: "16px", | ||
margin: "0px", | ||
".MuiTypography-root": { | ||
color: "rgba(13, 16, 48, 0.6)", | ||
fontSize: "14px", | ||
lineHeight: "24px", | ||
}, | ||
}); | ||
|
||
// default menu items | ||
const MenuItem = styled(MuiMenuItem)({ | ||
height: "48px", | ||
padding: "12px", | ||
}); | ||
|
||
const ListItemText = styled(MuiListItemText)({ | ||
margin: "0px", | ||
".MuiTypography-root": { | ||
color: "#0D1030", | ||
fontSize: "14px", | ||
lineHeight: "24px", | ||
}, | ||
}); | ||
|
||
const AvatarListItemText = styled(Typography)({ | ||
color: "#0d1030", | ||
fontSize: "14px", | ||
opacity: "0.6", | ||
const Divider = styled(MuiDivider)({ | ||
backgroundColor: "#E7E7EA", | ||
}); | ||
|
||
const Grow = styled(MuiGrow)((props: { placement: string }) => ({ | ||
|
@@ -96,17 +137,26 @@ const userId = (): string => { | |
return subject; | ||
}; | ||
|
||
const UserAvatar: React.FC = () => { | ||
return ( | ||
<Avatar> | ||
<Initials>{userId().slice(0, 2).toUpperCase()}</Initials> | ||
</Avatar> | ||
); | ||
interface UserAvatarProps { | ||
initials: string; | ||
} | ||
|
||
const UserAvatar: React.FC<UserAvatarProps> = ({ initials }) => { | ||
return <Avatar>{initials}</Avatar>; | ||
}; | ||
|
||
// TODO (sperry): add interface to render menu items | ||
interface UserData { | ||
value: string; | ||
} | ||
|
||
export interface UserInformationProps { | ||
data?: UserData[]; | ||
user?: string; | ||
} | ||
|
||
// TODO (sperry): investigate using popover instead of popper | ||
const UserInformation: React.FC = () => { | ||
const UserInformation: React.FC<UserInformationProps> = ({ data, user = userId() }) => { | ||
const userInitials = user.slice(0, 2).toUpperCase(); | ||
const [open, setOpen] = React.useState(false); | ||
const anchorRef = React.useRef(null); | ||
|
||
|
@@ -129,23 +179,17 @@ const UserInformation: React.FC = () => { | |
} | ||
|
||
return ( | ||
<Box> | ||
<> | ||
<UserPhoto | ||
ref={anchorRef} | ||
edge="end" | ||
aria-controls={open ? "account-options" : undefined} | ||
aria-haspopup="true" | ||
onClick={handleToggle} | ||
> | ||
<UserAvatar /> | ||
<UserAvatar initials={userInitials} /> | ||
</UserPhoto> | ||
<Popper | ||
open={open} | ||
anchorEl={anchorRef.current} | ||
role={undefined} | ||
transition | ||
placement="bottom-end" | ||
> | ||
<Popper open={open} anchorEl={anchorRef.current} transition placement="bottom-end"> | ||
{({ TransitionProps, placement }) => ( | ||
<Grow | ||
{...TransitionProps} | ||
|
@@ -154,21 +198,25 @@ const UserInformation: React.FC = () => { | |
<Paper> | ||
<ClickAwayListener onClickAway={handleClose}> | ||
<MenuList autoFocusItem={open} id="account-options" onKeyDown={handleListKeyDown}> | ||
<UserProfileMenuItem> | ||
<AvatarMenuItem> | ||
<AvatarListItemIcon> | ||
<UserAvatar /> | ||
<UserAvatar initials={userInitials} /> | ||
</AvatarListItemIcon> | ||
<ListItemText> | ||
<AvatarListItemText>{userId()}</AvatarListItemText> | ||
</ListItemText> | ||
</UserProfileMenuItem> | ||
<AvatarListItemText>{user}</AvatarListItemText> | ||
</AvatarMenuItem> | ||
{data?.length === 0 ? null : <Divider />} | ||
{data?.map(d => ( | ||
<MenuItem> | ||
<ListItemText>{d.value}</ListItemText> | ||
</MenuItem> | ||
))} | ||
</MenuList> | ||
</ClickAwayListener> | ||
</Paper> | ||
</Grow> | ||
)} | ||
</Popper> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: use example domain