baseui 10.12.1 → 11.0.2

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 (307) 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 +10 -2
  32. package/data-table/data-table.js.flow +4 -1
  33. package/data-table/header-cell.js +3 -0
  34. package/data-table/header-cell.js.flow +1 -1
  35. package/data-table/index.d.ts +7 -8
  36. package/data-table/stateful-data-table.js +2 -1
  37. package/data-table/stateful-data-table.js.flow +1 -0
  38. package/data-table/types.js.flow +8 -0
  39. package/datepicker/calendar.js +28 -15
  40. package/datepicker/calendar.js.flow +31 -14
  41. package/datepicker/constants.js +12 -2
  42. package/datepicker/constants.js.flow +10 -0
  43. package/datepicker/datepicker.js +117 -86
  44. package/datepicker/datepicker.js.flow +123 -66
  45. package/datepicker/day.js +85 -34
  46. package/datepicker/day.js.flow +118 -54
  47. package/datepicker/locale.js.flow +0 -1
  48. package/datepicker/month.js +3 -1
  49. package/datepicker/month.js.flow +2 -0
  50. package/datepicker/stateful-calendar.js +6 -1
  51. package/datepicker/stateful-calendar.js.flow +8 -1
  52. package/datepicker/stateful-container.js +23 -2
  53. package/datepicker/stateful-container.js.flow +17 -3
  54. package/datepicker/stateful-datepicker.js +6 -1
  55. package/datepicker/stateful-datepicker.js.flow +7 -1
  56. package/datepicker/styled-components.js +23 -1
  57. package/datepicker/styled-components.js.flow +12 -2
  58. package/datepicker/types.js.flow +46 -43
  59. package/datepicker/utils/date-helpers.js +30 -0
  60. package/datepicker/utils/date-helpers.js.flow +12 -0
  61. package/datepicker/week.js +3 -1
  62. package/datepicker/week.js.flow +2 -0
  63. package/es/accordion/accordion.js +52 -12
  64. package/es/accordion/panel.js +7 -5
  65. package/es/accordion/stateless-accordion.js +2 -4
  66. package/es/button/constants.js +1 -2
  67. package/es/button/styled-components.js +2 -29
  68. package/es/checkbox/checkbox.js +7 -32
  69. package/es/checkbox/constants.js +2 -1
  70. package/es/checkbox/index.js +1 -1
  71. package/es/checkbox/styled-components.js +51 -146
  72. package/es/data-table/column-categorical.js +1 -1
  73. package/es/data-table/column-datetime.js +1 -1
  74. package/es/data-table/column.js +6 -2
  75. package/es/data-table/data-table.js +6 -2
  76. package/es/data-table/header-cell.js +3 -0
  77. package/es/data-table/stateful-data-table.js +2 -1
  78. package/es/datepicker/calendar.js +28 -15
  79. package/es/datepicker/constants.js +8 -0
  80. package/es/datepicker/datepicker.js +106 -79
  81. package/es/datepicker/day.js +77 -34
  82. package/es/datepicker/month.js +3 -1
  83. package/es/datepicker/stateful-calendar.js +6 -1
  84. package/es/datepicker/stateful-container.js +22 -2
  85. package/es/datepicker/stateful-datepicker.js +6 -1
  86. package/es/datepicker/styled-components.js +8 -2
  87. package/es/datepicker/types.js +1 -1
  88. package/es/datepicker/utils/date-helpers.js +16 -0
  89. package/es/datepicker/week.js +3 -1
  90. package/es/file-uploader/file-uploader.js +4 -4
  91. package/es/form-control/styled-components.js +0 -1
  92. package/es/header-navigation/styled-components.js +3 -3
  93. package/es/helpers/overrides.js +1 -2
  94. package/es/input/styled-components.js +4 -4
  95. package/es/layer/layer.js +4 -4
  96. package/es/list/list-item.js +5 -1
  97. package/es/list/menu-adapter.js +4 -0
  98. package/es/locale/index.js +0 -7
  99. package/es/menu/stateful-container.js +0 -1
  100. package/es/menu/styled-components.js +1 -1
  101. package/es/modal/index.js +1 -1
  102. package/es/modal/modal.js +19 -65
  103. package/es/modal/styled-components.js +12 -48
  104. package/es/phone-input/default-props.js +1 -1
  105. package/es/phone-input/index.js +0 -4
  106. package/es/phone-input/phone-input-lite.js +55 -31
  107. package/es/radio/radio.js +1 -7
  108. package/es/radio/radiogroup.js +3 -28
  109. package/es/radio/styled-components.js +4 -5
  110. package/es/rating/styled-components.js +3 -3
  111. package/es/select/index.js +1 -2
  112. package/es/select/select-component.js +20 -20
  113. package/es/select/styled-components.js +21 -17
  114. package/es/snackbar/snackbar-context.js +1 -1
  115. package/es/snackbar/styled-components.js +2 -2
  116. package/es/spinner/index.js +3 -9
  117. package/es/spinner/styled-components.js +2 -32
  118. package/es/table/filter.js +3 -3
  119. package/es/tag/styled-components.js +1 -1
  120. package/es/themes/dark-theme/color-component-tokens.js +0 -38
  121. package/es/themes/dark-theme/color-tokens.js +0 -2
  122. package/es/themes/dark-theme/create-dark-theme.js +0 -2
  123. package/es/themes/dark-theme/dark-theme.js +0 -2
  124. package/es/themes/light-theme/color-component-tokens.js +0 -38
  125. package/es/themes/light-theme/color-tokens.js +0 -2
  126. package/es/themes/light-theme/create-light-theme.js +0 -2
  127. package/es/themes/light-theme/light-theme.js +0 -2
  128. package/es/timepicker/timepicker.js +1 -8
  129. package/es/typography/index.js +1 -31
  130. package/esm/accordion/accordion.js +60 -13
  131. package/esm/accordion/panel.js +7 -6
  132. package/esm/accordion/stateless-accordion.js +2 -4
  133. package/esm/button/constants.js +1 -2
  134. package/esm/button/styled-components.js +2 -29
  135. package/esm/checkbox/checkbox.js +7 -30
  136. package/esm/checkbox/constants.js +2 -1
  137. package/esm/checkbox/index.js +1 -1
  138. package/esm/checkbox/styled-components.js +52 -147
  139. package/esm/data-table/column-categorical.js +1 -1
  140. package/esm/data-table/column-datetime.js +1 -1
  141. package/esm/data-table/column.js +6 -2
  142. package/esm/data-table/data-table.js +10 -2
  143. package/esm/data-table/header-cell.js +3 -0
  144. package/esm/data-table/stateful-data-table.js +2 -1
  145. package/esm/datepicker/calendar.js +28 -15
  146. package/esm/datepicker/constants.js +8 -0
  147. package/esm/datepicker/datepicker.js +116 -86
  148. package/esm/datepicker/day.js +84 -34
  149. package/esm/datepicker/month.js +3 -1
  150. package/esm/datepicker/stateful-calendar.js +6 -1
  151. package/esm/datepicker/stateful-container.js +23 -2
  152. package/esm/datepicker/stateful-datepicker.js +6 -1
  153. package/esm/datepicker/styled-components.js +24 -2
  154. package/esm/datepicker/types.js +1 -1
  155. package/esm/datepicker/utils/date-helpers.js +30 -0
  156. package/esm/datepicker/week.js +3 -1
  157. package/esm/file-uploader/file-uploader.js +4 -4
  158. package/esm/form-control/styled-components.js +0 -1
  159. package/esm/header-navigation/styled-components.js +3 -3
  160. package/esm/helpers/overrides.js +1 -2
  161. package/esm/input/styled-components.js +4 -4
  162. package/esm/layer/layer.js +4 -4
  163. package/esm/list/list-item.js +5 -1
  164. package/esm/list/menu-adapter.js +4 -0
  165. package/esm/locale/index.js +0 -7
  166. package/esm/menu/stateful-container.js +0 -1
  167. package/esm/menu/styled-components.js +1 -1
  168. package/esm/modal/index.js +1 -1
  169. package/esm/modal/modal.js +28 -71
  170. package/esm/modal/styled-components.js +6 -38
  171. package/esm/phone-input/default-props.js +1 -1
  172. package/esm/phone-input/index.js +0 -4
  173. package/esm/phone-input/phone-input-lite.js +60 -37
  174. package/esm/radio/radio.js +1 -7
  175. package/esm/radio/radiogroup.js +3 -28
  176. package/esm/radio/styled-components.js +4 -5
  177. package/esm/rating/styled-components.js +3 -3
  178. package/esm/select/index.js +1 -2
  179. package/esm/select/select-component.js +20 -20
  180. package/esm/select/styled-components.js +21 -14
  181. package/esm/snackbar/snackbar-context.js +1 -1
  182. package/esm/snackbar/styled-components.js +2 -2
  183. package/esm/spinner/index.js +3 -9
  184. package/esm/spinner/styled-components.js +2 -40
  185. package/esm/table/filter.js +3 -3
  186. package/esm/tag/styled-components.js +1 -1
  187. package/esm/themes/dark-theme/color-component-tokens.js +0 -38
  188. package/esm/themes/dark-theme/color-tokens.js +0 -2
  189. package/esm/themes/dark-theme/create-dark-theme.js +1 -2
  190. package/esm/themes/dark-theme/dark-theme.js +1 -2
  191. package/esm/themes/light-theme/color-component-tokens.js +0 -38
  192. package/esm/themes/light-theme/color-tokens.js +0 -2
  193. package/esm/themes/light-theme/create-light-theme.js +1 -2
  194. package/esm/themes/light-theme/light-theme.js +1 -2
  195. package/esm/timepicker/timepicker.js +1 -8
  196. package/esm/typography/index.js +1 -35
  197. package/file-uploader/file-uploader.js +3 -3
  198. package/file-uploader/file-uploader.js.flow +4 -4
  199. package/form-control/index.d.ts +9 -0
  200. package/form-control/styled-components.js +0 -1
  201. package/form-control/styled-components.js.flow +0 -1
  202. package/header-navigation/styled-components.js +3 -3
  203. package/header-navigation/styled-components.js.flow +3 -3
  204. package/helpers/overrides.js +1 -2
  205. package/helpers/overrides.js.flow +1 -1
  206. package/input/index.d.ts +5 -9
  207. package/input/styled-components.js +4 -4
  208. package/input/styled-components.js.flow +4 -4
  209. package/layer/layer.js +4 -4
  210. package/layer/layer.js.flow +4 -3
  211. package/list/list-item.js +5 -1
  212. package/list/list-item.js.flow +4 -0
  213. package/list/menu-adapter.js +4 -0
  214. package/list/menu-adapter.js.flow +4 -0
  215. package/list/types.js.flow +4 -0
  216. package/locale/index.js +0 -7
  217. package/locale/index.js.flow +0 -7
  218. package/locale.ts +0 -1
  219. package/menu/index.d.ts +1 -3
  220. package/menu/stateful-container.js +0 -1
  221. package/menu/stateful-container.js.flow +0 -1
  222. package/menu/styled-components.js +1 -1
  223. package/menu/styled-components.js.flow +1 -1
  224. package/modal/index.d.ts +4 -6
  225. package/modal/index.js +0 -6
  226. package/modal/index.js.flow +0 -1
  227. package/modal/modal.js +27 -70
  228. package/modal/modal.js.flow +17 -83
  229. package/modal/styled-components.js +7 -40
  230. package/modal/styled-components.js.flow +12 -44
  231. package/modal/types.js.flow +1 -10
  232. package/package.json +3 -2
  233. package/phone-input/default-props.js +1 -1
  234. package/phone-input/default-props.js.flow +1 -1
  235. package/phone-input/index.d.ts +0 -1
  236. package/phone-input/index.js +0 -36
  237. package/phone-input/index.js.flow +0 -4
  238. package/phone-input/phone-input-lite.js +63 -38
  239. package/phone-input/phone-input-lite.js.flow +66 -44
  240. package/radio/index.d.ts +4 -9
  241. package/radio/radio.js +1 -7
  242. package/radio/radio.js.flow +1 -8
  243. package/radio/radiogroup.js +3 -28
  244. package/radio/radiogroup.js.flow +2 -26
  245. package/radio/styled-components.js +4 -5
  246. package/radio/styled-components.js.flow +3 -4
  247. package/radio/types.js.flow +4 -15
  248. package/rating/styled-components.js +3 -3
  249. package/rating/styled-components.js.flow +3 -3
  250. package/select/index.d.ts +0 -2
  251. package/select/index.js +0 -6
  252. package/select/index.js.flow +0 -2
  253. package/select/select-component.js +23 -24
  254. package/select/select-component.js.flow +25 -14
  255. package/select/styled-components.js +23 -17
  256. package/select/styled-components.js.flow +17 -12
  257. package/snackbar/snackbar-context.js +1 -1
  258. package/snackbar/snackbar-context.js.flow +1 -1
  259. package/snackbar/styled-components.js +1 -1
  260. package/snackbar/styled-components.js.flow +11 -11
  261. package/spinner/index.d.ts +5 -18
  262. package/spinner/index.js +2 -68
  263. package/spinner/index.js.flow +2 -27
  264. package/spinner/styled-components.js +9 -45
  265. package/spinner/styled-components.js.flow +2 -34
  266. package/spinner/types.js.flow +1 -19
  267. package/styles/types.js.flow +0 -2
  268. package/table/filter.js +3 -3
  269. package/table/filter.js.flow +3 -3
  270. package/tag/styled-components.js +1 -1
  271. package/tag/styled-components.js.flow +1 -1
  272. package/tag/types.js.flow +1 -1
  273. package/theme.ts +0 -81
  274. package/themes/dark-theme/color-component-tokens.js +0 -38
  275. package/themes/dark-theme/color-component-tokens.js.flow +0 -42
  276. package/themes/dark-theme/color-tokens.js +0 -2
  277. package/themes/dark-theme/color-tokens.js.flow +0 -2
  278. package/themes/dark-theme/create-dark-theme.js +1 -3
  279. package/themes/dark-theme/create-dark-theme.js.flow +0 -2
  280. package/themes/dark-theme/dark-theme.js +1 -3
  281. package/themes/dark-theme/dark-theme.js.flow +0 -2
  282. package/themes/light-theme/color-component-tokens.js +0 -38
  283. package/themes/light-theme/color-component-tokens.js.flow +0 -43
  284. package/themes/light-theme/color-tokens.js +0 -2
  285. package/themes/light-theme/color-tokens.js.flow +0 -2
  286. package/themes/light-theme/create-light-theme.js +1 -3
  287. package/themes/light-theme/create-light-theme.js.flow +0 -2
  288. package/themes/light-theme/light-theme.js +1 -3
  289. package/themes/light-theme/light-theme.js.flow +0 -2
  290. package/themes/types.js.flow +0 -68
  291. package/timepicker/timepicker.js +1 -8
  292. package/timepicker/timepicker.js.flow +4 -10
  293. package/typography/index.d.ts +0 -23
  294. package/typography/index.js +2 -57
  295. package/typography/index.js.flow +0 -31
  296. package/es/spinner/spinner.js +0 -68
  297. package/es/themes/dark-theme/color-deprecated-semantic-tokens.js +0 -35
  298. package/es/themes/light-theme/color-deprecated-semantic-tokens.js +0 -35
  299. package/esm/spinner/spinner.js +0 -125
  300. package/esm/themes/dark-theme/color-deprecated-semantic-tokens.js +0 -38
  301. package/esm/themes/light-theme/color-deprecated-semantic-tokens.js +0 -38
  302. package/spinner/spinner.js +0 -136
  303. package/spinner/spinner.js.flow +0 -75
  304. package/themes/dark-theme/color-deprecated-semantic-tokens.js +0 -50
  305. package/themes/dark-theme/color-deprecated-semantic-tokens.js.flow +0 -42
  306. package/themes/light-theme/color-deprecated-semantic-tokens.js +0 -50
  307. package/themes/light-theme/color-deprecated-semantic-tokens.js.flow +0 -42
