react-day-picker 9.3.2 → 9.4.0

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 (92) hide show
  1. package/README.md +2 -1
  2. package/dist/cjs/DayPicker.js +3 -2
  3. package/dist/cjs/DayPicker.js.map +1 -1
  4. package/dist/cjs/classes/DateLib.d.ts +16 -0
  5. package/dist/cjs/classes/DateLib.js +24 -0
  6. package/dist/cjs/classes/DateLib.js.map +1 -1
  7. package/dist/cjs/helpers/endOfBroadcastWeek.d.ts +7 -0
  8. package/dist/cjs/helpers/endOfBroadcastWeek.js +17 -0
  9. package/dist/cjs/helpers/endOfBroadcastWeek.js.map +1 -0
  10. package/dist/cjs/helpers/getBroadcastWeeksInMonth.d.ts +7 -0
  11. package/dist/cjs/helpers/getBroadcastWeeksInMonth.js +23 -0
  12. package/dist/cjs/helpers/getBroadcastWeeksInMonth.js.map +1 -0
  13. package/dist/cjs/helpers/getDataAttributes.js +2 -1
  14. package/dist/cjs/helpers/getDataAttributes.js.map +1 -1
  15. package/dist/cjs/helpers/getDates.d.ts +1 -3
  16. package/dist/cjs/helpers/getDates.js +14 -12
  17. package/dist/cjs/helpers/getDates.js.map +1 -1
  18. package/dist/cjs/helpers/getFocusableDate.d.ts +1 -1
  19. package/dist/cjs/helpers/getFocusableDate.js +12 -4
  20. package/dist/cjs/helpers/getFocusableDate.js.map +1 -1
  21. package/dist/cjs/helpers/getMonths.d.ts +1 -1
  22. package/dist/cjs/helpers/getMonths.js +14 -10
  23. package/dist/cjs/helpers/getMonths.js.map +1 -1
  24. package/dist/cjs/helpers/getWeekdays.d.ts +3 -1
  25. package/dist/cjs/helpers/getWeekdays.js +8 -4
  26. package/dist/cjs/helpers/getWeekdays.js.map +1 -1
  27. package/dist/cjs/helpers/startOfBroadcastWeek.d.ts +7 -0
  28. package/dist/cjs/helpers/startOfBroadcastWeek.js +22 -0
  29. package/dist/cjs/helpers/startOfBroadcastWeek.js.map +1 -0
  30. package/dist/cjs/types/props.d.ts +12 -0
  31. package/dist/cjs/useCalendar.d.ts +1 -1
  32. package/dist/cjs/useCalendar.js.map +1 -1
  33. package/dist/cjs/useGetModifiers.js +4 -2
  34. package/dist/cjs/useGetModifiers.js.map +1 -1
  35. package/dist/esm/DayPicker.js +3 -2
  36. package/dist/esm/DayPicker.js.map +1 -1
  37. package/dist/esm/classes/DateLib.d.ts +16 -0
  38. package/dist/esm/classes/DateLib.js +24 -0
  39. package/dist/esm/classes/DateLib.js.map +1 -1
  40. package/dist/esm/helpers/endOfBroadcastWeek.d.ts +7 -0
  41. package/dist/esm/helpers/endOfBroadcastWeek.js +14 -0
  42. package/dist/esm/helpers/endOfBroadcastWeek.js.map +1 -0
  43. package/dist/esm/helpers/getBroadcastWeeksInMonth.d.ts +7 -0
  44. package/dist/esm/helpers/getBroadcastWeeksInMonth.js +20 -0
  45. package/dist/esm/helpers/getBroadcastWeeksInMonth.js.map +1 -0
  46. package/dist/esm/helpers/getDataAttributes.js +2 -1
  47. package/dist/esm/helpers/getDataAttributes.js.map +1 -1
  48. package/dist/esm/helpers/getDates.d.ts +1 -3
  49. package/dist/esm/helpers/getDates.js +14 -11
  50. package/dist/esm/helpers/getDates.js.map +1 -1
  51. package/dist/esm/helpers/getFocusableDate.d.ts +1 -1
  52. package/dist/esm/helpers/getFocusableDate.js +12 -4
  53. package/dist/esm/helpers/getFocusableDate.js.map +1 -1
  54. package/dist/esm/helpers/getMonths.d.ts +1 -1
  55. package/dist/esm/helpers/getMonths.js +14 -10
  56. package/dist/esm/helpers/getMonths.js.map +1 -1
  57. package/dist/esm/helpers/getWeekdays.d.ts +3 -1
  58. package/dist/esm/helpers/getWeekdays.js +8 -4
  59. package/dist/esm/helpers/getWeekdays.js.map +1 -1
  60. package/dist/esm/helpers/startOfBroadcastWeek.d.ts +7 -0
  61. package/dist/esm/helpers/startOfBroadcastWeek.js +19 -0
  62. package/dist/esm/helpers/startOfBroadcastWeek.js.map +1 -0
  63. package/dist/esm/types/props.d.ts +12 -0
  64. package/dist/esm/useCalendar.d.ts +1 -1
  65. package/dist/esm/useCalendar.js.map +1 -1
  66. package/dist/esm/useGetModifiers.js +4 -2
  67. package/dist/esm/useGetModifiers.js.map +1 -1
  68. package/examples/BroadcastCalendar.tsx +7 -0
  69. package/examples/index.ts +1 -0
  70. package/package.json +1 -1
  71. package/src/DayPicker.tsx +3 -2
  72. package/src/classes/DateLib.ts +28 -0
  73. package/src/helpers/broadcastCalendar.test.ts +43 -0
  74. package/src/helpers/endOfBroadcastWeek.test.ts +25 -0
  75. package/src/helpers/endOfBroadcastWeek.ts +16 -0
  76. package/src/helpers/getBroadcastWeeksInMonth.test.ts +23 -0
  77. package/src/helpers/getBroadcastWeeksInMonth.ts +31 -0
  78. package/src/helpers/getDataAttributes.tsx +2 -1
  79. package/src/helpers/getDates.ts +21 -17
  80. package/src/helpers/getFocusableDate.ts +19 -8
  81. package/src/helpers/getMonths.ts +25 -17
  82. package/src/helpers/getWeekdays.ts +9 -4
  83. package/src/helpers/startOfBroadcastWeek.test.ts +24 -0
  84. package/src/helpers/startOfBroadcastWeek.ts +19 -0
  85. package/src/style.css +13 -4
  86. package/src/style.module.css +13 -4
  87. package/src/types/props.ts +12 -0
  88. package/src/useCalendar.ts +1 -0
  89. package/src/useGetModifiers.tsx +11 -2
  90. package/website/docs/docs/localization.mdx +23 -7
  91. package/website/docs/docs/styling.mdx +4 -4
  92. package/website/docs/intro.mdx +2 -1
