diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-03 18:52:57 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:14:41 +0100 |
| commit | a3fb0aa94717aafae897ac293488c43a099c0b2b (patch) | |
| tree | bb5c9fcb093779061cd11e08d94f30bbb3a9b854 /src/components/atoms/links/sharing-link/sharing-link.tsx | |
| parent | f914ff8376dd91c4f6f8ca149e1cb6becb622d88 (diff) | |
refactor(components): rewrite SharingLink component
* replace default label with label prop
* simplify CSS rules
Diffstat (limited to 'src/components/atoms/links/sharing-link/sharing-link.tsx')
| -rw-r--r-- | src/components/atoms/links/sharing-link/sharing-link.tsx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/components/atoms/links/sharing-link/sharing-link.tsx b/src/components/atoms/links/sharing-link/sharing-link.tsx new file mode 100644 index 0000000..186000e --- /dev/null +++ b/src/components/atoms/links/sharing-link/sharing-link.tsx @@ -0,0 +1,51 @@ +import type { AnchorHTMLAttributes, FC } from 'react'; +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}> + {/* eslint-disable-next-line -- SR class allowed */} + <span className="screen-reader-text">{label}</span> + </a> + ); +}; |
