aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/layout/page-header.tsx
blob: e70d66c0f21343e3eee65222c92f36c7e273df8d (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
57
58
59
60
61
62
import type { FC, ReactNode } from 'react';
import { Header, Heading } from '../../atoms';
import styles from './page-header.module.scss';

export type PageHeaderProps = {
  /**
   * Set additional classnames to the header element.
   */
  className?: string;
  /**
   * The page introduction.
   */
  intro?: string | ReactNode;
  /**
   * The page metadata.
   */
  meta?: ReactNode;
  /**
   * The page title.
   */
  title: ReactNode;
};

/**
 * PageHeader component
 *
 * Render a header element with page title, meta and intro.
 */
export const PageHeader: FC<PageHeaderProps> = ({
  className = '',
  intro,
  meta,
  title,
}) => {
  const headerClass = `${styles.wrapper} ${className}`;

  const getIntro = () => {
    if (typeof intro === 'string')
      return (
        <div
          className={styles.intro}
          /* eslint-disable-next-line react/no-danger -- Not safe but intro can
           * contains links or formatting so we need it. */
          dangerouslySetInnerHTML={{ __html: intro }}
        />
      );

    return <div className={styles.intro}>{intro}</div>;
  };

  return (
    <Header className={headerClass}>
      <div className={styles.body}>
        <Heading className={styles.title} level={1}>
          {title}
        </Heading>
        {meta}
        {intro ? getIntro() : null}
      </div>
    </Header>
  );
};