1- import React , { forwardRef , useCallback , useId , useMemo , useState } from "react" ;
1+ import React , { forwardRef , useId , useMemo } from "react" ;
22
3- import { SingleValue } from "react-select" ;
4- import TimezoneSelect from "react-timezone-select" ;
3+ import ReactTimezoneSelect , { useTimezoneSelect } from "react-timezone-select" ;
54
6- import { getSelectDarkStyles , getSelectLightStyles } from "@constants" ;
7- import { SelectOption , SelectProps } from "@interfaces/components" ;
5+ import { defaultTimezone , getSelectDarkStyles , getSelectLightStyles } from "@constants" ;
6+ import { ITimezoneOption , TimezoneSelectProps } from "@interfaces/components" ;
87import { cn } from "@utilities" ;
98
109import { Hint } from "@components/atoms" ;
1110
12- const defaultTimezone = { label : "UTC" , value : "UTC" } ;
13-
14- interface TimezoneSelectProps extends Omit < SelectProps , "options" | "value" | "onChange" > {
15- value ?: string ;
16- onChange ?: ( value : SingleValue < SelectOption > ) => void ;
17- }
18-
19- export const AkTimezoneSelect = forwardRef < HTMLDivElement , TimezoneSelectProps > (
11+ const TimezoneSelectBase = forwardRef < HTMLDivElement , TimezoneSelectProps > (
2012 (
2113 {
2214 dataTestid,
@@ -33,17 +25,9 @@ export const AkTimezoneSelect = forwardRef<HTMLDivElement, TimezoneSelectProps>(
3325 } ,
3426 ref
3527 ) => {
36- const [ selectedOption , setSelectedOption ] = useState < any > ( null ) ;
28+ const { parseTimezone } = useTimezoneSelect ( { } ) ;
3729
38- const timezoneValue = value ? { label : value , value } : defaultTimezone ;
39-
40- const handleChange = useCallback (
41- ( selected : any ) => {
42- setSelectedOption ( selected ) ;
43- onChange ?.( selected ) ;
44- } ,
45- [ onChange ]
46- ) ;
30+ const timezoneValue : ITimezoneOption = value ? parseTimezone ( value ) : defaultTimezone ;
4731
4832 const selectStyles = useMemo (
4933 ( ) =>
@@ -57,8 +41,9 @@ export const AkTimezoneSelect = forwardRef<HTMLDivElement, TimezoneSelectProps>(
5741 "pointer-events-none absolute -top-2 left-3 px-1 text-xs opacity-100 transition-all before:bg-gray-950" ,
5842 {
5943 "before:bg-white" : variant === "light" ,
60- } ,
61- { "text-gray-900" : variant === "light" }
44+ "text-gray-900" : variant === "light" ,
45+ "text-white" : variant !== "light" ,
46+ }
6247 ) ,
6348 [ variant ]
6449 ) ;
@@ -76,14 +61,14 @@ export const AkTimezoneSelect = forwardRef<HTMLDivElement, TimezoneSelectProps>(
7661 return (
7762 < >
7863 < div className = "relative" data-testid = { dataTestid } ref = { ref } >
79- < TimezoneSelect
64+ < ReactTimezoneSelect
8065 { ...rest }
8166 id = { id }
8267 isDisabled = { disabled }
83- onChange = { handleChange }
68+ onChange = { onChange }
8469 placeholder = { isRequired ? `${ placeholder } *` : placeholder }
8570 styles = { selectStyles as any }
86- value = { selectedOption || timezoneValue }
71+ value = { timezoneValue }
8772 />
8873
8974 < label className = { labelClass } htmlFor = { id } >
@@ -97,4 +82,6 @@ export const AkTimezoneSelect = forwardRef<HTMLDivElement, TimezoneSelectProps>(
9782 }
9883) ;
9984
100- AkTimezoneSelect . displayName = "AkTimezoneSelect" ;
85+ TimezoneSelectBase . displayName = "TimezoneSelect" ;
86+
87+ export const TimezoneSelect = React . memo ( TimezoneSelectBase ) ;
0 commit comments