@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.
Files changed (185) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -0
  3. package/UPSTREAM.md +24 -0
  4. package/package.json +77 -0
  5. package/src/DayPicker.tsrx +717 -0
  6. package/src/UI.ts +121 -0
  7. package/src/classes/CalendarDay.ts +82 -0
  8. package/src/classes/CalendarMonth.ts +20 -0
  9. package/src/classes/CalendarWeek.ts +19 -0
  10. package/src/classes/DateLib.ts +695 -0
  11. package/src/classes/index.ts +4 -0
  12. package/src/components/custom-components.tsrx +237 -0
  13. package/src/formatters/formatCaption.ts +18 -0
  14. package/src/formatters/formatDay.ts +17 -0
  15. package/src/formatters/formatMonthDropdown.ts +16 -0
  16. package/src/formatters/formatWeekNumber.ts +19 -0
  17. package/src/formatters/formatWeekNumberHeader.ts +11 -0
  18. package/src/formatters/formatWeekdayName.ts +17 -0
  19. package/src/formatters/formatYearDropdown.ts +15 -0
  20. package/src/formatters/index.ts +7 -0
  21. package/src/helpers/calculateFocusTarget.ts +79 -0
  22. package/src/helpers/createGetModifiers.ts +117 -0
  23. package/src/helpers/endOfBroadcastWeek.ts +22 -0
  24. package/src/helpers/getBroadcastWeeksInMonth.ts +32 -0
  25. package/src/helpers/getClassNamesForModifiers.ts +38 -0
  26. package/src/helpers/getComponents.ts +19 -0
  27. package/src/helpers/getDataAttributes.ts +17 -0
  28. package/src/helpers/getDates.ts +87 -0
  29. package/src/helpers/getDays.ts +19 -0
  30. package/src/helpers/getDefaultClassNames.ts +36 -0
  31. package/src/helpers/getDisplayMonths.ts +30 -0
  32. package/src/helpers/getFocusableDate.ts +66 -0
  33. package/src/helpers/getFormatters.ts +16 -0
  34. package/src/helpers/getInitialMonth.ts +35 -0
  35. package/src/helpers/getLabels.ts +93 -0
  36. package/src/helpers/getMonthOptions.ts +45 -0
  37. package/src/helpers/getMonths.ts +89 -0
  38. package/src/helpers/getNavMonth.ts +35 -0
  39. package/src/helpers/getNextFocus.ts +45 -0
  40. package/src/helpers/getNextMonth.ts +46 -0
  41. package/src/helpers/getPreviousMonth.ts +45 -0
  42. package/src/helpers/getStyleForModifiers.ts +31 -0
  43. package/src/helpers/getWeekdays.ts +33 -0
  44. package/src/helpers/getWeeks.ts +14 -0
  45. package/src/helpers/getYearOptions.ts +43 -0
  46. package/src/helpers/index.ts +2 -0
  47. package/src/helpers/startOfBroadcastWeek.ts +26 -0
  48. package/src/helpers/useControlledValue.ts +38 -0
  49. package/src/index.ts +13 -0
  50. package/src/labels/index.ts +12 -0
  51. package/src/labels/labelDayButton.ts +29 -0
  52. package/src/labels/labelGrid.ts +18 -0
  53. package/src/labels/labelGridcell.ts +26 -0
  54. package/src/labels/labelMonthDropdown.ts +14 -0
  55. package/src/labels/labelNav.ts +11 -0
  56. package/src/labels/labelNext.ts +17 -0
  57. package/src/labels/labelPrevious.ts +13 -0
  58. package/src/labels/labelWeekNumber.ts +15 -0
  59. package/src/labels/labelWeekNumberHeader.ts +14 -0
  60. package/src/labels/labelWeekday.ts +16 -0
  61. package/src/labels/labelYearDropdown.ts +14 -0
  62. package/src/locale/af.ts +48 -0
  63. package/src/locale/ar-DZ.ts +48 -0
  64. package/src/locale/ar-EG.ts +48 -0
  65. package/src/locale/ar-MA.ts +48 -0
  66. package/src/locale/ar-SA.ts +48 -0
  67. package/src/locale/ar-TN.ts +48 -0
  68. package/src/locale/ar.ts +48 -0
  69. package/src/locale/az.ts +48 -0
  70. package/src/locale/be-tarask.ts +51 -0
  71. package/src/locale/be.ts +48 -0
  72. package/src/locale/bg.ts +48 -0
  73. package/src/locale/bn.ts +48 -0
  74. package/src/locale/bs.ts +48 -0
  75. package/src/locale/ca.ts +48 -0
  76. package/src/locale/ckb.ts +51 -0
  77. package/src/locale/cs.ts +48 -0
  78. package/src/locale/cy.ts +48 -0
  79. package/src/locale/da.ts +48 -0
  80. package/src/locale/de-AT.ts +48 -0
  81. package/src/locale/de.ts +48 -0
  82. package/src/locale/el.ts +48 -0
  83. package/src/locale/en-AU.ts +48 -0
  84. package/src/locale/en-CA.ts +48 -0
  85. package/src/locale/en-GB.ts +51 -0
  86. package/src/locale/en-IE.ts +48 -0
  87. package/src/locale/en-IN.ts +48 -0
  88. package/src/locale/en-NZ.ts +48 -0
  89. package/src/locale/en-US.ts +72 -0
  90. package/src/locale/en-ZA.ts +48 -0
  91. package/src/locale/eo.ts +48 -0
  92. package/src/locale/es.ts +48 -0
  93. package/src/locale/et.ts +48 -0
  94. package/src/locale/eu.ts +48 -0
  95. package/src/locale/fa-IR.ts +48 -0
  96. package/src/locale/fi.ts +48 -0
  97. package/src/locale/fr-CA.ts +48 -0
  98. package/src/locale/fr-CH.ts +48 -0
  99. package/src/locale/fr.ts +48 -0
  100. package/src/locale/fy.ts +48 -0
  101. package/src/locale/gd.ts +48 -0
  102. package/src/locale/gl.ts +48 -0
  103. package/src/locale/gu.ts +48 -0
  104. package/src/locale/he.ts +48 -0
  105. package/src/locale/hi.ts +48 -0
  106. package/src/locale/hr.ts +48 -0
  107. package/src/locale/ht.ts +48 -0
  108. package/src/locale/hu.ts +48 -0
  109. package/src/locale/hy.ts +48 -0
  110. package/src/locale/id.ts +48 -0
  111. package/src/locale/is.ts +48 -0
  112. package/src/locale/it-CH.ts +48 -0
  113. package/src/locale/it.ts +48 -0
  114. package/src/locale/ja-Hira.ts +48 -0
  115. package/src/locale/ja.ts +48 -0
  116. package/src/locale/ka.ts +48 -0
  117. package/src/locale/kk.ts +48 -0
  118. package/src/locale/km.ts +48 -0
  119. package/src/locale/kn.ts +48 -0
  120. package/src/locale/ko.ts +48 -0
  121. package/src/locale/lb.ts +48 -0
  122. package/src/locale/lt.ts +48 -0
  123. package/src/locale/lv.ts +48 -0
  124. package/src/locale/mk.ts +48 -0
  125. package/src/locale/mn.ts +48 -0
  126. package/src/locale/ms.ts +48 -0
  127. package/src/locale/mt.ts +48 -0
  128. package/src/locale/nb.ts +48 -0
  129. package/src/locale/nl-BE.ts +48 -0
  130. package/src/locale/nl.ts +48 -0
  131. package/src/locale/nn.ts +48 -0
  132. package/src/locale/oc.ts +48 -0
  133. package/src/locale/pl.ts +48 -0
  134. package/src/locale/pt-BR.ts +48 -0
  135. package/src/locale/pt.ts +48 -0
  136. package/src/locale/ro.ts +48 -0
  137. package/src/locale/ru.ts +48 -0
  138. package/src/locale/se.ts +48 -0
  139. package/src/locale/sk.ts +48 -0
  140. package/src/locale/sl.ts +48 -0
  141. package/src/locale/sq.ts +48 -0
  142. package/src/locale/sr-Latn.ts +48 -0
  143. package/src/locale/sr.ts +48 -0
  144. package/src/locale/sv.ts +48 -0
  145. package/src/locale/ta.ts +48 -0
  146. package/src/locale/te.ts +48 -0
  147. package/src/locale/th.ts +48 -0
  148. package/src/locale/tr.ts +48 -0
  149. package/src/locale/ug.ts +48 -0
  150. package/src/locale/uk.ts +48 -0
  151. package/src/locale/uz-Cyrl.ts +48 -0
  152. package/src/locale/uz.ts +48 -0
  153. package/src/locale/vi.ts +48 -0
  154. package/src/locale/zh-CN.ts +48 -0
  155. package/src/locale/zh-HK.ts +51 -0
  156. package/src/locale/zh-TW.ts +51 -0
  157. package/src/locale.ts +108 -0
  158. package/src/noonDateLib.ts +202 -0
  159. package/src/selection/useMulti.ts +74 -0
  160. package/src/selection/useRange.ts +89 -0
  161. package/src/selection/useSingle.ts +77 -0
  162. package/src/style.css +451 -0
  163. package/src/style.css.d.ts +3 -0
  164. package/src/style.module.css +451 -0
  165. package/src/style.module.css.d.ts +29 -0
  166. package/src/types/index.ts +3 -0
  167. package/src/types/props.ts +671 -0
  168. package/src/types/selection.ts +97 -0
  169. package/src/types/shared.ts +346 -0
  170. package/src/useAnimation.ts +242 -0
  171. package/src/useCalendar.ts +233 -0
  172. package/src/useDayPicker.ts +91 -0
  173. package/src/useFocus.ts +109 -0
  174. package/src/useSelection.ts +36 -0
  175. package/src/utils/addToRange.ts +91 -0
  176. package/src/utils/convertMatchersToTimeZone.ts +88 -0
  177. package/src/utils/dateMatchModifiers.ts +72 -0
  178. package/src/utils/index.ts +7 -0
  179. package/src/utils/rangeContainsDayOfWeek.ts +33 -0
  180. package/src/utils/rangeContainsModifiers.ts +106 -0
  181. package/src/utils/rangeIncludesDate.ts +40 -0
  182. package/src/utils/rangeOverlaps.ts +26 -0
  183. package/src/utils/toTimeZone.ts +13 -0
  184. package/src/utils/typeguards.ts +71 -0
  185. package/status.json +13 -0
