baseui 10.12.1 → 11.0.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 (271) hide show
  1. package/README.md +3 -3
  2. package/accordion/accordion.js +60 -13
  3. package/accordion/accordion.js.flow +49 -12
  4. package/accordion/index.d.ts +0 -3
  5. package/accordion/panel.js +7 -6
  6. package/accordion/panel.js.flow +20 -20
  7. package/accordion/stateless-accordion.js +2 -4
  8. package/accordion/stateless-accordion.js.flow +0 -2
  9. package/accordion/types.js.flow +0 -5
  10. package/button/constants.js +1 -2
  11. package/button/constants.js.flow +0 -1
  12. package/button/index.d.ts +0 -1
  13. package/button/styled-components.js +2 -29
  14. package/button/styled-components.js.flow +2 -30
  15. package/checkbox/checkbox.js +6 -30
  16. package/checkbox/checkbox.js.flow +7 -38
  17. package/checkbox/constants.js +2 -1
  18. package/checkbox/constants.js.flow +2 -1
  19. package/checkbox/index.d.ts +4 -6
  20. package/checkbox/index.js +0 -6
  21. package/checkbox/index.js.flow +0 -1
  22. package/checkbox/styled-components.js +52 -149
  23. package/checkbox/styled-components.js.flow +59 -165
  24. package/checkbox/types.js.flow +0 -5
  25. package/data-table/column-categorical.js +1 -1
  26. package/data-table/column-categorical.js.flow +1 -1
  27. package/data-table/column-datetime.js +1 -1
  28. package/data-table/column-datetime.js.flow +3 -1
  29. package/data-table/column.js +6 -2
  30. package/data-table/column.js.flow +9 -7
  31. package/data-table/data-table.js +1 -1
  32. package/data-table/data-table.js.flow +1 -1
  33. package/data-table/header-cell.js +3 -0
  34. package/data-table/header-cell.js.flow +1 -1
  35. package/datepicker/calendar.js +15 -7
  36. package/datepicker/calendar.js.flow +23 -9
  37. package/datepicker/constants.js +12 -2
  38. package/datepicker/constants.js.flow +10 -0
  39. package/datepicker/datepicker.js +61 -30
  40. package/datepicker/datepicker.js.flow +77 -37
  41. package/datepicker/day.js +85 -34
  42. package/datepicker/day.js.flow +118 -54
  43. package/datepicker/locale.js.flow +0 -1
  44. package/datepicker/month.js +3 -1
  45. package/datepicker/month.js.flow +2 -0
  46. package/datepicker/stateful-container.js.flow +2 -1
  47. package/datepicker/styled-components.js +23 -1
  48. package/datepicker/styled-components.js.flow +12 -2
  49. package/datepicker/types.js.flow +35 -10
  50. package/datepicker/utils/date-helpers.js +30 -0
  51. package/datepicker/utils/date-helpers.js.flow +12 -0
  52. package/datepicker/week.js +3 -1
  53. package/datepicker/week.js.flow +2 -0
  54. package/es/accordion/accordion.js +52 -12
  55. package/es/accordion/panel.js +7 -5
  56. package/es/accordion/stateless-accordion.js +2 -4
  57. package/es/button/constants.js +1 -2
  58. package/es/button/styled-components.js +2 -29
  59. package/es/checkbox/checkbox.js +7 -32
  60. package/es/checkbox/constants.js +2 -1
  61. package/es/checkbox/index.js +1 -1
  62. package/es/checkbox/styled-components.js +51 -146
  63. package/es/data-table/column-categorical.js +1 -1
  64. package/es/data-table/column-datetime.js +1 -1
  65. package/es/data-table/column.js +6 -2
  66. package/es/data-table/data-table.js +1 -1
  67. package/es/data-table/header-cell.js +3 -0
  68. package/es/datepicker/calendar.js +15 -7
  69. package/es/datepicker/constants.js +8 -0
  70. package/es/datepicker/datepicker.js +56 -29
  71. package/es/datepicker/day.js +77 -34
  72. package/es/datepicker/month.js +3 -1
  73. package/es/datepicker/styled-components.js +8 -2
  74. package/es/datepicker/types.js +1 -1
  75. package/es/datepicker/utils/date-helpers.js +16 -0
  76. package/es/datepicker/week.js +3 -1
  77. package/es/file-uploader/file-uploader.js +4 -4
  78. package/es/header-navigation/styled-components.js +3 -3
  79. package/es/helpers/overrides.js +1 -2
  80. package/es/input/styled-components.js +4 -4
  81. package/es/layer/layer.js +4 -4
  82. package/es/locale/index.js +0 -7
  83. package/es/menu/stateful-container.js +0 -1
  84. package/es/menu/styled-components.js +1 -1
  85. package/es/modal/index.js +1 -1
  86. package/es/modal/modal.js +19 -65
  87. package/es/modal/styled-components.js +12 -48
  88. package/es/phone-input/default-props.js +1 -1
  89. package/es/phone-input/index.js +0 -4
  90. package/es/phone-input/phone-input-lite.js +55 -31
  91. package/es/radio/radio.js +1 -7
  92. package/es/radio/radiogroup.js +3 -28
  93. package/es/radio/styled-components.js +4 -5
  94. package/es/rating/styled-components.js +3 -3
  95. package/es/select/index.js +1 -2
  96. package/es/select/select-component.js +4 -8
  97. package/es/select/styled-components.js +4 -4
  98. package/es/snackbar/styled-components.js +2 -2
  99. package/es/spinner/index.js +3 -9
  100. package/es/spinner/styled-components.js +2 -32
  101. package/es/table/filter.js +3 -3
  102. package/es/tag/styled-components.js +1 -1
  103. package/es/themes/dark-theme/color-component-tokens.js +0 -38
  104. package/es/themes/dark-theme/color-tokens.js +0 -2
  105. package/es/themes/dark-theme/create-dark-theme.js +0 -2
  106. package/es/themes/dark-theme/dark-theme.js +0 -2
  107. package/es/themes/light-theme/color-component-tokens.js +0 -38
  108. package/es/themes/light-theme/color-tokens.js +0 -2
  109. package/es/themes/light-theme/create-light-theme.js +0 -2
  110. package/es/themes/light-theme/light-theme.js +0 -2
  111. package/es/timepicker/timepicker.js +1 -8
  112. package/es/typography/index.js +1 -31
  113. package/esm/accordion/accordion.js +60 -13
  114. package/esm/accordion/panel.js +7 -6
  115. package/esm/accordion/stateless-accordion.js +2 -4
  116. package/esm/button/constants.js +1 -2
  117. package/esm/button/styled-components.js +2 -29
  118. package/esm/checkbox/checkbox.js +7 -30
  119. package/esm/checkbox/constants.js +2 -1
  120. package/esm/checkbox/index.js +1 -1
  121. package/esm/checkbox/styled-components.js +52 -147
  122. package/esm/data-table/column-categorical.js +1 -1
  123. package/esm/data-table/column-datetime.js +1 -1
  124. package/esm/data-table/column.js +6 -2
  125. package/esm/data-table/data-table.js +1 -1
  126. package/esm/data-table/header-cell.js +3 -0
  127. package/esm/datepicker/calendar.js +15 -7
  128. package/esm/datepicker/constants.js +8 -0
  129. package/esm/datepicker/datepicker.js +60 -30
  130. package/esm/datepicker/day.js +84 -34
  131. package/esm/datepicker/month.js +3 -1
  132. package/esm/datepicker/styled-components.js +24 -2
  133. package/esm/datepicker/types.js +1 -1
  134. package/esm/datepicker/utils/date-helpers.js +30 -0
  135. package/esm/datepicker/week.js +3 -1
  136. package/esm/file-uploader/file-uploader.js +4 -4
  137. package/esm/header-navigation/styled-components.js +3 -3
  138. package/esm/helpers/overrides.js +1 -2
  139. package/esm/input/styled-components.js +4 -4
  140. package/esm/layer/layer.js +4 -4
  141. package/esm/locale/index.js +0 -7
  142. package/esm/menu/stateful-container.js +0 -1
  143. package/esm/menu/styled-components.js +1 -1
  144. package/esm/modal/index.js +1 -1
  145. package/esm/modal/modal.js +28 -71
  146. package/esm/modal/styled-components.js +6 -38
  147. package/esm/phone-input/default-props.js +1 -1
  148. package/esm/phone-input/index.js +0 -4
  149. package/esm/phone-input/phone-input-lite.js +60 -37
  150. package/esm/radio/radio.js +1 -7
  151. package/esm/radio/radiogroup.js +3 -28
  152. package/esm/radio/styled-components.js +4 -5
  153. package/esm/rating/styled-components.js +3 -3
  154. package/esm/select/index.js +1 -2
  155. package/esm/select/select-component.js +4 -8
  156. package/esm/select/styled-components.js +4 -4
  157. package/esm/snackbar/styled-components.js +2 -2
  158. package/esm/spinner/index.js +3 -9
  159. package/esm/spinner/styled-components.js +2 -40
  160. package/esm/table/filter.js +3 -3
  161. package/esm/tag/styled-components.js +1 -1
  162. package/esm/themes/dark-theme/color-component-tokens.js +0 -38
  163. package/esm/themes/dark-theme/color-tokens.js +0 -2
  164. package/esm/themes/dark-theme/create-dark-theme.js +1 -2
  165. package/esm/themes/dark-theme/dark-theme.js +1 -2
  166. package/esm/themes/light-theme/color-component-tokens.js +0 -38
  167. package/esm/themes/light-theme/color-tokens.js +0 -2
  168. package/esm/themes/light-theme/create-light-theme.js +1 -2
  169. package/esm/themes/light-theme/light-theme.js +1 -2
  170. package/esm/timepicker/timepicker.js +1 -8
  171. package/esm/typography/index.js +1 -35
  172. package/file-uploader/file-uploader.js +3 -3
  173. package/file-uploader/file-uploader.js.flow +4 -4
  174. package/header-navigation/styled-components.js +3 -3
  175. package/header-navigation/styled-components.js.flow +3 -3
  176. package/helpers/overrides.js +1 -2
  177. package/helpers/overrides.js.flow +1 -1
  178. package/input/index.d.ts +5 -9
  179. package/input/styled-components.js +4 -4
  180. package/input/styled-components.js.flow +4 -4
  181. package/layer/layer.js +4 -4
  182. package/layer/layer.js.flow +4 -3
  183. package/locale/index.js +0 -7
  184. package/locale/index.js.flow +0 -7
  185. package/locale.ts +0 -1
  186. package/menu/index.d.ts +1 -3
  187. package/menu/stateful-container.js +0 -1
  188. package/menu/stateful-container.js.flow +0 -1
  189. package/menu/styled-components.js +1 -1
  190. package/menu/styled-components.js.flow +1 -1
  191. package/modal/index.d.ts +4 -6
  192. package/modal/index.js +0 -6
  193. package/modal/index.js.flow +0 -1
  194. package/modal/modal.js +27 -70
  195. package/modal/modal.js.flow +17 -83
  196. package/modal/styled-components.js +7 -40
  197. package/modal/styled-components.js.flow +12 -44
  198. package/modal/types.js.flow +1 -10
  199. package/package.json +2 -2
  200. package/phone-input/default-props.js +1 -1
  201. package/phone-input/default-props.js.flow +1 -1
  202. package/phone-input/index.d.ts +0 -1
  203. package/phone-input/index.js +0 -36
  204. package/phone-input/index.js.flow +0 -4
  205. package/phone-input/phone-input-lite.js +63 -38
  206. package/phone-input/phone-input-lite.js.flow +66 -44
  207. package/radio/index.d.ts +4 -9
  208. package/radio/radio.js +1 -7
  209. package/radio/radio.js.flow +1 -8
  210. package/radio/radiogroup.js +3 -28
  211. package/radio/radiogroup.js.flow +2 -26
  212. package/radio/styled-components.js +4 -5
  213. package/radio/styled-components.js.flow +3 -4
  214. package/radio/types.js.flow +4 -15
  215. package/rating/styled-components.js +3 -3
  216. package/rating/styled-components.js.flow +3 -3
  217. package/select/index.d.ts +0 -2
  218. package/select/index.js +0 -6
  219. package/select/index.js.flow +0 -2
  220. package/select/select-component.js +4 -8
  221. package/select/select-component.js.flow +2 -3
  222. package/select/styled-components.js +4 -4
  223. package/select/styled-components.js.flow +4 -4
  224. package/snackbar/styled-components.js +1 -1
  225. package/snackbar/styled-components.js.flow +11 -11
  226. package/spinner/index.d.ts +5 -18
  227. package/spinner/index.js +2 -68
  228. package/spinner/index.js.flow +2 -27
  229. package/spinner/styled-components.js +9 -45
  230. package/spinner/styled-components.js.flow +2 -34
  231. package/spinner/types.js.flow +1 -19
  232. package/styles/types.js.flow +0 -2
  233. package/table/filter.js +3 -3
  234. package/table/filter.js.flow +3 -3
  235. package/tag/styled-components.js +1 -1
  236. package/tag/styled-components.js.flow +1 -1
  237. package/theme.ts +0 -81
  238. package/themes/dark-theme/color-component-tokens.js +0 -38
  239. package/themes/dark-theme/color-component-tokens.js.flow +0 -42
  240. package/themes/dark-theme/color-tokens.js +0 -2
  241. package/themes/dark-theme/color-tokens.js.flow +0 -2
  242. package/themes/dark-theme/create-dark-theme.js +1 -3
  243. package/themes/dark-theme/create-dark-theme.js.flow +0 -2
  244. package/themes/dark-theme/dark-theme.js +1 -3
  245. package/themes/dark-theme/dark-theme.js.flow +0 -2
  246. package/themes/light-theme/color-component-tokens.js +0 -38
  247. package/themes/light-theme/color-component-tokens.js.flow +0 -43
  248. package/themes/light-theme/color-tokens.js +0 -2
  249. package/themes/light-theme/color-tokens.js.flow +0 -2
  250. package/themes/light-theme/create-light-theme.js +1 -3
  251. package/themes/light-theme/create-light-theme.js.flow +0 -2
  252. package/themes/light-theme/light-theme.js +1 -3
  253. package/themes/light-theme/light-theme.js.flow +0 -2
  254. package/themes/types.js.flow +0 -68
  255. package/timepicker/timepicker.js +1 -8
  256. package/timepicker/timepicker.js.flow +4 -10
  257. package/typography/index.d.ts +0 -23
  258. package/typography/index.js +2 -57
  259. package/typography/index.js.flow +0 -31
  260. package/es/spinner/spinner.js +0 -68
  261. package/es/themes/dark-theme/color-deprecated-semantic-tokens.js +0 -35
  262. package/es/themes/light-theme/color-deprecated-semantic-tokens.js +0 -35
  263. package/esm/spinner/spinner.js +0 -125
  264. package/esm/themes/dark-theme/color-deprecated-semantic-tokens.js +0 -38
  265. package/esm/themes/light-theme/color-deprecated-semantic-tokens.js +0 -38
  266. package/spinner/spinner.js +0 -136
  267. package/spinner/spinner.js.flow +0 -75
  268. package/themes/dark-theme/color-deprecated-semantic-tokens.js +0 -50
  269. package/themes/dark-theme/color-deprecated-semantic-tokens.js.flow +0 -42
  270. package/themes/light-theme/color-deprecated-semantic-tokens.js +0 -50
  271. package/themes/light-theme/color-deprecated-semantic-tokens.js.flow +0 -42