@@ -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++;
@@ -19,6 +19,8 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
19
19
 
20
20
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
21
 
22
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+
22
24
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
25
 
24
26
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -56,7 +58,10 @@ var StatefulComponent = /*#__PURE__*/function (_React$Component) {
56
58
  key: "render",
57
59
  value: function render() {
58
60
  return /*#__PURE__*/React.createElement(_statefulContainer.default, this.props, function (extendedProps) {
59
- return /*#__PURE__*/React.createElement(_calendar.default, extendedProps);
61
+ return /*#__PURE__*/React.createElement(_calendar.default, _extends({}, extendedProps, {
62
+ // flowlint-next-line unclear-type:off
63
+ onChange: extendedProps.onChange
64
+ }));
60
65
  });
61
66
  }
62
67
  }]);
@@ -18,10 +18,17 @@ class StatefulComponent<T = Date> extends React.Component<PropsT<T>> {
18
18
  stateReducer: (type, nextState) => nextState,
19
19
  onSelect: () => {},
20
20
  };
21
+
21
22
  render() {
22
23
  return (
23
24
  <StatefulContainer {...this.props}>
24
- {(extendedProps) => <Calendar {...extendedProps} />}
25
+ {(extendedProps) => (
26
+ <Calendar
27
+ {...extendedProps}
28
+ // flowlint-next-line unclear-type:off
29
+ onChange={(extendedProps.onChange: any)}
30
+ />
31
+ )}
25
32
  </StatefulContainer>
26
33
  );
27
34
  }
