blob: f5f3ea50e7f20c00fa464476d89f06a0d58de487 (
plain)
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
|
import {
type ForwardRefRenderFunction,
forwardRef,
type HTMLAttributes,
} from 'react';
import { useIntl } from 'react-intl';
import { Article } from '../../atoms';
import { Breadcrumbs, type BreadcrumbsItem } from '../../organisms/nav';
import styles from './page.module.scss';
export type PageProps = HTMLAttributes<HTMLDivElement> & {
/**
* The breadcrumbs items.
*/
breadcrumbs?: BreadcrumbsItem[];
/**
* Add an extra padding to the body when there are no footer/comments.
*
* Note: this should be refactored when `:has()` pseudo-class will have a
* better support.
*
* @default false
*/
isBodyLastChild?: boolean;
};
const PageWithRef: ForwardRefRenderFunction<HTMLDivElement, PageProps> = (
{ breadcrumbs, children, className = '', isBodyLastChild = false, ...props },
ref
) => {
const wrapperClass = `${styles.wrapper} ${className}`;
const pageClass = `${styles.page} ${
styles[isBodyLastChild ? 'page--body-last' : '']
}`;
const intl = useIntl();
const breadcrumbsLabel = intl.formatMessage({
defaultMessage: 'Breadcrumbs',
description: 'Page: an accessible name for the breadcrumb nav.',
id: '/TTRRX',
});
return (
<div {...props} className={wrapperClass} ref={ref}>
{breadcrumbs ? (
<Breadcrumbs
aria-label={breadcrumbsLabel}
className={styles.breadcrumbs}
items={breadcrumbs}
/>
) : null}
<Article className={pageClass}>{children}</Article>
</div>
);
};
export const Page = forwardRef(PageWithRef);
|