1
- import type { FunctionComponent } from 'react' ;
1
+ import type { FunctionComponent , ReactNode } from 'react' ;
2
2
import {
3
3
Button ,
4
4
ButtonProps ,
@@ -10,15 +10,15 @@ import {
10
10
PageBreadcrumb ,
11
11
PageSection ,
12
12
Split ,
13
- SplitItem ,
13
+ SplitItem
14
14
} from '@patternfly/react-core' ;
15
15
import { ExternalLinkAltIcon } from '@patternfly/react-icons' ;
16
16
import { createUseStyles } from 'react-jss' ;
17
17
18
18
/** extends ButtonProps */
19
- export interface PageHeaderLinkProps extends ButtonProps {
19
+ export interface PageHeaderLinkProps extends Omit < ButtonProps , 'label' > {
20
20
/** Title for the link */
21
- label : string ;
21
+ label : ReactNode ;
22
22
/** Indicates if the link points to an external page */
23
23
isExternal ?: boolean ;
24
24
}
@@ -48,7 +48,7 @@ export interface PageHeaderProps extends React.PropsWithChildren {
48
48
49
49
const useStyles = createUseStyles ( {
50
50
iconMinWidth : {
51
- minWidth : '48px' ,
51
+ minWidth : '48px'
52
52
}
53
53
} ) ;
54
54
@@ -57,41 +57,39 @@ export const PageHeader: FunctionComponent<PageHeaderProps> = ({
57
57
subtitle,
58
58
linkProps,
59
59
icon,
60
- label,
60
+ label : labelProp ,
61
61
breadcrumbs = null ,
62
62
actionMenu,
63
63
ouiaId = 'PageHeader' ,
64
64
children = null ,
65
65
headingClassname = subtitle ? 'pf-v6-u-mb-sm' : ''
66
66
} : PageHeaderProps ) => {
67
67
const classes = useStyles ( ) ;
68
- const { isExternal = false , ...linkRestProps } = linkProps ?? { } ;
69
- const showSplitRow = title || label || actionMenu ;
68
+ const { isExternal = false , label = String ( linkProps ?. label ) , ...linkRestProps } = linkProps ?? { } ;
69
+ const showSplitRow = title || labelProp || actionMenu ;
70
70
const showMainFlex = showSplitRow || subtitle || linkProps ;
71
71
72
72
return (
73
73
< >
74
- { breadcrumbs && (
75
- < PageBreadcrumb >
76
- { breadcrumbs }
77
- </ PageBreadcrumb >
78
- ) }
74
+ { breadcrumbs && < PageBreadcrumb > { breadcrumbs } </ PageBreadcrumb > }
79
75
< PageSection hasBodyWrapper = { false } >
80
- { ( showMainFlex || icon ) &&
76
+ { ( showMainFlex || icon ) && (
81
77
< Flex >
82
78
{ icon && (
83
79
< >
84
80
< FlexItem alignSelf = { { default : 'alignSelfCenter' } } className = { classes . iconMinWidth } >
85
81
{ icon }
86
82
</ FlexItem >
87
- < Divider orientation = { {
88
- default : 'vertical' ,
89
- } } />
83
+ < Divider
84
+ orientation = { {
85
+ default : 'vertical'
86
+ } }
87
+ />
90
88
</ >
91
89
) }
92
- { ( showMainFlex ) && (
90
+ { showMainFlex && (
93
91
< FlexItem flex = { { default : 'flex_1' } } >
94
- { ( showSplitRow ) && (
92
+ { showSplitRow && (
95
93
< Split hasGutter >
96
94
{ title && (
97
95
< SplitItem >
@@ -100,17 +98,9 @@ export const PageHeader: FunctionComponent<PageHeaderProps> = ({
100
98
</ Content >
101
99
</ SplitItem >
102
100
) }
103
- { label && (
104
- < SplitItem >
105
- { label }
106
- </ SplitItem >
107
- ) }
101
+ { labelProp && < SplitItem > { labelProp } </ SplitItem > }
108
102
< SplitItem isFilled />
109
- { actionMenu && (
110
- < SplitItem >
111
- { actionMenu }
112
- </ SplitItem >
113
- ) }
103
+ { actionMenu && < SplitItem > { actionMenu } </ SplitItem > }
114
104
</ Split >
115
105
) }
116
106
{ subtitle && (
@@ -119,18 +109,27 @@ export const PageHeader: FunctionComponent<PageHeaderProps> = ({
119
109
</ Content >
120
110
) }
121
111
{ linkProps && (
122
- < Button variant = { ButtonVariant . link } component = "a" ouiaId = { `${ ouiaId } -link-button` } isInline icon = { isExternal ? < ExternalLinkAltIcon className = 'pf-v6-u-ml-sm' /> : null } iconPosition = "end" { ...linkRestProps } >
112
+ < Button
113
+ variant = { ButtonVariant . link }
114
+ component = "a"
115
+ ouiaId = { `${ ouiaId } -link-button` }
116
+ isInline
117
+ icon = { isExternal ? < ExternalLinkAltIcon className = "pf-v6-u-ml-sm" /> : null }
118
+ iconPosition = "end"
119
+ label = { label as string }
120
+ { ...linkRestProps }
121
+ >
123
122
{ linkProps . label }
124
123
</ Button >
125
124
) }
126
125
</ FlexItem >
127
126
) }
128
127
</ Flex >
129
- }
128
+ ) }
130
129
{ children }
131
130
</ PageSection >
132
131
</ >
133
- )
132
+ ) ;
134
133
} ;
135
134
136
135
export default PageHeader ;
0 commit comments