@@ -64,8 +64,29 @@ var StatefulContainer = /*#__PURE__*/function (_React$Component) {
64
64
  value: date
65
65
  });
66
66
 
67
- if (typeof _this.props.onChange === 'function') {
68
- _this.props.onChange(data);
67
+ var onChange = _this.props.onChange;
68
+
69
+ if (onChange) {
70
+ if (Array.isArray(date)) {
71
+ if (date.every(Boolean)) {
72
+ // flowlint-next-line unclear-type:off
73
+ onChange({
74
+ date: date
75
+ });
76
+ }
77
+ } else {
78
+ onChange({
79
+ date: date
80
+ });
81
+ }
82
+ }
83
+
84
+ var onRangeChange = _this.props.onRangeChange;
85
+
86
+ if (onRangeChange) {
87
+ onRangeChange({
88
+ date: date
89
+ });
69
90
  }
70
91
  });
71
92
 
@@ -33,11 +33,25 @@ class StatefulContainer<T = Date> extends React.Component<PropsT<T>, ContainerSt
33
33
  this.state = { value, ...props.initialState };
34
34
  }
35
35
 
36
- onChange: ({ date: ?T | Array<T> }) => mixed = (data) => {
36
+ onChange: ({ +date: ?T | Array<?T> }) => mixed = (data) => {
37
37
  const { date } = data;
38
38
  this.internalSetState(STATE_CHANGE_TYPE.change, { value: date });
39
- if (typeof this.props.onChange === 'function') {
40
- this.props.onChange(data);
39
+
40
+ const onChange = this.props.onChange;
41
+ if (onChange) {
42
+ if (Array.isArray(date)) {
43
+ if (date.every(Boolean)) {
44
+ // flowlint-next-line unclear-type:off
45
+ onChange({ date: ((date: any): Array<T>) });
46
+ }
47
+ } else {
48
+ onChange({ date });
49
+ }
50
+ }
51
+
52
+ const onRangeChange = this.props.onRangeChange;
53
+ if (onRangeChange) {
54
+ onRangeChange({ date });
41
55
  }
42
56
  };
43
57
 
@@ -19,6 +19,8 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
19
19
 
20
20
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
21
 
22
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+
22
24
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
25
 
24
26
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -56,7 +58,10 @@ var StatefulComponent = /*#__PURE__*/function (_React$Component) {
56
58
  key: "render",
57
59
  value: function render() {
58
60
  return /*#__PURE__*/React.createElement(_statefulContainer.default, this.props, function (extendedProps) {
59
- return /*#__PURE__*/React.createElement(_datepicker.default, extendedProps);
61
+ return /*#__PURE__*/React.createElement(_datepicker.default, _extends({}, extendedProps, {
62
+ // flowlint-next-line unclear-type:off
63
+ onChange: extendedProps.onChange
64
+ }));
60
65
  });
61
66
  }
62
67
  }]);
@@ -21,7 +21,13 @@ class StatefulComponent<T = Date> extends React.Component<PropsT<T>> {
21
21
  render() {
22
22
  return (
23
23
  <StatefulContainer {...this.props}>
24
- {(extendedProps) => <Datepicker {...extendedProps} />}
24
+ {(extendedProps) => (
25
+ <Datepicker
26
+ {...extendedProps}
27
+ // flowlint-next-line unclear-type:off
28
+ onChange={(extendedProps.onChange: any)}
29
+ />
30
+ )}
25
31
  </StatefulContainer>
26
32
  );
27
33
  }
@@ -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