@@ -4,13 +4,13 @@
4
4
  --rdp-accent-color: blue; /* The accent color used for selected days and UI elements. */
5
5
  --rdp-accent-background-color: #f0f0ff; /* The accent background color used for selected days and UI elements. */
6
6
 
7
- --rdp-day-height: 2.75rem; /* The height of the day cells. */
8
- --rdp-day-width: 2.75rem; /* The width of the day cells. */
7
+ --rdp-day-height: 44px; /* The height of the day cells. */
8
+ --rdp-day-width: 44px; /* The width of the day cells. */
9
9
 
10
10
  --rdp-day_button-border-radius: 100%; /* The border radius of the day cells. */
11
11
  --rdp-day_button-border: 2px solid transparent; /* The border of the day cells. */
12
- --rdp-day_button-height: var(--rdp-day-height); /* The height of the day cells. */
13
- --rdp-day_button-width: var(--rdp-day-width); /* The width of the day cells. */
12
+ --rdp-day_button-height: 42px; /* The height of the day cells. */
13
+ --rdp-day_button-width: 42px; /* The width of the day cells. */
14
14
 
15
15
  --rdp-selected-border: 2px solid var(--rdp-accent-color); /* The border of the selected days. */
16
16
  --rdp-disabled-opacity: 0.5; /* The opacity of the disabled days. */
@@ -57,6 +57,10 @@
57
57
  --rdp-gradient-direction: -90deg;
58
58
  }
59
59
 
60
+ .root[data-broadcast-calendar="true"] {
61
+ --rdp-outside-opacity: unset;
62
+ }
63
+
60
64
  /* Root of the component. */
61
65
  .root {
62
66
  position: relative; /* Required to position the navigation toolbar. */
@@ -105,6 +109,11 @@
105
109
  border: 0;
106
110
  }
107
111
 
112
+ .dropdown:focus-visible ~ .caption_label {
113
+ outline: 5px auto Highlight;
114
+ outline: 5px auto -webkit-focus-ring-color;
115
+ }
116
+
108
117
  .button_next,
