Commit 7a6b2db8 authored by Chunchi Che's avatar Chunchi Che

optimize I18NSelector

parent 31d59062
Pipeline #27199 passed with stages
in 6 minutes and 41 seconds
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Select } from "@/ui/Shared";
export const I18NSelector: React.FC = () => { export const I18NSelector: React.FC = () => {
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const onClickLanguageChange = (e: React.ChangeEvent<HTMLSelectElement>) => { const onClickLanguageChange = (language: any) => {
const language = e.target.value;
i18n.changeLanguage(language); i18n.changeLanguage(language);
}; };
...@@ -15,14 +16,18 @@ export const I18NSelector: React.FC = () => { ...@@ -15,14 +16,18 @@ export const I18NSelector: React.FC = () => {
}, [i18n.language]); }, [i18n.language]);
return ( return (
<select value={i18n.language} onChange={onClickLanguageChange}> <Select
<option value="cn">Chinese</option> value={i18n.language}
<option value="en">English</option> onChange={onClickLanguageChange}
<option value="fr">French</option> options={[
<option value="jp">Japanese</option> { value: "cn", label: "简体中文" },
<option value="br">Brazilian</option> { value: "en", label: "English" },
<option value="pt">Portuguese</option> { value: "fr", label: "Français" },
<option value="es">Spanish</option> { value: "jp", label: "日本語" },
</select> { value: "br", label: "português do Brasil" },
{ value: "pt", label: "português" },
{ value: "es", label: "Castellano" },
]}
/>
); );
}; };
...@@ -4,10 +4,10 @@ import classNames from "classnames"; ...@@ -4,10 +4,10 @@ import classNames from "classnames";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
export const Select: React.FC< export const Select: React.FC<
React.ComponentProps<typeof AntdSelect> & { title: string } React.ComponentProps<typeof AntdSelect> & { title?: string }
> = ({ title, className, dropdownStyle, ...rest }) => ( > = ({ title, className, dropdownStyle, ...rest }) => (
<div className={styles["custom-select"]}> <div className={styles["custom-select"]}>
<span className={styles.prefix}>{title}</span> {title && <span className={styles.prefix}>{title}</span>}
<AntdSelect <AntdSelect
className={classNames(styles.select, className)} className={classNames(styles.select, className)}
size="large" size="large"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment