generated from bcgov/EPIC.scaffold
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
showing UserProfileMenu on hovering name in appbar
- Loading branch information
1 parent
664fa7d
commit 40ca175
Showing
6 changed files
with
167 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from "react"; | ||
import { IconButton } from "@mui/material"; | ||
import { FileCopy, FileCopyOutlined } from "@mui/icons-material"; | ||
import { BCPalette } from "epic.theme"; | ||
|
||
const iconStyles = { color: BCPalette.theme.primaryBlue[90], fontSize: "1rem" }; | ||
|
||
const CopyButton = ({ ...props }) => { | ||
const copyHandler = (text: string) => { | ||
// showNotification("Copied to clipboard", { | ||
// type: "success", | ||
// }); | ||
navigator.clipboard.writeText(text); | ||
}; | ||
|
||
const [hover, setHover] = React.useState<boolean>(false); | ||
|
||
return ( | ||
<IconButton | ||
color="primary" | ||
onClick={() => copyHandler(props.copyText)} | ||
sx={{ | ||
width: "2rem", | ||
height: "2rem", | ||
borderRadius: "0.25rem", | ||
}} | ||
onMouseEnter={() => setHover(true)} | ||
onMouseLeave={() => setHover(false)} | ||
> | ||
{hover ? ( | ||
<FileCopy sx={iconStyles} /> | ||
) : ( | ||
<FileCopyOutlined sx={iconStyles} /> | ||
)} | ||
</IconButton> | ||
); | ||
}; | ||
|
||
export default CopyButton; |
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
File renamed without changes.
96 changes: 96 additions & 0 deletions
96
compliance-web/src/components/Shared/Header/UserProfileMenu.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,96 @@ | ||
import { Menu, Box, Avatar, Typography } from "@mui/material"; | ||
import { BCPalette } from "epic.theme"; | ||
import CopyButton from "@/components/Shared/CopyButton"; | ||
import { theme } from "@/styles/theme"; | ||
import { useAuth } from "react-oidc-context"; | ||
|
||
export default function UserProfileMenu({ ...props }) { | ||
const { user } = useAuth(); | ||
|
||
return ( | ||
<Menu | ||
id="profile-menu" | ||
anchorEl={props.anchorEl} | ||
open={Boolean(props.anchorEl)} | ||
onClose={props.handleClose} | ||
MenuListProps={{ | ||
style: { | ||
paddingTop: 0, | ||
paddingBottom: 0, | ||
pointerEvents: "auto", | ||
}, | ||
}} | ||
> | ||
<Box sx={{ display: "flex", flexDirection: "column", width: 320 }}> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
gap: "0.5rem", | ||
padding: "1rem", | ||
bgcolor: BCPalette.components.background.lightGray, | ||
borderBottom: `1px solid ${BCPalette.components.border.light}`, | ||
alignItems: "center", | ||
}} | ||
> | ||
<Avatar | ||
sx={{ | ||
bgcolor: theme.palette.primary.main, | ||
width: "2rem", | ||
height: "2rem", | ||
}} | ||
> | ||
<Typography | ||
variant="body2" | ||
fontWeight={700} | ||
color={theme.palette.primary.contrastText} | ||
>{`${user?.profile?.given_name?.charAt(0)}${user?.profile?.family_name?.charAt(0)}`}</Typography> | ||
</Avatar> | ||
<Typography | ||
variant="body2" | ||
fontWeight={700} | ||
>{`${user?.profile?.name}`}</Typography> | ||
</Box> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
gap: "8px", | ||
padding: "1rem", | ||
flexDirection: "column", | ||
}} | ||
> | ||
<Typography variant="body2" fontWeight={700}> | ||
Contact | ||
</Typography> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
}} | ||
> | ||
{userDetails(user?.profile?.email)} | ||
{userDetails(user?.profile?.phone_number)} | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Menu> | ||
); | ||
|
||
function userDetails(detail?: string) { | ||
return ( | ||
detail && ( | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography variant="body2" color={BCPalette.theme.primaryBlue[90]}> | ||
{detail} | ||
</Typography> | ||
<CopyButton copyText={detail} /> | ||
</Box> | ||
) | ||
); | ||
} | ||
} |
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