@@ -0,0 +1,45 @@
1
+ import type { DateLib } from '../classes/DateLib.js';
2
+ import type { DayPickerProps } from '../types/index.js';
3
+
4
+ /**
5
+ * Returns the previous month the user can navigate to, based on the given
6
+ * options.
7
+ *
8
+ * The previous month is not always the previous calendar month:
9
+ *
10
+ * - If it is before the `calendarStartMonth`, it returns `undefined`.
11
+ * - If paged navigation is enabled, it skips back by the number of displayed
12
+ * months.
13
+ *
14
+ * @param firstDisplayedMonth The first month currently displayed in the
15
+ * calendar.
16
+ * @param calendarStartMonth The earliest month the user can navigate to.
17
+ * @param options Navigation options, including `numberOfMonths` and
18
+ * `pagedNavigation`.
19
+ * @param dateLib The date library to use for date manipulation.
20
+ * @returns The previous month, or `undefined` if navigation is not possible.
21
+ */
22
+ export function getPreviousMonth(
23
+ firstDisplayedMonth: Date,
24
+ calendarStartMonth: Date | undefined,
25
+ options: Pick<DayPickerProps, 'numberOfMonths' | 'pagedNavigation' | 'disableNavigation'>,
26
+ dateLib: DateLib,
27
+ ): Date | undefined {
28
+ if (options.disableNavigation) {
29
+ return undefined;
30
+ }
31
+ const { pagedNavigation, numberOfMonths } = options;
32
+ const { startOfMonth, addMonths, differenceInCalendarMonths } = dateLib;
33
+ const offset = pagedNavigation ? (numberOfMonths ?? 1) : 1;
34
+ const month = startOfMonth(firstDisplayedMonth);
35
+ if (!calendarStartMonth) {
36
+ return addMonths(month, -offset);
37
+ }
38
+ const monthsDiff = differenceInCalendarMonths(month, calendarStartMonth);
39
+
40
+ if (monthsDiff <= 0) {
41
+ return undefined;
42
+ }
43
+
44
+ return addMonths(month, -offset);
45
+ }
@@ -0,0 +1,31 @@
1
+ import type { CSSProperties } from 'react';
2
+ import type { Modifiers, ModifiersStyles, Styles } from '../types/index.js';
3
+ import { UI } from '../UI.js';
4
+
5
+ /**
6
+ * Returns the computed style for a day based on its modifiers.
7
+ *
8
+ * This function merges the base styles for the day with any styles associated
9
+ * with active modifiers.
10
+ *
11
+ * @param dayModifiers The modifiers applied to the day.
12
+ * @param styles The base styles for the calendar elements.
13
+ * @param modifiersStyles The styles associated with specific modifiers.
14
+ * @returns The computed style for the day.
15
+ */
16
+ export function getStyleForModifiers(
17
+ dayModifiers: Modifiers,
18
+ styles: Partial<Styles> = {},
19
+ modifiersStyles: Partial<ModifiersStyles> = {},
20
+ ): CSSProperties {
21
+ let style: CSSProperties = { ...styles?.[UI.Day] };
22
+ Object.entries(dayModifiers)
23
+ .filter(([, active]) => active === true)
24
+ .forEach(([modifier]) => {
25
+ style = {
26
+ ...style,
27
+ ...modifiersStyles?.[modifier],
28
+ };
29
+ });
30
+ return style;
31
+ }
@@ -0,0 +1,33 @@
1
+ import type { DateLib } from '../classes/DateLib.js';
2
+
3
+ /**
4
+ * Generates a series of 7 days, starting from the beginning of the week, to use
5
+ * for formatting weekday names (e.g., Monday, Tuesday, etc.).
6
+ *
7
+ * @param dateLib The date library to use for date manipulation.
8
+ * @param ISOWeek Whether to use ISO week numbering (weeks start on Monday).
9
+ * @param broadcastCalendar Whether to use the broadcast calendar (weeks start
10
+ * on Monday, but may include adjustments for broadcast-specific rules).
11
+ * @returns An array of 7 dates representing the weekdays.
12
+ */
13
+ export function getWeekdays(
14
+ dateLib: DateLib,
15
+ ISOWeek?: boolean | undefined,
16
+ broadcastCalendar?: boolean | undefined,
17
+ today?: Date,
18
+ ): Date[] {
19
+ const referenceToday = today ?? dateLib.today();
20
+
21
+ const start = broadcastCalendar
22
+ ? dateLib.startOfBroadcastWeek(referenceToday, dateLib)
23
+ : ISOWeek
24
+ ? dateLib.startOfISOWeek(referenceToday)
25
+ : dateLib.startOfWeek(referenceToday);
26
+
27
+ const days: Date[] = [];
28
+ for (let i = 0; i < 7; i++) {
29
+ const day = dateLib.addDays(start, i);
30
+ days.push(day);
31
+ }
32
+ return days;
33
+ }
@@ -0,0 +1,14 @@
1
+ import type { CalendarMonth, CalendarWeek } from '../classes/index.js';
2
+
3
+ /**
4
+ * Returns an array of calendar weeks from an array of calendar months.
5
+ *
6
+ * @param months The array of calendar months.
7
+ * @returns An array of calendar weeks.
8
+ */
9
+ export function getWeeks(months: CalendarMonth[]) {
10
+ const initialWeeks: CalendarWeek[] = [];
11
+ return months.reduce((weeks, month) => {
12
+ return weeks.concat(month.weeks.slice());
13
+ }, initialWeeks.slice());
14
+ }
@@ -0,0 +1,43 @@
1
+ import type { DateLib } from '../classes/DateLib.js';
2
+ import type { DropdownOption } from '../components/custom-components.tsrx';
3
+ import type { Formatters } from '../types/index.js';
4
+
5
+ /**
6
+ * Returns the years to display in the dropdown.
7
+ *
8
+ * This function generates a list of years between the navigation start and end
9
+ * dates, formatted using the provided formatter.
10
+ *
11
+ * @param navStart The start date for navigation.
12
+ * @param navEnd The end date for navigation.
13
+ * @param formatters The formatters to use for formatting the year labels.
14
+ * @param dateLib The date library to use for date manipulation.
15
+ * @param reverse If true, reverses the order of the years (descending).
16
+ * @returns An array of dropdown options representing the years, or `undefined`
17
+ * if `navStart` or `navEnd` is not provided.
18
+ */
19
+ export function getYearOptions(
20
+ navStart: Date | undefined,
21
+ navEnd: Date | undefined,
22
+ formatters: Pick<Formatters, 'formatYearDropdown'>,
23
+ dateLib: DateLib,
24
+ reverse: boolean = false,
25
+ ): DropdownOption[] | undefined {
26
+ if (!navStart) return undefined;
27
+ if (!navEnd) return undefined;
28
+ const { startOfYear, endOfYear, eachYearOfInterval, getYear } = dateLib;
29
+ const firstNavYear = startOfYear(navStart);
30
+ const lastNavYear = endOfYear(navEnd);
31
+ const years = eachYearOfInterval({ start: firstNavYear, end: lastNavYear });
32
+
33
+ if (reverse) years.reverse();
34
+
35
+ return years.map((year) => {
36
+ const label = formatters.formatYearDropdown(year, dateLib);
37
+ return {
38
+ value: getYear(year),
39
+ label,
40
+ disabled: false,
41
+ };
42
+ });
43
+ }
@@ -0,0 +1,2 @@
1
+ // Only export helpers that can be useful to other developers.
2
+ export * from './getDefaultClassNames.js';
@@ -0,0 +1,26 @@
1
+ import type { DateLib } from '../classes/index.js';
2
+
3
+ /**
4
+ * Returns the start date of the week in the broadcast calendar.
5
+ *
6
+ * The broadcast week starts on Monday. If the first day of the month is not a
7
+ * Monday, this function calculates the previous Monday as the start of the
8
+ * broadcast week.
9
+ *
10
+ * @since 9.4.0
11
+ * @param date The date for which to calculate the start of the broadcast week.
12
+ * @param dateLib The date library to use for date manipulation.
13
+ * @returns The start date of the broadcast week.
14
+ */
15
+ export function startOfBroadcastWeek(date: Date, dateLib: DateLib): Date {
16
+ const firstOfMonth = dateLib.startOfMonth(date);
17
+ const dayOfWeek = firstOfMonth.getDay();
18
+
19
+ if (dayOfWeek === 1) {
20
+ return firstOfMonth;
21
+ } else if (dayOfWeek === 0) {
22
+ return dateLib.addDays(firstOfMonth, -1 * 6);
23
+ } else {
24
+ return dateLib.addDays(firstOfMonth, -1 * (dayOfWeek - 1));
25
+ }
26
+ }
@@ -0,0 +1,38 @@
1
+ import { useState } from 'octane';
2
+ import type React from 'react';
3
+
4
+ export type DispatchStateAction<T> = React.Dispatch<React.SetStateAction<T>>;
5
+
6
+ /**
7
+ * A custom hook for managing both controlled and uncontrolled component states.
8
+ *
9
+ * This hook allows a component to support both controlled and uncontrolled
10
+ * states by determining whether the `controlledValue` is provided. If it is
11
+ * undefined, the hook falls back to using the internal state.
12
+ *
13
+ * @example
14
+ * // Uncontrolled usage
15
+ * const [value, setValue] = useControlledValue(0, undefined);
16
+ *
17
+ * // Controlled usage
18
+ * const [value, setValue] = useControlledValue(0, props.value);
19
+ *
20
+ * @template T - The type of the value.
21
+ * @param defaultValue The initial value for the uncontrolled state.
22
+ * @param controlledValue The value for the controlled state. If undefined, the
23
+ * component will use the uncontrolled state.
24
+ * @returns A tuple where the first element is the current value (either
25
+ * controlled or uncontrolled) and the second element is a setter function to
26
+ * update the value.
27
+ */
28
+ export function useControlledValue<T>(
29
+ defaultValue: T,
30
+ controlledValue: T | undefined,
31
+ slot?: symbol,
32
+ ): [T, DispatchStateAction<T>] {
33
+ const [uncontrolledValue, setValue] = useState(defaultValue, slot);
34
+
35
+ const value = controlledValue === undefined ? uncontrolledValue : controlledValue;
36
+
37
+ return [value, setValue] as [T, DispatchStateAction<T>];
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ export { TZDate } from '@date-fns/tz';
2
+ export * from './classes/index.js';
3
+ export * from './components/custom-components.tsrx';
4
+ export * from './DayPicker.tsrx';
5
+
6
+ export * from './formatters/index.js';
7
+ export * from './helpers/index.js';
8
+ export * from './labels/index.js';
9
+ export * from './types/index.js';
10
+ export * from './UI.js';
11
+
12
+ export * from './useDayPicker.js';
13
+ export * from './utils/index.js';
@@ -0,0 +1,12 @@
1
+ export * from './labelDayButton.js';
2
+ export * from './labelGrid.js';
3
+ export * from './labelGrid.js';
4
+ export * from './labelGridcell.js';
5
+ export * from './labelMonthDropdown.js';
6
+ export * from './labelNav.js';
7
+ export * from './labelNext.js';
8
+ export * from './labelPrevious.js';
9
+ export * from './labelWeekday.js';
10
+ export * from './labelWeekNumber.js';
11
+ export * from './labelWeekNumberHeader.js';
12
+ export * from './labelYearDropdown.js';
@@ -0,0 +1,29 @@
1
+ import { DateLib, type DateLibOptions } from '../classes/DateLib.js';
2
+ import type { Modifiers } from '../types/index.js';
3
+
4
+ /**
5
+ * Generates the ARIA label for a day button.
6
+ *
7
+ * Use the `modifiers` argument to provide additional context for the label,
8
+ * such as indicating if the day is "today" or "selected."
9
+ *
10
+ * @defaultValue The formatted date.
11
+ * @param date - The date to format.
12
+ * @param modifiers - The modifiers providing context for the day.
13
+ * @param options - Optional configuration for the date formatting library.
14
+ * @param dateLib - An optional instance of the date formatting library.
15
+ * @returns The ARIA label for the day button.
16
+ * @group Labels
17
+ * @see https://daypicker.dev/docs/translation#aria-labels
18
+ */
19
+ export function labelDayButton(
20
+ date: Date,
21
+ modifiers: Modifiers,
22
+ options?: DateLibOptions,
23
+ dateLib?: DateLib,
24
+ ) {
25
+ let label = (dateLib ?? new DateLib(options)).format(date, 'PPPP');
26
+ if (modifiers.today) label = `Today, ${label}`;
27
+ if (modifiers.selected) label = `${label}, selected`;
28
+ return label;
29
+ }
@@ -0,0 +1,18 @@
1
+ import { DateLib, type DateLibOptions } from '../classes/DateLib.js';
2
+
3
+ /**
4
+ * Generates the ARIA label for the month grid, which is announced when entering
5
+ * the grid.
6
+ *
7
+ * @defaultValue Locale-specific month/year order (e.g., "November 2022").
8
+ * @param date - The date representing the month.
9
+ * @param options - Optional configuration for the date formatting library.
10
+ * @param dateLib - An optional instance of the date formatting library.
11
+ * @returns The ARIA label for the month grid.
12
+ * @group Labels
13
+ * @see https://daypicker.dev/docs/translation#aria-labels
14
+ */
15
+ export function labelGrid(date: Date, options?: DateLibOptions, dateLib?: DateLib) {
16
+ const lib = dateLib ?? new DateLib(options);
17
+ return lib.formatMonthYear(date);
18
+ }
@@ -0,0 +1,26 @@
1
+ import { DateLib, type DateLibOptions } from '../classes/DateLib.js';
2
+ import type { Modifiers } from '../types/index.js';
3
+
4
+ /**
5
+ * Generates the label for a day grid cell when the calendar is not interactive.
6
+ *
7
+ * @param date - The date to format.
8
+ * @param modifiers - Optional modifiers providing context for the day.
9
+ * @param options - Optional configuration for the date formatting library.
10
+ * @param dateLib - An optional instance of the date formatting library.
11
+ * @returns The label for the day grid cell.
12
+ * @group Labels
13
+ * @see https://daypicker.dev/docs/translation#aria-labels
14
+ */
15
+ export function labelGridcell(
16
+ date: Date,
17
+ modifiers?: Modifiers,
18
+ options?: DateLibOptions,
19
+ dateLib?: DateLib,
20
+ ) {
21
+ let label = (dateLib ?? new DateLib(options)).format(date, 'PPPP');
22
+ if (modifiers?.today) {
23
+ label = `Today, ${label}`;
24
+ }
25
+ return label;
26
+ }
@@ -0,0 +1,14 @@
1
+ import type { DateLibOptions } from '../classes/DateLib.js';
2
+
3
+ /**
4
+ * Generates the ARIA label for the months dropdown.
5
+ *
6
+ * @defaultValue `"Choose the Month"`
7
+ * @param options - Optional configuration for the date formatting library.
8
+ * @returns The ARIA label for the months dropdown.
9
+ * @group Labels
10
+ * @see https://daypicker.dev/docs/translation#aria-labels
11
+ */
12
+ export function labelMonthDropdown(_options?: DateLibOptions) {
13
+ return 'Choose the Month';
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generates the ARIA label for the navigation toolbar.
3
+ *
4
+ * @defaultValue `""`
5
+ * @returns The ARIA label for the navigation toolbar.
6
+ * @group Labels
7
+ * @see https://daypicker.dev/docs/translation#aria-labels
8
+ */
9
+ export function labelNav(): string {
10
+ return '';
11
+ }
@@ -0,0 +1,17 @@
1
+ import type { DateLibOptions } from '../classes/DateLib.js';
2
+
3
+ const defaultLabel = 'Go to the Next Month';
4
+
5
+ /**
6
+ * Generates the ARIA label for the "next month" button.
7
+ *
8
+ * @defaultValue `"Go to the Next Month"`
9
+ * @param month - The date representing the next month, or `undefined` if there
10
+ * is no next month.
11
+ * @returns The ARIA label for the "next month" button.
12
+ * @group Labels
13
+ * @see https://daypicker.dev/docs/translation#aria-labels
14
+ */
15
+ export function labelNext(_month: Date | undefined, _options?: DateLibOptions) {
16
+ return defaultLabel;
17
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generates the ARIA label for the "previous month" button.
3
+ *
4
+ * @defaultValue `"Go to the Previous Month"`
5
+ * @param month - The date representing the previous month, or `undefined` if
6
+ * there is no previous month.
7
+ * @returns The ARIA label for the "previous month" button.
8
+ * @group Labels
9
+ * @see https://daypicker.dev/docs/translation#aria-labels
10
+ */
11
+ export function labelPrevious(_month: Date | undefined) {
12
+ return 'Go to the Previous Month';
13
+ }
@@ -0,0 +1,15 @@
1
+ import type { DateLibOptions } from '../classes/DateLib.js';
2
+
3
+ /**
4
+ * Generates the ARIA label for the week number cell (the first cell in a row).
5
+ *
6
+ * @defaultValue `Week ${weekNumber}`
7
+ * @param weekNumber - The number of the week.
8
+ * @param options - Optional configuration for the date formatting library.
9
+ * @returns The ARIA label for the week number cell.
10
+ * @group Labels
11
+ * @see https://daypicker.dev/docs/translation#aria-labels
12
+ */
13
+ export function labelWeekNumber(weekNumber: number, _options?: DateLibOptions): string {
14
+ return `Week ${weekNumber}`;
15
+ }
@@ -0,0 +1,14 @@
1
+ import type { DateLibOptions } from '../classes/DateLib.js';
2
+
3
+ /**
4
+ * Generates the ARIA label for the week number header element.
5
+ *
6
+ * @defaultValue `"Week Number"`
7
+ * @param options - Optional configuration for the date formatting library.
8
+ * @returns The ARIA label for the week number header.
9
+ * @group Labels
10
+ * @see https://daypicker.dev/docs/translation#aria-labels
11
+ */
12
+ export function labelWeekNumberHeader(_options?: DateLibOptions): string {
13
+ return 'Week Number';
14
+ }
@@ -0,0 +1,16 @@
1
+ import { DateLib, type DateLibOptions } from '../classes/DateLib.js';
2
+
3
+ /**
4
+ * Generates the ARIA label for a weekday column header.
5
+ *
6
+ * @defaultValue `"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"`
7
+ * @param date - The date representing the weekday.
8
+ * @param options - Optional configuration for the date formatting library.
9
+ * @param dateLib - An optional instance of the date formatting library.
10
+ * @returns The ARIA label for the weekday column header.
11
+ * @group Labels
12
+ * @see https://daypicker.dev/docs/translation#aria-labels
13
+ */
14
+ export function labelWeekday(date: Date, options?: DateLibOptions, dateLib?: DateLib): string {
15
+ return (dateLib ?? new DateLib(options)).format(date, 'cccc');
16
+ }
@@ -0,0 +1,14 @@
1
+ import type { DateLibOptions } from '../classes/DateLib.js';
2
+
3
+ /**
4
+ * Generates the ARIA label for the years dropdown.
5
+ *
6
+ * @defaultValue `"Choose the Year"`
7
+ * @param options - Optional configuration for the date formatting library.
8
+ * @returns The ARIA label for the years dropdown.
9
+ * @group Labels
10
+ * @see https://daypicker.dev/docs/translation#aria-labels
11
+ */
12
+ export function labelYearDropdown(_options?: DateLibOptions) {
13
+ return 'Choose the Year';
14
+ }
@@ -0,0 +1,48 @@
1
+ import { af as dateFnsAf } from 'date-fns/locale';
2
+
3
+ import type { DateLibOptions, DayPickerLocale } from '../classes/DateLib.js';
4
+ import { DateLib } from '../classes/DateLib.js';
5
+ import type { Modifiers } from '../types/index.js';
6
+
7
+ /** Afrikaans locale extended with DayPicker-specific translations. */
8
+ export const af: DayPickerLocale = {
9
+ ...dateFnsAf,
10
+ labels: {
11
+ labelDayButton: (
12
+ date: Date,
13
+ modifiers: Modifiers,
14
+ options?: DateLibOptions,
15
+ dateLib?: DateLib,
16
+ ) => {
17
+ const lib = dateLib ?? new DateLib(options);
18
+ let label = lib.format(date, 'PPPP');
19
+ if (modifiers.today) label = `Vandag, ${label}`;
20
+ if (modifiers.selected) label = `${label}, gekies`;
21
+ return label;
22
+ },
23
+ labelMonthDropdown: 'Kies die maand',
24
+ labelNext: 'Gaan na volgende maand',
25
+ labelPrevious: 'Gaan na vorige maand',
26
+ labelWeekNumber: (weekNumber: number) => `Week ${weekNumber}`,
27
+ labelYearDropdown: 'Kies die jaar',
28
+ labelGrid: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
29
+ (dateLib ?? new DateLib(options)).formatMonthYear(date),
30
+ labelGridcell: (
31
+ date: Date,
32
+ modifiers?: Modifiers,
33
+ options?: DateLibOptions,
34
+ dateLib?: DateLib,
35
+ ) => {
36
+ const lib = dateLib ?? new DateLib(options);
37
+ let label = lib.format(date, 'PPPP');
38
+ if (modifiers?.today) {
39
+ label = `Vandag, ${label}`;
40
+ }
41
+ return label;
42
+ },
43
+ labelNav: 'Navigasiebalk',
44
+ labelWeekNumberHeader: 'Weeknommer',
45
+ labelWeekday: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
46
+ (dateLib ?? new DateLib(options)).format(date, 'cccc'),
47
+ },
48
+ };
@@ -0,0 +1,48 @@
1
+ import { arDZ as dateFnsArDZ } from 'date-fns/locale';
2
+
3
+ import type { DateLibOptions, DayPickerLocale } from '../classes/DateLib.js';
4
+ import { DateLib } from '../classes/DateLib.js';
5
+ import type { Modifiers } from '../types/index.js';
6
+
7
+ /** Arabic (Algeria) locale extended with DayPicker-specific translations. */
8
+ export const arDZ: DayPickerLocale = {
9
+ ...dateFnsArDZ,
10
+ labels: {
11
+ labelDayButton: (
12
+ date: Date,
13
+ modifiers: Modifiers,
14
+ options?: DateLibOptions,
15
+ dateLib?: DateLib,
16
+ ) => {
17
+ const lib = dateLib ?? new DateLib(options);
18
+ let label = lib.format(date, 'PPPP');
19
+ if (modifiers.today) label = `اليوم، ${label}`;
20
+ if (modifiers.selected) label = `${label}، محدد`;
21
+ return label;
22
+ },
23
+ labelMonthDropdown: 'اختر الشهر',
24
+ labelNext: 'اذهب إلى الشهر التالي',
25
+ labelPrevious: 'اذهب إلى الشهر السابق',
26
+ labelWeekNumber: (weekNumber: number) => `الأسبوع ${weekNumber}`,
27
+ labelYearDropdown: 'اختر السنة',
28
+ labelGrid: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
29
+ (dateLib ?? new DateLib(options)).formatMonthYear(date),
30
+ labelGridcell: (
31
+ date: Date,
32
+ modifiers?: Modifiers,
33
+ options?: DateLibOptions,
34
+ dateLib?: DateLib,
35
+ ) => {
36
+ const lib = dateLib ?? new DateLib(options);
37
+ let label = lib.format(date, 'PPPP');
38
+ if (modifiers?.today) {
39
+ label = `اليوم، ${label}`;
40
+ }
41
+ return label;
42
+ },
43
+ labelNav: 'شريط التنقل',
44
+ labelWeekNumberHeader: 'رقم الأسبوع',
45
+ labelWeekday: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
46
+ (dateLib ?? new DateLib(options)).format(date, 'cccc'),
47
+ },
48
+ };
@@ -0,0 +1,48 @@
1
+ import { arEG as dateFnsArEG } from 'date-fns/locale';
2
+
3
+ import type { DateLibOptions, DayPickerLocale } from '../classes/DateLib.js';
4
+ import { DateLib } from '../classes/DateLib.js';
5
+ import type { Modifiers } from '../types/index.js';
6
+
7
+ /** Arabic (Egypt) locale extended with DayPicker-specific translations. */
8
+ export const arEG: DayPickerLocale = {
9
+ ...dateFnsArEG,
10
+ labels: {
11
+ labelDayButton: (
12
+ date: Date,
13
+ modifiers: Modifiers,
14
+ options?: DateLibOptions,
15
+ dateLib?: DateLib,
16
+ ) => {
17
+ const lib = dateLib ?? new DateLib(options);
18
+ let label = lib.format(date, 'PPPP');
19
+ if (modifiers.today) label = `اليوم، ${label}`;
20
+ if (modifiers.selected) label = `${label}، محدد`;
21
+ return label;
22
+ },
23
+ labelMonthDropdown: 'اختر الشهر',
24
+ labelNext: 'اذهب إلى الشهر التالي',
25
+ labelPrevious: 'اذهب إلى الشهر السابق',
26
+ labelWeekNumber: (weekNumber: number) => `الأسبوع ${weekNumber}`,
27
+ labelYearDropdown: 'اختر السنة',
28
+ labelGrid: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
29
+ (dateLib ?? new DateLib(options)).formatMonthYear(date),
30
+ labelGridcell: (
31
+ date: Date,
32
+ modifiers?: Modifiers,
33
+ options?: DateLibOptions,
34
+ dateLib?: DateLib,
35
+ ) => {
36
+ const lib = dateLib ?? new DateLib(options);
37
+ let label = lib.format(date, 'PPPP');
38
+ if (modifiers?.today) {
39
+ label = `اليوم، ${label}`;
40
+ }
41
+ return label;
42
+ },
43
+ labelNav: 'شريط التنقل',
44
+ labelWeekNumberHeader: 'رقم الأسبوع',
45
+ labelWeekday: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
46
+ (dateLib ?? new DateLib(options)).format(date, 'cccc'),
47
+ },
48
+ };
@@ -0,0 +1,48 @@
1
+ import { arMA as dateFnsArMA } from 'date-fns/locale';
2
+
3
+ import type { DateLibOptions, DayPickerLocale } from '../classes/DateLib.js';
4
+ import { DateLib } from '../classes/DateLib.js';
5
+ import type { Modifiers } from '../types/index.js';
6
+
7
+ /** Arabic (Morocco) locale extended with DayPicker-specific translations. */
8
+ export const arMA: DayPickerLocale = {
9
+ ...dateFnsArMA,
10
+ labels: {
11
+ labelDayButton: (
12
+ date: Date,
13
+ modifiers: Modifiers,
14
+ options?: DateLibOptions,
15
+ dateLib?: DateLib,
16
+ ) => {
17
+ const lib = dateLib ?? new DateLib(options);
18
+ let label = lib.format(date, 'PPPP');
19
+ if (modifiers.today) label = `اليوم، ${label}`;
20
+ if (modifiers.selected) label = `${label}، محدد`;
21
+ return label;
22
+ },
23
+ labelMonthDropdown: 'اختر الشهر',
24
+ labelNext: 'اذهب إلى الشهر التالي',
25
+ labelPrevious: 'اذهب إلى الشهر السابق',
26
+ labelWeekNumber: (weekNumber: number) => `الأسبوع ${weekNumber}`,
27
+ labelYearDropdown: 'اختر السنة',
28
+ labelGrid: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
29
+ (dateLib ?? new DateLib(options)).formatMonthYear(date),
30
+ labelGridcell: (
31
+ date: Date,
32
+ modifiers?: Modifiers,
33
+ options?: DateLibOptions,
34
+ dateLib?: DateLib,
35
+ ) => {
36
+ const lib = dateLib ?? new DateLib(options);
37
+ let label = lib.format(date, 'PPPP');
38
+ if (modifiers?.today) {
39
+ label = `اليوم، ${label}`;
40
+ }
41
+ return label;
42
+ },
43
+ labelNav: 'شريط التنقل',
44
+ labelWeekNumberHeader: 'رقم الأسبوع',
45
+ labelWeekday: (date: Date, options?: DateLibOptions, dateLib?: DateLib) =>
46
+ (dateLib ?? new DateLib(options)).format(date, 'cccc'),
47
+ },
48
+ };