-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarHeader.tsx
38 lines (32 loc) · 1.04 KB
/
CalendarHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { getYear } from "date-fns"
import getMonth from "date-fns/getMonth"
import React, { useContext } from "react"
import { LocalesContext } from "../common/LocalesContext"
import { CalendarContext } from "./CalendarContext"
export interface HeadlessCalendarHeader {
date: Date
month: number
year: number
monthLong: string
monthShort: string
monthNarrow: string
}
export interface CalendarHeaderProps {
children: (value: HeadlessCalendarHeader) => JSX.Element[] | JSX.Element
}
export function CalendarHeader({ children }: CalendarHeaderProps) {
const locales = useContext(LocalesContext)
const { month } = useContext(CalendarContext)
const monthLong = month.toLocaleString(locales, { month: "long" })
const monthShort = month.toLocaleString(locales, { month: "short" })
const monthNarrow = month.toLocaleString(locales, { month: "narrow" })
const headlessValues = {
date: month,
month: getMonth(month),
year: getYear(month),
monthLong,
monthShort,
monthNarrow,
}
return <>{children(headlessValues)}</>
}