aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/layout/section/section.tsx
blob: 63c658aba205044fcad210247b5fa9cd6f9af0b2 (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
import {
  forwardRef,
  type ForwardRefRenderFunction,
  type HTMLAttributes,
  type ReactNode,
} from 'react';
import styles from './section.module.scss';

export type SectionVariant = 'dark' | 'light';

export type SectionProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
  /**
   * The section content.
   */
  children: ReactNode | ReactNode[];
  /**
   * Add a border at the bottom of the section.
   *
   * @default false
   */
  hasBorder?: boolean;
  /**
   * The section variant.
   *
   * @default 'light'
   */
  variant?: SectionVariant;
};

const SectionWithRef: ForwardRefRenderFunction<HTMLElement, SectionProps> = (
  { children, className = '', hasBorder = false, variant = 'light', ...props },
  ref
) => {
  const borderClass = hasBorder ? styles[`wrapper--borders`] : '';
  const variantClass = styles[`wrapper--${variant}`];
  const sectionClass = `${styles.wrapper} ${borderClass} ${variantClass} ${className}`;

  return (
    <section {...props} className={sectionClass} ref={ref}>
      {children}
    </section>
  );
};

/**
 * Section component
 *
 * Render a section element with a heading and a body.
 */
export const Section = forwardRef(SectionWithRef);