import React from "react"; import { Link as ReactLink } from "react-router-dom"; import { ErrorBoundary, FireCMSLogo } from "../components"; import { Avatar, cn, DarkModeIcon, IconButton, LightModeIcon, LogoutIcon, Menu, MenuItem, Skeleton, Typography } from "@firecms/ui"; import { useAuthController, useLargeLayout, useModeController, useNavigationController } from "../hooks"; import { User } from "../types"; export type FireCMSAppBarProps = { title: React.ReactNode; /** * A component that gets rendered on the upper side of the main toolbar */ endAdornment?: React.ReactNode; startAdornment?: React.ReactNode; dropDownActions?: React.ReactNode; includeDrawer?: boolean; drawerOpen: boolean; className?: string; style?: React.CSSProperties; logo?: string; user?: User; } & ADDITIONAL_PROPS; /** * This component renders the main app bar of FireCMS. * You will likely not need to use this component directly. * * @param title * @param toolbarExtraWidget * @param drawerOpen * @constructor */ export const FireCMSAppBar = function FireCMSAppBar({ title, endAdornment, startAdornment, drawerOpen, dropDownActions, includeDrawer, className, style, logo, user: userProp }: FireCMSAppBarProps) { const navigation = useNavigationController(); const authController = useAuthController(); const { mode, toggleMode } = useModeController(); const largeLayout = useLargeLayout(); const user = userProp ?? authController.user; let avatarComponent: JSX.Element; if (user && user.photoURL) { avatarComponent = ; } else if (user === undefined || authController.initialLoading) { avatarComponent =
; } else { const initial = user?.displayName ? user.displayName[0].toUpperCase() : (user?.email ? user.email[0].toUpperCase() : "A"); avatarComponent = {initial}; } return (
{navigation &&
{!includeDrawer && (logo ? Logo : )} {typeof title === "string" ? {title} : title}
} {startAdornment}
{endAdornment && {endAdornment} } {mode === "dark" ? : } {user &&
{user.displayName && {user.displayName} } {user.email && {user.email} }
} {dropDownActions} {!dropDownActions && Log Out }
); }