package/datepicker/day.js CHANGED
@@ -21,6 +21,8 @@ var _index = require("../locale/index.js");
21
21
 
22
22
  var _focusVisible = require("../utils/focusVisible.js");
23
23
 
24
+ var _constants = require("./constants.js");
25
+
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
27
 
26
28
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
@@ -96,22 +98,49 @@ var Day = /*#__PURE__*/function (_React$Component) {
96
98
  var _this$props = _this.props,
97
99
  range = _this$props.range,
98
100
  value = _this$props.value;
99
- var date;
101
+ var nextDate;
102
+
103
+ if (Array.isArray(value) && range && _this.props.hasLockedBehavior) {
104
+ var currentDate = _this.props.value;
105
+ var nextStartDate = null;
106
+ var nextEndDate = null;
107
+
108
+ if (_this.props.selectedInput === _constants.INPUT_ROLE.startDate) {
109
+ nextStartDate = selectedDate;
110
+ nextEndDate = Array.isArray(currentDate) && currentDate[1] ? currentDate[1] : null;
111
+ } else if (_this.props.selectedInput === _constants.INPUT_ROLE.endDate) {
112
+ nextStartDate = Array.isArray(currentDate) && currentDate[0] ? currentDate[0] : null;
113
+ nextEndDate = selectedDate;
114
+ }
100
115
 
101
- if (Array.isArray(value) && range) {
102
- if (!value.length || value.length > 1) {
103
- date = [selectedDate];
104
- } else if (_this.dateHelpers.isAfter(selectedDate, value[0])) {
105
- date = [value[0], selectedDate];
116
+ nextDate = [nextStartDate];
117
+
118
+ if (nextEndDate) {
119
+ nextDate.push(nextEndDate);
120
+ }
121
+ } else if (Array.isArray(value) && range && !_this.props.hasLockedBehavior) {
122
+ var _value = _slicedToArray(value, 2),
123
+ start = _value[0],
124
+ end = _value[1]; // Starting a new range
125
+
126
+
127
+ if (!start && !end || start && end) {
128
+ nextDate = [selectedDate, null]; // EndDate needs a StartDate, SelectedDate comes before EndDate
129
+ } else if (!start && end && _this.dateHelpers.isAfter(end, selectedDate)) {
130
+ nextDate = [selectedDate, end]; // EndDate needs a StartDate, but SelectedDate comes after EndDate
131
+ } else if (!start && end && _this.dateHelpers.isAfter(selectedDate, end)) {
132
+ nextDate = [end, selectedDate]; // StartDate needs an EndDate, SelectedDate comes after StartDate
133
+ } else if (start && !end && _this.dateHelpers.isAfter(selectedDate, start)) {
134
+ nextDate = [start, selectedDate];
106
135
  } else {
107
- date = [selectedDate, value[0]];
136
+ nextDate = [selectedDate, start];
108
137
  }
109
138
  } else {
110
- date = selectedDate;
139
+ nextDate = selectedDate;
111
140
  }
112
141
 
113
142
  _this.props.onSelect({
114
- date: date
143
+ date: nextDate
115
144
  });
116
145
  });
117
146
 
@@ -298,13 +327,18 @@ var Day = /*#__PURE__*/function (_React$Component) {
298
327
  var date = this.getDateProp();
299
328
  var value = this.props.value;
300
329
 
301
- if (Array.isArray(value) && !value[0] && !value[1]) {
302
- return false;
303
- } // fix flow by passing a specific arg type and remove 'Array.isArray(value)'
330
+ if (Array.isArray(value)) {
331
+ var _value2 = _slicedToArray(value, 2),
332
+ start = _value2[0],
333
+ end = _value2[1];
304
334
 
335
+ if (!start && !end) {
336
+ return false;
337
+ }
305
338
 
306
- if (Array.isArray(value) && value.length > 1) {
307
- return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(value[0]), this.clampToDayStart(value[1]));
339
+ if (start && end) {
340
+ return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(start), this.clampToDayStart(end));
341
+ }
308
342
  }
309
343
  } // calculated for range case only
