2022-10-10 18:50:43 +00:00
|
|
|
import { useMemo } from "react";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ITimezoneOption, ITimezone, Props as SelectProps } from "react-timezone-select";
|
|
|
|
import BaseSelect, { allTimezones } from "react-timezone-select";
|
2022-08-24 20:18:42 +00:00
|
|
|
|
2023-01-05 12:04:28 +00:00
|
|
|
import { getReactSelectProps } from "../select";
|
2022-10-10 18:50:43 +00:00
|
|
|
|
2023-01-05 12:04:28 +00:00
|
|
|
export function TimezoneSelect({ className, components, ...props }: SelectProps) {
|
2022-10-10 18:50:43 +00:00
|
|
|
const reactSelectProps = useMemo(() => {
|
|
|
|
return getReactSelectProps({ className, components: components || {} });
|
|
|
|
}, [className, components]);
|
2022-08-24 20:18:42 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BaseSelect
|
2022-10-10 18:50:43 +00:00
|
|
|
{...reactSelectProps}
|
2022-08-24 20:18:42 +00:00
|
|
|
timezones={{
|
|
|
|
...allTimezones,
|
|
|
|
"America/Asuncion": "Asuncion",
|
|
|
|
}}
|
|
|
|
{...props}
|
2023-02-08 12:08:00 +00:00
|
|
|
formatOptionLabel={(option) => <p className="truncate">{(option as ITimezoneOption).value}</p>}
|
|
|
|
getOptionLabel={(data) => {
|
|
|
|
const option = data as ITimezoneOption;
|
|
|
|
const formatedLabel = option.label.split(")")[0].replace("(", " ").replace("T", "T ");
|
|
|
|
return `${option.value}${formatedLabel}`;
|
|
|
|
}}
|
2022-08-24 20:18:42 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export type { ITimezone, ITimezoneOption };
|