rsuite 6.0.0-canary-20250827 → 6.0.0-canary-20250904

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 (40) hide show
  1. package/cjs/Calendar/CalendarBody.js +4 -1
  2. package/cjs/Calendar/CalendarContainer.js +0 -2
  3. package/cjs/Calendar/CalendarProvider.d.ts +0 -6
  4. package/cjs/Calendar/Grid/Grid.d.ts +2 -1
  5. package/cjs/Calendar/Grid/Grid.js +2 -2
  6. package/cjs/Calendar/Grid/GridRow.d.ts +8 -2
  7. package/cjs/Calendar/Grid/GridRow.js +63 -28
  8. package/cjs/Calendar/hooks/useCalendar.d.ts +0 -1
  9. package/cjs/Navbar/Navbar.d.ts +5 -1
  10. package/cjs/Navbar/Navbar.js +2 -1
  11. package/cjs/Navbar/NavbarContent.d.ts +8 -3
  12. package/cjs/Navbar/NavbarContent.js +30 -5
  13. package/cjs/internals/utils/date/getWeekStartDates.d.ts +4 -3
  14. package/cjs/internals/utils/date/getWeekStartDates.js +10 -5
  15. package/cjs/internals/utils/date/plainDate.d.ts +7 -0
  16. package/cjs/internals/utils/date/plainDate.js +26 -2
  17. package/cjs/internals/utils/date/types.d.ts +9 -0
  18. package/cjs/internals/utils/date/types.js +6 -0
  19. package/dist/rsuite.js +11 -11
  20. package/dist/rsuite.min.js +1 -1
  21. package/dist/rsuite.min.js.map +1 -1
  22. package/esm/Calendar/CalendarBody.js +4 -1
  23. package/esm/Calendar/CalendarContainer.js +1 -3
  24. package/esm/Calendar/CalendarProvider.d.ts +0 -6
  25. package/esm/Calendar/Grid/Grid.d.ts +2 -1
  26. package/esm/Calendar/Grid/Grid.js +2 -2
  27. package/esm/Calendar/Grid/GridRow.d.ts +8 -2
  28. package/esm/Calendar/Grid/GridRow.js +65 -29
  29. package/esm/Calendar/hooks/useCalendar.d.ts +0 -1
  30. package/esm/Navbar/Navbar.d.ts +5 -1
  31. package/esm/Navbar/Navbar.js +4 -3
  32. package/esm/Navbar/NavbarContent.d.ts +8 -3
  33. package/esm/Navbar/NavbarContent.js +29 -5
  34. package/esm/internals/utils/date/getWeekStartDates.d.ts +4 -3
  35. package/esm/internals/utils/date/getWeekStartDates.js +9 -4
  36. package/esm/internals/utils/date/plainDate.d.ts +7 -0
  37. package/esm/internals/utils/date/plainDate.js +24 -2
  38. package/esm/internals/utils/date/types.d.ts +9 -0
  39. package/esm/internals/utils/date/types.js +6 -0
  40. package/package.json +1 -1
