@octanejs/day-picker 0.0.1
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/LICENSE +21 -0
- package/README.md +14 -0
- package/UPSTREAM.md +24 -0
- package/package.json +77 -0
- package/src/DayPicker.tsrx +717 -0
- package/src/UI.ts +121 -0
- package/src/classes/CalendarDay.ts +82 -0
- package/src/classes/CalendarMonth.ts +20 -0
- package/src/classes/CalendarWeek.ts +19 -0
- package/src/classes/DateLib.ts +695 -0
- package/src/classes/index.ts +4 -0
- package/src/components/custom-components.tsrx +237 -0
- package/src/formatters/formatCaption.ts +18 -0
- package/src/formatters/formatDay.ts +17 -0
- package/src/formatters/formatMonthDropdown.ts +16 -0
- package/src/formatters/formatWeekNumber.ts +19 -0
- package/src/formatters/formatWeekNumberHeader.ts +11 -0
- package/src/formatters/formatWeekdayName.ts +17 -0
- package/src/formatters/formatYearDropdown.ts +15 -0
- package/src/formatters/index.ts +7 -0
- package/src/helpers/calculateFocusTarget.ts +79 -0
- package/src/helpers/createGetModifiers.ts +117 -0
- package/src/helpers/endOfBroadcastWeek.ts +22 -0
- package/src/helpers/getBroadcastWeeksInMonth.ts +32 -0
- package/src/helpers/getClassNamesForModifiers.ts +38 -0
- package/src/helpers/getComponents.ts +19 -0
- package/src/helpers/getDataAttributes.ts +17 -0
- package/src/helpers/getDates.ts +87 -0
- package/src/helpers/getDays.ts +19 -0
- package/src/helpers/getDefaultClassNames.ts +36 -0
- package/src/helpers/getDisplayMonths.ts +30 -0
- package/src/helpers/getFocusableDate.ts +66 -0
- package/src/helpers/getFormatters.ts +16 -0
- package/src/helpers/getInitialMonth.ts +35 -0
- package/src/helpers/getLabels.ts +93 -0
- package/src/helpers/getMonthOptions.ts +45 -0
- package/src/helpers/getMonths.ts +89 -0
- package/src/helpers/getNavMonth.ts +35 -0
- package/src/helpers/getNextFocus.ts +45 -0
- package/src/helpers/getNextMonth.ts +46 -0
- package/src/helpers/getPreviousMonth.ts +45 -0
- package/src/helpers/getStyleForModifiers.ts +31 -0
- package/src/helpers/getWeekdays.ts +33 -0
- package/src/helpers/getWeeks.ts +14 -0
- package/src/helpers/getYearOptions.ts +43 -0
- package/src/helpers/index.ts +2 -0
- package/src/helpers/startOfBroadcastWeek.ts +26 -0
- package/src/helpers/useControlledValue.ts +38 -0
- package/src/index.ts +13 -0
- package/src/labels/index.ts +12 -0
- package/src/labels/labelDayButton.ts +29 -0
- package/src/labels/labelGrid.ts +18 -0
- package/src/labels/labelGridcell.ts +26 -0
- package/src/labels/labelMonthDropdown.ts +14 -0
- package/src/labels/labelNav.ts +11 -0
- package/src/labels/labelNext.ts +17 -0
- package/src/labels/labelPrevious.ts +13 -0
- package/src/labels/labelWeekNumber.ts +15 -0
- package/src/labels/labelWeekNumberHeader.ts +14 -0
- package/src/labels/labelWeekday.ts +16 -0
- package/src/labels/labelYearDropdown.ts +14 -0
- package/src/locale/af.ts +48 -0
- package/src/locale/ar-DZ.ts +48 -0
- package/src/locale/ar-EG.ts +48 -0
- package/src/locale/ar-MA.ts +48 -0
- package/src/locale/ar-SA.ts +48 -0
- package/src/locale/ar-TN.ts +48 -0
- package/src/locale/ar.ts +48 -0
- package/src/locale/az.ts +48 -0
- package/src/locale/be-tarask.ts +51 -0
- package/src/locale/be.ts +48 -0
- package/src/locale/bg.ts +48 -0
- package/src/locale/bn.ts +48 -0
- package/src/locale/bs.ts +48 -0
- package/src/locale/ca.ts +48 -0
- package/src/locale/ckb.ts +51 -0
- package/src/locale/cs.ts +48 -0
- package/src/locale/cy.ts +48 -0
- package/src/locale/da.ts +48 -0
- package/src/locale/de-AT.ts +48 -0
- package/src/locale/de.ts +48 -0
- package/src/locale/el.ts +48 -0
- package/src/locale/en-AU.ts +48 -0
- package/src/locale/en-CA.ts +48 -0
- package/src/locale/en-GB.ts +51 -0
- package/src/locale/en-IE.ts +48 -0
- package/src/locale/en-IN.ts +48 -0
- package/src/locale/en-NZ.ts +48 -0
- package/src/locale/en-US.ts +72 -0
- package/src/locale/en-ZA.ts +48 -0
- package/src/locale/eo.ts +48 -0
- package/src/locale/es.ts +48 -0
- package/src/locale/et.ts +48 -0
- package/src/locale/eu.ts +48 -0
- package/src/locale/fa-IR.ts +48 -0
- package/src/locale/fi.ts +48 -0
- package/src/locale/fr-CA.ts +48 -0
- package/src/locale/fr-CH.ts +48 -0
- package/src/locale/fr.ts +48 -0
- package/src/locale/fy.ts +48 -0
- package/src/locale/gd.ts +48 -0
- package/src/locale/gl.ts +48 -0
- package/src/locale/gu.ts +48 -0
- package/src/locale/he.ts +48 -0
- package/src/locale/hi.ts +48 -0
- package/src/locale/hr.ts +48 -0
- package/src/locale/ht.ts +48 -0
- package/src/locale/hu.ts +48 -0
- package/src/locale/hy.ts +48 -0
- package/src/locale/id.ts +48 -0
- package/src/locale/is.ts +48 -0
- package/src/locale/it-CH.ts +48 -0
- package/src/locale/it.ts +48 -0
- package/src/locale/ja-Hira.ts +48 -0
- package/src/locale/ja.ts +48 -0
- package/src/locale/ka.ts +48 -0
- package/src/locale/kk.ts +48 -0
- package/src/locale/km.ts +48 -0
- package/src/locale/kn.ts +48 -0
- package/src/locale/ko.ts +48 -0
- package/src/locale/lb.ts +48 -0
- package/src/locale/lt.ts +48 -0
- package/src/locale/lv.ts +48 -0
- package/src/locale/mk.ts +48 -0
- package/src/locale/mn.ts +48 -0
- package/src/locale/ms.ts +48 -0
- package/src/locale/mt.ts +48 -0
- package/src/locale/nb.ts +48 -0
- package/src/locale/nl-BE.ts +48 -0
- package/src/locale/nl.ts +48 -0
- package/src/locale/nn.ts +48 -0
- package/src/locale/oc.ts +48 -0
- package/src/locale/pl.ts +48 -0
- package/src/locale/pt-BR.ts +48 -0
- package/src/locale/pt.ts +48 -0
- package/src/locale/ro.ts +48 -0
- package/src/locale/ru.ts +48 -0
- package/src/locale/se.ts +48 -0
- package/src/locale/sk.ts +48 -0
- package/src/locale/sl.ts +48 -0
- package/src/locale/sq.ts +48 -0
- package/src/locale/sr-Latn.ts +48 -0
- package/src/locale/sr.ts +48 -0
- package/src/locale/sv.ts +48 -0
- package/src/locale/ta.ts +48 -0
- package/src/locale/te.ts +48 -0
- package/src/locale/th.ts +48 -0
- package/src/locale/tr.ts +48 -0
- package/src/locale/ug.ts +48 -0
- package/src/locale/uk.ts +48 -0
- package/src/locale/uz-Cyrl.ts +48 -0
- package/src/locale/uz.ts +48 -0
- package/src/locale/vi.ts +48 -0
- package/src/locale/zh-CN.ts +48 -0
- package/src/locale/zh-HK.ts +51 -0
- package/src/locale/zh-TW.ts +51 -0
- package/src/locale.ts +108 -0
- package/src/noonDateLib.ts +202 -0
- package/src/selection/useMulti.ts +74 -0
- package/src/selection/useRange.ts +89 -0
- package/src/selection/useSingle.ts +77 -0
- package/src/style.css +451 -0
- package/src/style.css.d.ts +3 -0
- package/src/style.module.css +451 -0
- package/src/style.module.css.d.ts +29 -0
- package/src/types/index.ts +3 -0
- package/src/types/props.ts +671 -0
- package/src/types/selection.ts +97 -0
- package/src/types/shared.ts +346 -0
- package/src/useAnimation.ts +242 -0
- package/src/useCalendar.ts +233 -0
- package/src/useDayPicker.ts +91 -0
- package/src/useFocus.ts +109 -0
- package/src/useSelection.ts +36 -0
- package/src/utils/addToRange.ts +91 -0
- package/src/utils/convertMatchersToTimeZone.ts +88 -0
- package/src/utils/dateMatchModifiers.ts +72 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/rangeContainsDayOfWeek.ts +33 -0
- package/src/utils/rangeContainsModifiers.ts +106 -0
- package/src/utils/rangeIncludesDate.ts +40 -0
- package/src/utils/rangeOverlaps.ts +26 -0
- package/src/utils/toTimeZone.ts +13 -0
- package/src/utils/typeguards.ts +71 -0
- package/status.json +13 -0
package/src/UI.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { ClassNames, CustomComponents, Styles } from './types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enum representing the UI elements composing DayPicker. These elements are
|
|
5
|
+
* mapped to {@link CustomComponents}, {@link ClassNames}, and {@link Styles}.
|
|
6
|
+
*
|
|
7
|
+
* Some elements are extended by flags and modifiers.
|
|
8
|
+
*/
|
|
9
|
+
export enum UI {
|
|
10
|
+
/** The root component displaying the months and the navigation bar. */
|
|
11
|
+
Root = 'root',
|
|
12
|
+
/** The Chevron SVG element used by navigation buttons and dropdowns. */
|
|
13
|
+
Chevron = 'chevron',
|
|
14
|
+
/**
|
|
15
|
+
* The grid cell with the day's date. Extended by {@link DayFlag} and
|
|
16
|
+
* {@link SelectionState}.
|
|
17
|
+
*/
|
|
18
|
+
Day = 'day',
|
|
19
|
+
/** The button containing the formatted day's date, inside the grid cell. */
|
|
20
|
+
DayButton = 'day_button',
|
|
21
|
+
/** The caption label of the month (when not showing the dropdown navigation). */
|
|
22
|
+
CaptionLabel = 'caption_label',
|
|
23
|
+
/** The container of the dropdown navigation (when enabled). */
|
|
24
|
+
Dropdowns = 'dropdowns',
|
|
25
|
+
/** The dropdown element to select for years and months. */
|
|
26
|
+
Dropdown = 'dropdown',
|
|
27
|
+
/** The container element of the dropdown. */
|
|
28
|
+
DropdownRoot = 'dropdown_root',
|
|
29
|
+
/** The root element of the footer. */
|
|
30
|
+
Footer = 'footer',
|
|
31
|
+
/** The month grid. */
|
|
32
|
+
MonthGrid = 'month_grid',
|
|
33
|
+
/** Contains the dropdown navigation or the caption label. */
|
|
34
|
+
MonthCaption = 'month_caption',
|
|
35
|
+
/** The dropdown with the months. */
|
|
36
|
+
MonthsDropdown = 'months_dropdown',
|
|
37
|
+
/** Wrapper of the month grid. */
|
|
38
|
+
Month = 'month',
|
|
39
|
+
/** The container of the displayed months. */
|
|
40
|
+
Months = 'months',
|
|
41
|
+
/** The navigation bar with the previous and next buttons. */
|
|
42
|
+
Nav = 'nav',
|
|
43
|
+
/**
|
|
44
|
+
* The next month button in the navigation. *
|
|
45
|
+
*
|
|
46
|
+
* @since 9.1.0
|
|
47
|
+
*/
|
|
48
|
+
NextMonthButton = 'button_next',
|
|
49
|
+
/**
|
|
50
|
+
* The previous month button in the navigation.
|
|
51
|
+
*
|
|
52
|
+
* @since 9.1.0
|
|
53
|
+
*/
|
|
54
|
+
PreviousMonthButton = 'button_previous',
|
|
55
|
+
/** The row containing the week. */
|
|
56
|
+
Week = 'week',
|
|
57
|
+
/** The group of row weeks in a month (`tbody`). */
|
|
58
|
+
Weeks = 'weeks',
|
|
59
|
+
/** The column header with the weekday. */
|
|
60
|
+
Weekday = 'weekday',
|
|
61
|
+
/** The row grouping the weekdays in the column headers. */
|
|
62
|
+
Weekdays = 'weekdays',
|
|
63
|
+
/** The cell containing the week number. */
|
|
64
|
+
WeekNumber = 'week_number',
|
|
65
|
+
/** The cell header of the week numbers column. */
|
|
66
|
+
WeekNumberHeader = 'week_number_header',
|
|
67
|
+
/** The dropdown with the years. */
|
|
68
|
+
YearsDropdown = 'years_dropdown',
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Enum representing flags for the {@link UI | UI.Day} element. */
|
|
72
|
+
export enum DayFlag {
|
|
73
|
+
/** The day is disabled. */
|
|
74
|
+
disabled = 'disabled',
|
|
75
|
+
/** The day is hidden. */
|
|
76
|
+
hidden = 'hidden',
|
|
77
|
+
/** The day is outside the current month. */
|
|
78
|
+
outside = 'outside',
|
|
79
|
+
/** The day is focused. */
|
|
80
|
+
focused = 'focused',
|
|
81
|
+
/** The day is today. */
|
|
82
|
+
today = 'today',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Enum representing selection states that can be applied to the
|
|
87
|
+
* {@link UI | UI.Day} element in selection mode.
|
|
88
|
+
*/
|
|
89
|
+
export enum SelectionState {
|
|
90
|
+
/** The day is at the end of a selected range. */
|
|
91
|
+
range_end = 'range_end',
|
|
92
|
+
/** The day is at the middle of a selected range. */
|
|
93
|
+
range_middle = 'range_middle',
|
|
94
|
+
/** The day is at the start of a selected range. */
|
|
95
|
+
range_start = 'range_start',
|
|
96
|
+
/** The day is selected. */
|
|
97
|
+
selected = 'selected',
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Enum representing different animation states for transitioning between
|
|
102
|
+
* months.
|
|
103
|
+
*/
|
|
104
|
+
export enum Animation {
|
|
105
|
+
/** The entering weeks when they appear before the exiting month. */
|
|
106
|
+
weeks_before_enter = 'weeks_before_enter',
|
|
107
|
+
/** The exiting weeks when they disappear before the entering month. */
|
|
108
|
+
weeks_before_exit = 'weeks_before_exit',
|
|
109
|
+
/** The entering weeks when they appear after the exiting month. */
|
|
110
|
+
weeks_after_enter = 'weeks_after_enter',
|
|
111
|
+
/** The exiting weeks when they disappear after the entering month. */
|
|
112
|
+
weeks_after_exit = 'weeks_after_exit',
|
|
113
|
+
/** The entering caption when it appears after the exiting month. */
|
|
114
|
+
caption_after_enter = 'caption_after_enter',
|
|
115
|
+
/** The exiting caption when it disappears after the entering month. */
|
|
116
|
+
caption_after_exit = 'caption_after_exit',
|
|
117
|
+
/** The entering caption when it appears before the exiting month. */
|
|
118
|
+
caption_before_enter = 'caption_before_enter',
|
|
119
|
+
/** The exiting caption when it disappears before the entering month. */
|
|
120
|
+
caption_before_exit = 'caption_before_exit',
|
|
121
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type DateLib, defaultDateLib } from './DateLib.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a day displayed in the calendar.
|
|
5
|
+
*
|
|
6
|
+
* In DayPicker, a `CalendarDay` is a wrapper around a `Date` object that
|
|
7
|
+
* provides additional information about the day, such as whether it belongs to
|
|
8
|
+
* the displayed month.
|
|
9
|
+
*/
|
|
10
|
+
export class CalendarDay {
|
|
11
|
+
constructor(date: Date, displayMonth: Date, dateLib: DateLib = defaultDateLib) {
|
|
12
|
+
this.date = date;
|
|
13
|
+
this.displayMonth = displayMonth;
|
|
14
|
+
this.outside = Boolean(displayMonth && !dateLib.isSameMonth(date, displayMonth));
|
|
15
|
+
this.dateLib = dateLib;
|
|
16
|
+
this.isoDate = dateLib.format(date, 'yyyy-MM-dd');
|
|
17
|
+
this.displayMonthId = dateLib.format(displayMonth, 'yyyy-MM');
|
|
18
|
+
this.dateMonthId = dateLib.format(date, 'yyyy-MM');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Utility functions for manipulating dates.
|
|
23
|
+
*
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
readonly dateLib: DateLib;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Indicates whether the day does not belong to the displayed month.
|
|
30
|
+
*
|
|
31
|
+
* If `outside` is `true`, use `displayMonth` to determine the month to which
|
|
32
|
+
* the day belongs.
|
|
33
|
+
*/
|
|
34
|
+
readonly outside: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The month that is currently displayed in the calendar.
|
|
38
|
+
*
|
|
39
|
+
* This property is useful for determining if the day belongs to the same
|
|
40
|
+
* month as the displayed month, especially when `showOutsideDays` is
|
|
41
|
+
* enabled.
|
|
42
|
+
*/
|
|
43
|
+
readonly displayMonth: Date;
|
|
44
|
+
|
|
45
|
+
/** The date represented by this day. */
|
|
46
|
+
readonly date: Date;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Stable `yyyy-MM-dd` representation for reuse in keys/data attrs.
|
|
50
|
+
*
|
|
51
|
+
* @since V9.11.2
|
|
52
|
+
*/
|
|
53
|
+
readonly isoDate: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Stable `yyyy-MM` representation of the displayed month.
|
|
57
|
+
*
|
|
58
|
+
* @since V9.11.2
|
|
59
|
+
*/
|
|
60
|
+
readonly displayMonthId: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Stable `yyyy-MM` representation of the date's actual month.
|
|
64
|
+
*
|
|
65
|
+
* @since V9.11.2
|
|
66
|
+
*/
|
|
67
|
+
readonly dateMonthId: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Checks if this day is equal to another `CalendarDay`, considering both the
|
|
71
|
+
* date and the displayed month.
|
|
72
|
+
*
|
|
73
|
+
* @param day The `CalendarDay` to compare with.
|
|
74
|
+
* @returns `true` if the days are equal, otherwise `false`.
|
|
75
|
+
*/
|
|
76
|
+
isEqualTo(day: CalendarDay) {
|
|
77
|
+
return (
|
|
78
|
+
this.dateLib.isSameDay(day.date, this.date) &&
|
|
79
|
+
this.dateLib.isSameMonth(day.displayMonth, this.displayMonth)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CalendarWeek } from './CalendarWeek.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a month in a calendar year.
|
|
5
|
+
*
|
|
6
|
+
* A `CalendarMonth` contains the weeks within the month and the date of the
|
|
7
|
+
* month.
|
|
8
|
+
*/
|
|
9
|
+
export class CalendarMonth {
|
|
10
|
+
constructor(month: Date, weeks: CalendarWeek[]) {
|
|
11
|
+
this.date = month;
|
|
12
|
+
this.weeks = weeks;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The date representing the first day of the month. */
|
|
16
|
+
date: Date;
|
|
17
|
+
|
|
18
|
+
/** The weeks that belong to this month. */
|
|
19
|
+
weeks: CalendarWeek[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CalendarDay } from './CalendarDay.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a week in a calendar month.
|
|
5
|
+
*
|
|
6
|
+
* A `CalendarWeek` contains the days within the week and the week number.
|
|
7
|
+
*/
|
|
8
|
+
export class CalendarWeek {
|
|
9
|
+
constructor(weekNumber: number, days: CalendarDay[]) {
|
|
10
|
+
this.days = days;
|
|
11
|
+
this.weekNumber = weekNumber;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The number of the week within the year. */
|
|
15
|
+
weekNumber: number;
|
|
16
|
+
|
|
17
|
+
/** The days that belong to this week. */
|
|
18
|
+
days: CalendarDay[];
|
|
19
|
+
}
|