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

export type OverlayProps = HTMLAttributes<HTMLDivElement> & {
  /**
   * The elements to display in front of the overlay.
   */
  children: ReactNode;
};

const OverlayWithRef: ForwardRefRenderFunction<HTMLDivElement, OverlayProps> = (
  { children, className = '', ...props },
  ref
) => {
  const overlayClass = [styles.overlay, className].join(' ');

  return (
    <div {...props} className={overlayClass} ref={ref}>
      {children}
    </div>
  );
};

/**
 * Overlay component.
 */
export const Overlay = forwardRef(OverlayWithRef);