aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/layout/cards-list.tsx
blob: 29add3b604ca7a05d305b58fe55f2ffed738465d (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
63
import type { FC } from 'react';
import { List, ListItem } from '../../atoms';
import { Card, type CardProps } from '../../molecules';
import styles from './cards-list.module.scss';

export type CardsListItem = Omit<CardProps, 'className' | 'titleLevel'> & {
  /**
   * The card id.
   */
  id: string;
};

export type CardsListProps = Pick<CardProps, 'titleLevel'> & {
  /**
   * Set additional classnames to the list wrapper.
   */
  className?: string;
  /**
   * Should the cards list be ordered?
   *
   * @default false
   */
  isOrdered?: boolean;
  /**
   * The cards data.
   */
  items: CardsListItem[];
};

/**
 * CardsList component
 *
 * Return a list of Card components.
 */
export const CardsList: FC<CardsListProps> = ({
  className = '',
  isOrdered = false,
  items,
  titleLevel,
}) => {
  const kindModifier = `wrapper--${isOrdered ? 'ordered' : 'unordered'}`;

  return (
    <List
      className={`${styles.wrapper} ${styles[kindModifier]} ${className}`}
      hideMarker
      isInline
      isOrdered={isOrdered}
    >
      {items.map(({ id, ...item }) => (
        <ListItem key={id}>
          <Card
            {...item}
            className={styles.card}
            key={id}
            id={id}
            titleLevel={titleLevel}
          />
        </ListItem>
      ))}
    </List>
  );
};