From 8b86fbfd7fcd133b83c3c6feba27e93e60cd9971 Mon Sep 17 00:00:00 2001 From: Sonny Date: Sat, 16 Dec 2023 22:52:34 +0100 Subject: [PATCH] feat: change some icons --- public/icons/en.svg | 1 + public/icons/fr.svg | 1 + public/locales/en/common.json | 2 +- public/locales/fr/common.json | 2 +- src/components/LangSelector.tsx | 32 ++++++++++++++++++++--- src/components/Selector.tsx | 9 +++++-- src/components/Settings/SettingsModal.tsx | 22 +++++++++------- 7 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 public/icons/en.svg create mode 100644 public/icons/fr.svg diff --git a/public/icons/en.svg b/public/icons/en.svg new file mode 100644 index 0000000..1b8fb42 --- /dev/null +++ b/public/icons/en.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/icons/fr.svg b/public/icons/fr.svg new file mode 100644 index 0000000..c76dd71 --- /dev/null +++ b/public/icons/fr.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 3a8040a..c08eafc 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -33,7 +33,7 @@ "privacy": "Privacy", "terms": "Terms of use", "language": { - "fr": "French", + "fr": "Français", "en": "English" }, "lang": "Language", diff --git a/public/locales/fr/common.json b/public/locales/fr/common.json index d4e78e6..bf524ad 100644 --- a/public/locales/fr/common.json +++ b/public/locales/fr/common.json @@ -34,7 +34,7 @@ "terms": "CGU", "language": { "fr": "Français", - "en": "Anglais" + "en": "English" }, "lang": "Langage", "settings": "Paramètres", diff --git a/src/components/LangSelector.tsx b/src/components/LangSelector.tsx index d60bfd2..969194d 100644 --- a/src/components/LangSelector.tsx +++ b/src/components/LangSelector.tsx @@ -1,8 +1,15 @@ import { useTranslation } from 'next-i18next'; +import Image from 'next/image'; import { useRouter } from 'next/router'; import Selector from './Selector'; -export default function LangSelector() { +type Country = 'fr' | 'en'; + +export default function LangSelector({ + onSelected, +}: { + onSelected?: (country: Country) => void; +}) { const router = useRouter(); const { t, i18n } = useTranslation(); @@ -17,11 +24,30 @@ export default function LangSelector() { onToggleLanguageClick(value)} - options={languages.map((lang: 'fr' | 'en') => ({ + onChangeCallback={(value: Country) => { + onToggleLanguageClick(value); + if (onSelected) { + setTimeout(() => onSelected(value), 150); + } + }} + options={languages.map((lang: Country) => ({ label: t(`common:language.${lang}`), value: lang, }))} + formatOptionLabel={(country) => ( +
+ country-image + {country.label} +
+ )} /> ); } diff --git a/src/components/Selector.tsx b/src/components/Selector.tsx index be271bd..19ca786 100644 --- a/src/components/Selector.tsx +++ b/src/components/Selector.tsx @@ -1,5 +1,5 @@ -import { MutableRefObject, useEffect, useState } from 'react'; -import Select, { OptionsOrGroups, GroupBase } from 'react-select'; +import { MutableRefObject, ReactNode, useEffect, useState } from 'react'; +import Select, { GroupBase, OptionsOrGroups } from 'react-select'; type Option = { label: string | number; value: string | number }; @@ -13,6 +13,7 @@ interface SelectorProps { options: OptionsOrGroups>; value?: number | string; onChangeCallback?: (value: number | string) => void; + formatOptionLabel?: (data: Option) => ReactNode; disabled?: boolean; } @@ -26,6 +27,7 @@ export default function Selector({ value, options = [], onChangeCallback, + formatOptionLabel, disabled = false, }: SelectorProps): JSX.Element { const [selectorValue, setSelectorValue] = useState