aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/widgets/social-media-widget/social-media-widget.tsx
blob: d75f48f3659e38b3f2d69011deee7acf41993aa3 (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
import { forwardRef, type ForwardRefRenderFunction } from 'react';
import {
  List,
  ListItem,
  SocialLink,
  type SocialLinkProps,
} from '../../../atoms';
import { Collapsible, type CollapsibleProps } from '../../../molecules';

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

export type SocialMediaProps = Omit<CollapsibleProps, 'children'> & {
  media: SocialMediaData[];
};

const SocialMediaWidgetWithRef: ForwardRefRenderFunction<
  HTMLDivElement,
  SocialMediaProps
> = ({ media, ...props }, ref) => (
  <Collapsible {...props} ref={ref}>
    <List
      hideMarker
      isInline
      // eslint-disable-next-line react/jsx-no-literals
      spacing="xs"
    >
      {media.map(({ id, ...link }) => (
        <ListItem key={id}>
          <SocialLink {...link} />
        </ListItem>
      ))}
    </List>
  </Collapsible>
);

/**
 * Social Media widget component
 *
 * Render a social media list with links.
 */
export const SocialMediaWidget = forwardRef(SocialMediaWidgetWithRef);