-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathPageHeader.tsx
More file actions
133 lines (127 loc) · 3.83 KB
/
PageHeader.tsx
File metadata and controls
133 lines (127 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React from 'react';
import {
Button,
ButtonProps,
ButtonVariant,
Content,
Divider,
Flex,
FlexItem,
PageBreadcrumb,
PageSection,
Split,
SplitItem,
} from '@patternfly/react-core';
import { ExternalLinkAltIcon } from '@patternfly/react-icons';
import { createUseStyles } from 'react-jss';
/** extends ButtonProps */
export interface PageHeaderLinkProps extends ButtonProps {
/** Title for the link */
label: string;
/** Indicates if the link points to an external page */
isExternal?: boolean;
}
export interface PageHeaderProps extends React.PropsWithChildren {
/** Title for page header */
title?: React.ReactNode;
/** Subtitle for page header */
subtitle?: React.ReactNode;
/** Optional link below subtitle */
linkProps?: PageHeaderLinkProps;
/** Optional icon for page header (appears to the left of the page header's title with a divider) */
icon?: React.ReactNode;
/** Optional label for page header (appears to the right of the page header's title) */
label?: React.ReactNode;
/** Breadcrumbs component */
breadcrumbs?: React.ReactNode;
/** Menu that appears to the far right of the title */
actionMenu?: React.ReactNode;
/** Custom OUIA ID */
ouiaId?: string | number;
/** Child nodes */
children?: React.ReactNode;
}
const useStyles = createUseStyles({
iconMinWidth: {
minWidth: '48px',
}
});
export const PageHeader: React.FunctionComponent<PageHeaderProps> = ({
title,
subtitle,
linkProps,
icon,
label,
breadcrumbs = null,
actionMenu,
ouiaId = 'PageHeader',
children = null
}: PageHeaderProps) => {
const classes = useStyles();
const { isExternal = false, ...linkRestProps } = linkProps ?? {};
const showSplitRow = title || label || actionMenu;
const showMainFlex = showSplitRow || subtitle || linkProps;
return (
<>
{breadcrumbs && (
<PageBreadcrumb>
{breadcrumbs}
</PageBreadcrumb>
)}
<PageSection hasBodyWrapper={false}>
{(showMainFlex || icon) &&
<Flex>
{icon && (
<>
<FlexItem alignSelf={{ default: 'alignSelfCenter' }} className={classes.iconMinWidth}>
{icon}
</FlexItem>
<Divider orientation={{
default: 'vertical',
}} />
</>
)}
{(showMainFlex) && (
<FlexItem flex={{ default: 'flex_1' }}>
{(showSplitRow) && (
<Split hasGutter>
{title && (
<SplitItem>
<Content className="pf-v6-u-mb-sm" component="h1" ouiaId={`${ouiaId}-title`}>
{title}
</Content>
</SplitItem>
)}
{label && (
<SplitItem>
{label}
</SplitItem>
)}
<SplitItem isFilled />
{actionMenu && (
<SplitItem>
{actionMenu}
</SplitItem>
)}
</Split>
)}
{subtitle && (
<Content component="p" ouiaId={`${ouiaId}-subtitle`}>
{subtitle}
</Content>
)}
{linkProps && (
<Button variant={ButtonVariant.link} component="a" ouiaId={`${ouiaId}-link-button`} isInline icon={isExternal ? <ExternalLinkAltIcon className='pf-v6-u-ml-sm' /> : null} iconPosition="end" {...linkRestProps}>
{linkProps.label}
</Button>
)}
</FlexItem>
)}
</Flex>
}
{children}
</PageSection>
</>
)
};
export default PageHeader;