aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/widgets/social-media.tsx
blob: ddeb09c10de9129a5c68792e2aa0f48fcadca7ac (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
import type { FC } from 'react';
import { List, ListItem, SocialLink, type SocialLinkProps } from '../../atoms';
import { Widget, type WidgetProps } from '../../molecules';
import styles from './social-media.module.scss';

export type Media = Required<
  Pick<SocialLinkProps, 'icon' | 'id' | 'label' | 'url'>
>;

export type SocialMediaProps = Pick<WidgetProps, 'level' | 'title'> & {
  media: Media[];
};

/**
 * Social Media widget component
 *
 * Render a social media list with links.
 */
export const SocialMedia: FC<SocialMediaProps> = ({ media, ...props }) => {
  /**
   * Retrieve the social media items.
   *
   * @param {SocialMedia[]} links - An array of social media name and url.
   * @returns {JSX.Element[]} The social links.
   */
  const getItems = (links: Media[]): JSX.Element[] =>
    links.map(({ id, ...link }) => (
      <ListItem key={id}>
        <SocialLink {...link} />
      </ListItem>
    ));

  return (
    <Widget expanded={true} {...props}>
      <List className={styles.list} hideMarker isInline spacing="xs">
        {getItems(media)}
      </List>
    </Widget>
  );
};