From e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d Mon Sep 17 00:00:00 2001
From: Piotr Russ <mail@pruss.it>
Date: Mon, 16 Nov 2020 00:10:28 +0100
Subject: api, login, auth

---
 client/src/common/jsx/LangSwitch.jsx | 43 ++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 client/src/common/jsx/LangSwitch.jsx

(limited to 'client/src/common/jsx/LangSwitch.jsx')

diff --git a/client/src/common/jsx/LangSwitch.jsx b/client/src/common/jsx/LangSwitch.jsx
new file mode 100644
index 0000000..eba1b27
--- /dev/null
+++ b/client/src/common/jsx/LangSwitch.jsx
@@ -0,0 +1,43 @@
+import React from 'react';
+import WithHover from './WithHover.jsx';
+import texts from '../data/texts.js';
+
+const LangSwitch = ({ lang, setLang, setHover, opened, setOpened}) => {
+
+  const handleSetLang = (key) => {
+    setLang(key);
+    setOpened(false);
+  };
+
+  return (
+    <div className="lang-switch">
+      <WithHover setHover={setHover} message="click-to-change-language">
+        <span
+          className={`lang-switch__main-item${opened === 'lang' ? ' lang-switch__main-item--active' : ''}`}
+          onClick={() => setOpened(opened !== 'lang' ? 'lang' : false)}
+        >
+          {lang}
+        </span>
+        {
+          opened === 'lang' && (
+            <div className="lang-switch__list">
+              {
+                Object.keys(texts).map(key => key !== lang && (
+                  <span
+                    className="lang-switch__item"
+                    key={key}
+                    onClick={() => handleSetLang(key)}
+                  >
+                    {key}
+                  </span>
+                ))
+              }
+            </div>
+          )
+        }
+      </WithHover>
+    </div>
+  );
+};
+
+export default LangSwitch;
-- 
cgit v1.2.3

