reshaped 3.9.0-canary.3 → 3.9.0-canary.4

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.
@@ -24,6 +24,8 @@ export type BaseProps = {
24
24
  firstWeekDay?: number;
25
25
  /** Dates that are selected */
26
26
  selectedDates?: Date[];
27
+ /** Dates that are disabled */
28
+ disabledDates?: Date[];
27
29
  /** Render a custom weekday label, can be used for localization */
28
30
  renderWeekDay?: (args: {
29
31
  weekDay: number;
@@ -121,7 +123,7 @@ export type MonthProps = {
121
123
  hoveredDate: Date | null;
122
124
  onDateHover: (date: Date) => void;
123
125
  onDateHoverEnd: (date: Date) => void;
124
- } & Pick<BaseProps, "max" | "min" | "firstWeekDay" | "selectedDates" | "renderMonthLabel" | "renderWeekDay" | "renderSelectedMonthLabel" | "renderDateAriaLabel" | "renderDateSlot"> & Pick<ControlledProps, "value" | "onChange" | "range">;
126
+ } & Pick<BaseProps, "max" | "min" | "firstWeekDay" | "selectedDates" | "disabledDates" | "renderMonthLabel" | "renderWeekDay" | "renderSelectedMonthLabel" | "renderDateAriaLabel" | "renderDateSlot"> & Pick<ControlledProps, "value" | "onChange" | "range">;
125
127
  export type YearProps = {
126
128
  monthDate: Date;
127
129
  onMonthClick: (month: number) => void;
@@ -136,7 +138,7 @@ export type DateProps = {
136
138
  renderAriaLabel?: MonthProps["renderDateAriaLabel"];
137
139
  renderSlot?: MonthProps["renderDateSlot"];
138
140
  onDateFocus: (date: Date) => void;
139
- } & Pick<MonthProps, "hoveredDate" | "onDateHover" | "onDateHoverEnd" | "onChange" | "range" | "min" | "max" | "selectedDates">;
141
+ } & Pick<MonthProps, "hoveredDate" | "onDateHover" | "onDateHoverEnd" | "onChange" | "range" | "min" | "max" | "selectedDates" | "disabledDates">;
140
142
  export type ControlsProps = {
141
143
  selectionMode: SelectionMode;
142
144
  monthsToRender: number;
@@ -9,7 +9,7 @@ import CalendarMonth from "./CalendarMonth.js";
9
9
  import CalendarYear from "./CalendarYear.js";
10
10
  import useCalendarKeyboardNavigation from "./useCalendarKeyboardNavigation.js";
11
11
  const CalendarControlled = (props) => {
12
- const { value, onChange, defaultMonth, month, onMonthChange, min, max, range, firstWeekDay, selectedDates, monthsToRender = 1, renderMonthLabel, renderSelectedMonthLabel, renderWeekDay, previousMonthAriaLabel, previousYearAriaLabel, nextMonthAriaLabel, nextYearAriaLabel, monthSelectionAriaLabel, renderMonthAriaLabel, renderDateAriaLabel, renderDateSlot, } = props;
12
+ const { value, onChange, defaultMonth, month, onMonthChange, min, max, range, firstWeekDay, selectedDates, disabledDates, monthsToRender = 1, renderMonthLabel, renderSelectedMonthLabel, renderWeekDay, previousMonthAriaLabel, previousYearAriaLabel, nextMonthAriaLabel, nextYearAriaLabel, monthSelectionAriaLabel, renderMonthAriaLabel, renderDateAriaLabel, renderDateSlot, } = props;
13
13
  const [selectionMode, setSelectionMode] = React.useState("date");
14
14
  const [monthDate, setMonthDate] = React.useState(month || defaultMonth || new Date());
15
15
  const [hoveredDate, setHoveredDate] = React.useState(null);
@@ -97,7 +97,7 @@ const CalendarControlled = (props) => {
97
97
  Array.from({ length: monthsToRender }).map((_, index) => {
98
98
  const currentMonthDate = new Date(monthDate);
99
99
  currentMonthDate.setMonth(currentMonthDate.getMonth() + index);
100
- return (_jsx(View.Item, { grow: true, children: _jsx(CalendarMonth, { date: currentMonthDate, value: value, onChange: onChange, min: min, max: max, range: range, firstWeekDay: firstWeekDay, hoveredDate: hoveredDate, selectedDates: selectedDates, onDateHover: handleDateHover, onDateHoverEnd: handleDateHoverEnd, renderWeekDay: renderWeekDay, renderDateAriaLabel: renderDateAriaLabel, renderDateSlot: renderDateSlot }) }, index));
100
+ return (_jsx(View.Item, { grow: true, children: _jsx(CalendarMonth, { date: currentMonthDate, value: value, onChange: onChange, min: min, max: max, range: range, firstWeekDay: firstWeekDay, hoveredDate: hoveredDate, selectedDates: selectedDates, disabledDates: disabledDates, onDateHover: handleDateHover, onDateHoverEnd: handleDateHoverEnd, renderWeekDay: renderWeekDay, renderDateAriaLabel: renderDateAriaLabel, renderDateSlot: renderDateSlot }) }, index));
101
101
  }), selectionMode === "month" && (_jsx(CalendarYear, { monthDate: monthDate, onMonthClick: handleMonthClick, renderMonthLabel: renderMonthLabel, renderMonthAriaLabel: renderMonthAriaLabel, min: min, max: max }))] })] }));
