jevstrudel.git / website / src / components / Header / LanguageSelect.tsx
LanguageSelect.tsx49 lines · 1.6 KB · raw
1/** @jsxImportSource react */
2import type { FunctionComponent } from 'react';
3import './LanguageSelect.css';
4import { KNOWN_LANGUAGES, langPathRegex } from '../../languages';
5
6const LanguageSelect: FunctionComponent<{ lang: string }> = ({ lang }) => {
7  return (
8    <div className="language-select-wrapper">
9      <svg
10        aria-hidden="true"
11        focusable="false"
12        role="img"
13        xmlns="http://www.w3.org/2000/svg"
14        viewBox="0 0 88.6 77.3"
15        height="1.2em"
16        width="1.2em"
17      >
18        <path
19          fill="currentColor"
20          d="M61,24.6h7.9l18.7,51.6h-7.7l-5.4-15.5H54.3l-5.6,15.5h-7.2L61,24.6z M72.6,55l-8-22.8L56.3,55H72.6z"
21        />
22        <path
23          fill="currentColor"
24          d="M53.6,60.6c-10-4-16-9-22-14c0,0,1.3,1.3,0,0c-6,5-20,13-20,13l-4-6c8-5,10-6,19-13c-2.1-1.9-12-13-13-19h8          c4,9,10,14,10,14c10-8,10-19,10-19h8c0,0-1,13-12,24l0,0c5,5,10,9,19,13L53.6,60.6z M1.6,16.6h56v-8h-23v-7h-9v7h-24V16.6z"
25        />
26      </svg>
27      <select
28        className="language-select"
29        value={lang}
30        onChange={(e) => {
31          const newLang = e.target.value;
32          let actualDest = window.location.pathname.replace(langPathRegex, '/');
33          if (actualDest == '/') actualDest = `/introduction`;
34          window.location.pathname = '/' + newLang + actualDest;
35        }}
36      >
37        {Object.entries(KNOWN_LANGUAGES).map(([key, value]) => {
38          return (
39            <option value={value} key={value}>
40              {key}
41            </option>
42          );
43        })}
44      </select>
45    </div>
46  );
47};
48
49export default LanguageSelect;