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

ui v2: update UserInformation component #782

Merged
merged 6 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
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",
Copy link
Collaborator

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

Suggested change
user: "fooBar@gmail.com",
user: "fooBar@example.com",

};
156 changes: 102 additions & 54 deletions frontend/packages/core/src/AppLayout/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 }) => ({
Expand All @@ -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);

Expand All @@ -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}
Expand All @@ -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>
</>
);
};

Expand Down