109
118
  .button_previous {
110
119
  border: none;
@@ -230,6 +230,8 @@ export interface PropsBase {
230
230
  /**
231
231
  * Show the outside days (days falling in the next or the previous month).
232
232
  *
233
+ * **Note:** when {@link broadcastCalendar} is set, this prop defaults to true.
234
+ *
233
235
  * @see https://daypicker.dev/docs/customization#outside-days
234
236
  */
235
237
  showOutsideDays?: boolean;
@@ -243,6 +245,16 @@ export interface PropsBase {
243
245
  * @see https://daypicker.dev/docs/customization#showweeknumber
244
246
  */
245
247
  showWeekNumber?: boolean;
248
+ /**
249
+ * Display the weeks in the month following the broadcast calendar. Setting
250
+ * this prop will ignore {@link weekStartsOn} (always Monday) and
251
+ * {@link showOutsideDays} will default to true.
252
+ *
253
+ * @since 9.4.0
254
+ * @see https://daypicker.dev/docs/localization#broadcast-calendar
255
+ * @see https://en.wikipedia.org/wiki/Broadcast_calendar
256
+ */
257
+ broadcastCalendar?: boolean;
246
258
  /**
247
259
  * Use ISO week dates instead of the locale setting. Setting this prop will
248
260
  * ignore `weekStartsOn` and `firstWeekContainsDate`.
@@ -81,6 +81,7 @@ export function useCalendar(
81
81
  | "month"
82
82
  | "defaultMonth"
83
83
  | "timeZone"
84
+ | "broadcastCalendar"
84
85
  // Deprecated:
85
86
  | "fromMonth"
86
87
  | "fromYear"
@@ -17,7 +17,14 @@ export function useGetModifiers(
17
17
  props: DayPickerProps,
18
18
  dateLib: DateLib
19
19
  ) {
20
- const { disabled, hidden, modifiers, showOutsideDays, today } = props;
20
+ const {
21
+ disabled,
22
+ hidden,
23
+ modifiers,
24
+ showOutsideDays,
25
+ broadcastCalendar,
26
+ today
27
+ } = props;
21
28
 
22
29
  const {
23
30
  isSameDay,
@@ -60,7 +67,9 @@ export function useGetModifiers(
60
67
  Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) ||
61
68
  isBeforeStartMonth ||
62
69
  isAfterEndMonth ||
63
- (!showOutsideDays && isOutside);
70
+ // Broadcast calendar will show outside days as default
71
+ (!broadcastCalendar && !showOutsideDays && isOutside) ||
72
+ (broadcastCalendar && showOutsideDays === false && isOutside);
64
73
 
65
74
  const isToday = isSameDay(
66
75
  date,
@@ -6,13 +6,15 @@ sidebar_position: 6
6
6
 
7
7
  DayPicker provides various options to customize the calendar for different languages and regions.
8
8
 
9
- | Prop Name | Type | Description |
10
- | ----------------------- | --------------------------------------------- | ------------------------------------------------------------------------ |
11
- | `locale` | [`Locale`](https://date-fns.org/docs/I18n) | Set the locale. Default is `en-US`. |
12
- | `weekStartsOn` | `1` \| `2` \| `3` \| `4` \| `5` \| `6` \| `7` | Change the first day of the week. |
13
- | `firstWeekContainsDate` | `1` \| `4` | Configure the first date in the first week of the year. |
14
- | `ISOWeek` | `boolean` | Switch to [ISO Week Dates](https://en.wikipedia.org/wiki/ISO_week_date). |
15
- | `timeZone` | `string` | The time zone (IANA or UTC offset) to use in the calendar. |
9
+ | Prop Name | Type | Description |
10
+ | ----------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------- |
11
+ | `locale` | [`Locale`](https://date-fns.org/docs/I18n) | Set the locale. Default is `en-US`. |
12
+ | `weekStartsOn` | `1` \| `2` \| `3` \| `4` \| `5` \| `6` \| `7` | Change the first day of the week. |
13
+ | `firstWeekContainsDate` | `1` \| `4` | Configure the first date in the first week of the year. |
14
+ | `timeZone` | `string` | The time zone (IANA or UTC offset) to use in the calendar. |
15
+ | `ISOWeek` | `boolean` | Switch to [ISO Week Dates](https://en.wikipedia.org/wiki/ISO_week_date). |
16
+ | `broadcastCalendar` | `boolean` | Switch to the [US Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar). |
17
+ | `jalali` | `boolean` | Switch to the Jalali calendar. |
16
18
 
17
19
  ## Setting the Locale
18
20
 
@@ -94,6 +96,20 @@ Use the `ISOWeek` prop to switch to [ISO Week Dates](https://en.wikipedia.org/wi
94
96
  <Examples.WeeknumberIso />
95
97
  </BrowserWindow>
96
98
 
99
+ ## Broadcast Calendar
100
+
101
+ Switch to the [US Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar) by setting the `broadcastCalendar` prop.
102
+
103
+ In the broadcast calendar, weeks start on Monday and end on Sunday. Each month has either 28 or 35 days.
104
+
105
+ ```tsx
106
+ <DayPicker broadcastCalendar />
107
+ ```
108
+
109
+ <BrowserWindow>
110
+ <Examples.BroadcastCalendar />
111
+ </BrowserWindow>
112
+
97
113
  ## Jalali Calendar
98
114
 
99
115
  DayPicker supports the Jalali calendar through the [date-fns-jalali](https://www.npmjs.com/package/date-fns-jalali) package. To switch to the Jalali calendar, add `date-fns-jalali` to your dependencies and import `DayPicker` from `react-day-picker/jalali`.
@@ -56,13 +56,13 @@ The following table lists the CSS variables used by DayPicker within the `.rdp-r
56
56
  | ----------------------------------------- | -------------------------------------------------------------------- |
57
57
  | `--rdp-accent-color` | The accent color used for selected days and UI elements. |
58
58
  | `--rdp-accent-background-color` | The accent background color used for selected days and UI elements. |
59
- | `--rdp-day-height` | The height of the day cells. |
60
- | `--rdp-day-width` | The width of the day cells. |
59
+ | `--rdp-day-height` | The height of the day cells (default: `44px`). |
60
+ | `--rdp-day-width` | The width of the day cells (default: `44px`). |
61
61
  | `--rdp-chevron-disabled-opacity` | The opacity of the chevron when its container is disabled. |
62
62
  | `--rdp-day_button-border-radius` | The border radius of the day cells. |
63
63
  | `--rdp-day_button-border` | The border of the day cells. |
64
- | `--rdp-day_button-height` | The height of the day cells. |
65
- | `--rdp-day_button-width` | The width of the day cells. |
64
+ | `--rdp-day_button-height` | The height of the day cells (default: `42px`). |
65
+ | `--rdp-day_button-width` | The width of the day cells (default: `42px`). |
66
66
  | `--rdp-selected-border` | The border of the selected days. |
67
67
  | `--rdp-disabled-opacity` | The opacity of the disabled days. |
68
68
  | `--rdp-outside-opacity` | The opacity of the days outside the current month. |
@@ -14,7 +14,8 @@ DayPicker is a [React](https://react.dev) component for creating date pickers, c
14
14
  - 🛠 Extensive set of props for [customizing](./docs/customization.mdx) the calendar.
15
15
  - 🎨 Minimal design that can be [easily styled](./docs/styling.mdx) with CSS or any CSS framework.
16
16
  - 📅 Supports [selections](./docs/selection-modes.mdx) of single days, multiple days, ranges of days, or [custom selections](./guides/custom-selections.mdx).
17
- - 🌍 Can be [localized](./docs/localization.mdx) into any language, supports [ISO 8601 dates](./docs/localization.mdx#iso-week-dates), [time zones](./docs/localization.mdx#time-zone), and the [Jalali calendar](./docs/localization.mdx#jalali-calendar).
17
+ - 🌍 Can be [localized](https://daypicker.dev/docs/localization) into any language and [time zones](https://daypicker.dev/docs/localization#time-zone).
18
+ - 🌐 Support for [ISO 8601 dates](https://daypicker.dev/docs/localization#iso-week-dates), [Jalali](https://daypicker.dev/docs/localization#jalali-calendar), and [broadcast](https://daypicker.dev/docs/localization#broadcast-calendar) calendar.
18
19
  - 🦮 Complies with WCAG 2.1 AA requirements for [accessibility](./guides/accessibility.mdx).
19
20
  - ⚙️ [Customizable components](./guides/custom-components.mdx) to extend the rendered elements.
20
21
  - 🔤 Easy integration [with input fields](./guides/input-fields.mdx).