grommet 2.25.0 → 2.25.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 (47) hide show
  1. package/components/Calendar/Calendar.js +232 -292
  2. package/components/Calendar/utils.js +16 -129
  3. package/components/Chart/calcs.js +44 -27
  4. package/components/Chart/stories/Scan.js +11 -9
  5. package/components/Chart/stories/data.js +16 -17
  6. package/components/CheckBox/CheckBox.js +3 -2
  7. package/components/DataChart/DataChart.js +3 -15
  8. package/components/DataChart/Detail.js +18 -11
  9. package/components/DataChart/stories/Pad.js +54 -0
  10. package/components/DateInput/DateInput.js +60 -68
  11. package/components/DateInput/utils.js +30 -5
  12. package/components/FileInput/FileInput.js +2 -1
  13. package/components/FileInput/StyledFileInput.js +1 -1
  14. package/components/Form/Form.js +6 -1
  15. package/components/FormField/FormField.js +25 -28
  16. package/components/Image/Image.js +4 -2
  17. package/components/Menu/index.d.ts +2 -2
  18. package/components/Select/SelectContainer.js +24 -36
  19. package/components/Tabs/Tabs.js +2 -1
  20. package/components/Video/StyledVideo.js +2 -2
  21. package/es6/components/Calendar/Calendar.js +230 -292
  22. package/es6/components/Calendar/utils.js +13 -114
  23. package/es6/components/Chart/calcs.js +44 -27
  24. package/es6/components/Chart/stories/Scan.js +10 -9
  25. package/es6/components/Chart/stories/data.js +16 -17
  26. package/es6/components/CheckBox/CheckBox.js +3 -2
  27. package/es6/components/DataChart/DataChart.js +4 -15
  28. package/es6/components/DataChart/Detail.js +20 -10
  29. package/es6/components/DataChart/stories/Pad.js +42 -0
  30. package/es6/components/DateInput/DateInput.js +57 -64
  31. package/es6/components/DateInput/utils.js +29 -7
  32. package/es6/components/FileInput/FileInput.js +2 -1
  33. package/es6/components/FileInput/StyledFileInput.js +1 -1
  34. package/es6/components/Form/Form.js +6 -1
  35. package/es6/components/FormField/FormField.js +25 -29
  36. package/es6/components/Image/Image.js +4 -2
  37. package/es6/components/Menu/index.d.ts +2 -2
  38. package/es6/components/Select/SelectContainer.js +25 -37
  39. package/es6/components/Tabs/Tabs.js +2 -1
  40. package/es6/components/Video/StyledVideo.js +2 -2
  41. package/es6/themes/base.d.ts +13 -27
  42. package/es6/themes/base.js +6 -1
  43. package/grommet.min.js +1 -1
  44. package/grommet.min.js.map +1 -1
  45. package/package.json +44 -42
  46. package/themes/base.d.ts +13 -27
  47. package/themes/base.js +6 -1
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.Calendar = void 0;
4
+ exports.getOutputFormat = exports.Calendar = void 0;
5
5
 
6
6
  var _react = _interopRequireWildcard(require("react"));
7
7
 
@@ -27,7 +27,7 @@ var _utils = require("./utils");
27
27
 
28
28
  var _propTypes = require("./propTypes");
29
29
 
30
- var _excluded = ["activeDate", "animate", "bounds", "children", "date", "dates", "daysOfWeek", "disabled", "initialFocus", "fill", "firstDayOfWeek", "header", "locale", "messages", "normalize", "onReference", "onSelect", "range", "reference", "showAdjacentDays", "size", "timestamp"];
30
+ var _excluded = ["activeDate", "animate", "bounds", "children", "date", "dates", "daysOfWeek", "disabled", "initialFocus", "fill", "firstDayOfWeek", "header", "locale", "messages", "onReference", "onSelect", "range", "reference", "showAdjacentDays", "size", "timestamp"];
31
31
 
32
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
33
 
@@ -42,113 +42,125 @@ var headingPadMap = {
42
42
  medium: 'small',
43
43
  large: 'medium'
44
44
  };
