import { DatePicker as ArkDatePicker } from "@ark-ui/react/date-picker"; import { type DateValue } from "@ark-ui/react/date-picker"; import { injectComponentStyle } from "@bysages/core/styling"; import type { CSSProperties } from "react"; import type { ComponentProps } from "react"; import { iconNode } from "../../internal/icon"; import { useElementId } from "../../internal/id"; export type { DatePickerFocusChangeDetails, DatePickerOpenChangeDetails, DatePickerValueChangeDetails, DatePickerViewChangeDetails, DatePickerVisibleRangeChangeDetails, } from "@ark-ui/react/date-picker"; type DatePickerRootProps = ComponentProps & { /** One rung of the control-height ladder for the field row. */ size?: "sm" | "md" | "lg"; }; function DatePickerRoot(props: DatePickerRootProps) { injectComponentStyle("date-picker"); const id = useElementId("date-picker", props); const { size = "md", ...rest } = props; return ; } /** Ark's DatePicker, dressed in the paper-and-ink system: the popup * dissolves in on elevation, selected days take the flat ink fill, and * range middles run subtle with cut corners. The API is Ark's own — * Root, Label, Control, Input, Trigger, ClearTrigger, Positioner, * Content, View, ViewControl, ViewTrigger, RangeText, PrevTrigger, * NextTrigger, Table*, MonthSelect, YearSelect, PresetTrigger. */ type DatePickerFacadeValue = DateValue | DateValue[]; type DatePickerFacadeProps = { value?: DatePickerFacadeValue; defaultValue?: DatePickerFacadeValue; disabled?: boolean; invalid?: boolean; required?: boolean; label?: string; placeholder?: string; size?: "sm" | "md" | "lg"; className?: string; style?: CSSProperties; onValueChange?: (value: DateValue[]) => void; }; function toDatePickerValue(value: DatePickerFacadeValue | undefined) { if (value === undefined) return undefined; return Array.isArray(value) ? value : [value]; } /** The complete picker behind one date: the field opens a single day grid, * while ranges, multiple selection, and custom views remain anatomy work. */ function DatePickerFacade(props: DatePickerFacadeProps) { const { value, defaultValue, disabled, invalid, required, label, placeholder, size = "md", className, style, onValueChange, } = props; return ( onValueChange?.(event.value)} > {label ? {label} : null} {iconNode("calendar", { width: 16, height: 16 })} {(dp: any) => ( <> {iconNode("chevron-left", { width: 14, height: 14 })} {iconNode("chevron-right", { width: 14, height: 14 })} {dp.weekDays.map((day: any, index: number) => ( {day.narrow} ))} {dp.weeks.map((week: any[], index: number) => ( {week.map((day: any, dayIndex: number) => ( {day.day} ))} ))} )} ); } export const DatePicker: typeof DatePickerFacade & Omit & { Root: typeof DatePickerRoot } = Object.assign( DatePickerFacade, { ...ArkDatePicker, Root: DatePickerRoot, }, ) as typeof DatePickerFacade & Omit & { Root: typeof DatePickerRoot };