Refactor header: extract Avatar into standalone UserAvatarMenu component, and add _hover styling
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { chakra, useRecipe, Box, Button, Avatar, Stack, Text, Menu, Portal, Flex } from "@chakra-ui/react"
|
||||
import { chakra, useRecipe, Box, Button, Stack, Text, Flex } from "@chakra-ui/react"
|
||||
import UserAvatarMenu from "./UserAvatarMenu";
|
||||
|
||||
export default function Header() {
|
||||
const recipe = useRecipe({ key: "header" });
|
||||
@@ -12,26 +13,7 @@ export default function Header() {
|
||||
<Text color="color" fontWeight="bold" textStyle="lg">{user.name}</Text>
|
||||
<Text color="fg.muted" textStyle="sm">{user.email}</Text>
|
||||
</Stack>
|
||||
|
||||
{/* Add a drop down menu to the avatar */}
|
||||
<Menu.Root>
|
||||
<Menu.Trigger rounded="full" focusRing="outside">
|
||||
<Avatar.Root>
|
||||
<Avatar.Fallback name={user.name} />
|
||||
<Avatar.Image src={user.avatar} />
|
||||
</Avatar.Root>
|
||||
</Menu.Trigger>
|
||||
<Portal>
|
||||
<Menu.Positioner zIndex="popover">
|
||||
<Menu.Content>
|
||||
<Menu.Item value="account">Account</Menu.Item>
|
||||
<Menu.Item value="settings">Settings</Menu.Item>
|
||||
<Menu.Item value="logout">Logout</Menu.Item>
|
||||
</Menu.Content>
|
||||
</Menu.Positioner>
|
||||
</Portal>
|
||||
</Menu.Root>
|
||||
{/* End drop down menu */}
|
||||
<UserAvatarMenu name={user.name} avatar={user.avatar} />
|
||||
</Flex>
|
||||
</chakra.div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Avatar, Menu, Portal, Box } from "@chakra-ui/react"
|
||||
|
||||
|
||||
export default function UserAvatarMenu({ name, avatar }) {
|
||||
return (
|
||||
<Menu.Root>
|
||||
<Menu.Trigger focusRing="none">
|
||||
<Box
|
||||
rounded="full"
|
||||
tabIndex={0}
|
||||
_hover={{ boxShadow: "0 0 0 2px rgb(37, 77, 197)" }}
|
||||
>
|
||||
<Avatar.Root shape="full">
|
||||
<Avatar.Fallback name={name} />
|
||||
<Avatar.Image src={avatar} />
|
||||
</Avatar.Root>
|
||||
</Box>
|
||||
</Menu.Trigger>
|
||||
<Portal>
|
||||
<Menu.Positioner zIndex="popover">
|
||||
<Menu.Content>
|
||||
<Menu.Item value="account">Account</Menu.Item>
|
||||
<Menu.Item value="settings">Settings</Menu.Item>
|
||||
<Menu.Item value="logout">Logout</Menu.Item>
|
||||
</Menu.Content>
|
||||
</Menu.Positioner>
|
||||
</Portal>
|
||||
</Menu.Root>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user