From 84903c1e5182124b1bb618b7d8754cb70d0a6647 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Wed, 23 Feb 2022 18:11:37 +0100
Subject: feat: improve Ackee tracking (#11)

* build(deps): add use-ackee hook package

* chore: create a context provider for Ackee

The provider allows users to change the 'detailed' settings.

* chore: add a select menu to choose which info to share with Ackee

* chore: add a tooltip for askee settings

* chore: replace default select styles with custom styles

* chore: register user choice in localstorage

* chore: replace Matomo with Ackee in legal notice
---
 src/components/Tooltip/Tooltip.tsx | 57 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 src/components/Tooltip/Tooltip.tsx

(limited to 'src/components/Tooltip/Tooltip.tsx')

diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx
new file mode 100644
index 0000000..5929c96
--- /dev/null
+++ b/src/components/Tooltip/Tooltip.tsx
@@ -0,0 +1,57 @@
+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',
+      })
+    : intl.formatMessage({
+        defaultMessage: 'Show help',
+        description: 'Tooltip: button title',
+      });
+
+  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;
-- 
cgit v1.2.3

