aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/meta-list/meta-list.tsx
blob: c19f0fde320fc2b0b8e117fa14dc82066a249938 (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
import {
  type ForwardRefRenderFunction,
  forwardRef,
  type ReactNode,
} from 'react';
import { DescriptionList, type DescriptionListProps } from '../../atoms';
import styles from './meta-list.module.scss';

export type MetaListProps = Omit<
  DescriptionListProps,
  'children' | 'spacing'
> & {
  /**
   * The meta items.
   */
  children: ReactNode;
  /**
   * Should the meta be centered?
   *
   * @default false
   */
  isCentered?: boolean;
};

const MetaListWithRef: ForwardRefRenderFunction<
  HTMLDListElement,
  MetaListProps
> = (
  { children, className = '', isCentered = false, isInline = false, ...props },
  ref
) => {
  const listClass = [
    styles.list,
    styles[isCentered ? 'list--centered' : ''],
    styles[isInline ? 'list--inlined' : 'list--stacked'],
    className,
  ].join(' ');

  return (
    <DescriptionList {...props} className={listClass} ref={ref}>
      {children}
    </DescriptionList>
  );
};

export const MetaList = forwardRef(MetaListWithRef);