stash/ui/v2.5/src/components/Shared/CountrySelect.tsx
DingDongSoLong4 a1851b3713
Update dependencies (#3123)
* Update localforage, remove query-string
* Update fontawesome and flag-icons
* Update formatjs
* Update axios and videojs
* Update apollo client and graphql
* Update bootstrap and react
* Update polyfills
* Update vite
* Update ESLint
* Update stylelint
* Update configs
* Rebuild yarn.lock
2023-02-16 14:06:44 +11:00

52 lines
1.2 KiB
TypeScript

import React from "react";
import Creatable from "react-select/creatable";
import { useIntl } from "react-intl";
import { getCountries } from "src/utils";
import CountryLabel from "./CountryLabel";
interface IProps {
value?: string;
onChange?: (value: string) => void;
disabled?: boolean;
className?: string;
showFlag?: boolean;
isClearable?: boolean;
}
const CountrySelect: React.FC<IProps> = ({
value,
onChange,
disabled = false,
isClearable = true,
showFlag,
className,
}) => {
const { locale } = useIntl();
const options = getCountries(locale);
const selected = options.find((opt) => opt.value === value) ?? {
label: value,
value,
};
return (
<Creatable
classNamePrefix="react-select"
value={selected}
isClearable={isClearable}
formatOptionLabel={(option) => (
<CountryLabel country={option.value} showFlag={showFlag} />
)}
placeholder="Country"
options={options}
onChange={(selectedOption) => onChange?.(selectedOption?.value ?? "")}
isDisabled={disabled || !onChange}
components={{
IndicatorSeparator: null,
}}
className={`CountrySelect ${className}`}
/>
);
};
export default CountrySelect;