11import React from 'react' ;
22import {
3+ Button ,
4+ ButtonProps ,
5+ ButtonVariant ,
6+ Content ,
7+ Divider ,
38 Flex ,
49 FlexItem ,
10+ PageBreadcrumb ,
11+ PageSection ,
512 Split ,
613 SplitItem ,
7- Content ,
8- PageSection ,
9- Button ,
10- ButtonVariant ,
11- ButtonProps ,
12- Divider ,
1314} from '@patternfly/react-core' ;
1415import { ExternalLinkAltIcon } from '@patternfly/react-icons' ;
1516import { createUseStyles } from 'react-jss' ;
@@ -24,9 +25,9 @@ export interface PageHeaderLinkProps extends ButtonProps {
2425
2526export interface PageHeaderProps extends React . PropsWithChildren {
2627 /** Title for page header */
27- title : React . ReactNode ;
28+ title ? : React . ReactNode ;
2829 /** Subtitle for page header */
29- subtitle : React . ReactNode ;
30+ subtitle ? : React . ReactNode ;
3031 /** Optional link below subtitle */
3132 linkProps ?: PageHeaderLinkProps ;
3233 /** Optional icon for page header (appears to the left of the page header's title with a divider) */
@@ -62,56 +63,71 @@ export const PageHeader: React.FunctionComponent<PageHeaderProps> = ({
6263} : PageHeaderProps ) => {
6364 const classes = useStyles ( ) ;
6465 const { isExternal = false , ...linkRestProps } = linkProps ?? { } ;
66+ const showSplitRow = title || label || actionMenu ;
67+ const showMainFlex = showSplitRow || subtitle || linkProps ;
6568
6669 return (
67- < PageSection hasBodyWrapper = { false } >
68- { breadcrumbs && (
69- < div className = "pf-v6-u-mb-md" >
70+ < >
71+ { breadcrumbs && (
72+ < PageBreadcrumb >
7073 { breadcrumbs }
71- </ div >
74+ </ PageBreadcrumb >
7275 ) }
73- < Flex >
74- { icon && (
75- < >
76- < FlexItem alignSelf = { { default : 'alignSelfCenter' } } className = { `${ classes . iconMinWidth } ` } >
77- { icon }
78- </ FlexItem >
79- < Divider orientation = { {
80- default : 'vertical' ,
81- } } />
82- </ >
83- ) }
84- < FlexItem flex = { { default : 'flex_1' } } >
85- < Split hasGutter >
86- < SplitItem >
87- < Content className = "pf-v6-u-mb-sm" component = "h1" ouiaId = { `${ ouiaId } -title` } >
88- { title }
89- </ Content >
90- </ SplitItem >
91- { label && (
92- < SplitItem >
93- { label }
94- </ SplitItem >
76+ < PageSection hasBodyWrapper = { false } >
77+ { ( showMainFlex || icon ) &&
78+ < Flex >
79+ { icon && (
80+ < >
81+ < FlexItem alignSelf = { { default : 'alignSelfCenter' } } className = { classes . iconMinWidth } >
82+ { icon }
83+ </ FlexItem >
84+ < Divider orientation = { {
85+ default : 'vertical' ,
86+ } } />
87+ </ >
9588 ) }
96- < SplitItem isFilled />
97- { actionMenu && (
98- < SplitItem >
99- { actionMenu }
100- </ SplitItem >
89+ { ( showMainFlex ) && (
90+ < FlexItem flex = { { default : 'flex_1' } } >
91+ { ( showSplitRow ) && (
92+ < Split hasGutter >
93+ { title && (
94+ < SplitItem >
95+ < Content className = "pf-v6-u-mb-sm" component = "h1" ouiaId = { `${ ouiaId } -title` } >
96+ { title }
97+ </ Content >
98+ </ SplitItem >
99+ ) }
100+ { label && (
101+ < SplitItem >
102+ { label }
103+ </ SplitItem >
104+ ) }
105+ < SplitItem isFilled />
106+ { actionMenu && (
107+ < SplitItem >
108+ { actionMenu }
109+ </ SplitItem >
110+ ) }
111+ </ Split >
112+ ) }
113+ { subtitle && (
114+ < Content component = "p" ouiaId = { `${ ouiaId } -subtitle` } >
115+ { subtitle }
116+ </ Content >
117+ ) }
118+ { linkProps && (
119+ < Button variant = { ButtonVariant . link } component = "a" ouiaId = { `${ ouiaId } -link-button` } isInline icon = { isExternal ? < ExternalLinkAltIcon className = 'pf-v6-u-ml-sm' /> : null } iconPosition = "end" { ...linkRestProps } >
120+ { linkProps . label }
121+ </ Button >
122+ ) }
123+ </ FlexItem >
101124 ) }
102- </ Split >
103- < Content component = "p" ouiaId = { `${ ouiaId } -subtitle` } >
104- { subtitle }
105- </ Content >
106- { linkProps && (
107- < Button variant = { ButtonVariant . link } component = "a" ouiaId = { `${ ouiaId } -link-button` } isInline icon = { isExternal ? < ExternalLinkAltIcon className = 'pf-v6-u-ml-sm' /> : null } iconPosition = "end" { ...linkRestProps } >
108- { linkProps . label }
109- </ Button >
110- ) }
111- </ FlexItem >
112- </ Flex >
113- { children }
114- </ PageSection >
115- ) } ;
125+ </ Flex >
126+ }
127+ { children }
128+ </ PageSection >
129+ </ >
130+ )
131+ } ;
116132
117133export default PageHeader ;
0 commit comments