aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/buttons/help-button.tsx
blob: 12348356301784a9292719f3f80f95fccd4a5500 (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 { forwardRef, ForwardRefRenderFunction } from 'react';
import { useIntl } from 'react-intl';
import { Button, type ButtonProps } from '../../atoms';
import styles from './help-button.module.scss';

export type HelpButtonProps = Pick<
  ButtonProps,
  'aria-pressed' | 'className' | 'onClick'
>;

const HelpButtonWithRef: ForwardRefRenderFunction<
  HTMLButtonElement,
  HelpButtonProps
> = ({ className = '', ...props }, ref) => {
  const intl = useIntl();
  const text = intl.formatMessage({
    defaultMessage: 'Help',
    id: 'i+/ckF',
    description: 'HelpButton: screen reader text',
  });

  return (
    <Button
      className={`${styles.btn} ${className}`}
      ref={ref}
      shape="circle"
      {...props}
    >
      <span className="screen-reader-text">{text}</span>
      <span className={styles.icon}>?</span>
    </Button>
  );
};

/**
 * HelpButton component
 *
 * Render a button with an interrogation mark icon.
 */
export const HelpButton = forwardRef(HelpButtonWithRef);