From 826b0ce3efcf87ae1d231e892db176f5e64b7b97 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Wed, 6 Apr 2022 23:50:10 +0200
Subject: chore: add a ThemeToggle component

---
 src/components/molecules/forms/theme-toggle.tsx | 52 +++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 src/components/molecules/forms/theme-toggle.tsx

(limited to 'src/components/molecules/forms/theme-toggle.tsx')

diff --git a/src/components/molecules/forms/theme-toggle.tsx b/src/components/molecules/forms/theme-toggle.tsx
new file mode 100644
index 0000000..1c43acf
--- /dev/null
+++ b/src/components/molecules/forms/theme-toggle.tsx
@@ -0,0 +1,52 @@
+import Toggle, {
+  ToggleChoices,
+  ToggleProps,
+} from '@components/atoms/forms/toggle';
+import Moon from '@components/atoms/icons/moon';
+import Sun from '@components/atoms/icons/sun';
+import { FC, useState } from 'react';
+import { useIntl } from 'react-intl';
+
+export type ThemeToggleProps = Pick<ToggleProps, 'value'>;
+
+/**
+ * ThemeToggle component
+ *
+ * Render a Toggle component to set theme.
+ */
+const ThemeToggle: FC<ThemeToggleProps> = ({ value }) => {
+  const intl = useIntl();
+  const [isDarkTheme, setIsDarkTheme] = useState<boolean>(value);
+  const themeLabel = intl.formatMessage({
+    defaultMessage: 'Theme:',
+    description: 'SettingsModal: theme label',
+    id: 'SGPivK',
+  });
+  const lightThemeLabel = intl.formatMessage({
+    defaultMessage: 'Light theme',
+    description: 'SettingsModal: light theme label',
+    id: 'jPxP9t',
+  });
+  const darkThemeLabel = intl.formatMessage({
+    defaultMessage: 'Dark theme',
+    description: 'SettingsModal: dark theme label',
+    id: 'E5JCDA',
+  });
+  const themeChoices: ToggleChoices = {
+    left: <Sun title={lightThemeLabel} />,
+    right: <Moon title={darkThemeLabel} />,
+  };
+
+  return (
+    <Toggle
+      id="theme-settings"
+      name="theme-settings"
+      label={themeLabel}
+      choices={themeChoices}
+      value={isDarkTheme}
+      setValue={setIsDarkTheme}
+    />
+  );
+};
+
+export default ThemeToggle;
-- 
cgit v1.2.3

