Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*feat AppHeader aside content #575

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions packages/ui/__stories__/AppHeader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,50 @@ export const WithoutMenu = () => {
/>
)
}

export const WithoutMenuAndWithAsideContent = () => {
const [cluster, setCluster] = useState<string | null>(null)

return (
<AppHeaderComponent
name="Management Center"
clusterSelectProps={{
clusterName: cluster,
clusterNames: ['Cluster-1', 'Cluster-2'],
clusterVersions: { 'Cluster-1': '5.5', 'Cluster-2': '6.0', 'Cluster-3': '3.1.2' },
onChange: setCluster,
}}
logoProps={{
LinkComponent: ({ children, className }) => <span className={className}>{children}</span>,
}}
asideContent={<Button>Link</Button>}
menuContent={() => (
<>
<Button color="light" variant="text">
Item 1
</Button>
</>
)}
/>
)
}

export const WithAsideContent = () => {
const [cluster, setCluster] = useState<string | null>(null)

return (
<AppHeaderComponent
name="Management Center"
clusterSelectProps={{
clusterName: cluster,
clusterNames: ['Cluster-1', 'Cluster-2'],
clusterVersions: { 'Cluster-1': '5.5', 'Cluster-2': '6.0', 'Cluster-3': '3.1.2' },
onChange: setCluster,
}}
asideContent={<Button>Link</Button>}
logoProps={{
LinkComponent: ({ children, className }) => <span className={className}>{children}</span>,
}}
/>
)
}
3 changes: 3 additions & 0 deletions packages/ui/src/AppHeader/AppHeader.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
}

.aside {
display: flex;
align-items: center;
margin-left: auto;
gap: c.$grid * 4;
}
7 changes: 6 additions & 1 deletion packages/ui/src/AppHeader/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface AppHeaderProps extends DataTestProp {
name: ReactNode
className?: string
children?: ReactNode
asideContent?: ReactNode
environment?: 'production'
logoProps: AppHeaderLogoProps
clusterSelectProps?: SelectClusterProps
Expand All @@ -27,6 +28,7 @@ export const AppHeader = ({
clusterSelectProps,
logoProps,
menuContent,
asideContent,
'data-test': dataTest = 'app-header',
}: AppHeaderProps) => (
<header data-test={dataTest} className={cls(styles.root, className)}>
Expand All @@ -35,6 +37,9 @@ export const AppHeader = ({
{clusterSelectProps && <SelectCluster {...clusterSelectProps} />}
{children}
{environment && <EnvironmentBadge environment={environment} />}
<div className={styles.aside}>{menuContent && <AppHeaderMenu>{menuContent}</AppHeaderMenu>}</div>
<div className={styles.aside}>
{asideContent}
{menuContent && <AppHeaderMenu separator={!!asideContent}>{menuContent}</AppHeaderMenu>}
</div>
</header>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
@use '../../../styles/constants' as c;

.root {
display: flex;
align-items: center;
}

.separator {
border-left: 1px solid c.$colorNeutralLight;
}

.content {
padding: c.$grid * 2;
color: c.$colorNeutralLighter;
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/src/AppHeader/AppHeaderMenu/AppHeaderMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactNode, useState } from 'react'
import { Menu as MenuIcon } from 'react-feather'
import cn from 'classnames'

import { Button } from '../../Button'
import { Popover } from '../../Popover'
Expand All @@ -8,15 +9,16 @@ import { useOpenCloseState } from '../../hooks'
import styles from './AppHeaderMenu.module.scss'

export interface AppHeaderMenuProps {
separator?: boolean
children: (props: { onClose: () => void }) => ReactNode
}

export const AppHeaderMenu = ({ children }: AppHeaderMenuProps) => {
export const AppHeaderMenu = ({ separator, children }: AppHeaderMenuProps) => {
const [anchorElement, setAnchorElement] = useState<HTMLElement | null>()
const { isOpen, toggle, close } = useOpenCloseState()

return (
<>
<div className={cn(styles.root, { [styles.separator]: separator })}>
<Button
variant="text"
color="light"
Expand All @@ -34,6 +36,6 @@ export const AppHeaderMenu = ({ children }: AppHeaderMenuProps) => {
<Popover open={isOpen} anchorElement={anchorElement} onClose={close} className={styles.content}>
{children({ onClose: close })}
</Popover>
</>
</div>
)
}
Loading