@cdx-ui/primitives 0.0.1-beta.140 → 0.0.1-beta.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/calendar/CalendarGrid.js +33 -0
- package/lib/commonjs/calendar/CalendarGrid.js.map +1 -0
- package/lib/commonjs/calendar/CalendarRoot.js +95 -0
- package/lib/commonjs/calendar/CalendarRoot.js.map +1 -0
- package/lib/commonjs/calendar/context.js +17 -0
- package/lib/commonjs/calendar/context.js.map +1 -0
- package/lib/commonjs/calendar/index.js +27 -0
- package/lib/commonjs/calendar/index.js.map +1 -0
- package/lib/commonjs/calendar/types.js +6 -0
- package/lib/commonjs/calendar/types.js.map +1 -0
- package/lib/commonjs/date-field/DateFieldHiddenInput.js +148 -0
- package/lib/commonjs/date-field/DateFieldHiddenInput.js.map +1 -0
- package/lib/commonjs/date-field/DateFieldInput.js +122 -0
- package/lib/commonjs/date-field/DateFieldInput.js.map +1 -0
- package/lib/commonjs/date-field/DateFieldRoot.js +85 -0
- package/lib/commonjs/date-field/DateFieldRoot.js.map +1 -0
- package/lib/commonjs/date-field/DateFieldSegment.js +92 -0
- package/lib/commonjs/date-field/DateFieldSegment.js.map +1 -0
- package/lib/commonjs/date-field/context.js +19 -0
- package/lib/commonjs/date-field/context.js.map +1 -0
- package/lib/commonjs/date-field/index.js +34 -0
- package/lib/commonjs/date-field/index.js.map +1 -0
- package/lib/commonjs/date-field/segmentIndex.js +23 -0
- package/lib/commonjs/date-field/segmentIndex.js.map +1 -0
- package/lib/commonjs/date-field/segmentKeyboard.js +169 -0
- package/lib/commonjs/date-field/segmentKeyboard.js.map +1 -0
- package/lib/commonjs/date-field/types.js +6 -0
- package/lib/commonjs/date-field/types.js.map +1 -0
- package/lib/commonjs/date-field/useDateFieldSegmentState.js +381 -0
- package/lib/commonjs/date-field/useDateFieldSegmentState.js.map +1 -0
- package/lib/commonjs/date-field/useRangeDateFieldBridge.js +67 -0
- package/lib/commonjs/date-field/useRangeDateFieldBridge.js.map +1 -0
- package/lib/commonjs/date-picker/DatePickerRoot.js +123 -0
- package/lib/commonjs/date-picker/DatePickerRoot.js.map +1 -0
- package/lib/commonjs/date-picker/context.js +17 -0
- package/lib/commonjs/date-picker/context.js.map +1 -0
- package/lib/commonjs/date-picker/index.js +26 -0
- package/lib/commonjs/date-picker/index.js.map +1 -0
- package/lib/commonjs/date-range-picker/DateRangePickerRoot.js +144 -0
- package/lib/commonjs/date-range-picker/DateRangePickerRoot.js.map +1 -0
- package/lib/commonjs/date-range-picker/context.js +23 -0
- package/lib/commonjs/date-range-picker/context.js.map +1 -0
- package/lib/commonjs/date-range-picker/index.js +26 -0
- package/lib/commonjs/date-range-picker/index.js.map +1 -0
- package/lib/commonjs/date-time-field/DateTimeFieldHiddenInput.js +150 -0
- package/lib/commonjs/date-time-field/DateTimeFieldHiddenInput.js.map +1 -0
- package/lib/commonjs/date-time-field/DateTimeFieldInput.js +104 -0
- package/lib/commonjs/date-time-field/DateTimeFieldInput.js.map +1 -0
- package/lib/commonjs/date-time-field/DateTimeFieldRoot.js +159 -0
- package/lib/commonjs/date-time-field/DateTimeFieldRoot.js.map +1 -0
- package/lib/commonjs/date-time-field/DateTimeFieldSegment.js +87 -0
- package/lib/commonjs/date-time-field/DateTimeFieldSegment.js.map +1 -0
- package/lib/commonjs/date-time-field/context.js +17 -0
- package/lib/commonjs/date-time-field/context.js.map +1 -0
- package/lib/commonjs/date-time-field/index.js +40 -0
- package/lib/commonjs/date-time-field/index.js.map +1 -0
- package/lib/commonjs/date-time-field/useDateTimeFieldSegmentState.js +564 -0
- package/lib/commonjs/date-time-field/useDateTimeFieldSegmentState.js.map +1 -0
- package/lib/commonjs/date-time-list/DateTimeListRoot.js +418 -0
- package/lib/commonjs/date-time-list/DateTimeListRoot.js.map +1 -0
- package/lib/commonjs/date-time-list/context.js +26 -0
- package/lib/commonjs/date-time-list/context.js.map +1 -0
- package/lib/commonjs/date-time-list/index.js +62 -0
- package/lib/commonjs/date-time-list/index.js.map +1 -0
- package/lib/commonjs/date-time-picker/DateTimePickerRoot.js +134 -0
- package/lib/commonjs/date-time-picker/DateTimePickerRoot.js.map +1 -0
- package/lib/commonjs/date-time-picker/context.js +17 -0
- package/lib/commonjs/date-time-picker/context.js.map +1 -0
- package/lib/commonjs/date-time-picker/index.js +26 -0
- package/lib/commonjs/date-time-picker/index.js.map +1 -0
- package/lib/commonjs/dialog/DialogRoot.js +1 -1
- package/lib/commonjs/dialog/DialogRoot.js.map +1 -1
- package/lib/commonjs/index.js +148 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/month-calendar/MonthCalendarCell.js +64 -0
- package/lib/commonjs/month-calendar/MonthCalendarCell.js.map +1 -0
- package/lib/commonjs/month-calendar/MonthCalendarRoot.js +103 -0
- package/lib/commonjs/month-calendar/MonthCalendarRoot.js.map +1 -0
- package/lib/commonjs/month-calendar/MonthCalendarYearCell.js +63 -0
- package/lib/commonjs/month-calendar/MonthCalendarYearCell.js.map +1 -0
- package/lib/commonjs/month-calendar/context.js +17 -0
- package/lib/commonjs/month-calendar/context.js.map +1 -0
- package/lib/commonjs/month-calendar/index.js +34 -0
- package/lib/commonjs/month-calendar/index.js.map +1 -0
- package/lib/commonjs/month-picker/MonthPickerRoot.js +118 -0
- package/lib/commonjs/month-picker/MonthPickerRoot.js.map +1 -0
- package/lib/commonjs/month-picker/context.js +17 -0
- package/lib/commonjs/month-picker/context.js.map +1 -0
- package/lib/commonjs/month-picker/index.js +26 -0
- package/lib/commonjs/month-picker/index.js.map +1 -0
- package/lib/commonjs/overlay/useAnchorPosition.js +27 -16
- package/lib/commonjs/overlay/useAnchorPosition.js.map +1 -1
- package/lib/commonjs/overlay/useDismissOverlay.web.js +10 -2
- package/lib/commonjs/overlay/useDismissOverlay.web.js.map +1 -1
- package/lib/commonjs/overlay/useOverlayPosition.js +5 -2
- package/lib/commonjs/overlay/useOverlayPosition.js.map +1 -1
- package/lib/commonjs/portal/portal.js +59 -2
- package/lib/commonjs/portal/portal.js.map +1 -1
- package/lib/commonjs/range-calendar/RangeCalendarRoot.js +148 -0
- package/lib/commonjs/range-calendar/RangeCalendarRoot.js.map +1 -0
- package/lib/commonjs/range-calendar/context.js +17 -0
- package/lib/commonjs/range-calendar/context.js.map +1 -0
- package/lib/commonjs/range-calendar/index.js +20 -0
- package/lib/commonjs/range-calendar/index.js.map +1 -0
- package/lib/commonjs/select/SelectRoot.js +1 -1
- package/lib/commonjs/select/SelectRoot.js.map +1 -1
- package/lib/commonjs/utils/accessibleLabel.js +23 -0
- package/lib/commonjs/utils/accessibleLabel.js.map +1 -0
- package/lib/commonjs/utils/createPortal.web.js +21 -0
- package/lib/commonjs/utils/createPortal.web.js.map +1 -0
- package/lib/module/calendar/CalendarGrid.js +29 -0
- package/lib/module/calendar/CalendarGrid.js.map +1 -0
- package/lib/module/calendar/CalendarRoot.js +91 -0
- package/lib/module/calendar/CalendarRoot.js.map +1 -0
- package/lib/module/calendar/context.js +12 -0
- package/lib/module/calendar/context.js.map +1 -0
- package/lib/module/calendar/index.js +6 -0
- package/lib/module/calendar/index.js.map +1 -0
- package/lib/module/calendar/types.js +4 -0
- package/lib/module/calendar/types.js.map +1 -0
- package/lib/module/date-field/DateFieldHiddenInput.js +146 -0
- package/lib/module/date-field/DateFieldHiddenInput.js.map +1 -0
- package/lib/module/date-field/DateFieldInput.js +118 -0
- package/lib/module/date-field/DateFieldInput.js.map +1 -0
- package/lib/module/date-field/DateFieldRoot.js +81 -0
- package/lib/module/date-field/DateFieldRoot.js.map +1 -0
- package/lib/module/date-field/DateFieldSegment.js +88 -0
- package/lib/module/date-field/DateFieldSegment.js.map +1 -0
- package/lib/module/date-field/context.js +15 -0
- package/lib/module/date-field/context.js.map +1 -0
- package/lib/module/date-field/index.js +7 -0
- package/lib/module/date-field/index.js.map +1 -0
- package/lib/module/date-field/segmentIndex.js +18 -0
- package/lib/module/date-field/segmentIndex.js.map +1 -0
- package/lib/module/date-field/segmentKeyboard.js +157 -0
- package/lib/module/date-field/segmentKeyboard.js.map +1 -0
- package/lib/module/date-field/types.js +4 -0
- package/lib/module/date-field/types.js.map +1 -0
- package/lib/module/date-field/useDateFieldSegmentState.js +378 -0
- package/lib/module/date-field/useDateFieldSegmentState.js.map +1 -0
- package/lib/module/date-field/useRangeDateFieldBridge.js +63 -0
- package/lib/module/date-field/useRangeDateFieldBridge.js.map +1 -0
- package/lib/module/date-picker/DatePickerRoot.js +119 -0
- package/lib/module/date-picker/DatePickerRoot.js.map +1 -0
- package/lib/module/date-picker/context.js +12 -0
- package/lib/module/date-picker/context.js.map +1 -0
- package/lib/module/date-picker/index.js +5 -0
- package/lib/module/date-picker/index.js.map +1 -0
- package/lib/module/date-range-picker/DateRangePickerRoot.js +140 -0
- package/lib/module/date-range-picker/DateRangePickerRoot.js.map +1 -0
- package/lib/module/date-range-picker/context.js +19 -0
- package/lib/module/date-range-picker/context.js.map +1 -0
- package/lib/module/date-range-picker/index.js +5 -0
- package/lib/module/date-range-picker/index.js.map +1 -0
- package/lib/module/date-time-field/DateTimeFieldHiddenInput.js +148 -0
- package/lib/module/date-time-field/DateTimeFieldHiddenInput.js.map +1 -0
- package/lib/module/date-time-field/DateTimeFieldInput.js +100 -0
- package/lib/module/date-time-field/DateTimeFieldInput.js.map +1 -0
- package/lib/module/date-time-field/DateTimeFieldRoot.js +154 -0
- package/lib/module/date-time-field/DateTimeFieldRoot.js.map +1 -0
- package/lib/module/date-time-field/DateTimeFieldSegment.js +83 -0
- package/lib/module/date-time-field/DateTimeFieldSegment.js.map +1 -0
- package/lib/module/date-time-field/context.js +12 -0
- package/lib/module/date-time-field/context.js.map +1 -0
- package/lib/module/date-time-field/index.js +7 -0
- package/lib/module/date-time-field/index.js.map +1 -0
- package/lib/module/date-time-field/useDateTimeFieldSegmentState.js +561 -0
- package/lib/module/date-time-field/useDateTimeFieldSegmentState.js.map +1 -0
- package/lib/module/date-time-list/DateTimeListRoot.js +416 -0
- package/lib/module/date-time-list/DateTimeListRoot.js.map +1 -0
- package/lib/module/date-time-list/context.js +20 -0
- package/lib/module/date-time-list/context.js.map +1 -0
- package/lib/module/date-time-list/index.js +5 -0
- package/lib/module/date-time-list/index.js.map +1 -0
- package/lib/module/date-time-picker/DateTimePickerRoot.js +130 -0
- package/lib/module/date-time-picker/DateTimePickerRoot.js.map +1 -0
- package/lib/module/date-time-picker/context.js +12 -0
- package/lib/module/date-time-picker/context.js.map +1 -0
- package/lib/module/date-time-picker/index.js +5 -0
- package/lib/module/date-time-picker/index.js.map +1 -0
- package/lib/module/dialog/DialogRoot.js +1 -1
- package/lib/module/dialog/DialogRoot.js.map +1 -1
- package/lib/module/index.js +11 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/month-calendar/MonthCalendarCell.js +60 -0
- package/lib/module/month-calendar/MonthCalendarCell.js.map +1 -0
- package/lib/module/month-calendar/MonthCalendarRoot.js +99 -0
- package/lib/module/month-calendar/MonthCalendarRoot.js.map +1 -0
- package/lib/module/month-calendar/MonthCalendarYearCell.js +59 -0
- package/lib/module/month-calendar/MonthCalendarYearCell.js.map +1 -0
- package/lib/module/month-calendar/context.js +12 -0
- package/lib/module/month-calendar/context.js.map +1 -0
- package/lib/module/month-calendar/index.js +7 -0
- package/lib/module/month-calendar/index.js.map +1 -0
- package/lib/module/month-picker/MonthPickerRoot.js +114 -0
- package/lib/module/month-picker/MonthPickerRoot.js.map +1 -0
- package/lib/module/month-picker/context.js +12 -0
- package/lib/module/month-picker/context.js.map +1 -0
- package/lib/module/month-picker/index.js +5 -0
- package/lib/module/month-picker/index.js.map +1 -0
- package/lib/module/overlay/useAnchorPosition.js +27 -16
- package/lib/module/overlay/useAnchorPosition.js.map +1 -1
- package/lib/module/overlay/useDismissOverlay.web.js +9 -2
- package/lib/module/overlay/useDismissOverlay.web.js.map +1 -1
- package/lib/module/overlay/useOverlayPosition.js +5 -2
- package/lib/module/overlay/useOverlayPosition.js.map +1 -1
- package/lib/module/portal/portal.js +59 -2
- package/lib/module/portal/portal.js.map +1 -1
- package/lib/module/range-calendar/RangeCalendarRoot.js +144 -0
- package/lib/module/range-calendar/RangeCalendarRoot.js.map +1 -0
- package/lib/module/range-calendar/context.js +12 -0
- package/lib/module/range-calendar/context.js.map +1 -0
- package/lib/module/range-calendar/index.js +5 -0
- package/lib/module/range-calendar/index.js.map +1 -0
- package/lib/module/select/SelectRoot.js +1 -1
- package/lib/module/select/SelectRoot.js.map +1 -1
- package/lib/module/utils/accessibleLabel.js +18 -0
- package/lib/module/utils/accessibleLabel.js.map +1 -0
- package/lib/module/utils/createPortal.web.js +17 -0
- package/lib/module/utils/createPortal.web.js.map +1 -0
- package/lib/typescript/calendar/CalendarGrid.d.ts +7 -0
- package/lib/typescript/calendar/CalendarGrid.d.ts.map +1 -0
- package/lib/typescript/calendar/CalendarRoot.d.ts +10 -0
- package/lib/typescript/calendar/CalendarRoot.d.ts.map +1 -0
- package/lib/typescript/calendar/context.d.ts +18 -0
- package/lib/typescript/calendar/context.d.ts.map +1 -0
- package/lib/typescript/calendar/index.d.ts +5 -0
- package/lib/typescript/calendar/index.d.ts.map +1 -0
- package/lib/typescript/calendar/types.d.ts +29 -0
- package/lib/typescript/calendar/types.d.ts.map +1 -0
- package/lib/typescript/date-field/DateFieldHiddenInput.d.ts +4 -0
- package/lib/typescript/date-field/DateFieldHiddenInput.d.ts.map +1 -0
- package/lib/typescript/date-field/DateFieldInput.d.ts +8 -0
- package/lib/typescript/date-field/DateFieldInput.d.ts.map +1 -0
- package/lib/typescript/date-field/DateFieldRoot.d.ts +10 -0
- package/lib/typescript/date-field/DateFieldRoot.d.ts.map +1 -0
- package/lib/typescript/date-field/DateFieldSegment.d.ts +9 -0
- package/lib/typescript/date-field/DateFieldSegment.d.ts.map +1 -0
- package/lib/typescript/date-field/context.d.ts +33 -0
- package/lib/typescript/date-field/context.d.ts.map +1 -0
- package/lib/typescript/date-field/index.d.ts +9 -0
- package/lib/typescript/date-field/index.d.ts.map +1 -0
- package/lib/typescript/date-field/segmentIndex.d.ts +7 -0
- package/lib/typescript/date-field/segmentIndex.d.ts.map +1 -0
- package/lib/typescript/date-field/segmentKeyboard.d.ts +23 -0
- package/lib/typescript/date-field/segmentKeyboard.d.ts.map +1 -0
- package/lib/typescript/date-field/types.d.ts +38 -0
- package/lib/typescript/date-field/types.d.ts.map +1 -0
- package/lib/typescript/date-field/useDateFieldSegmentState.d.ts +26 -0
- package/lib/typescript/date-field/useDateFieldSegmentState.d.ts.map +1 -0
- package/lib/typescript/date-field/useRangeDateFieldBridge.d.ts +4 -0
- package/lib/typescript/date-field/useRangeDateFieldBridge.d.ts.map +1 -0
- package/lib/typescript/date-picker/DatePickerRoot.d.ts +28 -0
- package/lib/typescript/date-picker/DatePickerRoot.d.ts.map +1 -0
- package/lib/typescript/date-picker/context.d.ts +25 -0
- package/lib/typescript/date-picker/context.d.ts.map +1 -0
- package/lib/typescript/date-picker/index.d.ts +5 -0
- package/lib/typescript/date-picker/index.d.ts.map +1 -0
- package/lib/typescript/date-range-picker/DateRangePickerRoot.d.ts +43 -0
- package/lib/typescript/date-range-picker/DateRangePickerRoot.d.ts.map +1 -0
- package/lib/typescript/date-range-picker/context.d.ts +42 -0
- package/lib/typescript/date-range-picker/context.d.ts.map +1 -0
- package/lib/typescript/date-range-picker/index.d.ts +4 -0
- package/lib/typescript/date-range-picker/index.d.ts.map +1 -0
- package/lib/typescript/date-time-field/DateTimeFieldHiddenInput.d.ts +4 -0
- package/lib/typescript/date-time-field/DateTimeFieldHiddenInput.d.ts.map +1 -0
- package/lib/typescript/date-time-field/DateTimeFieldInput.d.ts +10 -0
- package/lib/typescript/date-time-field/DateTimeFieldInput.d.ts.map +1 -0
- package/lib/typescript/date-time-field/DateTimeFieldRoot.d.ts +24 -0
- package/lib/typescript/date-time-field/DateTimeFieldRoot.d.ts.map +1 -0
- package/lib/typescript/date-time-field/DateTimeFieldSegment.d.ts +10 -0
- package/lib/typescript/date-time-field/DateTimeFieldSegment.d.ts.map +1 -0
- package/lib/typescript/date-time-field/context.d.ts +27 -0
- package/lib/typescript/date-time-field/context.d.ts.map +1 -0
- package/lib/typescript/date-time-field/index.d.ts +8 -0
- package/lib/typescript/date-time-field/index.d.ts.map +1 -0
- package/lib/typescript/date-time-field/useDateTimeFieldSegmentState.d.ts +26 -0
- package/lib/typescript/date-time-field/useDateTimeFieldSegmentState.d.ts.map +1 -0
- package/lib/typescript/date-time-list/DateTimeListRoot.d.ts +42 -0
- package/lib/typescript/date-time-list/DateTimeListRoot.d.ts.map +1 -0
- package/lib/typescript/date-time-list/context.d.ts +29 -0
- package/lib/typescript/date-time-list/context.d.ts.map +1 -0
- package/lib/typescript/date-time-list/index.d.ts +4 -0
- package/lib/typescript/date-time-list/index.d.ts.map +1 -0
- package/lib/typescript/date-time-picker/DateTimePickerRoot.d.ts +36 -0
- package/lib/typescript/date-time-picker/DateTimePickerRoot.d.ts.map +1 -0
- package/lib/typescript/date-time-picker/context.d.ts +25 -0
- package/lib/typescript/date-time-picker/context.d.ts.map +1 -0
- package/lib/typescript/date-time-picker/index.d.ts +4 -0
- package/lib/typescript/date-time-picker/index.d.ts.map +1 -0
- package/lib/typescript/dialog/types.d.ts +2 -1
- package/lib/typescript/dialog/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +11 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/month-calendar/MonthCalendarCell.d.ts +9 -0
- package/lib/typescript/month-calendar/MonthCalendarCell.d.ts.map +1 -0
- package/lib/typescript/month-calendar/MonthCalendarRoot.d.ts +30 -0
- package/lib/typescript/month-calendar/MonthCalendarRoot.d.ts.map +1 -0
- package/lib/typescript/month-calendar/MonthCalendarYearCell.d.ts +9 -0
- package/lib/typescript/month-calendar/MonthCalendarYearCell.d.ts.map +1 -0
- package/lib/typescript/month-calendar/context.d.ts +20 -0
- package/lib/typescript/month-calendar/context.d.ts.map +1 -0
- package/lib/typescript/month-calendar/index.d.ts +7 -0
- package/lib/typescript/month-calendar/index.d.ts.map +1 -0
- package/lib/typescript/month-picker/MonthPickerRoot.d.ts +29 -0
- package/lib/typescript/month-picker/MonthPickerRoot.d.ts.map +1 -0
- package/lib/typescript/month-picker/context.d.ts +23 -0
- package/lib/typescript/month-picker/context.d.ts.map +1 -0
- package/lib/typescript/month-picker/index.d.ts +4 -0
- package/lib/typescript/month-picker/index.d.ts.map +1 -0
- package/lib/typescript/overlay/useAnchorPosition.d.ts.map +1 -1
- package/lib/typescript/overlay/useDismissOverlay.web.d.ts.map +1 -1
- package/lib/typescript/overlay/useOverlayPosition.d.ts.map +1 -1
- package/lib/typescript/portal/portal.d.ts.map +1 -1
- package/lib/typescript/range-calendar/RangeCalendarRoot.d.ts +34 -0
- package/lib/typescript/range-calendar/RangeCalendarRoot.d.ts.map +1 -0
- package/lib/typescript/range-calendar/context.d.ts +26 -0
- package/lib/typescript/range-calendar/context.d.ts.map +1 -0
- package/lib/typescript/range-calendar/index.d.ts +5 -0
- package/lib/typescript/range-calendar/index.d.ts.map +1 -0
- package/lib/typescript/select/types.d.ts +2 -1
- package/lib/typescript/select/types.d.ts.map +1 -1
- package/lib/typescript/utils/accessibleLabel.d.ts +13 -0
- package/lib/typescript/utils/accessibleLabel.d.ts.map +1 -0
- package/lib/typescript/utils/createPortal.web.d.ts +17 -0
- package/lib/typescript/utils/createPortal.web.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/calendar/CalendarGrid.tsx +29 -0
- package/src/calendar/CalendarRoot.tsx +138 -0
- package/src/calendar/context.tsx +28 -0
- package/src/calendar/index.ts +4 -0
- package/src/calendar/types.ts +30 -0
- package/src/date-field/DateFieldHiddenInput.tsx +152 -0
- package/src/date-field/DateFieldInput.tsx +138 -0
- package/src/date-field/DateFieldRoot.tsx +117 -0
- package/src/date-field/DateFieldSegment.tsx +97 -0
- package/src/date-field/context.tsx +48 -0
- package/src/date-field/index.ts +8 -0
- package/src/date-field/segmentIndex.tsx +17 -0
- package/src/date-field/segmentKeyboard.ts +207 -0
- package/src/date-field/types.ts +40 -0
- package/src/date-field/useDateFieldSegmentState.ts +455 -0
- package/src/date-field/useRangeDateFieldBridge.ts +78 -0
- package/src/date-picker/DatePickerRoot.tsx +186 -0
- package/src/date-picker/context.tsx +34 -0
- package/src/date-picker/index.ts +4 -0
- package/src/date-range-picker/DateRangePickerRoot.tsx +236 -0
- package/src/date-range-picker/context.tsx +48 -0
- package/src/date-range-picker/index.ts +8 -0
- package/src/date-time-field/DateTimeFieldHiddenInput.tsx +156 -0
- package/src/date-time-field/DateTimeFieldInput.tsx +119 -0
- package/src/date-time-field/DateTimeFieldRoot.tsx +209 -0
- package/src/date-time-field/DateTimeFieldSegment.tsx +95 -0
- package/src/date-time-field/context.tsx +41 -0
- package/src/date-time-field/index.ts +7 -0
- package/src/date-time-field/useDateTimeFieldSegmentState.ts +672 -0
- package/src/date-time-list/DateTimeListRoot.tsx +530 -0
- package/src/date-time-list/context.tsx +45 -0
- package/src/date-time-list/index.ts +16 -0
- package/src/date-time-picker/DateTimePickerRoot.tsx +210 -0
- package/src/date-time-picker/context.tsx +33 -0
- package/src/date-time-picker/index.ts +7 -0
- package/src/dialog/DialogRoot.tsx +1 -1
- package/src/dialog/types.ts +2 -1
- package/src/index.ts +21 -2
- package/src/month-calendar/MonthCalendarCell.tsx +53 -0
- package/src/month-calendar/MonthCalendarRoot.tsx +153 -0
- package/src/month-calendar/MonthCalendarYearCell.tsx +54 -0
- package/src/month-calendar/context.tsx +30 -0
- package/src/month-calendar/index.ts +6 -0
- package/src/month-picker/MonthPickerRoot.tsx +183 -0
- package/src/month-picker/context.tsx +31 -0
- package/src/month-picker/index.ts +3 -0
- package/src/overlay/useAnchorPosition.ts +25 -11
- package/src/overlay/useDismissOverlay.web.ts +10 -2
- package/src/overlay/useOverlayPosition.ts +5 -2
- package/src/portal/portal.tsx +79 -2
- package/src/range-calendar/RangeCalendarRoot.tsx +213 -0
- package/src/range-calendar/context.tsx +33 -0
- package/src/range-calendar/index.ts +4 -0
- package/src/select/SelectRoot.tsx +1 -1
- package/src/select/types.ts +2 -1
- package/src/utils/accessibleLabel.ts +22 -0
- package/src/utils/createPortal.web.ts +18 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type ComponentRef,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { View, type ViewProps } from 'react-native';
|
|
12
|
+
import {
|
|
13
|
+
clampDateTimeId,
|
|
14
|
+
isLocaleHour12,
|
|
15
|
+
nowDateTimeId,
|
|
16
|
+
resolveDateComponentLabels,
|
|
17
|
+
type DateComponentLabels,
|
|
18
|
+
type DateTimeGranularity,
|
|
19
|
+
type DateTimeId,
|
|
20
|
+
} from '@cdx-ui/formatters';
|
|
21
|
+
import { mergeRefs, useControllableState } from '@cdx-ui/utils';
|
|
22
|
+
import { DateTimeFieldRoot } from '../date-time-field/DateTimeFieldRoot';
|
|
23
|
+
import { Slot } from '../slot';
|
|
24
|
+
import { dataAttributes, mergeDataAttributes } from '../utils/dataAttributes';
|
|
25
|
+
import type { PickerSurfaceType } from '../date-picker/context';
|
|
26
|
+
import { DateTimePickerContext } from './context';
|
|
27
|
+
|
|
28
|
+
export interface DateTimePickerRootProps extends Omit<ViewProps, 'children'> {
|
|
29
|
+
asChild?: boolean;
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
className?: string;
|
|
32
|
+
value?: DateTimeId;
|
|
33
|
+
defaultValue?: DateTimeId;
|
|
34
|
+
/** Called with the new `DateTimeId`, or `undefined` when the selection is cleared. */
|
|
35
|
+
onValueChange?: (value: DateTimeId | undefined) => void;
|
|
36
|
+
/** Controlled open state. Use `defaultOpen` for the uncontrolled variant. */
|
|
37
|
+
isOpen?: boolean;
|
|
38
|
+
defaultOpen?: boolean;
|
|
39
|
+
onOpenChange?: (open: boolean) => void;
|
|
40
|
+
isDisabled?: boolean;
|
|
41
|
+
isReadOnly?: boolean;
|
|
42
|
+
isInvalid?: boolean;
|
|
43
|
+
isRequired?: boolean;
|
|
44
|
+
/** Earliest selectable date-time, applied to the scroll list. Build with `dateTimeId(...)`. */
|
|
45
|
+
minValue?: DateTimeId;
|
|
46
|
+
/** Latest selectable date-time, applied to the scroll list. Build with `dateTimeId(...)`. */
|
|
47
|
+
maxValue?: DateTimeId;
|
|
48
|
+
name?: string;
|
|
49
|
+
locale?: string;
|
|
50
|
+
labels?: Partial<DateComponentLabels>;
|
|
51
|
+
/** Which field segments and list columns to show, from coarsest (`day`) to finest (`second`). */
|
|
52
|
+
granularity?: DateTimeGranularity;
|
|
53
|
+
/**
|
|
54
|
+
* Force a 12-hour clock (AM/PM column) or a 24-hour clock. Defaults to the
|
|
55
|
+
* locale's convention when omitted.
|
|
56
|
+
*/
|
|
57
|
+
hour12?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const DateTimePickerRoot = forwardRef<ComponentRef<typeof View>, DateTimePickerRootProps>(
|
|
61
|
+
(
|
|
62
|
+
{
|
|
63
|
+
asChild,
|
|
64
|
+
children,
|
|
65
|
+
value: valueProp,
|
|
66
|
+
defaultValue,
|
|
67
|
+
onValueChange,
|
|
68
|
+
isOpen: openProp,
|
|
69
|
+
defaultOpen = false,
|
|
70
|
+
onOpenChange,
|
|
71
|
+
isDisabled: disabled = false,
|
|
72
|
+
isReadOnly,
|
|
73
|
+
isInvalid,
|
|
74
|
+
isRequired,
|
|
75
|
+
minValue,
|
|
76
|
+
maxValue,
|
|
77
|
+
locale = 'en-US',
|
|
78
|
+
labels: labelsProp,
|
|
79
|
+
granularity = 'minute',
|
|
80
|
+
hour12: hour12Prop,
|
|
81
|
+
...props
|
|
82
|
+
},
|
|
83
|
+
ref,
|
|
84
|
+
) => {
|
|
85
|
+
const hour12 = hour12Prop ?? isLocaleHour12(locale);
|
|
86
|
+
const labels = useMemo(() => resolveDateComponentLabels(labelsProp), [labelsProp]);
|
|
87
|
+
const [value, setValue] = useControllableState<DateTimeId | undefined>({
|
|
88
|
+
prop: valueProp,
|
|
89
|
+
defaultProp: defaultValue,
|
|
90
|
+
onChange: onValueChange,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const [open, setOpenState] = useControllableState<boolean>({
|
|
94
|
+
prop: openProp,
|
|
95
|
+
defaultProp: defaultOpen,
|
|
96
|
+
onChange: onOpenChange,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const [draftValue, setDraftValue] = useState<DateTimeId | undefined>(value);
|
|
100
|
+
|
|
101
|
+
const surfacesRef = useRef<Set<PickerSurfaceType>>(new Set());
|
|
102
|
+
const anchorRef = useRef<ComponentRef<typeof View>>(null);
|
|
103
|
+
const triggerRef = useRef<ComponentRef<typeof View>>(null);
|
|
104
|
+
|
|
105
|
+
const setOpen = useCallback(
|
|
106
|
+
(next: boolean) => {
|
|
107
|
+
if (disabled && next) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (next) {
|
|
111
|
+
const base = value ?? nowDateTimeId({ granularity });
|
|
112
|
+
setDraftValue(clampDateTimeId(base, { min: minValue, max: maxValue }));
|
|
113
|
+
} else if (value === undefined) {
|
|
114
|
+
setDraftValue(undefined);
|
|
115
|
+
}
|
|
116
|
+
setOpenState(next);
|
|
117
|
+
},
|
|
118
|
+
[disabled, granularity, maxValue, minValue, setOpenState, value],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const registerSurface = useCallback((type: PickerSurfaceType) => {
|
|
122
|
+
if (surfacesRef.current.has(type)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
surfacesRef.current.add(type);
|
|
126
|
+
if (surfacesRef.current.size > 1) {
|
|
127
|
+
console.warn(
|
|
128
|
+
'[Forge UI] DateTimePicker: multiple presentation surfaces detected. Use only one of Popover, Dialog, or BottomSheet.',
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}, []);
|
|
132
|
+
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (value !== undefined) {
|
|
135
|
+
setDraftValue(value);
|
|
136
|
+
}
|
|
137
|
+
}, [value]);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (!open) {
|
|
141
|
+
surfacesRef.current.clear();
|
|
142
|
+
}
|
|
143
|
+
}, [open]);
|
|
144
|
+
|
|
145
|
+
const contextValue = useMemo(
|
|
146
|
+
() => ({
|
|
147
|
+
value,
|
|
148
|
+
onValueChange: setValue,
|
|
149
|
+
draftValue,
|
|
150
|
+
setDraftValue,
|
|
151
|
+
open: open ?? false,
|
|
152
|
+
setOpen,
|
|
153
|
+
disabled,
|
|
154
|
+
minValue,
|
|
155
|
+
maxValue,
|
|
156
|
+
registerSurface,
|
|
157
|
+
anchorRef,
|
|
158
|
+
triggerRef,
|
|
159
|
+
granularity,
|
|
160
|
+
locale,
|
|
161
|
+
labels,
|
|
162
|
+
hour12,
|
|
163
|
+
}),
|
|
164
|
+
[
|
|
165
|
+
value,
|
|
166
|
+
setValue,
|
|
167
|
+
draftValue,
|
|
168
|
+
open,
|
|
169
|
+
setOpen,
|
|
170
|
+
disabled,
|
|
171
|
+
minValue,
|
|
172
|
+
maxValue,
|
|
173
|
+
registerSurface,
|
|
174
|
+
granularity,
|
|
175
|
+
locale,
|
|
176
|
+
labels,
|
|
177
|
+
hour12,
|
|
178
|
+
],
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const Comp = asChild ? Slot : View;
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<DateTimePickerContext.Provider value={contextValue}>
|
|
185
|
+
<Comp
|
|
186
|
+
ref={mergeRefs(ref, anchorRef)}
|
|
187
|
+
{...props}
|
|
188
|
+
{...mergeDataAttributes(props, dataAttributes({ disabled, open }))}
|
|
189
|
+
>
|
|
190
|
+
<DateTimeFieldRoot
|
|
191
|
+
value={value}
|
|
192
|
+
onValueChange={setValue}
|
|
193
|
+
granularity={granularity}
|
|
194
|
+
locale={locale}
|
|
195
|
+
hour12={hour12}
|
|
196
|
+
labels={labels}
|
|
197
|
+
isDisabled={disabled}
|
|
198
|
+
isReadOnly={isReadOnly}
|
|
199
|
+
isInvalid={isInvalid}
|
|
200
|
+
isRequired={isRequired}
|
|
201
|
+
>
|
|
202
|
+
{children}
|
|
203
|
+
</DateTimeFieldRoot>
|
|
204
|
+
</Comp>
|
|
205
|
+
</DateTimePickerContext.Provider>
|
|
206
|
+
);
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
DateTimePickerRoot.displayName = 'DateTimePickerRoot';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createContext, useContext, type RefObject } from 'react';
|
|
2
|
+
import type { View } from 'react-native';
|
|
3
|
+
import type { DateComponentLabels, DateTimeGranularity, DateTimeId } from '@cdx-ui/formatters';
|
|
4
|
+
import type { PickerSurfaceType } from '../date-picker/context';
|
|
5
|
+
|
|
6
|
+
export interface DateTimePickerContextValue {
|
|
7
|
+
value?: DateTimeId;
|
|
8
|
+
onValueChange?: (value: DateTimeId | undefined) => void;
|
|
9
|
+
draftValue?: DateTimeId;
|
|
10
|
+
setDraftValue: (value: DateTimeId | undefined) => void;
|
|
11
|
+
open: boolean;
|
|
12
|
+
setOpen: (open: boolean) => void;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
minValue?: DateTimeId;
|
|
15
|
+
maxValue?: DateTimeId;
|
|
16
|
+
registerSurface: (type: PickerSurfaceType) => void;
|
|
17
|
+
anchorRef: RefObject<View | null>;
|
|
18
|
+
triggerRef: RefObject<View | null>;
|
|
19
|
+
granularity: DateTimeGranularity;
|
|
20
|
+
locale: string;
|
|
21
|
+
labels: DateComponentLabels;
|
|
22
|
+
hour12: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const DateTimePickerContext = createContext<DateTimePickerContextValue | null>(null);
|
|
26
|
+
|
|
27
|
+
export function useDateTimePickerContext(): DateTimePickerContextValue {
|
|
28
|
+
const ctx = useContext(DateTimePickerContext);
|
|
29
|
+
if (!ctx) {
|
|
30
|
+
throw new Error('DateTimePicker compound components must be used within DateTimePickerRoot');
|
|
31
|
+
}
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
@@ -13,7 +13,7 @@ export interface DialogRootProps extends Omit<ViewProps, 'children' | 'role'>, I
|
|
|
13
13
|
export const DialogRoot = forwardRef<ComponentRef<typeof View>, DialogRootProps>(
|
|
14
14
|
(
|
|
15
15
|
{
|
|
16
|
-
|
|
16
|
+
isOpen: openProp,
|
|
17
17
|
onOpenChange,
|
|
18
18
|
defaultOpen = false,
|
|
19
19
|
closeOnBackdropPress = true,
|
package/src/dialog/types.ts
CHANGED
|
@@ -11,7 +11,8 @@ export interface IDialogContextType {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface IDialogRootProps {
|
|
14
|
-
|
|
14
|
+
/** Controlled open state. Use `defaultOpen` for the uncontrolled variant. */
|
|
15
|
+
readonly isOpen?: boolean;
|
|
15
16
|
readonly onOpenChange?: (open: boolean) => void;
|
|
16
17
|
readonly defaultOpen?: boolean;
|
|
17
18
|
readonly closeOnBackdropPress?: boolean;
|
package/src/index.ts
CHANGED
|
@@ -9,10 +9,29 @@ export * from './form';
|
|
|
9
9
|
export * from './full-window-overlay';
|
|
10
10
|
export * from './input';
|
|
11
11
|
export * from './otp-input';
|
|
12
|
+
export * from './date-field';
|
|
13
|
+
export * from './calendar';
|
|
14
|
+
export * from './range-calendar';
|
|
15
|
+
export * from './month-calendar';
|
|
16
|
+
export * from './date-picker';
|
|
17
|
+
export * from './date-range-picker';
|
|
18
|
+
export * from './month-picker';
|
|
19
|
+
export * from './date-time-field';
|
|
20
|
+
export * from './date-time-list';
|
|
21
|
+
export * from './date-time-picker';
|
|
12
22
|
export * from './link';
|
|
13
23
|
export * from './list-item';
|
|
14
|
-
export {
|
|
15
|
-
|
|
24
|
+
export {
|
|
25
|
+
type EdgeInsets,
|
|
26
|
+
OverlayContainer,
|
|
27
|
+
OverlayInsetsProvider,
|
|
28
|
+
useAnchorPosition,
|
|
29
|
+
useDismissOverlay,
|
|
30
|
+
useEscapeKey,
|
|
31
|
+
useOverlayPosition,
|
|
32
|
+
type AnchorLayout,
|
|
33
|
+
type OverlayPosition,
|
|
34
|
+
} from './overlay';
|
|
16
35
|
export * from './select';
|
|
17
36
|
export * from './switch';
|
|
18
37
|
export * from './tabs';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { forwardRef, type ComponentRef } from 'react';
|
|
2
|
+
import { Pressable, View, type ViewProps } from 'react-native';
|
|
3
|
+
import { compareMonthIds, formatMonthId, type MonthId } from '@cdx-ui/formatters';
|
|
4
|
+
import { Slot } from '../slot';
|
|
5
|
+
import { dataAttributes, mergeDataAttributes } from '../utils/dataAttributes';
|
|
6
|
+
import { useMonthCalendarContext } from './context';
|
|
7
|
+
|
|
8
|
+
export interface MonthCalendarCellProps extends Omit<ViewProps, 'children'> {
|
|
9
|
+
month: number;
|
|
10
|
+
asChild?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MonthCalendarCell = forwardRef<ComponentRef<typeof View>, MonthCalendarCellProps>(
|
|
16
|
+
({ asChild, month, className, style, children, ...props }, ref) => {
|
|
17
|
+
const { visibleYear, value, onValueChange, disabled, minValue, maxValue } =
|
|
18
|
+
useMonthCalendarContext();
|
|
19
|
+
const monthId: MonthId = formatMonthId({ year: visibleYear, month });
|
|
20
|
+
const selected = value === monthId;
|
|
21
|
+
const outOfRange =
|
|
22
|
+
(minValue != null && compareMonthIds(monthId, minValue) < 0) ||
|
|
23
|
+
(maxValue != null && compareMonthIds(monthId, maxValue) > 0);
|
|
24
|
+
const cellDisabled = disabled || outOfRange;
|
|
25
|
+
const Comp = asChild ? Slot : Pressable;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Comp
|
|
29
|
+
ref={ref}
|
|
30
|
+
className={className}
|
|
31
|
+
style={style}
|
|
32
|
+
accessibilityRole="button"
|
|
33
|
+
accessibilityState={{ selected, disabled: cellDisabled }}
|
|
34
|
+
disabled={cellDisabled}
|
|
35
|
+
onPress={() => {
|
|
36
|
+
if (cellDisabled) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
onValueChange?.(monthId);
|
|
40
|
+
}}
|
|
41
|
+
{...props}
|
|
42
|
+
{...mergeDataAttributes(
|
|
43
|
+
props,
|
|
44
|
+
dataAttributes({ selected, disabled: cellDisabled, slot: 'month-calendar-cell' }),
|
|
45
|
+
)}
|
|
46
|
+
>
|
|
47
|
+
{children}
|
|
48
|
+
</Comp>
|
|
49
|
+
);
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
MonthCalendarCell.displayName = 'MonthCalendarCell';
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useMemo, useRef, type ComponentRef, type ReactNode } from 'react';
|
|
2
|
+
import { View, type ViewProps } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
parseMonthId,
|
|
5
|
+
resolveDateComponentLabels,
|
|
6
|
+
type DateComponentLabels,
|
|
7
|
+
type MonthId,
|
|
8
|
+
} from '@cdx-ui/formatters';
|
|
9
|
+
import { useControllableState } from '@cdx-ui/utils';
|
|
10
|
+
import { Slot } from '../slot';
|
|
11
|
+
import { accessibleLabelAttributes, resolveAccessibleLabel } from '../utils/accessibleLabel';
|
|
12
|
+
import { dataAttributes, mergeDataAttributes } from '../utils/dataAttributes';
|
|
13
|
+
import { MonthCalendarContext, type MonthCalendarView } from './context';
|
|
14
|
+
|
|
15
|
+
export interface MonthCalendarRootProps extends Omit<ViewProps, 'children'> {
|
|
16
|
+
asChild?: boolean;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
className?: string;
|
|
19
|
+
value?: MonthId;
|
|
20
|
+
defaultValue?: MonthId;
|
|
21
|
+
/** Called with the new `MonthId`, or `undefined` when the selection is cleared. */
|
|
22
|
+
onValueChange?: (value: MonthId | undefined) => void;
|
|
23
|
+
view?: MonthCalendarView;
|
|
24
|
+
defaultView?: MonthCalendarView;
|
|
25
|
+
onViewChange?: (view: MonthCalendarView) => void;
|
|
26
|
+
visibleYear?: number;
|
|
27
|
+
defaultVisibleYear?: number;
|
|
28
|
+
onVisibleYearChange?: (year: number) => void;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/** Earliest selectable month. Build with `monthId(...)` from `@cdx-ui/formatters`. */
|
|
31
|
+
minValue?: MonthId;
|
|
32
|
+
/** Latest selectable month. Build with `monthId(...)` from `@cdx-ui/formatters`. */
|
|
33
|
+
maxValue?: MonthId;
|
|
34
|
+
locale?: string;
|
|
35
|
+
labels?: Partial<DateComponentLabels>;
|
|
36
|
+
/** Accessible name for the month-calendar region. */
|
|
37
|
+
accessibilityLabel?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const MonthCalendarRoot = forwardRef<ComponentRef<typeof View>, MonthCalendarRootProps>(
|
|
41
|
+
(
|
|
42
|
+
{
|
|
43
|
+
asChild,
|
|
44
|
+
children,
|
|
45
|
+
value: valueProp,
|
|
46
|
+
defaultValue,
|
|
47
|
+
onValueChange,
|
|
48
|
+
view: viewProp,
|
|
49
|
+
defaultView = 'month',
|
|
50
|
+
onViewChange,
|
|
51
|
+
visibleYear: visibleYearProp,
|
|
52
|
+
defaultVisibleYear,
|
|
53
|
+
onVisibleYearChange,
|
|
54
|
+
disabled = false,
|
|
55
|
+
minValue,
|
|
56
|
+
maxValue,
|
|
57
|
+
locale = 'en-US',
|
|
58
|
+
labels: labelsProp,
|
|
59
|
+
accessibilityLabel: accessibilityLabelProp,
|
|
60
|
+
'aria-label': ariaLabelProp,
|
|
61
|
+
...props
|
|
62
|
+
},
|
|
63
|
+
ref,
|
|
64
|
+
) => {
|
|
65
|
+
const labels = useMemo(() => resolveDateComponentLabels(labelsProp), [labelsProp]);
|
|
66
|
+
const accessibilityLabel = resolveAccessibleLabel({
|
|
67
|
+
accessibilityLabel: accessibilityLabelProp,
|
|
68
|
+
'aria-label': ariaLabelProp,
|
|
69
|
+
});
|
|
70
|
+
const [value, setValue] = useControllableState<MonthId | undefined>({
|
|
71
|
+
prop: valueProp,
|
|
72
|
+
defaultProp: defaultValue,
|
|
73
|
+
onChange: onValueChange,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const parsed = value ? parseMonthId(value) : null;
|
|
77
|
+
const [view, setView] = useControllableState<MonthCalendarView>({
|
|
78
|
+
prop: viewProp,
|
|
79
|
+
defaultProp: defaultView,
|
|
80
|
+
onChange: onViewChange,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const [visibleYear, setVisibleYear] = useControllableState<number>({
|
|
84
|
+
prop: visibleYearProp,
|
|
85
|
+
defaultProp: defaultVisibleYear ?? parsed?.year ?? new Date().getFullYear(),
|
|
86
|
+
onChange: onVisibleYearChange,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const prevValueRef = useRef(value);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (visibleYearProp !== undefined) {
|
|
92
|
+
prevValueRef.current = value;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (value === undefined || prevValueRef.current === value) {
|
|
96
|
+
prevValueRef.current = value;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
prevValueRef.current = value;
|
|
100
|
+
const nextParsed = parseMonthId(value);
|
|
101
|
+
if (nextParsed) {
|
|
102
|
+
setVisibleYear(nextParsed.year);
|
|
103
|
+
}
|
|
104
|
+
}, [setVisibleYear, value, visibleYearProp]);
|
|
105
|
+
|
|
106
|
+
const contextValue = useMemo(
|
|
107
|
+
() => ({
|
|
108
|
+
value,
|
|
109
|
+
onValueChange: setValue,
|
|
110
|
+
view: view ?? 'month',
|
|
111
|
+
onViewChange: setView,
|
|
112
|
+
visibleYear: visibleYear ?? new Date().getFullYear(),
|
|
113
|
+
onVisibleYearChange: setVisibleYear,
|
|
114
|
+
disabled,
|
|
115
|
+
minValue,
|
|
116
|
+
maxValue,
|
|
117
|
+
locale,
|
|
118
|
+
labels,
|
|
119
|
+
}),
|
|
120
|
+
[
|
|
121
|
+
value,
|
|
122
|
+
setValue,
|
|
123
|
+
view,
|
|
124
|
+
setView,
|
|
125
|
+
visibleYear,
|
|
126
|
+
setVisibleYear,
|
|
127
|
+
disabled,
|
|
128
|
+
minValue,
|
|
129
|
+
maxValue,
|
|
130
|
+
locale,
|
|
131
|
+
labels,
|
|
132
|
+
],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const Comp = asChild ? Slot : View;
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<MonthCalendarContext.Provider value={contextValue}>
|
|
139
|
+
<Comp
|
|
140
|
+
ref={ref}
|
|
141
|
+
accessibilityRole="none"
|
|
142
|
+
{...props}
|
|
143
|
+
{...mergeDataAttributes(props, dataAttributes({ disabled }))}
|
|
144
|
+
{...accessibleLabelAttributes(accessibilityLabel)}
|
|
145
|
+
>
|
|
146
|
+
{children}
|
|
147
|
+
</Comp>
|
|
148
|
+
</MonthCalendarContext.Provider>
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
MonthCalendarRoot.displayName = 'MonthCalendarRoot';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { forwardRef, type ComponentRef } from 'react';
|
|
2
|
+
import { Pressable, View, type ViewProps } from 'react-native';
|
|
3
|
+
import { parseMonthId } from '@cdx-ui/formatters';
|
|
4
|
+
import { Slot } from '../slot';
|
|
5
|
+
import { dataAttributes, mergeDataAttributes } from '../utils/dataAttributes';
|
|
6
|
+
import { useMonthCalendarContext } from './context';
|
|
7
|
+
|
|
8
|
+
export interface MonthCalendarYearCellProps extends Omit<ViewProps, 'children'> {
|
|
9
|
+
year: number;
|
|
10
|
+
asChild?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MonthCalendarYearCell = forwardRef<
|
|
16
|
+
ComponentRef<typeof View>,
|
|
17
|
+
MonthCalendarYearCellProps
|
|
18
|
+
>(({ asChild, year, className, style, children, ...props }, ref) => {
|
|
19
|
+
const { visibleYear, onVisibleYearChange, onViewChange, disabled, minValue, maxValue } =
|
|
20
|
+
useMonthCalendarContext();
|
|
21
|
+
const selected = visibleYear === year;
|
|
22
|
+
const minYear = minValue ? parseMonthId(minValue)?.year : undefined;
|
|
23
|
+
const maxYear = maxValue ? parseMonthId(maxValue)?.year : undefined;
|
|
24
|
+
const outOfRange = (minYear != null && year < minYear) || (maxYear != null && year > maxYear);
|
|
25
|
+
const cellDisabled = disabled || outOfRange;
|
|
26
|
+
const Comp = asChild ? Slot : Pressable;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Comp
|
|
30
|
+
ref={ref}
|
|
31
|
+
className={className}
|
|
32
|
+
style={style}
|
|
33
|
+
accessibilityRole="button"
|
|
34
|
+
accessibilityState={{ selected, disabled: cellDisabled }}
|
|
35
|
+
disabled={cellDisabled}
|
|
36
|
+
onPress={() => {
|
|
37
|
+
if (cellDisabled) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
onVisibleYearChange(year);
|
|
41
|
+
onViewChange('month');
|
|
42
|
+
}}
|
|
43
|
+
{...props}
|
|
44
|
+
{...mergeDataAttributes(
|
|
45
|
+
props,
|
|
46
|
+
dataAttributes({ selected, disabled: cellDisabled, slot: 'month-calendar-year-cell' }),
|
|
47
|
+
)}
|
|
48
|
+
>
|
|
49
|
+
{children}
|
|
50
|
+
</Comp>
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
MonthCalendarYearCell.displayName = 'MonthCalendarYearCell';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
import type { DateComponentLabels, MonthId } from '@cdx-ui/formatters';
|
|
3
|
+
|
|
4
|
+
export type MonthCalendarView = 'month' | 'year';
|
|
5
|
+
|
|
6
|
+
export interface MonthCalendarContextValue {
|
|
7
|
+
value?: MonthId;
|
|
8
|
+
onValueChange?: (value: MonthId | undefined) => void;
|
|
9
|
+
view: MonthCalendarView;
|
|
10
|
+
onViewChange: (view: MonthCalendarView) => void;
|
|
11
|
+
visibleYear: number;
|
|
12
|
+
onVisibleYearChange: (year: number) => void;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
/** Earliest selectable month (`YYYY-MM-01`). Months before this are disabled. */
|
|
15
|
+
minValue?: MonthId;
|
|
16
|
+
/** Latest selectable month (`YYYY-MM-01`). Months after this are disabled. */
|
|
17
|
+
maxValue?: MonthId;
|
|
18
|
+
locale: string;
|
|
19
|
+
labels: DateComponentLabels;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const MonthCalendarContext = createContext<MonthCalendarContextValue | null>(null);
|
|
23
|
+
|
|
24
|
+
export function useMonthCalendarContext(): MonthCalendarContextValue {
|
|
25
|
+
const ctx = useContext(MonthCalendarContext);
|
|
26
|
+
if (!ctx) {
|
|
27
|
+
throw new Error('MonthCalendar compound components must be used within MonthCalendarRoot');
|
|
28
|
+
}
|
|
29
|
+
return ctx;
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { MonthCalendarRoot } from './MonthCalendarRoot';
|
|
2
|
+
export type { MonthCalendarRootProps } from './MonthCalendarRoot';
|
|
3
|
+
export { MonthCalendarCell } from './MonthCalendarCell';
|
|
4
|
+
export { MonthCalendarYearCell } from './MonthCalendarYearCell';
|
|
5
|
+
export { useMonthCalendarContext } from './context';
|
|
6
|
+
export type { MonthCalendarView } from './context';
|