102
102
  };
103
103
  CalendarControlled.displayName = "CalendarControlled";
@@ -5,17 +5,19 @@ import { classNames } from "../../utilities/props.js";
5
5
  import s from "./Calendar.module.css";
6
6
  import { getLocalISODate } from "./Calendar.utils.js";
7
7
  const CalendarDate = (props) => {
8
- const { date, isoDate, startValue, endValue, disabled, focusable, onChange, range, hoveredDate, onDateHover, onDateHoverEnd, onDateFocus, selectedDates, renderAriaLabel, renderSlot, } = props;
8
+ const { date, isoDate, startValue, endValue, disabled: passedDisabled, focusable, onChange, range, hoveredDate, onDateHover, onDateHoverEnd, onDateFocus, selectedDates, disabledDates, renderAriaLabel, renderSlot, } = props;
9
9
  if (!date)
10
10
  return _jsx("td", { className: s.cell, "aria-hidden": "true" });
11
11
  const isoStartValue = startValue && getLocalISODate({ date: startValue });
12
12
  const isoEndValue = endValue && getLocalISODate({ date: endValue });
13
- const isStartValue = !!isoDate && !!isoStartValue && isoDate === isoStartValue;
14
- const isEndValue = !!isoDate && !!isoEndValue && isoDate === isoEndValue;
15
- const isAfterStartValue = startValue && date > startValue;
16
- const isBeforeEndValue = endValue && date < endValue;
17
- const isInHoveredRange = hoveredDate && !endValue && hoveredDate > date;
18
- const isInSelectedDates = !!selectedDates?.find((selectedDate) => getLocalISODate({ date: selectedDate }) === isoDate);
13
+ const isStartValue = Boolean(isoDate && !!isoStartValue && isoDate === isoStartValue);
14
+ const isEndValue = Boolean(isoDate && !!isoEndValue && isoDate === isoEndValue);
15
+ const isAfterStartValue = Boolean(isoDate && isoStartValue && isoDate > isoStartValue);
16
+ const isBeforeEndValue = Boolean(isoDate && isoEndValue && isoDate < isoEndValue);
17
+ const isInHoveredRange = Boolean(hoveredDate && !endValue && hoveredDate > date);
18
+ const isInSelectedDates = !!selectedDates?.some((selectedDate) => getLocalISODate({ date: selectedDate }) === isoDate);
19
+ const disabled = passedDisabled ||
20
+ disabledDates?.some((disabledDate) => getLocalISODate({ date: disabledDate }) === isoDate);
19
21
  let selection;
20
22
  switch (true) {
21
23
  case isAfterStartValue && isInHoveredRange:
@@ -5,7 +5,7 @@ import s from "./Calendar.module.css";
5
5
  import { getMonthWeeks, getWeekdayNames, getLocalISODate, isDateFocusable } from "./Calendar.utils.js";
6
6
  import CalendarDate from "./CalendarDate.js";
7
7
  const CalendarMonth = (props) => {
8
- const { date, value, onChange, min, max, range, firstWeekDay, selectedDates, hoveredDate, onDateHover, onDateHoverEnd, renderWeekDay, renderDateAriaLabel, renderDateSlot, } = props;
8
+ const { date, value, onChange, min, max, range, firstWeekDay, selectedDates, disabledDates, hoveredDate, onDateHover, onDateHoverEnd, renderWeekDay, renderDateAriaLabel, renderDateSlot, } = props;
9
9
  let foundFocusableDate = false;
10
10
  const [lastFocusedDate, setLastFocusedDate] = useState();
11
11
  const month = date.getMonth();
@@ -26,7 +26,7 @@ const CalendarMonth = (props) => {
26
26
  // eslint-disable-next-line react-hooks/immutability
27
27
  if (focusable)
28
28
  foundFocusableDate = true;
29
- return (_jsx(CalendarDate, { date: date, isoDate: isoDate, disabled: disabled, range: range, focusable: focusable, startValue: startValue, endValue: endValue, onChange: onChange, hoveredDate: hoveredDate, onDateHover: onDateHover, onDateHoverEnd: onDateHoverEnd, onDateFocus: setLastFocusedDate, renderAriaLabel: renderDateAriaLabel, selectedDates: selectedDates, renderSlot: renderDateSlot }, index));
29
+ return (_jsx(CalendarDate, { date: date, isoDate: isoDate, disabled: disabled, range: range, focusable: focusable, startValue: startValue, endValue: endValue, onChange: onChange, hoveredDate: hoveredDate, onDateHover: onDateHover, onDateHoverEnd: onDateHoverEnd, onDateFocus: setLastFocusedDate, renderAriaLabel: renderDateAriaLabel, selectedDates: selectedDates, disabledDates: disabledDates, renderSlot: renderDateSlot }, index));
30
30
  }) }, key));
31
31
  }) })] }));
32
32
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reshaped",
3
3
  "description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
4
- "version": "3.9.0-canary.3",
4
+ "version": "3.9.0-canary.4",
5
5
  "license": "MIT",
6
6
  "email": "hello@reshaped.so",
7
7
  "homepage": "https://reshaped.so",