Files
LingvAI/components/LangSelect.tsx

34 lines
902 B
TypeScript
Raw Normal View History

2021-03-16 01:33:19 +01:00
import { FC, ChangeEvent } from "react";
import { Select } from "@chakra-ui/react";
import { LangCode } from "lingva-scraper";
2021-03-16 01:33:19 +01:00
type Props = {
value: string,
onChange: (e: ChangeEvent<any>) => void,
langs: {
[code in LangCode]: string
},
detectedSource?: LangCode<"source">,
2021-03-16 01:33:19 +01:00
[key: string]: any
};
const LangSelect: FC<Props> = ({ value, onChange, langs, detectedSource, ...props }) => (
2021-03-16 01:33:19 +01:00
<Select
value={value}
onChange={onChange}
variant="flushed"
px={[2, null, 3]}
2021-03-16 01:33:19 +01:00
textAlign="center"
2021-03-17 21:30:47 +01:00
style={{ textAlignLast: "center" }}
2021-03-16 01:33:19 +01:00
{...props}
>
{Object.entries(langs).map(([code, name]) => (
<option value={code} key={code}>
{name}{code === "auto" && !!detectedSource && ` (${langs[detectedSource]})`}
</option>
2021-03-16 01:33:19 +01:00
))}
</Select>
);
export default LangSelect;