310
344
 
@@ -316,16 +350,29 @@ var Day = /*#__PURE__*/function (_React$Component) {
316
350
  value = _this$props4.value,
317
351
  highlightedDate = _this$props4.highlightedDate;
318
352
 
319
- if (Array.isArray(value) && !value[0] && !value[1]) {
320
- return false;
321
- } // fix flow by passing a specific arg type and remove 'Array.isArray(value)'
353
+ if (Array.isArray(value)) {
354
+ var _value3 = _slicedToArray(value, 2),
355
+ start = _value3[0],
356
+ end = _value3[1];
322
357
 
358
+ if (!start && !end) {
359
+ return false;
360
+ }
323
361
 
324
- if (Array.isArray(value) && highlightedDate && value[0] && !value[1]) {
325
- if (this.dateHelpers.isAfter(highlightedDate, value[0])) {
326
- return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(value[0]), this.clampToDayStart(highlightedDate));
327
- } else {
328
- return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(highlightedDate), this.clampToDayStart(value[0]));
362
+ if (highlightedDate && start && !end) {
363
+ if (this.dateHelpers.isAfter(highlightedDate, start)) {
364
+ return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(start), this.clampToDayStart(highlightedDate));
365
+ } else {
366
+ return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(highlightedDate), this.clampToDayStart(start));
367
+ }
368
+ }
369
+
370
+ if (highlightedDate && !start && end) {
371
+ if (this.dateHelpers.isAfter(highlightedDate, end)) {
372
+ return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(end), this.clampToDayStart(highlightedDate));
373
+ } else {
374
+ return this.dateHelpers.isDayInRange(this.clampToDayStart(date), this.clampToDayStart(highlightedDate), this.clampToDayStart(end));
375
+ }
329
376
  }
