forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompass.tsx
More file actions
125 lines (117 loc) · 4.14 KB
/
Compass.tsx
File metadata and controls
125 lines (117 loc) · 4.14 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
import { Drawer, DrawerContent, DrawerContentBody, DrawerProps } from '../Drawer';
import styles from '@patternfly/react-styles/css/components/Compass/compass';
import { css } from '@patternfly/react-styles';
import compassBackgroundImageLight from '@patternfly/react-tokens/dist/esm/c_compass_BackgroundImage_light';
import compassBackgroundImageDark from '@patternfly/react-tokens/dist/esm/c_compass_BackgroundImage_dark';
export interface CompassProps extends React.HTMLProps<HTMLDivElement> {
/** Additional classes added to the Compass. */
className?: string;
/** Content of the docked navigation area of the layout */
dock?: React.ReactNode;
/** Content placed at the top of the layout */
header?: React.ReactNode;
/** Flag indicating if the header is expanded */
isHeaderExpanded?: boolean;
/** Content placed at the horizontal start of the layout, before the main content */
sidebarStart?: React.ReactNode;
/** Flag indicating if the start sidebar is expanded */
isSidebarStartExpanded?: boolean;
/** Content placed at the center of the layout */
main?: React.ReactNode;
/** Content placed at the horizontal end of the layout, after the main content */
sidebarEnd?: React.ReactNode;
/** Flag indicating if the end sidebar is expanded */
isSidebarEndExpanded?: boolean;
/** Content placed at the bottom of the layout */
footer?: React.ReactNode;
/** Flag indicating if the footer is expanded */
isFooterExpanded?: boolean;
/** Content rendered in an optional drawer wrapping the layout */
drawerContent?: React.ReactNode;
/** Additional props passed to the drawer */
drawerProps?: DrawerProps;
/** Light theme background image path of the Compass */
backgroundSrcLight?: string;
/** Dark theme background image path of the Compass */
backgroundSrcDark?: string;
}
export const Compass: React.FunctionComponent<CompassProps> = ({
className,
dock,
header,
isHeaderExpanded = true,
sidebarStart,
isSidebarStartExpanded = true,
main,
sidebarEnd,
isSidebarEndExpanded = true,
footer,
isFooterExpanded = true,
drawerContent,
drawerProps,
backgroundSrcLight,
backgroundSrcDark,
...props
}: CompassProps) => {
const hasDrawer = drawerContent !== undefined;
const backgroundImageStyles: { [key: string]: string } = {};
if (backgroundSrcLight) {
backgroundImageStyles[compassBackgroundImageLight.name] = `url(${backgroundSrcLight})`;
}
if (backgroundSrcDark) {
backgroundImageStyles[compassBackgroundImageDark.name] = `url(${backgroundSrcDark})`;
}
const compassContent = (
<div
className={css(styles.compass, dock !== undefined && styles.modifiers.dock, className)}
{...props}
style={{ ...props.style, ...backgroundImageStyles }}
>
{dock && <div className={css(`${styles.compass}__dock`)}>{dock}</div>}
{header && (
<div
className={css(styles.compassHeader, isHeaderExpanded && 'pf-m-expanded')}
{...(!isHeaderExpanded && { inert: 'true' })}
>
{header}
</div>
)}
{sidebarStart && (
<div
className={css(styles.compassSidebar, styles.modifiers.start, isSidebarStartExpanded && 'pf-m-expanded')}
{...(!isSidebarStartExpanded && { inert: 'true' })}
>
{sidebarStart}
</div>
)}
{main && <div className={css(styles.compassMain)}>{main}</div>}
{sidebarEnd && (
<div
className={css(styles.compassSidebar, styles.modifiers.end, isSidebarEndExpanded && 'pf-m-expanded')}
{...(!isSidebarEndExpanded && { inert: 'true' })}
>
{sidebarEnd}
</div>
)}
{footer && (
<div
className={css(styles.compassFooter, isFooterExpanded && 'pf-m-expanded')}
{...(!isFooterExpanded && { inert: 'true' })}
>
{footer}
</div>
)}
</div>
);
if (hasDrawer) {
return (
<Drawer isPill {...drawerProps}>
<DrawerContent panelContent={drawerContent}>
<DrawerContentBody>{compassContent}</DrawerContentBody>
</DrawerContent>
</Drawer>
);
}
return compassContent;
};
Compass.displayName = 'Compass';