aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/loaders/spinner/spinner.tsx
blob: 6c6c23c9125423889c3aa8f021d4f0e683585cef (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
import type { FC, HTMLAttributes, ReactNode } from 'react';
import type { Position } from '../../../../types';
import styles from './spinner.module.scss';

export type SpinnerProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
  /**
   * The loading message.
   */
  children?: ReactNode;
  /**
   * Define the position of the loading message if any.
   *
   * @default 'right'
   */
  position?: Exclude<Position, 'center'>;
};

/**
 * Spinner component
 *
 * Render a loading message with animation.
 */
export const Spinner: FC<SpinnerProps> = ({
  children,
  className = '',
  position = 'right',
  ...props
}) => {
  const positionClass = styles[`wrapper--${position}`];
  const wrapperClass = `${styles.wrapper} ${positionClass} ${className}`;

  return (
    <div {...props} className={wrapperClass}>
      <div aria-hidden className={styles.icon}>
        <div className={styles.icon__ball} />
        <div className={styles.icon__ball} />
        <div className={styles.icon__ball} />
      </div>
      <div className={styles.body}>{children}</div>
    </div>
  );
};