aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/links/sharing-link/sharing-link.tsx
blob: a460a4d5df7367e0c5cf433e99381010247f38a0 (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
import type { AnchorHTMLAttributes, FC } from 'react';
import { VisuallyHidden } from '../../visually-hidden';
import styles from './sharing-link.module.scss';

export type SharingMedium =
  | 'diaspora'
  | 'email'
  | 'facebook'
  | 'journal-du-hacker'
  | 'linkedin'
  | 'twitter';

export type SharingLinkProps = Omit<
  AnchorHTMLAttributes<HTMLElement>,
  'children' | 'href'
> & {
  /**
   * An accessible label (visually hidden).
   */
  label: string;
  /**
   * The sharing medium id.
   */
  medium: SharingMedium;
  /**
   * The sharing url.
   */
  url: string;
};

/**
 * SharingLink component
 *
 * Render a sharing link.
 */
export const SharingLink: FC<SharingLinkProps> = ({
  className = '',
  label,
  medium,
  url,
  ...props
}) => {
  const mediumClass = `link--${medium}`;
  const linkClass = `${styles.link} ${styles[mediumClass]} ${className}`;

  return (
    <a {...props} className={linkClass} href={url}>
      <VisuallyHidden>{label}</VisuallyHidden>
    </a>
  );
};