330
377
  }
331
378
  }
@@ -337,21 +384,22 @@ var Day = /*#__PURE__*/function (_React$Component) {
337
384
  value = _this$props5.value,
338
385
  highlightedDate = _this$props5.highlightedDate,
339
386
  range = _this$props5.range,
340
- highlighted = _this$props5.highlighted;
387
+ highlighted = _this$props5.highlighted,
388
+ peekNextMonth = _this$props5.peekNextMonth;
341
389
  var $isHighlighted = highlighted;
342
390
  var $selected = this.isSelected();
343
- var $hasRangeHighlighted = !!(Array.isArray(value) && range && value.length === 1 && highlightedDate && !this.dateHelpers.isSameDay(value[0], highlightedDate));
344
- var $outsideMonth = !this.props.peekNextMonth && this.isOutsideMonth();
345
- var $outsideMonthWithinRange = !!(Array.isArray(value) && range && $outsideMonth && !this.props.peekNextMonth && this.isOutsideOfMonthButWithinRange());
391
+ var $hasRangeHighlighted = !!(Array.isArray(value) && range && highlightedDate && (value[0] && !value[1] && !this.dateHelpers.isSameDay(value[0], highlightedDate) || !value[0] && value[1] && !this.dateHelpers.isSameDay(value[1], highlightedDate)));
392
+ var $outsideMonth = !peekNextMonth && this.isOutsideMonth();
393
+ var $outsideMonthWithinRange = !!(Array.isArray(value) && range && $outsideMonth && !peekNextMonth && this.isOutsideOfMonthButWithinRange());
346
394
  return {
347
395
  $date: date,
348
396
  $density: this.props.density,
349
397
  $disabled: this.props.disabled,
350
- $endDate: Array.isArray(value) && this.props.range && $selected && this.dateHelpers.isSameDay(date, value[1]) || false,
398
+ $endDate: Array.isArray(value) && !!(value[0] && value[1]) && range && $selected && this.dateHelpers.isSameDay(date, value[1]) || false,
351
399
  $hasDateLabel: !!this.props.dateLabel,
352
400
  $hasRangeHighlighted: $hasRangeHighlighted,
353
- $hasRangeOnRight: Array.isArray(value) && $hasRangeHighlighted && highlightedDate && value[0] && this.dateHelpers.isAfter(highlightedDate, value[0]),
354
- $hasRangeSelected: Array.isArray(value) ? value.length === 2 : false,
401
+ $hasRangeOnRight: Array.isArray(value) && $hasRangeHighlighted && highlightedDate && (value[0] && this.dateHelpers.isAfter(highlightedDate, value[0]) || value[1] && this.dateHelpers.isAfter(highlightedDate, value[1])),
402
+ $hasRangeSelected: Array.isArray(value) ? !!(value[0] && value[1]) : false,
355
403
  $highlightedDate: highlightedDate,
356
404
  $isHighlighted: $isHighlighted,
357
405
  $isHovered: this.state.isHovered,
@@ -361,12 +409,15 @@ var Day = /*#__PURE__*/function (_React$Component) {
361
409
  $month: this.getMonthProp(),
362
410
  $outsideMonth: $outsideMonth,
363
411
  $outsideMonthWithinRange: $outsideMonthWithinRange,
364
- $peekNextMonth: this.props.peekNextMonth,
365
- $pseudoHighlighted: this.props.range && !$isHighlighted && !$selected ? this.isPseudoHighlighted() : false,
366
- $pseudoSelected: this.props.range && !$selected ? this.isPseudoSelected() : false,
367
- $range: this.props.range,
412
+ $peekNextMonth: peekNextMonth,
413
+ $pseudoHighlighted: range && !$isHighlighted && !$selected ? this.isPseudoHighlighted() : false,
414
+ $pseudoSelected: range && !$selected ? this.isPseudoSelected() : false,
415
+ $range: range,
368
416
  $selected: $selected,
369
- $startDate: Array.isArray(this.props.value) && this.props.value.length > 1 && this.props.range && $selected ? this.dateHelpers.isSameDay(date, this.props.value[0]) : false
417
+ $startDate: Array.isArray(value) && value[0] && value[1] && range && $selected ? this.dateHelpers.isSameDay(date, value[0]) : false,
418
+ $hasLockedBehavior: this.props.hasLockedBehavior,
419
+ $selectedInput: this.props.selectedInput,
420
+ $value: this.props.value
370
421
  };
371
422
  }
372
423
  }, {
@@ -14,6 +14,7 @@ import type { DayPropsT, DayStateT } from './types.js';
14
14
  import { LocaleContext } from '../locale/index.js';
15
15
  import type { LocaleT } from '../locale/types.js';
16
16
  import { isFocusVisible } from '../utils/focusVisible.js';
17
+ import { INPUT_ROLE } from './constants.js';
17
18
 
18
19
  export default class Day<T = Date> extends React.Component<DayPropsT<T>, DayStateT> {
19
20
  static defaultProps = {
@@ -72,21 +73,58 @@ export default class Day<T = Date> extends React.Component<DayPropsT<T>, DayStat
72
73
  : this.props.month;
73
74
  };
74
75
 
76
+ /**
77
+ * Determines how the day value(s) should be updated when a new day is selected.
78
+ * Note: time values are incorporated into new day/date values downstream in `Calendar`.
79
+ * Note: Situations where Start Dates are after End Dates are handled downstream in `Datepicker`.
80
+ * */
75
81
  onSelect: (T) => void = (selectedDate) => {
76
82
  const { range, value } = this.props;
77
- let date;
78
- if (Array.isArray(value) && range) {
79
- if (!value.length || value.length > 1) {
80
- date = [selectedDate];
81
- } else if (this.dateHelpers.isAfter(selectedDate, value[0])) {
82
- date = [value[0], selectedDate];
83
+
84
+ let nextDate;
85
+ if (Array.isArray(value) && range && this.props.hasLockedBehavior) {
86
+ const currentDate = this.props.value;
87
+ let nextStartDate = null;
88
+ let nextEndDate = null;
89
+
90
+ if (this.props.selectedInput === INPUT_ROLE.startDate) {
91
+ nextStartDate = selectedDate;
92
+ nextEndDate = Array.isArray(currentDate) && currentDate[1] ? currentDate[1] : null;
93
+ } else if (this.props.selectedInput === INPUT_ROLE.endDate) {
94
+ nextStartDate = Array.isArray(currentDate) && currentDate[0] ? currentDate[0] : null;
95
+ nextEndDate = selectedDate;
96
+ }
97
+
98
+ nextDate = [nextStartDate];
99
+ if (nextEndDate) {
100
+ nextDate.push(nextEndDate);
101
+ }
102
+ } else if (Array.isArray(value) && range && !this.props.hasLockedBehavior) {
103
+ const [start, end] = value;
104
+
105
+ // Starting a new range
106
+ if ((!start && !end) || (start && end)) {
107
+ nextDate = [selectedDate, null];
108
+
109
+ // EndDate needs a StartDate, SelectedDate comes before EndDate
110
+ } else if (!start && end && this.dateHelpers.isAfter(end, selectedDate)) {
111
+ nextDate = [selectedDate, end];
112
+
113
+ // EndDate needs a StartDate, but SelectedDate comes after EndDate
114
+ } else if (!start && end && this.dateHelpers.isAfter(selectedDate, end)) {
115
+ nextDate = [end, selectedDate];
116
+
117
+ // StartDate needs an EndDate, SelectedDate comes after StartDate
118
+ } else if (start && !end && this.dateHelpers.isAfter(selectedDate, start)) {
119
+ nextDate = [start, selectedDate];
83
120
  } else {
84
- date = [selectedDate, value[0]];
121
+ nextDate = [selectedDate, start];
85
122
  }
86
123
  } else {
87
- date = selectedDate;
124
+ nextDate = selectedDate;
88
125
  }
89
- this.props.onSelect({ date });
126
+
127
+ this.props.onSelect({ date: nextDate });
90
128
  };
91
129
 
92
130
  onKeyDown = (event: KeyboardEvent) => {
@@ -205,16 +243,21 @@ export default class Day<T = Date> extends React.Component<DayPropsT<T>, DayStat
205
243
  isPseudoSelected() {
206
244
  const date = this.getDateProp();
207
245
  const { value } = this.props;
208
- if (Array.isArray(value) && !value[0] && !value[1]) {
209
- return false;
210
- }
211
- // fix flow by passing a specific arg type and remove 'Array.isArray(value)'
212
- if (Array.isArray(value) && value.length > 1) {
213
- return this.dateHelpers.isDayInRange(
214
- this.clampToDayStart(date),
215
- this.clampToDayStart(value[0]),
216
- this.clampToDayStart(value[1])
217
- );
246
+
247
+ if (Array.isArray(value)) {
248
+ const [start, end] = value;
249
+
250
+ if (!start && !end) {
251
+ return false;
252
+ }
253
+
254
+ if (start && end) {
255
+ return this.dateHelpers.isDayInRange(
256
+ this.clampToDayStart(date),
257
+ this.clampToDayStart(start),
258
+ this.clampToDayStart(end)
259
+ );
260
+ }
218
261
  }
219
262
  }
220
263
 
@@ -222,46 +265,66 @@ export default class Day<T = Date> extends React.Component<DayPropsT<T>, DayStat
222
265
  isPseudoHighlighted() {
223
266
  const date = this.getDateProp();
224
267
  const { value, highlightedDate } = this.props;
225
- if (Array.isArray(value) && !value[0] && !value[1]) {
226
- return false;
227
- }
228
268
 
229
- // fix flow by passing a specific arg type and remove 'Array.isArray(value)'
230
- if (Array.isArray(value) && highlightedDate && value[0] && !value[1]) {
231
- if (this.dateHelpers.isAfter(highlightedDate, value[0])) {
232
- return this.dateHelpers.isDayInRange(
233
- this.clampToDayStart(date),
234
- this.clampToDayStart(value[0]),
235
- this.clampToDayStart(highlightedDate)
236
- );
237
- } else {
238
- return this.dateHelpers.isDayInRange(
239
- this.clampToDayStart(date),
240
- this.clampToDayStart(highlightedDate),
241
- this.clampToDayStart(value[0])
242
- );
269
+ if (Array.isArray(value)) {
270
+ const [start, end] = value;
271
+
272
+ if (!start && !end) {
273
+ return false;
274
+ }
275
+
276
+ if (highlightedDate && start && !end) {
277
+ if (this.dateHelpers.isAfter(highlightedDate, start)) {
278
+ return this.dateHelpers.isDayInRange(
279
+ this.clampToDayStart(date),
280
+ this.clampToDayStart(start),
281
+ this.clampToDayStart(highlightedDate)
282
+ );
283
+ } else {
284
+ return this.dateHelpers.isDayInRange(
285
+ this.clampToDayStart(date),
286
+ this.clampToDayStart(highlightedDate),
287
+ this.clampToDayStart(start)
288
+ );
289
+ }
290
+ }
291
+
292
+ if (highlightedDate && !start && end) {
293
+ if (this.dateHelpers.isAfter(highlightedDate, end)) {
294
+ return this.dateHelpers.isDayInRange(
295
+ this.clampToDayStart(date),
296
+ this.clampToDayStart(end),
297
+ this.clampToDayStart(highlightedDate)
298
+ );
299
+ } else {
300
+ return this.dateHelpers.isDayInRange(
301
+ this.clampToDayStart(date),
302
+ this.clampToDayStart(highlightedDate),
303
+ this.clampToDayStart(end)
304
+ );
305
+ }
243
306
  }
244
307
  }
245
308
  }
246
309
 
247
310
  getSharedProps() {
248
311
  const date = this.getDateProp();
249
- const { value, highlightedDate, range, highlighted } = this.props;
312
+ const { value, highlightedDate, range, highlighted, peekNextMonth } = this.props;
250
313
  const $isHighlighted = highlighted;
251
314
  const $selected = this.isSelected();
252
315
  const $hasRangeHighlighted = !!(
253
316
  Array.isArray(value) &&
254
317
  range &&
255
- value.length === 1 &&
256
318
  highlightedDate &&
257
- !this.dateHelpers.isSameDay(value[0], highlightedDate)
319
+ ((value[0] && !value[1] && !this.dateHelpers.isSameDay(value[0], highlightedDate)) ||
320
+ (!value[0] && value[1] && !this.dateHelpers.isSameDay(value[1], highlightedDate)))
258
321
  );
259
- const $outsideMonth = !this.props.peekNextMonth && this.isOutsideMonth();
322
+ const $outsideMonth = !peekNextMonth && this.isOutsideMonth();
260
323
  const $outsideMonthWithinRange = !!(
261
324
  Array.isArray(value) &&
262
325
  range &&
263
326
  $outsideMonth &&
264
- !this.props.peekNextMonth &&
327
+ !peekNextMonth &&
265
328
  this.isOutsideOfMonthButWithinRange()
266
329
  );
267
330
  return {
@@ -270,7 +333,8 @@ export default class Day<T = Date> extends React.Component<DayPropsT<T>, DayStat
270
333
  $disabled: this.props.disabled,
271
334
  $endDate:
272
335
  (Array.isArray(value) &&
273
- this.props.range &&
336
+ !!(value[0] && value[1]) &&
337
+ range &&
274
338
  $selected &&
275
339
  this.dateHelpers.isSameDay(date, value[1])) ||
276
340
  false,
@@ -280,9 +344,9 @@ export default class Day<T = Date> extends React.Component<DayPropsT<T>, DayStat
280
344
  Array.isArray(value) &&
281
345
  $hasRangeHighlighted &&
282
346
  highlightedDate &&
283
- value[0] &&
284
- this.dateHelpers.isAfter(highlightedDate, value[0]),
285
- $hasRangeSelected: Array.isArray(value) ? value.length === 2 : false,
347
+ ((value[0] && this.dateHelpers.isAfter(highlightedDate, value[0])) ||
348
+ (value[1] && this.dateHelpers.isAfter(highlightedDate, value[1]))),
349
+ $hasRangeSelected: Array.isArray(value) ? !!(value[0] && value[1]) : false,
286
350
  $highlightedDate: highlightedDate,
287
351
  $isHighlighted,
288
352
  $isHovered: this.state.isHovered,
@@ -292,19 +356,19 @@ export default class Day<T = Date> extends React.Component<DayPropsT<T>, DayStat
292
356
  $month: this.getMonthProp(),
293
357
  $outsideMonth,
294
358
  $outsideMonthWithinRange,
295
- $peekNextMonth: this.props.peekNextMonth,
359
+ $peekNextMonth: peekNextMonth,
296
360
  $pseudoHighlighted:
297
- this.props.range && !$isHighlighted && !$selected ? this.isPseudoHighlighted() : false,
298
- $pseudoSelected: this.props.range && !$selected ? this.isPseudoSelected() : false,
299
- $range: this.props.range,
361
+ range && !$isHighlighted && !$selected ? this.isPseudoHighlighted() : false,
362
+ $pseudoSelected: range && !$selected ? this.isPseudoSelected() : false,
363
+ $range: range,
300
364
  $selected,
301
365
  $startDate:
302
- Array.isArray(this.props.value) &&
303
- this.props.value.length > 1 &&
304
- this.props.range &&
305
- $selected
306
- ? this.dateHelpers.isSameDay(date, this.props.value[0])
366
+ Array.isArray(value) && value[0] && value[1] && range && $selected
367
+ ? this.dateHelpers.isSameDay(date, value[0])
307
368
  : false,
369
+ $hasLockedBehavior: this.props.hasLockedBehavior,
370
+ $selectedInput: this.props.selectedInput,
371
+ $value: this.props.value,
308
372
  };
309
373
  }
310
374
 
@@ -28,7 +28,6 @@ export type DatepickerLocaleT = {|
28
28
  quickSelectPlaceholder: string,
29
29
  timeSelectEndLabel: string,
30
30
  timeSelectStartLabel: string,
31
- timePickerAriaLabel?: string,
32
31
  timePickerAriaLabel12Hour: string,
33
32
  timePickerAriaLabel24Hour: string,
34
33
  timezonePickerAriaLabel: string,
@@ -143,7 +143,9 @@ var CalendarMonth = /*#__PURE__*/function (_React$Component) {
143
143
  onChange: _this.props.onChange,
144
144
  overrides: _this.props.overrides,
145
145
  peekNextMonth: _this.props.peekNextMonth,
146
- value: _this.props.value
146
+ value: _this.props.value,
147
+ hasLockedBehavior: _this.props.hasLockedBehavior,
148
+ selectedInput: _this.props.selectedInput
147
149
  }));
148
150
  i++;
149
151
  currentWeekStart = _this.dateHelpers.addWeeks(currentWeekStart, 1); // It will break on the next week if the week is out of the month
@@ -100,6 +100,8 @@ export default class CalendarMonth<T = Date> extends React.Component<MonthPropsT
100
100
  overrides={this.props.overrides}
101
101
  peekNextMonth={this.props.peekNextMonth}
102
102
  value={this.props.value}
103
+ hasLockedBehavior={this.props.hasLockedBehavior}
104
+ selectedInput={this.props.selectedInput}
103
105
  />
104
106
  );
105
107
  i++;
@@ -14,6 +14,7 @@ import type {
14
14
  StatefulContainerPropsT,
15
15
  StateChangeTypeT,
16
16
  StateReducerT,
17
+ DateValueT,
17
18
  } from './types.js';
18
19
 
19
20
  type InputProps<T> = CalendarPropsT<T> | DatepickerPropsT<T>;
@@ -33,7 +34,7 @@ class StatefulContainer<T = Date> extends React.Component<PropsT<T>, ContainerSt
33
34
  this.state = { value, ...props.initialState };
34
35
  }
35
36
 
36
- onChange: ({ date: ?T | Array<T> }) => mixed = (data) => {
37
+ onChange: ({ date: DateValueT<T> }) => mixed = (data) => {
37
38
  const { date } = data;
38
39
  this.internalSetState(STATE_CHANGE_TYPE.change, { value: date });
39
40
  if (typeof this.props.onChange === 'function') {
@@ -13,6 +13,18 @@ var _constants = require("./constants.js");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
+
18
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
+
20
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
21
+
22
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
+
24
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
25
+
26
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
+
16
28
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17
29
 
18
30
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -448,6 +460,9 @@ var StyledDay = (0, _index.styled)('div', function (props) {
448
460
  $outsideMonthWithinRange = props.$outsideMonthWithinRange,
449
461
  $hasDateLabel = props.$hasDateLabel,
450
462
  $density = props.$density,
463
+ $hasLockedBehavior = props.$hasLockedBehavior,
464
+ $selectedInput = props.$selectedInput,
465
+ $value = props.$value,
451
466
  _props$$theme4 = props.$theme,
452
467
  colors = _props$$theme4.colors,
453
468
  typography = _props$$theme4.typography,
@@ -469,6 +484,13 @@ var StyledDay = (0, _index.styled)('div', function (props) {
469
484
  }
470
485
  }
471
486
 
487
+ var _ref9 = Array.isArray($value) ? $value : [$value, null],
488
+ _ref10 = _slicedToArray(_ref9, 2),
489
+ startDate = _ref10[0],
490
+ endDate = _ref10[1];
491
+
492
+ var oppositeInputIsPopulated = $selectedInput === _constants.INPUT_ROLE.startDate ? endDate !== null && typeof endDate !== 'undefined' : startDate !== null && typeof startDate !== 'undefined';
493
+ var shouldHighlightRange = $range && !($hasLockedBehavior && !oppositeInputIsPopulated);
472
494
  return _objectSpread(_objectSpread(_objectSpread({}, $density === _constants.DENSITY.high ? typography.ParagraphSmall : typography.ParagraphMedium), {}, {
473
495
  boxSizing: 'border-box',
474
496
  position: 'relative',
@@ -530,7 +552,7 @@ var StyledDay = (0, _index.styled)('div', function (props) {
530
552
  }, getDayStyles(code, props.$theme)[':after'] || {}), $outsideMonthWithinRange ? {
531
553
  content: null
532
554
  } : {})
533
- }, $range ? {
555
+ }, shouldHighlightRange ? {
534
556
  // :before pseudo element defines a grey background style that extends
535
557
  // the selected/highlighted day's circle and spans through a range
536
558
  ':before': _objectSpread(_objectSpread({
@@ -8,7 +8,7 @@ LICENSE file in the root directory of this source tree.
8
8
  import { styled } from '../styles/index.js';
9
9
  import getDayStateCode from './utils/day-state.js';
10
10
  import type { SharedStylePropsT, CalendarPropsT } from './types.js';
11
- import { ORIENTATION, DENSITY } from './constants.js';
11
+ import { ORIENTATION, DENSITY, INPUT_ROLE } from './constants.js';
12
12
 
13
13
  /**
14
14
  * Main component container element
@@ -408,6 +408,9 @@ export const StyledDay = styled<SharedStylePropsT>('div', (props) => {
408
408
  $outsideMonthWithinRange,
409
409
  $hasDateLabel,
410
410
  $density,
411
+ $hasLockedBehavior,
412
+ $selectedInput,
413
+ $value,
411
414
  $theme: { colors, typography, sizing },
412
415
  } = props;
413
416
  const code = getDayStateCode(props);
@@ -427,6 +430,13 @@ export const StyledDay = styled<SharedStylePropsT>('div', (props) => {
427
430
  }
428
431
  }
429
432
 
433
+ const [startDate, endDate] = Array.isArray($value) ? $value : [$value, null];
434
+ const oppositeInputIsPopulated =
435
+ $selectedInput === INPUT_ROLE.startDate
436
+ ? endDate !== null && typeof endDate !== 'undefined'
437
+ : startDate !== null && typeof startDate !== 'undefined';
438
+ const shouldHighlightRange = $range && !($hasLockedBehavior && !oppositeInputIsPopulated);
439
+
430
440
  return ({
431
441
  ...($density === DENSITY.high ? typography.ParagraphSmall : typography.ParagraphMedium),
432
442
  boxSizing: 'border-box',
@@ -496,7 +506,7 @@ export const StyledDay = styled<SharedStylePropsT>('div', (props) => {
496
506
  ...(getDayStyles(code, props.$theme)[':after'] || {}),
497
507
  ...($outsideMonthWithinRange ? { content: null } : {}),
498
508
  },
499
- ...($range
509
+ ...(shouldHighlightRange
500
510
  ? {
501
511
  // :before pseudo element defines a grey background style that extends
502
512
  // the selected/highlighted day's circle and spans through a range