Raw
1 "use client"
2
3 import * as React from "react"
4 import {
5 AriaTimeFieldProps,
6 TimeValue,
7 useLocale,
8 useTimeField,
9 } from "react-aria"
10 import { useTimeFieldState } from "react-stately"
11
12 import { DateSegment } from "@/components/date-segment"
13 import { clx } from "@/utils/clx"
14
15 const TimeInput = (props: AriaTimeFieldProps<TimeValue>) => {
16 const ref = React.useRef<HTMLDivElement>(null)
17
18 const { locale } = useLocale()
19 const state = useTimeFieldState({
20 ...props,
21 locale,
22 })
23 const { fieldProps } = useTimeField(props, state, ref)
24
25 return (
26 <div
27 ref={ref}
28 {...fieldProps}
29 aria-label="Time input"
30 className={clx(
31 "bg-ui-bg-field shadow-borders-base txt-compact-small flex items-center rounded-md px-2 py-1",
32 {
33 "": props.isDisabled,
34 }
35 )}
36 >
37 {state.segments.map((segment, index) => {
38 return <DateSegment key={index} segment={segment} state={state} />
39 })}
40 </div>
41 )
42 }
43
44 export { TimeInput }