45
- var activeDates = {
46
- start: 'start',
47
- end: 'end'
45
+
46
+ var getLocaleString = function getLocaleString(value, locale) {
47
+ return value == null ? void 0 : value.toLocaleDateString(locale, {
48
+ month: 'long',
49
+ day: 'numeric',
50
+ year: 'numeric'
51
+ });
48
52
  };
49
53
 
50
- var formatSelectedDatesString = function formatSelectedDatesString(date, normalize) {
51
- return "Currently selected\n " + (date == null ? void 0 : date.map(function (item) {
52
- var dates;
54
+ var currentlySelectedString = function currentlySelectedString(value, locale) {
55
+ var selected;
53
56
 
54
- if (!Array.isArray(item)) {
55
- dates = (0, _utils.formatToLocalYYYYMMDD)(item, normalize) + " ";
56
- } else {
57
- var start = item[0] !== undefined ? (0, _utils.formatToLocalYYYYMMDD)(item[0], normalize) : 'none';
58
- var end = item[1] !== undefined ? (0, _utils.formatToLocalYYYYMMDD)(item[1], normalize) : 'none';
59
- dates = start + " through " + end;
60
- }
57
+ if (value instanceof Date) {
58
+ selected = "Currently selected " + getLocaleString(value, locale) + ";";
59
+ } else if (value != null && value.length) {
60
+ selected = "Currently selected " + value.map(function (item) {
61
+ var dates;
61
62
 
62
- return dates;
63
- }));
64
- };
63
+ if (!Array.isArray(item)) {
64
+ dates = "" + getLocaleString(item, locale);
65
+ } else {
66
+ var start = item[0] !== undefined ? getLocaleString(item[0], locale) : 'none';
67
+ var end = item[1] !== undefined ? getLocaleString(item[1], locale) : 'none';
68
+ dates = start + " through " + end;
69
+ }
65
70
 
66
- var getAccessibilityString = function getAccessibilityString(date, dates, normalize) {
67
- if (date && !Array.isArray(date)) {
68
- return "Currently selected " + (0, _utils.formatToLocalYYYYMMDD)(date, normalize) + ";";
71
+ return dates;
72
+ });
73
+ } else {
74
+ selected = 'No date selected';
69
75
  }
70
76
 
71
- if (date && Array.isArray(date)) {
72
- return formatSelectedDatesString(date, normalize);
73
- }
77
+ return selected;
78
+ }; // calendar value may be a single date, multiple dates, a range of dates
79
+ // supplied as ISOstrings.
74
80
 
75
- if (dates != null && dates.length) {
76
- return formatSelectedDatesString(dates, normalize);
77
- }
78
81
 
79
- return 'No date selected';
80
- }; // function that runs inside the useEffect for date and dates
82
+ var normalizeInput = function normalizeInput(dateValue) {
83
+ var result;
81
84
 
85
+ if (dateValue instanceof Date) {
86
+ result = dateValue;
87
+ } // date may be an empty string ''
88
+ else if (typeof dateValue === 'string' && dateValue.length) {
89
+ var adjustedDate = new Date(dateValue); // if time is not specified in ISOstring, normalize to midnight
82
90
 
83
- var normalizeDate = function normalizeDate(dateValue, timestamp, normalize) {
84
- if (typeof dateValue === 'string') {
85
- return (0, _utils.normalizeForTimezone)(dateValue, timestamp, normalize);
91
+ if (dateValue.indexOf('T') === -1) {
92
+ var offset = adjustedDate.getTimezoneOffset();
93
+ var hour = adjustedDate.getHours();
94
+ adjustedDate.setHours(hour, offset);
95
+ }
96
+
97
+ result = adjustedDate;
98
+ } else if (Array.isArray(dateValue)) {
99
+ result = dateValue.map(function (d) {
100
+ return normalizeInput(d);
101
+ });
86
102
  }
87
103
 
88
- if (Array.isArray(dateValue)) {
89
- if (Array.isArray(dateValue[0])) {
90
- var _dateValue$0$map = dateValue[0].map(function (day) {
91
- return (0, _utils.normalizeForTimezone)(day, timestamp, normalize) || undefined;
92
- }),
93
- from = _dateValue$0$map[0],
94
- to = _dateValue$0$map[1];
104
+ return result;
105
+ };
95
106
 
96
- return [[from, to]];
107
+ var normalizeOutput = function normalizeOutput(dateValue, outputFormat) {
108
+ var result;
109
+
110
+ var normalize = function normalize(value) {
111
+ var normalizedValue = value.toISOString();
112
+
113
+ if (normalizedValue && outputFormat === 'no timezone') {
114
+ var _handleOffset$toISOSt = (0, _utils.handleOffset)(normalizedValue).toISOString().split('T');
115
+
116
+ normalizedValue = _handleOffset$toISOSt[0];
97
117
  }
98
118
 
99
- var dateArray = [];
100
- dateValue.forEach(function (d) {
101
- if (Array.isArray(d)) {
102
- var _d$map = d.map(function (day) {
103
- return (0, _utils.normalizeForTimezone)(day, timestamp, normalize);
104
- }),
105
- _from = _d$map[0],
106
- _to = _d$map[1];
119
+ return normalizedValue;
120
+ };
107
121
 
108
- dateArray.push([_from, _to]);
109
- } else {
110
- dateArray.push((0, _utils.normalizeForTimezone)(d, timestamp, normalize));
111
- }
122
+ if (dateValue instanceof Date) {
123
+ result = normalize(dateValue);
124
+ } else if (typeof dateValue === 'undefined') {
125
+ result = undefined;
126
+ } else {
127
+ result = dateValue.map(function (d) {
128
+ return normalizeOutput(d, outputFormat);
112
129
  });
113
- return dateArray;
114
130
  }
115
131
 
116
- return undefined;
132
+ return result;
133
+ }; // format value to [[]] for internal functions
134
+
135
+
136
+ var normalizeRange = function normalizeRange(value, activeDate) {
137
+ var range = value;
138
+ if (range instanceof Date) range = activeDate === 'start' ? [[undefined, range]] : [[range, undefined]];else if (Array.isArray(range) && !Array.isArray(range[0])) range = [range];
139
+ return range;
117
140
  };
118
141
 
119
- var normalizeReference = function normalizeReference(reference, date, dates, timestamp) {
120
- var normalizedReference;
121
-
122
- if (reference) {
123
- normalizedReference = new Date((0, _utils.normalizeForTimezone)(reference, timestamp));
124
- } else if (date) {
125
- if (typeof date === 'string') {
126
- normalizedReference = new Date(date);
127
- } else if (Array.isArray(date)) {
128
- if (typeof date[0] === 'string') {
129
- normalizedReference = new Date(date[0]);
130
- } else if (Array.isArray(date[0])) {
131
- normalizedReference = new Date(date[0][0] ? date[0][0] : date[0][1]);
142
+ var getReference = function getReference(reference, value) {
143
+ var nextReference;
144
+
145
+ if (value) {
146
+ if (Array.isArray(value)) {
147
+ if (value[0] instanceof Date) {
148
+ nextReference = value[0];
149
+ } else if (Array.isArray(value[0])) {
150
+ nextReference = value[0][0] ? value[0][0] : value[0][1];
132
151
  } else {
133
- normalizedReference = new Date();
134
- normalizedReference.setHours(0, 0, 0, 0);
152
+ nextReference = new Date();
153
+ nextReference.setHours(0, 0, 0, 0);
135
154
  }
136
- }
137
- } else if (dates && dates.length > 0) {
138
- if (typeof dates[0] === 'string') {
139
- normalizedReference = new Date(dates[0]);
140
- } else if (Array.isArray(dates[0])) {
141
- normalizedReference = new Date(dates[0][0] ? dates[0][0] : dates[0][1]);
142
- } else {
143
- normalizedReference = new Date();
144
- normalizedReference.setHours(0, 0, 0, 0);
145
- }
155
+ } else nextReference = value;
156
+ } else if (reference) {
157
+ nextReference = reference;
146
158
  } else {
147
- normalizedReference = new Date();
148
- normalizedReference.setHours(0, 0, 0, 0);
159
+ nextReference = new Date();
160
+ nextReference.setHours(0, 0, 0, 0);
149
161
  }
150
162
 
151
- return normalizedReference;
163
+ return nextReference;
152
164
  };
153
165
 
154
166
  var buildDisplayBounds = function buildDisplayBounds(reference, firstDayOfWeek) {
@@ -165,6 +177,19 @@ var buildDisplayBounds = function buildDisplayBounds(reference, firstDayOfWeek)
165
177
  return [start, end];
166
178
  };
167
179
 
180
+ var getOutputFormat = function getOutputFormat(dates) {
181
+ if (typeof dates === 'string' && (dates == null ? void 0 : dates.indexOf('T')) === -1) {
182
+ return 'no timezone';
183
+ }
184
+
185
+ if (Array.isArray(dates)) {
186
+ return getOutputFormat(dates[0]);
187
+ }
188
+
189
+ return 'date timezone';
190
+ };
191
+
192
+ exports.getOutputFormat = getOutputFormat;
168
193
  var millisecondsPerYear = 31557600000;
169
194
 
170
195
  var CalendarDayButton = function CalendarDayButton(props) {
@@ -240,8 +265,6 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
240
265
  _ref3$locale = _ref3.locale,
241
266
  locale = _ref3$locale === void 0 ? 'en-US' : _ref3$locale,
242
267
  messages = _ref3.messages,
243
- _ref3$normalize = _ref3.normalize,
244
- normalizeProp = _ref3$normalize === void 0 ? true : _ref3$normalize,
245
268
  onReference = _ref3.onReference,
246
269
  onSelect = _ref3.onSelect,
247
270
  range = _ref3.range,
@@ -281,102 +304,67 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
281
304
  document.removeEventListener('mousedown', onMouseDown);
282
305
  document.removeEventListener('mouseup', onMouseUp);
283
306
  };
284
- }, []); // whether or not we should normalize the date based on the timestamp.
285
- // will be set to false if the initial timestamp is undefined (meaning
286
- // a user did not provide a defaultValue or value). in this case, we
287
- // will just rely on the UTC timestamp and don't need to normalize.
288
-
289
- var _useState2 = (0, _react.useState)(normalizeProp),
290
- normalize = _useState2[0],
291
- setNormalize = _useState2[1]; // set activeDate when caller changes it, allows us to change
307
+ }, []); // set activeDate when caller changes it, allows us to change
292
308
  // it internally too
293
309
 
294
-
295
- var _useState3 = (0, _react.useState)(dateProp && typeof dateProp === 'string' && range ? activeDates.end : activeDates.start),
296
- activeDate = _useState3[0],
297
- setActiveDate = _useState3[1];
310
+ var _useState2 = (0, _react.useState)(dateProp && typeof dateProp === 'string' && range ? 'end' : 'start'),
311
+ activeDate = _useState2[0],
312
+ setActiveDate = _useState2[1];
298
313
 
299
314
  (0, _react.useEffect)(function () {
300
315
  if (activeDateProp) setActiveDate(activeDateProp);
301
316
  }, [activeDateProp]);
302
- var timestamp = (0, _react.useMemo)(function () {
303
- return timestampProp;
304
- }, [timestampProp]);
305
-
306
- if (timestampProp === undefined) {
307
- if (Array.isArray(dateProp) && dateProp.length) {
308
- if (Array.isArray(dateProp[0])) {
309
- timestamp = (0, _utils.getTimestamp)(dateProp[0][0]);
310
- } else timestamp = (0, _utils.getTimestamp)(dateProp[0]); // check to see if value is not an empty string
311
- // empty string should behave like undefined
312
-
313
- } else if (typeof dateProp === 'string' && dateProp.length) {
314
- timestamp = (0, _utils.getTimestamp)(dateProp);
315
- } else if (Array.isArray(datesProp) && datesProp.length) {
316
- if (Array.isArray(datesProp[0])) {
317
- timestamp = (0, _utils.getTimestamp)(datesProp[0][0]);
318
- } else timestamp = (0, _utils.getTimestamp)(datesProp[0]);
319
- } else if (typeof datesProp === 'string') {
320
- timestamp = (0, _utils.getTimestamp)(datesProp);
321
- } else if (typeof referenceProp === 'string') {
322
- timestamp = (0, _utils.getTimestamp)(referenceProp);
323
- }
324
- }
325
317
 
326
- var normalizedDate = (0, _react.useMemo)(function () {
327
- return timestampProp === undefined ? normalizeDate(dateProp, timestamp, normalize) : dateProp;
328
- }, [dateProp, normalize, timestamp, timestampProp]);
329
- var normalizedDates = (0, _react.useMemo)(function () {
330
- return timestampProp === undefined ? normalizeDate(datesProp, timestamp, normalize) : datesProp;
331
- }, [datesProp, normalize, timestamp, timestampProp]); // set date when caller changes it, allows us to change it internally too
332
-
333
- var _useState4 = (0, _react.useState)(normalizedDate),
334
- date = _useState4[0],
335
- setDate = _useState4[1];
318
+ var _useState3 = (0, _react.useState)(normalizeInput(dateProp || datesProp)),
319
+ value = _useState3[0],
320
+ setValue = _useState3[1];
336
321
 
337
322
  (0, _react.useEffect)(function () {
338
- setDate(normalizedDate);
339
- }, [normalizedDate]); // set dates when caller changes it, allows us to change it internally too
323
+ var val = dateProp || datesProp;
324
+ setValue(normalizeInput(val));
325
+ }, [dateProp, datesProp]);
340
326
 
341
- var _useState5 = (0, _react.useState)(normalizedDates),
342
- dates = _useState5[0],
343
- setDates = _useState5[1];
327
+ var _useState4 = (0, _react.useState)(getReference(normalizeInput(referenceProp), value)),
328
+ reference = _useState4[0],
329
+ setReference = _useState4[1];
344
330
 
345
331
  (0, _react.useEffect)(function () {
346
- setDates(normalizedDates);
347
- }, [normalizedDates]); // set reference based on what the caller passed or date/dates.
332
+ if (value) {
333
+ setReference(getReference(normalizeInput(referenceProp), value));
334
+ }
335
+ }, [referenceProp, value]);
348
336
 
349
- var _useState6 = (0, _react.useState)(normalizeReference(referenceProp, normalizedDate, normalizedDates, timestamp)),
350
- reference = _useState6[0],
351
- setReference = _useState6[1];
337
+ var _useState5 = (0, _react.useState)(getOutputFormat(dateProp || datesProp)),
338
+ outputFormat = _useState5[0],
339
+ setOutputFormat = _useState5[1];
352
340
 
353
341
  (0, _react.useEffect)(function () {
354
- return setReference(normalizeReference(referenceProp, normalizedDate, normalizedDates, timestamp));
355
- }, [referenceProp, normalizedDate, normalizedDates, timestamp]); // normalize bounds
342
+ setOutputFormat(getOutputFormat(dateProp || datesProp));
343
+ }, [dateProp, datesProp]); // normalize bounds
356
344
 
357
- var _useState7 = (0, _react.useState)(boundsProp),
358
- bounds = _useState7[0],
359
- setBounds = _useState7[1];
345
+ var _useState6 = (0, _react.useState)(boundsProp),
346
+ bounds = _useState6[0],
347
+ setBounds = _useState6[1];
360
348
 
361
349
  (0, _react.useEffect)(function () {
362
350
  if (boundsProp) setBounds(boundsProp);else setBounds(undefined);
363
351
  }, [boundsProp]); // calculate the bounds we display based on the reference
364
352
 
365
- var _useState8 = (0, _react.useState)(buildDisplayBounds(reference, firstDayOfWeek)),
366
- displayBounds = _useState8[0],
367
- setDisplayBounds = _useState8[1];
353
+ var _useState7 = (0, _react.useState)(buildDisplayBounds(reference, firstDayOfWeek)),
354
+ displayBounds = _useState7[0],
355
+ setDisplayBounds = _useState7[1];
356
+
357
+ var _useState8 = (0, _react.useState)(),
358
+ targetDisplayBounds = _useState8[0],
359
+ setTargetDisplayBounds = _useState8[1];
368
360
 
369
361
  var _useState9 = (0, _react.useState)(),
370
- targetDisplayBounds = _useState9[0],
371
- setTargetDisplayBounds = _useState9[1];
362
+ slide = _useState9[0],
363
+ setSlide = _useState9[1];
372
364
 
373
365
  var _useState10 = (0, _react.useState)(),
374
- slide = _useState10[0],
375
- setSlide = _useState10[1];
376
-
377
- var _useState11 = (0, _react.useState)(),
378
- animating = _useState11[0],
379
- setAnimating = _useState11[1]; // When the reference changes, we need to update the displayBounds.
366
+ animating = _useState10[0],
367
+ setAnimating = _useState10[1]; // When the reference changes, we need to update the displayBounds.
380
368
  // This is easy when we aren't animating. If we are animating,
381
369
  // we temporarily increase the displayBounds to be the union of the old
382
370
  // and new ones and set slide to drive the animation. We keep track
@@ -411,11 +399,16 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
411
399
  }
