|
1
|
"use client" |
|
2
|
|
|
3
|
import { createCalendar } from "@internationalized/date" |
|
4
|
import { TriangleLeftMini, TriangleRightMini } from "@medusajs/icons" |
|
5
|
import * as React from "react" |
|
6
|
import { |
|
7
|
DateValue, |
|
8
|
useCalendar, |
|
9
|
useLocale, |
|
10
|
type CalendarProps, |
|
11
|
} from "react-aria" |
|
12
|
import { useCalendarState } from "react-stately" |
|
13
|
|
|
14
|
import { CalendarButton } from "./calendar-button" |
|
15
|
import { CalendarGrid } from "./calendar-grid" |
|
16
|
|
|
17
|
/** |
|
18
|
* InternalCalendar is the internal implementation of the Calendar component. |
|
19
|
* It's not for public use, but only used for other components like DatePicker. |
|
20
|
*/ |
|
21
|
const InternalCalendar = <TDateValue extends DateValue>( |
|
22
|
props: CalendarProps<TDateValue> |
|
23
|
) => { |
|
24
|
const { locale } = useLocale() |
|
25
|
|
|
26
|
const state = useCalendarState({ |
|
27
|
...props, |
|
28
|
locale, |
|
29
|
createCalendar, |
|
30
|
}) |
|
31
|
|
|
32
|
const { calendarProps, prevButtonProps, nextButtonProps, title } = |
|
33
|
useCalendar(props, state) |
|
34
|
|
|
35
|
return ( |
|
36
|
<div {...calendarProps} className="flex flex-col gap-y-2"> |
|
37
|
<div className="bg-ui-bg-field border-base grid grid-cols-[28px_1fr_28px] items-center gap-1 rounded-md border p-0.5"> |
|
38
|
<CalendarButton {...prevButtonProps}> |
|
39
|
<TriangleLeftMini /> |
|
40
|
</CalendarButton> |
|
41
|
<div className="flex items-center justify-center"> |
|
42
|
<h2 className="txt-compact-small-plus">{title}</h2> |
|
43
|
</div> |
|
44
|
<CalendarButton {...nextButtonProps}> |
|
45
|
<TriangleRightMini /> |
|
46
|
</CalendarButton> |
|
47
|
</div> |
|
48
|
<CalendarGrid state={state} /> |
|
49
|
</div> |
|
50
|
) |
|
51
|
} |
|
52
|
|
|
53
|
export { InternalCalendar } |