@@ -33,7 +33,10 @@ const CalendarBody = forwardRef((props, ref) => {
33
33
  ref: ref,
34
34
  className: classes
35
35
  }), /*#__PURE__*/React.createElement(Grid, {
36
- rows: getWeekStartDates(thisMonthDate, {
36
+ rows: getWeekStartDates({
37
+ year: date.getFullYear(),
38
+ month: date.getMonth() + 1
39
+ }, {
37
40
  weekStart,
38
41
  locale: locale === null || locale === void 0 ? void 0 : locale.dateLocale
39
42
  }),
@@ -9,7 +9,7 @@ import CalendarBody from "./CalendarBody.js";
9
9
  import CalendarHeader from "./CalendarHeader.js";
10
10
  import { useStyles, useEventCallback } from "../internals/hooks/index.js";
11
11
  import { forwardRef } from "../internals/utils/index.js";
12
- import { startOfToday, disableTime, isSameMonth, calendarOnlyProps, omitHideDisabledProps, DateMode, useDateMode, isValid } from "../internals/utils/date/index.js";
12
+ import { startOfToday, disableTime, calendarOnlyProps, omitHideDisabledProps, DateMode, useDateMode, isValid } from "../internals/utils/date/index.js";
13
13
  import { CalendarProvider } from "./CalendarProvider.js";
14
14
  import { useCalendarState, CalendarState } from "./hooks/index.js";
15
15
  const CalendarContainer = forwardRef((props, ref) => {
@@ -82,7 +82,6 @@ const CalendarContainer = forwardRef((props, ref) => {
82
82
  } = useDateMode(format);
83
83
  const timeMode = calendarState === CalendarState.TIME || mode === DateMode.Time;
84
84
  const monthMode = calendarState === CalendarState.MONTH || mode === DateMode.Month;
85
- const inSameThisMonthDate = date => isSameMonth(calendarDate, date);
86
85
  const calendarClasses = merge(className, withPrefix({
87
86
  'time-view': timeMode,
88
87
  'month-view': monthMode,
@@ -108,7 +107,6 @@ const CalendarContainer = forwardRef((props, ref) => {
108
107
  monthDropdownProps,
109
108
  cellClassName,
110
109
  disabledDate: isDateDisabled,
111
- inSameMonth: inSameThisMonthDate,
112
110
  onChangeMonth: handleChangeMonth,
113
111
  onChangeTime,
114
112
  onMouseMove,
@@ -55,12 +55,6 @@ export interface CalendarInnerContextValue {
55
55
  * @returns True if the date is disabled, false otherwise.
56
56
  */
57
57
  disabledDate?: (date: Date, selectRangeValue?: Date[], type?: string) => boolean;
58
- /**
59
- * A function that determines if a date is in the same month as the current date in the calendar.
60
- * @param date - The date to check.
61
- * @returns True if the date is in the same month, false otherwise.
62
- */
63
- inSameMonth?: (date: Date) => boolean;
64
58
  /**
65
59
  * A callback function that is called when the month is changed in the calendar.
66
60
  * @param nextPageDate - The next page date.
@@ -1,6 +1,7 @@
1
1
  import { WithAsProps } from '../../internals/types';
2
+ import type { PlainDate } from '../../internals/utils/date';
2
3
  export interface GridProps extends WithAsProps {
3
- rows: any[];
4
+ rows: readonly PlainDate[];
4
5
  }
5
6
  declare const Grid: import("../../internals/types").InternalRefForwardingComponent<"div", GridProps, never> & Record<string, never>;
6
7
  export default Grid;
@@ -29,9 +29,9 @@ const Grid = forwardRef((props, ref) => {
29
29
  }, rest, {
30
30
  ref: ref,
31
31
  className: classes
32
- }), /*#__PURE__*/React.createElement(GridHeaderRow, null), rows.map((week, index) => /*#__PURE__*/React.createElement(GridRow, {
32
+ }), /*#__PURE__*/React.createElement(GridHeaderRow, null), rows.map((rowStartingDate, index) => /*#__PURE__*/React.createElement(GridRow, {
33
33
  key: index,
34
- weekendDate: week,
34
+ startingDate: rowStartingDate,
35
35
  rowIndex: index + 1
36
36
  })));
37
37
  });
@@ -1,7 +1,13 @@
1
+ import { type PlainDate } from '../../internals/utils/date';
1
2
  import { WithAsProps } from '../../internals/types';
3
+ /**
4
+ * A row in the calendar month view grid, i.e. a week of days.
5
+ */
2
6
  export interface GridRowProps extends WithAsProps {
3
- /** The weekend: Sunday */
4
- weekendDate?: Date;
7
+ /**
8
+ * The starting day of the row of dates.
9
+ */
10
+ startingDate: PlainDate;
5
11
  /** The index of the row */
6
12
  rowIndex?: number;
7
13
  }
@@ -3,17 +3,23 @@ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import React, { useCallback } from 'react';
4
4
  import GridCell from "./GridCell.js";
5
5
  import { forwardRef } from "../../internals/utils/index.js";
6
- import { isSameDay, addDays, isBefore, isAfter, format } from "../../internals/utils/date/index.js";
6
+ import { format } from "../../internals/utils/date/index.js";
7
7
  import { DATERANGE_DISABLED_TARGET } from "../../internals/constants/index.js";
8
8
  import { useStyles } from "../../internals/hooks/index.js";
9
9
  import { useCalendar } from "../hooks/index.js";
10
+ import { addDays, compare, isSameDay } from "../../internals/utils/date/plainDate.js";
11
+
12
+ /**
13
+ * A row in the calendar month view grid, i.e. a week of days.
14
+ */
15
+
10
16
  const GridRow = forwardRef((props, ref) => {
11
17
  var _locale$dateLocale$op, _locale$dateLocale;
12
18
  const {
13
19
  as: Component = 'div',
14
20
  className,
15
21
  classPrefix = 'calendar-table',
16
- weekendDate = new Date(),
22
+ startingDate,
17
23
  rowIndex,
18
24
  ...rest
19
25
  } = props;
@@ -25,7 +31,6 @@ const GridRow = forwardRef((props, ref) => {
25
31
  weekStart,
26
32
  showWeekNumbers,
27
33
  locale,
28
- inSameMonth,
29
34
  disabledDate,
30
35
  onSelect
31
36
  } = useCalendar();
@@ -41,53 +46,84 @@ const GridRow = forwardRef((props, ref) => {
41
46
  }, [onSelect]);
42
47
  const renderDays = () => {
43
48
  const days = [];
44
- const [selectedStartDate, selectedEndDate] = dateRange || [];
45
- const [hoverStartDate, hoverEndDate] = hoverRangeValue !== null && hoverRangeValue !== void 0 ? hoverRangeValue : [];
49
+ // The start and end dates of the range selection
50
+ // Note that they can be
51
+ // - Invalid date - when the user is inputting the date with text input
52
+ // - undefined - when the range selection isn't completed
53
+ const [selectedStartDateJS, selectedEndDateJS] = dateRange || [];
54
+ const [hoverStartDateJS, hoverEndDateJS] = hoverRangeValue !== null && hoverRangeValue !== void 0 ? hoverRangeValue : [];
46
55
  const isRangeSelectionMode = typeof dateRange !== 'undefined';
47
56
  for (let i = 0; i < 7; i += 1) {
48
- const thisDate = addDays(weekendDate, i);
49
- const disabled = disabledDate === null || disabledDate === void 0 ? void 0 : disabledDate(thisDate, dateRange, DATERANGE_DISABLED_TARGET.CALENDAR);
50
- const unSameMonth = !(inSameMonth !== null && inSameMonth !== void 0 && inSameMonth(thisDate));
51
- const rangeStart = !unSameMonth && selectedStartDate && isSameDay(thisDate, selectedStartDate);
52
- const rangeEnd = !unSameMonth && selectedEndDate && isSameDay(thisDate, selectedEndDate);
53
- const isSelected = isRangeSelectionMode ? rangeStart || rangeEnd : isSameDay(thisDate, selected);
57
+ const thisDate = addDays(startingDate, i);
58
+ const thisDateJS = new Date(thisDate.year, thisDate.month - 1, thisDate.day);
59
+ const disabled = disabledDate === null || disabledDate === void 0 ? void 0 : disabledDate(thisDateJS, dateRange, DATERANGE_DISABLED_TARGET.CALENDAR);
60
+
61
+ // Whether this date is in a different month from the selected date
62
+ const isSameMonth = selected.getFullYear() === thisDate.year && selected.getMonth() + 1 === thisDate.month;
63
+
64
+ // Whether this date is the range start date and is in the same month with the selected date
65
+ const isRangeStart = isSameMonth && selectedStartDateJS && isSameDay(thisDate, selectedStartDateJS);
66
+
67
+ // Whether this date is the range end date and is in the same month with the selected date
68
+ const isRangeEnd = isSameMonth && selectedEndDateJS && isSameDay(thisDate, selectedEndDateJS);
69
+
70
+ // Whether this date should be displayed in the "selected" state
71
+ // Either
72
+ // - In range selection mode, it's either the range start or end date
73
+ // - Otherwise, it's the selected date itself
74
+ const isSelected = isRangeSelectionMode ? isRangeStart || isRangeEnd : isSameDay(thisDate, selected);
54
75
 
55
76
  // TODO-Doma Move those logic that's for DatePicker/DateRangePicker to a separate component
56
77
  // Calendar is not supposed to be reused this way
57
78
  let inRange = false;
58
79
  // for Selected
59
- if (selectedStartDate && selectedEndDate) {
60
- if (isBefore(thisDate, selectedEndDate) && isAfter(thisDate, selectedStartDate)) {
80
+ if (selectedStartDateJS && selectedEndDateJS) {
81
+ const selectedStartDate = {
82
+ year: selectedStartDateJS.getFullYear(),
83
+ month: selectedStartDateJS.getMonth() + 1,
84
+ day: selectedStartDateJS.getDate()
85
+ };
86
+ const selectedEndDate = {
87
+ year: selectedEndDateJS.getFullYear(),
88
+ month: selectedEndDateJS.getMonth() + 1,
89
+ day: selectedEndDateJS.getDate()
90
+ };
91
+ if (compare(thisDate, selectedEndDate) < 0 && compare(thisDate, selectedStartDate) > 0) {
61
92
  inRange = true;
62
93
  }
63
- if (isBefore(thisDate, selectedStartDate) && isAfter(thisDate, selectedEndDate)) {
94
+ if (compare(thisDate, selectedStartDate) < 0 && compare(thisDate, selectedEndDate) > 0) {
64
95
  inRange = true;
65
96
  }
66
97
  }
67
98
 
68
99
  // for Hovering
69
- if (!isSelected && hoverStartDate && hoverEndDate) {
70
- if (!isAfter(thisDate, hoverEndDate) && !isBefore(thisDate, hoverStartDate)) {
100
+ if (!isSelected && hoverStartDateJS && hoverEndDateJS) {
101
+ const hoverStartDate = {
102
+ year: hoverStartDateJS.getFullYear(),
103
+ month: hoverStartDateJS.getMonth() + 1,
104
+ day: hoverStartDateJS.getDate()
105
+ };
106
+ const hoverEndDate = {
107
+ year: hoverEndDateJS.getFullYear(),
108
+ month: hoverEndDateJS.getMonth() + 1,
109
+ day: hoverEndDateJS.getDate()
110
+ };
111
+ if (compare(thisDate, hoverEndDate) <= 0 && compare(thisDate, hoverStartDate) >= 0) {
71
112
  inRange = true;
72
113
  }
73
- if (!isAfter(thisDate, hoverStartDate) && !isBefore(thisDate, hoverEndDate)) {
114
+ if (compare(thisDate, hoverStartDate) <= 0 && compare(thisDate, hoverEndDate) >= 0) {
74
115
  inRange = true;
75
116
  }
76
117
  }
77
- const thisDatePlain = {
78
- year: thisDate.getFullYear(),
79
- month: thisDate.getMonth() + 1,
80
- day: thisDate.getDate()
81
- };
82
118
  days.push(/*#__PURE__*/React.createElement(GridCell, {
83
- key: format(thisDate, 'yyyy-MM-dd'),
84
- date: thisDatePlain,
119
+ key: format(thisDateJS, 'yyyy-MM-dd'),
120
+ date: thisDate,
85
121
  disabled: disabled,
86
122
  selected: isSelected,
87
123
  onSelect: handleSelect,
88
- unSameMonth: unSameMonth,
89
- rangeStart: rangeStart,
90
- rangeEnd: rangeEnd,
124
+ unSameMonth: !isSameMonth,
125
+ rangeStart: isRangeStart,
126
+ rangeEnd: isRangeEnd,
91
127
  inRange: inRange
92
128
  }));
93
129
  }
@@ -98,8 +134,8 @@ const GridRow = forwardRef((props, ref) => {
98
134
  firstWeekContainsDate
99
135
  } = (_locale$dateLocale$op = locale === null || locale === void 0 || (_locale$dateLocale = locale.dateLocale) === null || _locale$dateLocale === void 0 ? void 0 : _locale$dateLocale.options) !== null && _locale$dateLocale$op !== void 0 ? _locale$dateLocale$op : {};
100
136
  // ISO week starts on Monday
101
- const date = isoWeek ? addDays(weekendDate, 1) : weekendDate;
102
- const week = format(date, isoWeek ? 'I' : 'w', {
137
+ const date = isoWeek ? addDays(startingDate, 1) : startingDate;
138
+ const week = format(new Date(date.year, date.month - 1, date.day), isoWeek ? 'I' : 'w', {
103
139
  locale: locale === null || locale === void 0 ? void 0 : locale.dateLocale,
104
140
  firstWeekContainsDate,
105
141
  weekStartsOn: weekStart
@@ -9,7 +9,6 @@ export declare const useCalendar: () => {
9
9
  targetId?: string | undefined;
10
10
  monthDropdownProps?: import("../types").MonthDropdownProps | undefined;
11
11
  disabledDate?: ((date: Date, selectRangeValue?: Date[] | undefined, type?: string | undefined) => boolean) | undefined;
12
- inSameMonth?: ((date: Date) => boolean) | undefined;
13
12
  onChangeMonth?: ((nextPageDate: Date, event: import("react").MouseEvent<Element, MouseEvent>) => void) | undefined;
14
13
  onChangeTime?: ((nextPageTime: Date, event: import("react").MouseEvent<Element, MouseEvent>) => void) | undefined;
15
14
  onMouseMove?: ((date: Date) => void) | undefined;
@@ -5,6 +5,10 @@ export interface NavbarProps extends BoxProps {
5
5
  * The appearance style of the Navbar component.
6
6
  */
7
7
  appearance?: 'default' | 'inverse' | 'subtle';
8
+ /**
9
+ * The open state of the drawer.
10
+ */
11
+ drawerOpen?: boolean;
8
12
  /**
9
13
  * Callback when the drawer is opened or closed.
10
14
  */
@@ -16,7 +20,7 @@ export interface NavbarProps extends BoxProps {
16
20
  */
17
21
  declare const Navbar: import("../internals/types").InternalRefForwardingComponent<"div", NavbarProps, never> & {
18
22
  Brand: import("../internals/types").InternalRefForwardingComponent<"a", Partial<import("../internals/utils").ComponentProps>, never> & Record<string, never>;
19
- Content: import("../internals/types").InternalRefForwardingComponent<import("../internals/types").InternalRefForwardingComponent<"div", BoxProps, never> & Record<string, never>, Partial<import("./NavbarContent").NavbarContentProps>, never> & Record<string, never>;
23
+ Content: React.ForwardRefExoticComponent<import("./NavbarContent").NavbarContentProps & React.RefAttributes<any>>;
20
24
  Toggle: React.ForwardRefExoticComponent<import("./NavbarToggle").NavbarToggleProps & React.RefAttributes<any>>;
21
25
  Drawer: React.ForwardRefExoticComponent<import("..").DrawerProps & React.RefAttributes<any>>;
22
26
  };
@@ -1,13 +1,13 @@
1
1
  'use client';
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- import React, { useMemo, useState } from 'react';
3
+ import React, { useMemo } from 'react';
4
4
  import NavbarBrand from "./NavbarBrand.js";
5
5
  import NavbarContent from "./NavbarContent.js";
6
6
  import NavbarToggle from "./NavbarToggle.js";
7
7
  import NavbarDrawer from "./NavbarDrawer.js";
8
8
  import Box from "../internals/Box/index.js";
9
9
  import { forwardRef } from "../internals/utils/index.js";
10
- import { useStyles, useCustom, useEventCallback, useUniqueId } from "../internals/hooks/index.js";
10
+ import { useStyles, useCustom, useEventCallback, useUniqueId, useControlled } from "../internals/hooks/index.js";
11
11
  import { NavbarContext } from "./NavbarContext.js";
12
12
  const Subcomponents = {
13
13
  Brand: NavbarBrand,
@@ -29,6 +29,7 @@ const Navbar = forwardRef((props, ref) => {
29
29
  as = 'nav',
30
30
  classPrefix = 'navbar',
31
31
  appearance = 'default',
32
+ drawerOpen,
32
33
  onDrawerOpenChange,
33
34
  ...rest
34
35
  } = propsWithDefaults;
@@ -37,7 +38,7 @@ const Navbar = forwardRef((props, ref) => {
37
38
  merge
38
39
  } = useStyles(classPrefix);
39
40
  const classes = merge(className, withPrefix());
40
- const [open, setOpen] = useState(false);
41
+ const [open, setOpen] = useControlled(drawerOpen, false);
41
42
  const handleToggle = useEventCallback(nextOpen => {
42
43
  setOpen(nextOpen);
43
44
  onDrawerOpenChange === null || onDrawerOpenChange === void 0 || onDrawerOpenChange(nextOpen);
@@ -1,5 +1,10 @@
1
- import { ComponentProps } from '../internals/utils';
1
+ import React from 'react';
2
2
  import { BoxProps } from '../internals/Box';
3
- export type NavbarContentProps = ComponentProps & BoxProps;
4
- declare const NavbarContent: import("../internals/types").InternalRefForwardingComponent<import("../internals/types").InternalRefForwardingComponent<"div", BoxProps, never> & Record<string, never>, Partial<NavbarContentProps>, never> & Record<string, never>;
3
+ interface ChildProps {
4
+ onClose: () => void;
5
+ }
6
+ export interface NavbarContentProps extends Omit<BoxProps, 'children'> {
7
+ children?: React.ReactNode | (({ onClose }: ChildProps) => React.ReactNode);
8
+ }
9
+ declare const NavbarContent: React.ForwardRefExoticComponent<NavbarContentProps & React.RefAttributes<any>>;
5
10
  export default NavbarContent;
@@ -1,9 +1,33 @@
1
1
  'use client';
2
- import { createComponent } from "../internals/utils/index.js";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import React, { useCallback, useContext } from 'react';
3
4
  import Box from "../internals/Box/index.js";
4
- const NavbarContent = createComponent({
5
- name: 'NavbarContent',
6
- componentAs: Box,
7
- componentClassPrefix: 'navbar-content'
5
+ import { useStyles } from "../internals/hooks/index.js";
6
+ import { NavbarContext } from "./NavbarContext.js";
7
+ const NavbarContent = /*#__PURE__*/React.forwardRef((props, ref) => {
8
+ const {
9
+ className,
10
+ classPrefix = 'navbar-content',
11
+ children,
12
+ ...rest
13
+ } = props;
14
+ const {
15
+ onToggle
16
+ } = useContext(NavbarContext) || {};
17
+ const {
18
+ withPrefix,
19
+ merge
20
+ } = useStyles(classPrefix);
21
+ const classes = merge(className, withPrefix());
22
+ const onClose = useCallback(() => {
23
+ onToggle === null || onToggle === void 0 || onToggle(false);
24
+ }, [onToggle]);
25
+ return /*#__PURE__*/React.createElement(Box, _extends({
26
+ ref: ref,
27
+ className: classes
28
+ }, rest), typeof children === 'function' ? children({
29
+ onClose
30
+ }) : children);
8
31
  });
32
+ NavbarContent.displayName = 'NavbarContent';
9
33
  export default NavbarContent;
@@ -1,13 +1,14 @@
1
1
  import type { Locale } from 'date-fns';
2
+ import type { PlainDate, PlainYearMonth } from './types';
2
3
  /**
3
4
  * Get the first days of weeks in a month。
4
- * @param firstDayOfMonth The first day of the month
5
+ * @param month The month
5
6
  * @param options.weekStart the index of the first day of the week (0 - Sunday)
6
7
  * @param options.isoWeek Whether to use ISO week
7
8
  * @returns A list of first days of weeks in a month
8
9
  */
9
- export declare function getWeekStartDates(firstDayOfMonth: Date, options: {
10
+ export declare function getWeekStartDates(month: PlainYearMonth, options: {
10
11
  weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
11
12
  locale?: Locale;
12
- }): Date[];
13
+ }): PlainDate[];
13
14
  export default getWeekStartDates;
@@ -1,22 +1,27 @@
1
1
  'use client';
2
- import { addDays } from 'date-fns/addDays';
3
2
  import { startOfWeek } from 'date-fns/startOfWeek';
3
+ import { addDays } from "./plainDate.js";
4
4
  /**
5
5
  * Get the first days of weeks in a month。
6
- * @param firstDayOfMonth The first day of the month
6
+ * @param month The month
7
7
  * @param options.weekStart the index of the first day of the week (0 - Sunday)
8
8
  * @param options.isoWeek Whether to use ISO week
9
9
  * @returns A list of first days of weeks in a month
10
10
  */
11
- export function getWeekStartDates(firstDayOfMonth, options) {
11
+ export function getWeekStartDates(month, options) {
12
12
  const {
13
13
  weekStart,
14
14
  locale
15
15
  } = options;
16
- const firstDay = startOfWeek(firstDayOfMonth, {
16
+ const firstDayJs = startOfWeek(new Date(month.year, month.month - 1, 1), {
17
17
  weekStartsOn: weekStart,
18
18
  locale
19
19
  });
20
+ const firstDay = {
21
+ year: firstDayJs.getFullYear(),
22
+ month: firstDayJs.getMonth() + 1,
23
+ day: firstDayJs.getDate()
24
+ };
20
25
  const days = [firstDay];
21
26
  for (let i = 1; i < 6; i++) {
22
27
  days.push(addDays(firstDay, i * 7));
@@ -1,2 +1,9 @@
1
1
  import type { PlainDate } from './types';
2
+ /**
3
+ * Resembles the behavior of `Temporal.PlainDate.compare`.
4
+ *
5
+ * @see https://tc39.es/proposal-temporal/docs/plaindatetime.html#compare
6
+ */
7
+ export declare function compare(date1: PlainDate, date2: PlainDate): -1 | 0 | 1;
2
8
  export declare function isSameDay(date: PlainDate, jsDate: Date): boolean;
9
+ export declare function addDays(date: PlainDate, days: number): PlainDate;
@@ -6,7 +6,13 @@ function toPlainDate(date) {
6
6
  day: date.getDate()
7
7
  };
8
8
  }
9
- function comparePlainDates(date1, date2) {
9
+
10
+ /**
11
+ * Resembles the behavior of `Temporal.PlainDate.compare`.
12
+ *
13
+ * @see https://tc39.es/proposal-temporal/docs/plaindatetime.html#compare
14
+ */
15
+ export function compare(date1, date2) {
10
16
  if (date1.year < date2.year) return -1;
11
17
  if (date1.year > date2.year) return 1;
12
18
  if (date1.month < date2.month) return -1;
@@ -15,6 +21,22 @@ function comparePlainDates(date1, date2) {
15
21
  if (date1.day > date2.day) return 1;
16
22
  return 0;
17
23
  }
24
+
25
+ /**
26
+ * Resembles the behavior of `Temporal.PlainDate.prototype.equals`.
27
+ *
28
+ * @see https://tc39.es/proposal-temporal/docs/plaindatetime.html#equals
29
+ */
30
+ function equals(date1, date2) {
31
+ return compare(date1, date2) === 0;
32
+ }
18
33
  export function isSameDay(date, jsDate) {
19
- return comparePlainDates(date, toPlainDate(jsDate)) === 0;
34
+ // If jsDate is an invalid date, always return false
35
+ if (Number.isNaN(jsDate.valueOf())) return false;
36
+ return equals(date, toPlainDate(jsDate));
37
+ }
38
+ export function addDays(date, days) {
39
+ const jsDate = new Date(date.year, date.month - 1, date.day);
40
+ jsDate.setDate(jsDate.getDate() + days);
41
+ return toPlainDate(jsDate);
20
42
  }
@@ -75,3 +75,12 @@ export type PlainDate = {
75
75
  readonly month: number;
76
76
  readonly day: number;
77
77
  };
78
+ /**
79
+ * Resembles Temporal.PlainYearMonth
80
+ *
81
+ * @see https://tc39.es/proposal-temporal/docs/plainyearmonth.html
82
+ */
83
+ export type PlainYearMonth = {
84
+ readonly year: number;
85
+ readonly month: number;
86
+ };
@@ -18,4 +18,10 @@ export const calendarOnlyProps = [TimeProp.DisabledHours, TimeProp.DisabledMinut
18
18
  *
19
19
  * Resembles Temporal.PlainDate
20
20
  * @see https://tc39.es/proposal-temporal/docs/plaindate.html
21
+ */
22
+
23
+ /**
24
+ * Resembles Temporal.PlainYearMonth
25
+ *
26
+ * @see https://tc39.es/proposal-temporal/docs/plainyearmonth.html
21
27
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "6.0.0-canary-20250827",
3
+ "version": "6.0.0-canary-20250904",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",