412
400
  }, [animate, firstDayOfWeek, reference, displayBounds]);
413
401
  (0, _react.useEffect)(function () {
402
+ // if the reference timezone has changed (e.g., controlled component),
403
+ // both ends of the displayBounds should inherit that new timestamp
414
404
  if (targetDisplayBounds) {
405
+ if (targetDisplayBounds[0].getTime() < displayBounds[0].getTime() || targetDisplayBounds[1].getTime() > displayBounds[1].getTime()) {
406
+ setDisplayBounds([targetDisplayBounds[0], targetDisplayBounds[1]]);
407
+ }
408
+
415
409
  if (targetDisplayBounds[0].getTime() < displayBounds[0].getTime()) {
416
410
  // only animate if the duration is within a year
417
- if (displayBounds[0].getTime() - targetDisplayBounds[0].getTime() < millisecondsPerYear) {
418
- setDisplayBounds([targetDisplayBounds[0], displayBounds[1]]);
411
+ if (displayBounds[0].getTime() - targetDisplayBounds[0].getTime() < millisecondsPerYear && (0, _utils.daysApart)(displayBounds[0], targetDisplayBounds[0])) {
419
412
  setSlide({
420
413
  direction: 'down',
421
414
  weeks: (0, _utils.daysApart)(displayBounds[0], targetDisplayBounds[0]) / 7
@@ -423,8 +416,7 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
423
416
  setAnimating(true);
424
417
  }
425
418
  } else if (targetDisplayBounds[1].getTime() > displayBounds[1].getTime()) {
426
- if (targetDisplayBounds[1].getTime() - displayBounds[1].getTime() < millisecondsPerYear) {
427
- setDisplayBounds([displayBounds[0], targetDisplayBounds[1]]);
419
+ if (targetDisplayBounds[1].getTime() - displayBounds[1].getTime() < millisecondsPerYear && (0, _utils.daysApart)(targetDisplayBounds[1], displayBounds[1])) {
428
420
  setSlide({
429
421
  direction: 'up',
430
422
  weeks: (0, _utils.daysApart)(targetDisplayBounds[1], displayBounds[1]) / 7
@@ -469,13 +461,13 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
469
461
  }, [reference]);
470
462
  var daysRef = (0, _react.useRef)();
471
463
 
472
- var _useState12 = (0, _react.useState)(),
473
- focus = _useState12[0],
474
- setFocus = _useState12[1];
464
+ var _useState11 = (0, _react.useState)(),
465
+ focus = _useState11[0],
466
+ setFocus = _useState11[1];
475
467
 
476
- var _useState13 = (0, _react.useState)(),
477
- active = _useState13[0],
478
- setActive = _useState13[1];
468
+ var _useState12 = (0, _react.useState)(),
469
+ active = _useState12[0],
470
+ setActive = _useState12[1];
479
471
 
480
472
  (0, _react.useEffect)(function () {
481
473
  if (initialFocus === 'days') daysRef.current.focus();
@@ -486,123 +478,81 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
486
478
  if (onReference) onReference(nextReference.toISOString());
487
479
  }
488
480
  }, [onReference, bounds]);
489
- var selectDate = (0, _react.useCallback)(function (selectedDate) {
490
- var nextDates;
491
- var nextDate; // timestamp will be undefined if no defaultValue or value have
492
- // been passed in, indicating that we should stay local
493
-
494
- var nextNormalize = normalize;
495
-
496
- if (timestamp === undefined) {
497
- nextNormalize = false;
498
- setNormalize(nextNormalize);
499
- }
500
-
501
- if (!range) {
502
- nextDate = selectedDate;
503
- } // everything down is a range
504
- else if (!dates && !Array.isArray(date)) {
505
- // if user supplies date, convert this into dates
506
- if (date) {
507
- var priorDate = new Date(date);
508
- var selDate = new Date(selectedDate);
509
-
510
- if (activeDate === activeDates.start) {
511
- if (selDate.getTime() > priorDate.getTime()) {
512
- nextDates = [[selectedDate, undefined]];
513
- } else {
514
- nextDates = [[selectedDate, date]];
515
- }
516
-
517
- setActiveDate(activeDates.end);
518
- if (activeDateProp) setActiveDate(activeDateProp);
519
- } else if (activeDate === activeDates.end) {
520
- if (selDate.getTime() < priorDate.getTime()) {
521
- nextDates = [[selectedDate, undefined]];
522
- setActiveDate(activeDates.end);
523
- } else {
524
- nextDates = [[date, selectedDate]];
525
- setActiveDate(activeDates.start);
526
- }
527
-
528
- if (activeDateProp) setActiveDate(activeDateProp);
529
- }
530
- } else if (activeDate === activeDates.start) {
531
- nextDates = [[selectedDate, undefined]];
532
- setActiveDate(activeDates.end);
533
- } else if (activeDate === activeDates.end) {
534
- nextDates = [[undefined, selectedDate]];
481
+ var handleRange = (0, _react.useCallback)(function (selectedDate) {
482
+ var _priorRange$, _priorRange$$, _priorRange$2, _priorRange$2$;
483
+
484
+ var result;
485
+ var priorRange = normalizeRange(value, activeDate); // deselect when date clicked was the start/end of the range
486
+
487
+ if (selectedDate.getTime() === (priorRange == null ? void 0 : (_priorRange$ = priorRange[0]) == null ? void 0 : (_priorRange$$ = _priorRange$[0]) == null ? void 0 : _priorRange$$.getTime())) {
488
+ result = [[undefined, priorRange[0][1]]];
489
+ setActiveDate('start');
490
+ } else if (selectedDate.getTime() === (priorRange == null ? void 0 : (_priorRange$2 = priorRange[0]) == null ? void 0 : (_priorRange$2$ = _priorRange$2[1]) == null ? void 0 : _priorRange$2$.getTime())) {
491
+ result = [[priorRange[0][0], undefined]];
492
+ setActiveDate('end');
493
+ } // selecting start date
494
+ else if (activeDate === 'start') {
495
+ if (!priorRange) {
496
+ result = [[selectedDate, undefined]];
497
+ } else if (!priorRange[0][1]) {
498
+ result = [[selectedDate, priorRange[0][1]]];
499
+ } else if (selectedDate.getTime() < priorRange[0][1].getTime()) {
500
+ result = [[selectedDate, priorRange[0][1]]];
501
+ } else if (selectedDate.getTime() > priorRange[0][1].getTime()) {
502
+ result = [[selectedDate, undefined]];
535
503
  }
536
504
 
537
- if (activeDateProp) setActiveDate(activeDateProp);
538
- } else if (dates || date) {
539
- var handleSelection = function handleSelection(dateValue) {
540
- var priorDates = dateValue[0].map(function (d) {
541
- return new Date(d);
505
+ setActiveDate('end');
506
+ } // selecting end date
507
+ else if (!priorRange) {
508
+ result = [[undefined, selectedDate]];
509
+ setActiveDate('start');
510
+ } else if (selectedDate.getTime() < priorRange[0][0].getTime()) {
511
+ result = [[selectedDate, undefined]];
512
+ setActiveDate('end');
513
+ } else if (selectedDate.getTime() > priorRange[0][0].getTime()) {
514
+ result = [[priorRange[0][0], selectedDate]];
515
+ setActiveDate('start');
516
+ } // If no dates selected, always return undefined; else format
517
+ // result according to specified range value.
518
+
519
+
520
+ if (result[0].includes(undefined)) {
521
+ if (range === 'array') {
522
+ result = !result[0][0] && !result[0][1] ? undefined : result;
523
+ } else {
524
+ result = result[0].find(function (d) {
525
+ return d !== undefined;
542
526
  });
543
- var selDate = new Date(selectedDate);
544
-
545
- if (selDate.getTime() === priorDates[0].getTime()) {
546
- nextDates = [[undefined, dateValue[0][1]]];
547
- setActiveDate(activeDates.start);
548
- } else if (selDate.getTime() === priorDates[1].getTime()) {
549
- nextDates = [[dateValue[0][0], undefined]];
550
- setActiveDate(activeDates.end);
551
- if (activeDateProp) setActiveDate(activeDateProp);
552
- } else if (activeDate === activeDates.start) {
553
- if (selDate.getTime() > priorDates[1].getTime()) {
554
- nextDates = [[selectedDate, undefined]];
555
- } else {
556
- nextDates = [[selectedDate, dateValue[0][1]]];
557
- }
558
-
559
- setActiveDate(activeDates.end);
560
- if (activeDateProp) setActiveDate(activeDateProp);
561
- } else if (activeDate === activeDates.end) {
562
- if (selDate.getTime() < priorDates[0].getTime()) {
563
- nextDates = [[selectedDate, undefined]];
564
- setActiveDate(activeDates.end);
565
- } else {
566
- nextDates = [[dateValue[0][0], selectedDate]];
567
- setActiveDate(activeDates.start);
568
- }
569
-
570
- if (activeDateProp) setActiveDate(activeDateProp);
571
- } // cleanup
572
-
573
-
574
- if (!nextDates[0][0] && !nextDates[0][1]) nextDates = undefined;
575
- }; // have dates
576
-
577
-
578
- if (dates) {
579
- handleSelection(dates);
580
- } else if (date && Array.isArray(date)) {
581
- handleSelection(date);
582
527
  }
583
528
  }
584
529
 
585
- setDates(nextDates);
530
+ setValue(result);
531
+ return result;
532
+ }, [activeDate, value, range]);
533
+ var selectDate = (0, _react.useCallback)(function (selectedDate) {
534
+ var nextValue;
586
535
 
587
- if (date && typeof date === 'string') {
588
- setDate(nextDate);
589
- } else if (date && Array.isArray(date)) {
590
- setDate(nextDates);
536
+ if (range || Array.isArray(value == null ? void 0 : value[0])) {
537
+ nextValue = handleRange(selectedDate);
538
+ } else {
539
+ nextValue = selectedDate;
591
540
  }
592
541
 
593
- setActive(new Date(selectedDate));
594
-
595
542
  if (onSelect) {
596
- // format date/dates to match structure provided by caller
597
- // which could take format of:
598
- // 1. ISO8601 with a timestamp
599
- // 2. ISO8601 without a timestamp
600
- // 3. Caller did not provide value/defaultValue, so return date
601
- // in ISO8601 with timestamp in UTC relative to user's local timezone
602
- var formattedDate = (0, _utils.getFormattedDate)(nextDate, nextDates, nextNormalize, range, timestamp);
603
- onSelect(formattedDate);
543
+ nextValue = normalizeOutput(nextValue, outputFormat);
544
+ onSelect(nextValue);
604
545
  }
605
- }, [activeDate, activeDateProp, date, dates, normalize, onSelect, range, timestamp]);
546
+ }, [handleRange, onSelect, outputFormat, range, value]);
547
+
548
+ var _onClick = function onClick(selectedDate) {
549
+ selectDate(selectedDate);
550
+ announce("Selected " + getLocaleString(selectedDate, locale), 'assertive'); // Chrome moves the focus indicator to this button. Set
551
+ // the focus to the grid of days instead.
552
+
553
+ daysRef.current.focus();
554
+ setActive(selectedDate);
555
+ };
606
556
 
607
557
  var renderCalendarHeader = function renderCalendarHeader() {
608
558
  var PreviousIcon = size === 'small' ? theme.calendar.icons.small.previous : theme.calendar.icons.previous;
@@ -766,11 +716,11 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
766
716
  })));
767
717
  } else {
768
718
  (function () {
769
- var dateString = day.toISOString(); // this.dayRefs[dateString] = React.createRef();
719
+ var dateObject = day; // this.dayRefs[dateObject] = React.createRef();
770
720
 
771
721
  var selected = false;
772
722
  var inRange = false;
773
- var selectedState = (0, _utils.withinDates)(day, date || dates);
723
+ var selectedState = (0, _utils.withinDates)(day, range ? normalizeRange(value, activeDate) : value);
774
724
 
775
725
  if (selectedState === 2) {
776
726
  selected = true;
@@ -778,10 +728,10 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
778
728
  inRange = true;
779
729
  }
780
730
 
781
- var dayDisabled = (0, _utils.withinDates)(day, disabled) || bounds && !(0, _utils.betweenDates)(day, bounds);
731
+ var dayDisabled = (0, _utils.withinDates)(day, normalizeInput(disabled)) || bounds && !(0, _utils.betweenDates)(day, normalizeInput(bounds));
782
732
 
783
733
  if (!firstDayInMonth && !dayDisabled && day.getMonth() === reference.getMonth()) {
784
- firstDayInMonth = dateString;
734
+ firstDayInMonth = dateObject;
785
735
  }
786
736
 
787
737
  if (!children) {
@@ -792,15 +742,10 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
792
742
  active: active && active.getTime() === day.getTime(),
793
743
  disabled: dayDisabled && !!dayDisabled,
794
744
  onClick: function onClick() {
795
- selectDate(dateString);
796
- announce("Selected " + (0, _utils.formatToLocalYYYYMMDD)(dateString, normalize), 'assertive'); // Chrome moves the focus indicator to this button. Set
797
- // the focus to the grid of days instead.
798
-
799
- daysRef.current.focus();
800
- setActive(new Date(dateString));
745
+ return _onClick(dateObject);
801
746
  },
802
747
  onMouseOver: function onMouseOver() {
803
- return setActive(new Date(dateString));
748
+ return setActive(dateObject);
804
749
  },
805
750
  onMouseOut: function onMouseOut() {
806
751
  return setActive(undefined);
@@ -820,15 +765,10 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
820
765
  active: active && active.getTime() === day.getTime(),
821
766
  disabled: dayDisabled && !!dayDisabled,
822
767
  onClick: function onClick() {
823
- selectDate(dateString);
824
- announce("Selected\n " + (0, _utils.formatToLocalYYYYMMDD)(dateString, normalize), 'assertive'); // Chrome moves the focus indicator to this button. Set
825
- // the focus to the grid of days instead.
826
-
827
- daysRef.current.focus();
828
- setActive(new Date(dateString));
768
+ return _onClick(dateObject);
829
769
  },
830
770
  onMouseOver: function onMouseOver() {
831
- return setActive(new Date(dateString));
771
+ return setActive(dateObject);
832
772
  },
833
773
  onMouseOut: function onMouseOut() {
834
774
  return setActive(undefined);
@@ -895,7 +835,7 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
895
835
  nextInBound: (0, _utils.betweenDates)(nextMonth, bounds)
896
836
  }) : renderCalendarHeader(previousMonth, nextMonth), daysOfWeek && renderDaysOfWeek(), /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
897
837
  onEnter: function onEnter() {
898
- return active !== undefined ? selectDate(active.toISOString()) : undefined;
838
+ return active !== undefined ? _onClick(active) : undefined;
899
839
  },
900
840
  onUp: function onUp(event) {
901
841
  event.preventDefault();
@@ -934,10 +874,10 @@ var Calendar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
934
874
  }, /*#__PURE__*/_react["default"].createElement(_StyledCalendar.StyledWeeksContainer, {
935
875
  tabIndex: 0,
936
876
  role: "grid",
937
- "aria-label": "\n " + reference.toLocaleDateString(locale, {
877
+ "aria-label": reference.toLocaleDateString(locale, {
938
878
  month: 'long',
939
879
  year: 'numeric'
940
- }) + ";\n " + getAccessibilityString(date, dates, normalize) + "\n ",
880
+ }) + "; " + currentlySelectedString(value, locale),
941
881
  ref: daysRef,
942
882
  sizeProp: size,
943
883
  fillContainer: fill,