@@ -4,25 +4,37 @@ import { RING_COLOR } from "../constants";
44import DatepickerContext from "../contexts/DatepickerContext" ;
55import { classNames as cn } from "../helpers" ;
66
7+ import { DoubleVerticalChevronRightIcon } from "./utils" ;
8+
79import { PeriodDay } from "types" ;
810
911const Time : React . FC = ( ) => {
1012 // Contexts
11-
1213 const { primaryColor, changeHour, changeMinute, changePeriodDay } =
1314 useContext ( DatepickerContext ) ;
15+
1416 const ringFocusColor = RING_COLOR . focus [ primaryColor as keyof typeof RING_COLOR . focus ] ;
1517
16- const HOURS = Array . from ( { length : 12 } ) ;
17- const MINUTES = Array . from ( { length : 12 } ) ;
18+ const svgString = `
19+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
20+ <path fill-rule="evenodd" clip-rule="evenodd" d="M8.35355 4.06066C8.15829 3.8654 7.84171 3.8654 7.64645 4.06066L5.35355 6.35355C5.15829 6.54882 4.84171 6.54882 4.64645 6.35355C4.45118 6.15829 4.45118 5.84171 4.64645 5.64645L6.93934 3.35356C7.52513 2.76777 8.47487 2.76777 9.06066 3.35355L11.3536 5.64645C11.5488 5.84171 11.5488 6.15829 11.3536 6.35355C11.1583 6.54882 10.8417 6.54882 10.6464 6.35355L8.35355 4.06066Z" fill="#6b7280"/>
21+ <path fill-rule="evenodd" clip-rule="evenodd" d="M8.35355 11.9393C8.15829 12.1346 7.84171 12.1346 7.64645 11.9393L5.35355 9.64645C5.15829 9.45119 4.84171 9.45119 4.64645 9.64645C4.45118 9.84171 4.45118 10.1583 4.64645 10.3536L6.93934 12.6464C7.52513 13.2322 8.47487 13.2322 9.06066 12.6464L11.3536 10.3536C11.5488 10.1583 11.5488 9.84171 11.3536 9.64645C11.1583 9.45119 10.8417 9.45119 10.6464 9.64645L8.35355 11.9393Z" fill="#6b7280"/>
22+ </svg>
23+ ` ;
24+ const dataUri = `data:image/svg+xml;base64,${ Buffer . from ( svgString ) . toString ( "base64" ) } ` ;
1825
1926 const selectClassname = cn (
20- "!bg-none !bg-transparent !text-sm !text-center !outline-none !focus:outline-none" ,
21- "!px-2 !py-1 rounded-[8px] !w-fit" ,
27+ "!bg-[length:1rem_1rem]" ,
28+ "bg-[right_0.25rem_center]" ,
29+ "!bg-no-repeat !bg-transparent !text-sm !text-center !outline-none !focus:outline-none" ,
30+ "!pl-2 !pr-6 !py-1 rounded-[8px] !w-fit" ,
2231 "!border border-gray-300 focus:border-none" ,
2332 `${ ringFocusColor } `
2433 ) ;
2534
35+ const HOURS = Array . from ( { length : 12 } ) ;
36+ const MINUTES = Array . from ( { length : 12 } ) ;
37+
2638 const handleChangeHour = ( e : ChangeEvent < HTMLSelectElement > ) => changeHour ( e . target . value ) ;
2739
2840 const handleChangeMinute = ( e : ChangeEvent < HTMLSelectElement > ) => changeMinute ( e . target . value ) ;
@@ -33,11 +45,18 @@ const Time: React.FC = () => {
3345 return (
3446 < div className = "w-full md:w-auto flex items-center justify-center space-x-3" >
3547 < div className = "pb-6" >
36- < select name = "hour" className = { selectClassname } onChange = { handleChangeHour } >
48+ < select
49+ name = "hour"
50+ className = { selectClassname }
51+ onChange = { handleChangeHour }
52+ style = { {
53+ backgroundImage : "url(" + dataUri + ")"
54+ } }
55+ >
3756 { HOURS . map ( ( _ , index ) => {
3857 const hour = index + 1 ;
3958 return (
40- < option key = { hour } value = { hour + 1 } >
59+ < option key = { hour } value = { hour } >
4160 { hour }
4261 </ option >
4362 ) ;
@@ -48,19 +67,29 @@ const Time: React.FC = () => {
4867 name = "minute"
4968 className = { cn ( selectClassname , "mr-4" ) }
5069 onChange = { handleChangeMinute }
70+ style = { {
71+ backgroundImage : "url(" + dataUri + ")"
72+ } }
5173 >
5274 { MINUTES . map ( ( _ , index ) => {
5375 const minute = index * 5 ;
5476 return (
55- < option key = { minute } value = { minute + 1 } >
77+ < option key = { minute } value = { minute } >
5678 { new Intl . NumberFormat ( "en-US" , {
5779 minimumIntegerDigits : 2
5880 } ) . format ( minute ) }
5981 </ option >
6082 ) ;
6183 } ) }
6284 </ select >
63- < select name = "ampm" className = { selectClassname } onChange = { handleChangePeriodDay } >
85+ < select
86+ name = "ampm"
87+ className = { selectClassname }
88+ onChange = { handleChangePeriodDay }
89+ style = { {
90+ backgroundImage : "url(" + dataUri + ")"
91+ } }
92+ >
6493 < option value = "AM" > AM</ option >
6594 < option value = "PM" > PM</ option >
6695 </ select >
0 commit comments