forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageGroup.tsx
More file actions
79 lines (76 loc) · 2.89 KB
/
PageGroup.tsx
File metadata and controls
79 lines (76 loc) · 2.89 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
import { useContext, useEffect } from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Page/page';
import { formatBreakpointMods } from '../../helpers/util';
import { PageContext } from './PageContext';
export interface PageGroupProps extends React.HTMLProps<HTMLDivElement> {
/** Additional classes to apply to the PageGroup */
className?: string;
/** Content rendered inside of the PageGroup */
children?: React.ReactNode;
/** Modifier indicating if the PageBreadcrumb is sticky to the top or bottom at various breakpoints */
stickyOnBreakpoint?: {
default?: 'top' | 'bottom';
sm?: 'top' | 'bottom';
md?: 'top' | 'bottom';
lg?: 'top' | 'bottom';
xl?: 'top' | 'bottom';
'2xl'?: 'top' | 'bottom';
};
/** Enables the page group to fill the available vertical space if true, or disable filling if false. */
isFilled?: boolean;
/** Modifier indicating if PageGroup should have a shadow at the top */
hasShadowTop?: boolean;
/** Modifier indicating if PageGroup should have a shadow at the bottom */
hasShadowBottom?: boolean;
/** Flag indicating if the PageGroup has a scrolling overflow */
hasOverflowScroll?: boolean;
/** Adds an accessible name to the page group when the hasOverflowScroll prop is set to true. */
'aria-label'?: string;
/** Adds plain styling to the page group. */
isPlain?: boolean;
/** @beta Prevents the page group from automatically applying plain styling when glass theme is enabled. */
isNoPlainOnGlass?: boolean;
}
export const PageGroup = ({
className = '',
children,
stickyOnBreakpoint,
isFilled,
hasShadowTop = false,
hasShadowBottom = false,
hasOverflowScroll = false,
'aria-label': ariaLabel,
isPlain = false,
isNoPlainOnGlass = false,
...props
}: PageGroupProps) => {
const { height, getVerticalBreakpoint } = useContext(PageContext);
useEffect(() => {
if (hasOverflowScroll && !ariaLabel) {
/* eslint-disable no-console */
console.warn('PageGroup: An accessible aria-label is required when hasOverflowScroll is set to true.');
}
}, [hasOverflowScroll, ariaLabel]);
return (
<div
{...props}
className={css(
styles.pageMainGroup,
formatBreakpointMods(stickyOnBreakpoint, styles, 'sticky-', getVerticalBreakpoint(height), true),
isFilled === false && styles.modifiers.noFill,
isFilled === true && styles.modifiers.fill,
hasShadowTop && styles.modifiers.shadowTop,
hasShadowBottom && styles.modifiers.shadowBottom,
hasOverflowScroll && styles.modifiers.overflowScroll,
isPlain && styles.modifiers.plain,
isNoPlainOnGlass && styles.modifiers.noPlainOnGlass,
className
)}
{...(hasOverflowScroll && { tabIndex: 0, role: 'region', 'aria-label': ariaLabel })}
>
{children}
</div>
);
};
PageGroup.displayName = 'PageGroup';