Debian Codegraph @

node/@patternfly/react-core/src/components/Page/PageBreadcrumb.tsx

raw
1 import { useContext, useEffect } from 'react';
2 import { css } from '@patternfly/react-styles';
3 import styles from '@patternfly/react-styles/css/components/Page/page';
4 import { formatBreakpointMods, Mods } from '../../helpers/util';
5 import { PageContext } from './PageContext';
6 import { PageBody } from './PageBody';
7
8 export interface PageBreadcrumbProps extends React.HTMLProps<HTMLElement> {
9 /** Additional classes to apply to the PageBreadcrumb */
10 className?: string;
11 /** Content rendered inside of the PageBreadcrumb */
12 children?: React.ReactNode;
13 /** Limits the width of the breadcrumb */
14 isWidthLimited?: boolean;
15 /** Modifier indicating if the PageBreadcrumb is sticky to the top or bottom at various breakpoints */
16 stickyOnBreakpoint?: {
17 default?: 'top' | 'bottom';
18 sm?: 'top' | 'bottom';
19 md?: 'top' | 'bottom';
20 lg?: 'top' | 'bottom';
21 xl?: 'top' | 'bottom';
22 '2xl'?: 'top' | 'bottom';
23 };
24 /** Flag indicating if PageBreadcrumb should have a shadow at the top */
25 hasShadowTop?: boolean;
26 /** Flag indicating if PageBreadcrumb should have a shadow at the bottom */
27 hasShadowBottom?: boolean;
28 /** Flag indicating if the PageBreadcrumb has a scrolling overflow */
29 hasOverflowScroll?: boolean;
30 /** @beta Flag indicating whether children passed to the component should be wrapped by a PageBody.
31 * Set this to false in order to pass multiple, custom PageBody's as children.
32 */
33 hasBodyWrapper?: boolean;
34 /** Adds an accessible name to the breadcrumb section. Required when the hasOverflowScroll prop is set to true. */
35 'aria-label'?: string;
36 }
37
38 export const PageBreadcrumb = ({
39 className = '',
40 children,
41 isWidthLimited,
42 stickyOnBreakpoint,
43 hasShadowTop = false,
44 hasShadowBottom = false,
45 hasOverflowScroll = false,
46 'aria-label': ariaLabel,
47 hasBodyWrapper = true,
48 ...props
49 }: PageBreadcrumbProps) => {
50 const { height, getVerticalBreakpoint } = useContext(PageContext);
51
52 useEffect(() => {
53 if (hasOverflowScroll && !ariaLabel) {
54 /* eslint-disable no-console */
55 console.warn('PageBreadcrumb: An accessible aria-label is required when hasOverflowScroll is set to true.');
56 }
57 }, [hasOverflowScroll, ariaLabel]);
58
59 return (
60 <section
61 className={css(
62 styles.pageMainBreadcrumb,
63 formatBreakpointMods(stickyOnBreakpoint as Mods, styles, 'sticky-', getVerticalBreakpoint(height), true),
64 isWidthLimited && styles.modifiers.limitWidth,
65 hasShadowTop && styles.modifiers.shadowTop,
66 hasShadowBottom && styles.modifiers.shadowBottom,
67 hasOverflowScroll && styles.modifiers.overflowScroll,
68 className
69 )}
70 {...(hasOverflowScroll && { tabIndex: 0 })}
71 aria-label={ariaLabel}
72 {...props}
73 >
74 {hasBodyWrapper ? <PageBody>{children}</PageBody> : children}
75 </section>
76 );
77 };
78 PageBreadcrumb.displayName = 'PageBreadcrumb';