@patternfly/react-core 4.200.2 → 4.201.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.200.2",
3
+ "version": "4.201.0",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -34,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.51.2",
38
- "@patternfly/react-styles": "^4.50.2",
39
- "@patternfly/react-tokens": "^4.52.2",
37
+ "@patternfly/react-icons": "^4.52.0",
38
+ "@patternfly/react-styles": "^4.51.0",
39
+ "@patternfly/react-tokens": "^4.53.0",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "78e64c6891ebd263e6c35a9d70d95759aba3c7ad"
63
+ "gitHead": "0d60b35858f995deab44e2ede3e013114e495b5e"
64
64
  }
@@ -45,7 +45,7 @@ export interface CalendarFormat {
45
45
 
46
46
  export interface CalendarProps extends CalendarFormat, Omit<React.HTMLProps<HTMLDivElement>, 'onChange'> {
47
47
  /** Month/year to base other dates around */
48
- date: Date;
48
+ date?: Date;
49
49
  /** Callback when date is selected */
50
50
  onChange?: (date: Date) => void;
51
51
  /** Functions that returns if a date is valid and selectable */
@@ -60,8 +60,8 @@ export interface CalendarProps extends CalendarFormat, Omit<React.HTMLProps<HTML
60
60
  const yearFormat = (date: Date) => date.getFullYear();
61
61
 
62
62
  const buildCalendar = (year: number, month: number, weekStart: number, validators: ((date: Date) => boolean)[]) => {
63
- const selectedDate = new Date(year, month);
64
- const firstDayOfWeek = new Date(selectedDate);
63
+ const defaultDate = new Date(year, month);
64
+ const firstDayOfWeek = new Date(defaultDate);
65
65
  firstDayOfWeek.setDate(firstDayOfWeek.getDate() - firstDayOfWeek.getDay() + weekStart);
66
66
  // We will always show 6 weeks like google calendar
67
67
  // Assume we just want the numbers for now...
@@ -90,7 +90,7 @@ export const isValidDate = (date: Date) => Boolean(date && !isNaN(date as any));
90
90
  const today = new Date();
91
91
 
92
92
  export const CalendarMonth = ({
93
- date: dateProp = today,
93
+ date: dateProp,
94
94
  locale = undefined,
95
95
  monthFormat = date => date.toLocaleDateString(locale, { month: 'long' }),
96
96
  weekdayFormat = date => date.toLocaleDateString(locale, { weekday: 'narrow' }),
@@ -110,6 +110,7 @@ export const CalendarMonth = ({
110
110
  }: CalendarProps) => {
111
111
  const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(monthNum => new Date(1990, monthNum)).map(monthFormat);
112
112
  const [isSelectOpen, setIsSelectOpen] = React.useState(false);
113
+ const [selectedDate, setSelectedDate] = React.useState(new Date(dateProp));
113
114
  // eslint-disable-next-line prefer-const
114
115
  let [focusedDate, setFocusedDate] = React.useState(new Date(dateProp));
115
116
  if (!isValidDate(focusedDate)) {
@@ -118,7 +119,7 @@ export const CalendarMonth = ({
118
119
  const [hoveredDate, setHoveredDate] = React.useState(new Date(focusedDate));
119
120
  const focusRef = React.useRef<HTMLButtonElement>();
120
121
  const [hiddenMonthId] = React.useState(getUniqueId('hidden-month-span'));
121
- const [shouldFocus, setShouldFocus] = React.useState(true);
122
+ const [shouldFocus, setShouldFocus] = React.useState(false);
122
123
 
123
124
  const isValidated = (date: Date) => validators.every(validator => validator(date));
124
125
  const focusedDateValidated = isValidated(focusedDate);
@@ -126,7 +127,8 @@ export const CalendarMonth = ({
126
127
  if (!(isValidDate(dateProp) && isSameDate(focusedDate, dateProp))) {
127
128
  setFocusedDate(dateProp);
128
129
  }
129
- }, [dateProp, focusedDate]);
130
+ }, [dateProp]);
131
+
130
132
  useEffect(() => {
131
133
  // When using header controls don't move focus
132
134
  if (shouldFocus) {
@@ -136,7 +138,7 @@ export const CalendarMonth = ({
136
138
  } else {
137
139
  setShouldFocus(true);
138
140
  }
139
- }, [focusedDate, focusedDateValidated, shouldFocus]);
141
+ }, [focusedDate]);
140
142
 
141
143
  const onMonthClick = (newDate: Date) => {
142
144
  setFocusedDate(newDate);
@@ -275,7 +277,7 @@ export const CalendarMonth = ({
275
277
  {week.map(({ date, isValid }, index) => {
276
278
  const dayFormatted = dayFormat(date);
277
279
  const isToday = isSameDate(date, today);
278
- const isSelected = isValidDate(dateProp) && isSameDate(date, dateProp);
280
+ const isSelected = isValidDate(selectedDate) && isSameDate(date, selectedDate);
279
281
  const isFocused = isSameDate(date, focusedDate);
280
282
  const isAdjacentMonth = date.getMonth() !== focusedDate.getMonth();
281
283
  let isInRange = false;
@@ -312,7 +314,11 @@ export const CalendarMonth = ({
312
314
  !isValid && styles.modifiers.disabled
313
315
  )}
314
316
  type="button"
315
- onClick={() => onChange(date)}
317
+ onClick={() => {
318
+ setSelectedDate(date);
319
+ setFocusedDate(date);
320
+ onChange(date);
321
+ }}
316
322
  onMouseOver={() => setHoveredDate(date)}
317
323
  tabIndex={isFocused ? 0 : -1}
318
324
  disabled={!isValid}