Skip to content

Commit

Permalink
Add buttonChildren and children props to UserHeaderItem (#2234)
Browse files Browse the repository at this point in the history
This increases the flexibility by allowing customization.
  • Loading branch information
jomunker authored Jul 2, 2024
1 parent 1c2731b commit cdc861c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .changeset/cyan-chicken-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@comet/cms-admin": minor
---

Add `buttonChildren` and `children` props to `UserHeaderItem`

This increases the flexibility of the `UserHeaderItem` component by allowing the `AppHeaderDropdown` label to be passed via `buttonChildren`. More buttons or other list items in the dropdown can be passed via `children`.

**Example:**
```tsx
<UserHeaderItem buttonChildren="Some custom label">
<Button variant="contained">Some custom button</Button>
<Button>Some custom button 2</Button>
</UserHeaderItem>
```
15 changes: 8 additions & 7 deletions packages/admin/cms-admin/src/common/header/UserHeaderItem.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AppHeaderDropdown, Loading } from "@comet/admin";
import { gql, useMutation } from "@apollo/client";
import { AppHeaderDropdown, AppHeaderDropdownProps, Loading } from "@comet/admin";
import { Account, Info, Logout } from "@comet/admin-icons";
import { Box, Button as MUIButton } from "@mui/material";
import { styled } from "@mui/material/styles";
import React from "react";
import { FormattedMessage } from "react-intl";

import { useCurrentUser } from "../../userPermissions/hooks/currentUser";
import { AboutModal } from "./about/AboutModal";
import { GQLSignOutMutation } from "./UserHeaderItem.generated";

Expand All @@ -24,10 +26,6 @@ const Separator = styled(Box)`
margin-bottom: 20px;
`;

import { gql, useMutation } from "@apollo/client";

import { useCurrentUser } from "../../userPermissions/hooks/currentUser";

const signOutMutation = gql`
mutation SignOut {
currentUserSignOut
Expand All @@ -36,17 +34,19 @@ const signOutMutation = gql`

interface UserHeaderItemProps {
aboutModalLogo?: React.ReactElement;
buttonChildren?: AppHeaderDropdownProps["buttonChildren"];
children?: React.ReactNode;
}

export function UserHeaderItem(props: UserHeaderItemProps): React.ReactElement {
const { aboutModalLogo } = props;
const { aboutModalLogo, buttonChildren, children } = props;

const user = useCurrentUser();
const [showAboutModal, setShowAboutModal] = React.useState(false);
const [signOut, { loading: isSigningOut }] = useMutation<GQLSignOutMutation>(signOutMutation);

return (
<AppHeaderDropdown buttonChildren={user.name} startIcon={<Account />}>
<AppHeaderDropdown buttonChildren={buttonChildren ?? user.name} startIcon={<Account />}>
<DropdownContent padding={4}>
<Button
fullWidth={true}
Expand All @@ -58,6 +58,7 @@ export function UserHeaderItem(props: UserHeaderItemProps): React.ReactElement {
>
<FormattedMessage id="comet.about" defaultMessage="About" />
</Button>
{children}
<Separator />
{isSigningOut ? (
<Loading />
Expand Down

0 comments on commit cdc861c

Please sign in to comment.