"use client"; import React from "react"; import { Combobox, Group, InputBase, Loader, ScrollArea, Text, useCombobox } from "@mantine/core"; import { IconCheck } from "@tabler/icons-react"; import type { SupportedLanguage } from "@homarr/translation"; import { localeConfigurations, supportedLanguages } from "@homarr/translation"; import classes from "./language-combobox.module.css"; import "flag-icons/css/flag-icons.min.css"; interface LanguageComboboxProps { label?: string; value: SupportedLanguage; onChange: (value: SupportedLanguage) => void; isPending?: boolean; width?: string; } export const LanguageCombobox = ({ label, value, onChange, isPending, width }: LanguageComboboxProps) => { const combobox = useCombobox({ onDropdownClose: () => combobox.resetSelectedOption(), }); const handleOnOptionSubmit = React.useCallback( (value: string) => { if (!value) { return; } onChange(value as SupportedLanguage); combobox.closeDropdown(); }, [onChange, combobox], ); const handleOnClick = React.useCallback(() => { combobox.toggleDropdown(); }, [combobox]); return ( : null} rightSection={} rightSectionPointerEvents="none" onClick={handleOnClick} variant="filled" w={width} > {supportedLanguages.map((languageKey) => ( ))} ); }; const OptionItem = ({ currentLocale, localeKey, showCheck, }: { currentLocale: SupportedLanguage; localeKey: SupportedLanguage; showCheck?: boolean; }) => { return ( {localeConfigurations[localeKey].name} ({localeConfigurations[localeKey].translatedName}) {showCheck && localeKey === currentLocale && } ); };