aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/buttons/back-to-top/back-to-top.tsx
blob: 83e21619cc9f41f6193f8b02f1ed2ed47569e71a (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
import type { FC } from 'react';
import {
  ButtonLink,
  type ButtonLinkProps,
  Icon,
  VisuallyHidden,
} from '../../../atoms';
import styles from './back-to-top.module.scss';

export type BackToTopProps = Omit<
  ButtonLinkProps,
  'children' | 'isExternal' | 'kind' | 'to'
> & {
  /**
   * Define the anchor.
   */
  anchor: string;
  /**
   * Define an accessible label for the button.
   */
  label: string;
};

/**
 * BackToTop component
 *
 * Render a back to top link.
 */
export const BackToTop: FC<BackToTopProps> = ({
  anchor,
  className = '',
  label,
  shape = 'square',
  ...props
}) => {
  const btnClass = `${styles.link} ${className}`;

  return (
    <ButtonLink {...props} className={btnClass} shape={shape} to={anchor}>
      {/* eslint-disable-next-line react/jsx-no-literals -- Config allowed */}
      <Icon aria-hidden orientation="top" shape="arrow" />
      <VisuallyHidden>{label}</VisuallyHidden>
    </ButtonLink>
  );
};