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
|
import {
type ForwardRefRenderFunction,
forwardRef,
type HTMLAttributes,
} from 'react';
import { useIntl } from 'react-intl';
import { ARTICLE_ID } from '../../../utils/constants';
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[];
/**
* Is it a regular page or a sectioned one?
*
* @default false
*/
hasSections?: boolean;
/**
* 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 = '',
hasSections = false,
isBodyLastChild = false,
...props
},
ref
) => {
const wrapperClass = `${styles.wrapper} ${className}`;
const pageClass = [
styles.page,
styles[hasSections ? 'page--full' : 'page--regular'],
styles[isBodyLastChild ? 'page--body-last' : ''],
].join(' ');
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} id={ARTICLE_ID}>
{children}
</Article>
</div>
);
};
export const Page = forwardRef(PageWithRef);
|