diff --git a/packages/smarthr-ui/src/components/Header/Header.tsx b/packages/smarthr-ui/src/components/Header/Header.tsx index 3539de4a98..a021f8f4e0 100644 --- a/packages/smarthr-ui/src/components/Header/Header.tsx +++ b/packages/smarthr-ui/src/components/Header/Header.tsx @@ -62,25 +62,90 @@ type Props = { type ElementProps = Omit, keyof Props> +const COMMON_GAP = { column: 0.25, row: 0 } as const +const CHILDREN_GAP = { column: 0.5, row: 0.25 } as const + export const Header: React.FC & ElementProps> = ({ enableNew, - logo = , - logoHref = '/', + logo, + logoHref, featureName, - apps = [], + apps, tenants, currentTenantId, onTenantSelect, children, className, }) => { - const { - wrapper, - logoLink, - tenantInfo: tenantInfoStyle, - tenantNameText, - actions, - } = header({ enableNew }) + const styles = useMemo(() => { + const { + wrapper, + logoLink, + tenantInfo: tenantInfoStyle, + tenantNameText, + actions, + } = header({ enableNew }) + + return { + wrapper: wrapper({ className }), + logoLink: logoLink(), + tenantInfo: tenantInfoStyle(), + tenantNameText: tenantNameText(), + actions: actions(), + } + }, [enableNew, className]) + + return ( + + + + {logo} + + {enableNew ? ( + + ) : ( + + )} + + + {children} + + + ) +} + +const Logo = React.memo< + Pick & { children: Props['logo']; href: Props['logoHref']; className: string } +>(({ children, href, enableNew, className }) => ( + + {children || } + +)) + +const MemoizedAppLauncher = React.memo>( + ({ featureName, apps = [], enableNew }) => { + const decorators = useMemo(() => { + if (!featureName) { + return undefined + } + + return { triggerLabel: () => featureName } + }, [featureName]) + + return featureName && + }, +) + +const TenantSwitcher = React.memo< + Pick & { + styles: { tenantInfo: string; tenantNameText: string } + } +>(({ currentTenantId, tenants, styles, onTenantSelect }) => { const currentTenantName = useMemo(() => { if (tenants && tenants.length >= 1) { const current = tenants.find(({ id }) => id === currentTenantId) @@ -89,53 +154,46 @@ export const Header: React.FC & ElementProps> = ({ return undefined }, [currentTenantId, tenants]) - const tenantInfo = useMemo( + + return ( + currentTenantName && ( +
+ {tenants && tenants.length > 1 ? ( + + ) : ( + + {currentTenantName} + + )} +
+ ) + ) +}) + +const MultiTenantDropdownMenuButton = React.memo< + Pick, 'tenants'> & Pick & { label: ReactNode } +>(({ label, tenants, onTenantSelect }) => { + const onClick = useMemo( () => - tenants && tenants.length > 1 ? ( - - {tenants.map(({ id, name }) => ( - - ))} - - ) : ( - - {currentTenantName} - - ), - [currentTenantName, onTenantSelect, tenants, tenantNameText], + onTenantSelect + ? (e: React.MouseEvent) => { + onTenantSelect(e.currentTarget.value) + } + : undefined, + [onTenantSelect], ) return ( - - - - {logo} - - {enableNew - ? featureName && ( - featureName }} - /> - ) - : currentTenantName &&
{tenantInfo}
} -
- - {children} - -
+ + {tenants.map(({ id, name }) => ( + + ))} + ) -} +}) diff --git a/packages/smarthr-ui/src/components/Header/HeaderLink.tsx b/packages/smarthr-ui/src/components/Header/HeaderLink.tsx index aac7df051a..7b485aa511 100644 --- a/packages/smarthr-ui/src/components/Header/HeaderLink.tsx +++ b/packages/smarthr-ui/src/components/Header/HeaderLink.tsx @@ -22,5 +22,6 @@ const headerLink = tv({ export const HeaderLink: React.FC = ({ enableNew, className, ...props }) => { const style = headerLink({ enableNew, className }) + return }