summaryrefslogtreecommitdiffstats
path: root/src/components/Tooltip/Tooltip.tsx
blob: 56a87ab1c02cda46c2854e737d8dd609e1b4a81c (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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color
import { ButtonHelp } from '@components/Buttons';
import { useState } from 'react';
import { useIntl } from 'react-intl';
import styles from './Tooltip.module.scss';

const Tooltip = ({
  message,
  title,
}: {
  message: string | string[];
  title: string;
}) => {
  const intl = useIntl();
  const [isOpen, setIsOpen] = useState<boolean>(false);

  const getMessageFromArray = (strings: string[]) => {
    let keyIndex = 0;
    return (
      <ul>
        {strings.map((string) => {
          keyIndex = keyIndex + 1;
          return <li key={`message-${keyIndex}`}>{string}</li>;
        })}
      </ul>
    );
  };

  const buttonTitle = isOpen
    ? intl.formatMessage({
        defaultMessage: 'Close help',
        description: 'Tooltip: button title',
        id: '9kx83j',
      })
    : intl.formatMessage({
        defaultMessage: 'Show help',
        description: 'Tooltip: button title',
        id: 'A5n+C9',
      });

  const wrapperModifier = isOpen ? styles.visible : styles.hidden;

  return (
    <div>
      <ButtonHelp
        showHelp={isOpen}
        setShowHelp={setIsOpen}
        title={buttonTitle}
      />
      <div className={`${styles.wrapper} ${wrapperModifier}`}>
        <div className={styles.title}>{title}</div>
        <div className={styles.message}>
          {Array.isArray(message) ? getMessageFromArray(message) : message}
        </div>
      </div>
    </div>
  );
};

export default Tooltip;