@cloudscape-design/components 3.0.28 → 3.0.31

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 (279) hide show
  1. package/app-layout/visual-refresh/styles.css.js +59 -59
  2. package/app-layout/visual-refresh/styles.scoped.css +146 -146
  3. package/app-layout/visual-refresh/styles.selectors.js +59 -59
  4. package/autosuggest/autosuggest-option.d.ts +1 -0
  5. package/autosuggest/autosuggest-option.d.ts.map +1 -1
  6. package/autosuggest/autosuggest-option.js +2 -2
  7. package/autosuggest/autosuggest-option.js.map +1 -1
  8. package/autosuggest/controller.d.ts +2 -5
  9. package/autosuggest/controller.d.ts.map +1 -1
  10. package/autosuggest/controller.js +5 -49
  11. package/autosuggest/controller.js.map +1 -1
  12. package/autosuggest/internal.d.ts.map +1 -1
  13. package/autosuggest/internal.js +19 -25
  14. package/autosuggest/internal.js.map +1 -1
  15. package/autosuggest/options-controller.d.ts +25 -0
  16. package/autosuggest/options-controller.d.ts.map +1 -0
  17. package/autosuggest/options-controller.js +64 -0
  18. package/autosuggest/options-controller.js.map +1 -0
  19. package/autosuggest/options-list.d.ts +3 -2
  20. package/autosuggest/options-list.d.ts.map +1 -1
  21. package/autosuggest/options-list.js +8 -7
  22. package/autosuggest/options-list.js.map +1 -1
  23. package/autosuggest/plain-list.d.ts +2 -2
  24. package/autosuggest/plain-list.d.ts.map +1 -1
  25. package/autosuggest/plain-list.js +4 -4
  26. package/autosuggest/plain-list.js.map +1 -1
  27. package/autosuggest/virtual-list.d.ts +1 -1
  28. package/autosuggest/virtual-list.d.ts.map +1 -1
  29. package/autosuggest/virtual-list.js +4 -4
  30. package/autosuggest/virtual-list.js.map +1 -1
  31. package/breadcrumb-group/internal.d.ts.map +1 -1
  32. package/breadcrumb-group/internal.js +4 -4
  33. package/breadcrumb-group/internal.js.map +1 -1
  34. package/button-dropdown/category-elements/category-element.d.ts +1 -1
  35. package/button-dropdown/category-elements/category-element.d.ts.map +1 -1
  36. package/button-dropdown/category-elements/category-element.js +2 -2
  37. package/button-dropdown/category-elements/category-element.js.map +1 -1
  38. package/button-dropdown/category-elements/expandable-category-element.d.ts +1 -1
  39. package/button-dropdown/category-elements/expandable-category-element.d.ts.map +1 -1
  40. package/button-dropdown/category-elements/expandable-category-element.js +4 -2
  41. package/button-dropdown/category-elements/expandable-category-element.js.map +1 -1
  42. package/button-dropdown/category-elements/mobile-expandable-category-element.d.ts +1 -1
  43. package/button-dropdown/category-elements/mobile-expandable-category-element.d.ts.map +1 -1
  44. package/button-dropdown/category-elements/mobile-expandable-category-element.js +4 -2
  45. package/button-dropdown/category-elements/mobile-expandable-category-element.js.map +1 -1
  46. package/button-dropdown/category-elements/styles.css.js +13 -12
  47. package/button-dropdown/category-elements/styles.scoped.css +26 -22
  48. package/button-dropdown/category-elements/styles.selectors.js +13 -12
  49. package/button-dropdown/interfaces.d.ts +3 -1
  50. package/button-dropdown/interfaces.d.ts.map +1 -1
  51. package/button-dropdown/interfaces.js.map +1 -1
  52. package/button-dropdown/internal.d.ts.map +1 -1
  53. package/button-dropdown/internal.js +6 -11
  54. package/button-dropdown/internal.js.map +1 -1
  55. package/button-dropdown/item-element/index.d.ts +1 -1
  56. package/button-dropdown/item-element/index.d.ts.map +1 -1
  57. package/button-dropdown/item-element/index.js +2 -1
  58. package/button-dropdown/item-element/index.js.map +1 -1
  59. package/button-dropdown/item-element/styles.css.js +14 -13
  60. package/button-dropdown/item-element/styles.scoped.css +21 -17
  61. package/button-dropdown/item-element/styles.selectors.js +14 -13
  62. package/button-dropdown/items-list.d.ts +1 -1
  63. package/button-dropdown/items-list.d.ts.map +1 -1
  64. package/button-dropdown/items-list.js +4 -4
  65. package/button-dropdown/items-list.js.map +1 -1
  66. package/button-dropdown/utils/use-button-dropdown.d.ts +2 -2
  67. package/button-dropdown/utils/use-button-dropdown.d.ts.map +1 -1
  68. package/button-dropdown/utils/use-button-dropdown.js +7 -5
  69. package/button-dropdown/utils/use-button-dropdown.js.map +1 -1
  70. package/button-dropdown/utils/use-highlighted-menu.d.ts +1 -0
  71. package/button-dropdown/utils/use-highlighted-menu.d.ts.map +1 -1
  72. package/button-dropdown/utils/use-highlighted-menu.js +11 -3
  73. package/button-dropdown/utils/use-highlighted-menu.js.map +1 -1
  74. package/checkbox/styles.css.js +3 -3
  75. package/checkbox/styles.scoped.css +6 -6
  76. package/checkbox/styles.selectors.js +3 -3
  77. package/date-picker/calendar/index.d.ts.map +1 -1
  78. package/date-picker/calendar/index.js +2 -1
  79. package/date-picker/calendar/index.js.map +1 -1
  80. package/date-picker/calendar/utils/memoized-date.d.ts +2 -0
  81. package/date-picker/calendar/utils/memoized-date.d.ts.map +1 -0
  82. package/date-picker/calendar/utils/memoized-date.js +13 -0
  83. package/date-picker/calendar/utils/memoized-date.js.map +1 -0
  84. package/date-picker/embedded.js +1 -1
  85. package/date-picker/embedded.js.map +1 -1
  86. package/date-picker/index.js +1 -1
  87. package/date-picker/index.js.map +1 -1
  88. package/date-picker/use-date-picker.d.ts.map +1 -1
  89. package/date-picker/use-date-picker.js +1 -1
  90. package/date-picker/use-date-picker.js.map +1 -1
  91. package/date-range-picker/calendar/grids/day/index.js +1 -1
  92. package/date-range-picker/calendar/grids/day/index.js.map +1 -1
  93. package/date-range-picker/calendar/index.d.ts.map +1 -1
  94. package/date-range-picker/calendar/index.js +3 -3
  95. package/date-range-picker/calendar/index.js.map +1 -1
  96. package/date-range-picker/dropdown.d.ts +1 -0
  97. package/date-range-picker/dropdown.d.ts.map +1 -1
  98. package/date-range-picker/dropdown.js +18 -30
  99. package/date-range-picker/dropdown.js.map +1 -1
  100. package/date-range-picker/embedded.d.ts +7 -0
  101. package/date-range-picker/embedded.d.ts.map +1 -0
  102. package/date-range-picker/embedded.js +46 -0
  103. package/date-range-picker/embedded.js.map +1 -0
  104. package/date-range-picker/index.d.ts.map +1 -1
  105. package/date-range-picker/index.js +5 -18
  106. package/date-range-picker/index.js.map +1 -1
  107. package/date-range-picker/interfaces.d.ts +46 -44
  108. package/date-range-picker/interfaces.d.ts.map +1 -1
  109. package/date-range-picker/interfaces.js.map +1 -1
  110. package/date-range-picker/time-offset.d.ts +0 -7
  111. package/date-range-picker/time-offset.d.ts.map +1 -1
  112. package/date-range-picker/time-offset.js +4 -60
  113. package/date-range-picker/time-offset.js.map +1 -1
  114. package/date-range-picker/use-date-range-picker.d.ts +29 -0
  115. package/date-range-picker/use-date-range-picker.d.ts.map +1 -0
  116. package/date-range-picker/use-date-range-picker.js +58 -0
  117. package/date-range-picker/use-date-range-picker.js.map +1 -0
  118. package/icon/icons.js +1 -1
  119. package/icon/interfaces.d.ts +1 -1
  120. package/icon/interfaces.d.ts.map +1 -1
  121. package/icon/interfaces.js.map +1 -1
  122. package/input/styles.css.js +13 -13
  123. package/input/styles.scoped.css +35 -37
  124. package/input/styles.selectors.js +13 -13
  125. package/internal/components/abstract-switch/index.d.ts.map +1 -1
  126. package/internal/components/abstract-switch/index.js +5 -5
  127. package/internal/components/abstract-switch/index.js.map +1 -1
  128. package/internal/components/abstract-switch/styles.css.js +11 -11
  129. package/internal/components/abstract-switch/styles.scoped.css +20 -13
  130. package/internal/components/abstract-switch/styles.selectors.js +11 -11
  131. package/internal/components/date-input/index.d.ts.map +1 -1
  132. package/internal/components/date-input/index.js +3 -2
  133. package/internal/components/date-input/index.js.map +1 -1
  134. package/internal/components/masked-input/utils/mask-format.d.ts.map +1 -1
  135. package/internal/components/masked-input/utils/mask-format.js +2 -1
  136. package/internal/components/masked-input/utils/mask-format.js.map +1 -1
  137. package/internal/components/masked-input/utils/strings.d.ts +0 -1
  138. package/internal/components/masked-input/utils/strings.d.ts.map +1 -1
  139. package/internal/components/masked-input/utils/strings.js +0 -6
  140. package/internal/components/masked-input/utils/strings.js.map +1 -1
  141. package/internal/components/options-list/utils/use-highlight-option.d.ts +7 -2
  142. package/internal/components/options-list/utils/use-highlight-option.d.ts.map +1 -1
  143. package/internal/components/options-list/utils/use-highlight-option.js +10 -3
  144. package/internal/components/options-list/utils/use-highlight-option.js.map +1 -1
  145. package/internal/components/selectable-item/index.d.ts +1 -1
  146. package/internal/components/selectable-item/index.d.ts.map +1 -1
  147. package/internal/components/selectable-item/index.js +2 -2
  148. package/internal/components/selectable-item/index.js.map +1 -1
  149. package/internal/components/selectable-item/styles.css.js +16 -16
  150. package/internal/components/selectable-item/styles.scoped.css +29 -30
  151. package/internal/components/selectable-item/styles.selectors.js +16 -16
  152. package/internal/environment.js +1 -1
  153. package/internal/utils/date-time/display-format.d.ts +9 -0
  154. package/internal/utils/date-time/display-format.d.ts.map +1 -0
  155. package/internal/utils/date-time/display-format.js +15 -0
  156. package/internal/utils/date-time/display-format.js.map +1 -0
  157. package/internal/utils/date-time/format-date.d.ts +7 -0
  158. package/internal/utils/date-time/format-date.d.ts.map +1 -0
  159. package/internal/utils/date-time/format-date.js +15 -0
  160. package/internal/utils/date-time/format-date.js.map +1 -0
  161. package/internal/utils/date-time/format-time.d.ts +5 -0
  162. package/internal/utils/date-time/format-time.d.ts.map +1 -0
  163. package/internal/utils/date-time/format-time.js +13 -0
  164. package/internal/utils/date-time/format-time.js.map +1 -0
  165. package/internal/utils/date-time/format-timezone-offset.d.ts +2 -0
  166. package/internal/utils/date-time/format-timezone-offset.d.ts.map +1 -0
  167. package/internal/utils/date-time/format-timezone-offset.js +11 -0
  168. package/internal/utils/date-time/format-timezone-offset.js.map +1 -0
  169. package/internal/utils/date-time/get-browser-timezone-offset.d.ts +7 -0
  170. package/internal/utils/date-time/get-browser-timezone-offset.d.ts.map +1 -0
  171. package/internal/utils/date-time/get-browser-timezone-offset.js +11 -0
  172. package/internal/utils/date-time/get-browser-timezone-offset.js.map +1 -0
  173. package/internal/utils/date-time/index.d.ts +11 -0
  174. package/internal/utils/date-time/index.d.ts.map +1 -0
  175. package/internal/utils/date-time/index.js +13 -0
  176. package/internal/utils/date-time/index.js.map +1 -0
  177. package/internal/utils/date-time/is-iso-date-only.d.ts +5 -0
  178. package/internal/utils/date-time/is-iso-date-only.d.ts.map +1 -0
  179. package/internal/utils/date-time/is-iso-date-only.js +10 -0
  180. package/internal/utils/date-time/is-iso-date-only.js.map +1 -0
  181. package/internal/utils/date-time/join-date-time.d.ts +2 -0
  182. package/internal/utils/date-time/join-date-time.d.ts.map +1 -0
  183. package/internal/utils/date-time/join-date-time.js +6 -0
  184. package/internal/utils/date-time/join-date-time.js.map +1 -0
  185. package/internal/utils/date-time/parse-date.d.ts +8 -0
  186. package/internal/utils/date-time/parse-date.d.ts.map +1 -0
  187. package/internal/utils/date-time/parse-date.js +16 -0
  188. package/internal/utils/date-time/parse-date.js.map +1 -0
  189. package/internal/utils/date-time/parse-timezone-offset.d.ts +5 -0
  190. package/internal/utils/date-time/parse-timezone-offset.d.ts.map +1 -0
  191. package/internal/utils/date-time/parse-timezone-offset.js +20 -0
  192. package/internal/utils/date-time/parse-timezone-offset.js.map +1 -0
  193. package/internal/utils/date-time/shift-timezone-offset.d.ts +12 -0
  194. package/internal/utils/date-time/shift-timezone-offset.d.ts.map +1 -0
  195. package/internal/utils/date-time/shift-timezone-offset.js +27 -0
  196. package/internal/utils/date-time/shift-timezone-offset.js.map +1 -0
  197. package/internal/utils/strings/index.d.ts +3 -0
  198. package/internal/utils/strings/index.d.ts.map +1 -0
  199. package/internal/utils/strings/index.js +5 -0
  200. package/internal/utils/strings/index.js.map +1 -0
  201. package/internal/utils/strings/join-strings.d.ts +5 -0
  202. package/internal/utils/strings/join-strings.d.ts.map +1 -0
  203. package/internal/utils/{strings.js → strings/join-strings.js} +7 -6
  204. package/internal/utils/strings/join-strings.js.map +1 -0
  205. package/internal/utils/strings/pad-left-zeros.d.ts +5 -0
  206. package/internal/utils/strings/pad-left-zeros.d.ts.map +1 -0
  207. package/internal/utils/strings/pad-left-zeros.js +12 -0
  208. package/internal/utils/strings/pad-left-zeros.js.map +1 -0
  209. package/multiselect/internal.d.ts.map +1 -1
  210. package/multiselect/internal.js +2 -2
  211. package/multiselect/internal.js.map +1 -1
  212. package/package.json +1 -1
  213. package/popover/styles.css.js +48 -48
  214. package/popover/styles.scoped.css +65 -60
  215. package/popover/styles.selectors.js +48 -48
  216. package/radio-group/styles.css.js +9 -9
  217. package/radio-group/styles.scoped.css +16 -16
  218. package/radio-group/styles.selectors.js +9 -9
  219. package/select/internal.d.ts.map +1 -1
  220. package/select/internal.js +2 -2
  221. package/select/internal.js.map +1 -1
  222. package/select/parts/item.d.ts +1 -1
  223. package/select/parts/item.d.ts.map +1 -1
  224. package/select/parts/item.js +6 -3
  225. package/select/parts/item.js.map +1 -1
  226. package/select/parts/multiselect-item.d.ts +1 -1
  227. package/select/parts/multiselect-item.d.ts.map +1 -1
  228. package/select/parts/multiselect-item.js +2 -2
  229. package/select/parts/multiselect-item.js.map +1 -1
  230. package/select/parts/plain-list.d.ts +1 -1
  231. package/select/parts/plain-list.d.ts.map +1 -1
  232. package/select/parts/plain-list.js +4 -4
  233. package/select/parts/plain-list.js.map +1 -1
  234. package/select/parts/styles.css.js +8 -7
  235. package/select/parts/styles.scoped.css +12 -7
  236. package/select/parts/styles.selectors.js +8 -7
  237. package/select/parts/virtual-list.js +4 -4
  238. package/select/parts/virtual-list.js.map +1 -1
  239. package/select/utils/get-item-props.d.ts +1 -2
  240. package/select/utils/get-item-props.d.ts.map +1 -1
  241. package/select/utils/get-item-props.js +3 -3
  242. package/select/utils/get-item-props.js.map +1 -1
  243. package/select/utils/render-options.d.ts +2 -2
  244. package/select/utils/render-options.d.ts.map +1 -1
  245. package/select/utils/render-options.js +2 -3
  246. package/select/utils/render-options.js.map +1 -1
  247. package/select/utils/use-select.d.ts +1 -0
  248. package/select/utils/use-select.d.ts.map +1 -1
  249. package/select/utils/use-select.js +2 -1
  250. package/select/utils/use-select.js.map +1 -1
  251. package/split-panel/index.d.ts.map +1 -1
  252. package/split-panel/index.js +2 -2
  253. package/split-panel/index.js.map +1 -1
  254. package/table/styles.css.js +32 -32
  255. package/table/styles.scoped.css +40 -43
  256. package/table/styles.selectors.js +32 -32
  257. package/tabs/styles.css.js +21 -21
  258. package/tabs/styles.scoped.css +40 -43
  259. package/tabs/styles.selectors.js +21 -21
  260. package/textarea/styles.css.js +4 -4
  261. package/textarea/styles.scoped.css +13 -14
  262. package/textarea/styles.selectors.js +4 -4
  263. package/toggle/internal.d.ts.map +1 -1
  264. package/toggle/internal.js +3 -1
  265. package/toggle/internal.js.map +1 -1
  266. package/toggle/styles.css.js +8 -8
  267. package/toggle/styles.scoped.css +15 -14
  268. package/toggle/styles.selectors.js +8 -8
  269. package/date-picker/calendar/utils/date.d.ts +0 -10
  270. package/date-picker/calendar/utils/date.d.ts.map +0 -1
  271. package/date-picker/calendar/utils/date.js +0 -50
  272. package/date-picker/calendar/utils/date.js.map +0 -1
  273. package/internal/components/date-input/utils/date.d.ts +0 -5
  274. package/internal/components/date-input/utils/date.d.ts.map +0 -1
  275. package/internal/components/date-input/utils/date.js +0 -11
  276. package/internal/components/date-input/utils/date.js.map +0 -1
  277. package/internal/utils/strings.d.ts +0 -2
  278. package/internal/utils/strings.d.ts.map +0 -1
  279. package/internal/utils/strings.js.map +0 -1
@@ -0,0 +1,46 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import React, { useRef } from 'react';
4
+ import Calendar from './calendar';
5
+ import InternalBox from '../box/internal';
6
+ import SpaceBetween from '../space-between/index.js';
7
+ import RelativeRangePicker from './relative-range';
8
+ import ModeSwitcher from './mode-switcher';
9
+ import { useDateRangePicker } from './use-date-range-picker';
10
+ import { fireNonCancelableEvent } from '../internal/events/index.js';
11
+ import { getBrowserTimezoneOffset } from '../internal/utils/date-time';
12
+ import { formatValue } from './use-date-range-picker.js';
13
+ import { useMobile } from '../internal/hooks/use-mobile';
14
+ export function DateRangePickerEmbedded(_a) {
15
+ var value = _a.value, _b = _a.locale, locale = _b === void 0 ? '' : _b, startOfWeek = _a.startOfWeek, _c = _a.isDateEnabled, isDateEnabled = _c === void 0 ? function () { return true; } : _c, relativeOptions = _a.relativeOptions, i18nStrings = _a.i18nStrings, _d = _a.dateOnly, dateOnly = _d === void 0 ? false : _d, _e = _a.timeInputFormat, timeInputFormat = _e === void 0 ? 'hh:mm:ss' : _e, _f = _a.rangeSelectorMode, rangeSelectorMode = _f === void 0 ? 'default' : _f, onChange = _a.onChange, _g = _a.timeOffset, timeOffset = _g === void 0 ? getBrowserTimezoneOffset() : _g;
16
+ var _h = useDateRangePicker({
17
+ value: value,
18
+ relativeOptions: relativeOptions,
19
+ rangeSelectorMode: rangeSelectorMode
20
+ }), fillMissingTime = _h.fillMissingTime, rangeSelectionMode = _h.rangeSelectionMode, setRangeSelectionMode = _h.setRangeSelectionMode, selectedAbsoluteRange = _h.selectedAbsoluteRange, setSelectedAbsoluteRange = _h.setSelectedAbsoluteRange, selectedRelativeRange = _h.selectedRelativeRange, setSelectedRelativeRange = _h.setSelectedRelativeRange;
21
+ var isSingleGrid = useMobile();
22
+ function updateRange(value) {
23
+ var newValue = value.type === 'relative' ? value : fillMissingTime(value);
24
+ fireNonCancelableEvent(onChange, { value: formatValue(newValue, { dateOnly: dateOnly, timeOffset: timeOffset }) });
25
+ }
26
+ var focusRefs = {
27
+ "default": useRef(null),
28
+ 'absolute-only': useRef(null),
29
+ 'relative-only': useRef(null)
30
+ };
31
+ return (React.createElement(SpaceBetween, { size: "l" },
32
+ React.createElement(InternalBox, { padding: { top: 'm', horizontal: 'l' } },
33
+ React.createElement(SpaceBetween, { direction: "vertical", size: "s" },
34
+ rangeSelectorMode === 'default' && (React.createElement(ModeSwitcher, { ref: focusRefs["default"], mode: rangeSelectionMode, onChange: function (mode) {
35
+ setRangeSelectionMode(mode);
36
+ }, i18nStrings: i18nStrings })),
37
+ rangeSelectionMode === 'absolute' && (React.createElement(Calendar, { ref: focusRefs['absolute-only'], isSingleGrid: isSingleGrid, initialEndDate: selectedAbsoluteRange === null || selectedAbsoluteRange === void 0 ? void 0 : selectedAbsoluteRange.endDate, initialStartDate: selectedAbsoluteRange === null || selectedAbsoluteRange === void 0 ? void 0 : selectedAbsoluteRange.startDate, locale: locale, startOfWeek: startOfWeek, isDateEnabled: isDateEnabled, i18nStrings: i18nStrings, onSelectDateRange: function (range) {
38
+ setSelectedAbsoluteRange(range);
39
+ updateRange(range);
40
+ }, dateOnly: dateOnly, timeInputFormat: timeInputFormat })),
41
+ rangeSelectionMode === 'relative' && (React.createElement(RelativeRangePicker, { ref: focusRefs['relative-only'], isSingleGrid: isSingleGrid, options: relativeOptions, dateOnly: dateOnly, initialSelection: selectedRelativeRange, onChange: function (range) {
42
+ setSelectedRelativeRange(range);
43
+ updateRange(range);
44
+ }, i18nStrings: i18nStrings }))))));
45
+ }
46
+ //# sourceMappingURL=embedded.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedded.js","sourceRoot":"","sources":["../../../src/date-range-picker/embedded.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,YAAY,MAAM,2BAA2B,CAAC;AAErD,OAAO,mBAAmB,MAAM,kBAAkB,CAAC;AACnD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAOzD,MAAM,UAAU,uBAAuB,CAAC,EAYT;QAX7B,KAAK,WAAA,EACL,cAAW,EAAX,MAAM,mBAAG,EAAE,KAAA,EACX,WAAW,iBAAA,EACX,qBAA0B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AChB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useRef } from 'react';\nimport Calendar from './calendar';\nimport InternalBox from '../box/internal';\nimport SpaceBetween from '../space-between/index.js';\n\nimport RelativeRangePicker from './relative-range';\nimport ModeSwitcher from './mode-switcher';\nimport { useDateRangePicker } from './use-date-range-picker';\nimport { DateRangePickerBaseProps } from './interfaces';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport { DateRangePickerProps, Focusable } from './interfaces';\nimport { getBrowserTimezoneOffset } from '../internal/utils/date-time';\nimport { formatValue } from './use-date-range-picker.js';\nimport { useMobile } from '../internal/hooks/use-mobile';\n\nexport interface DateRangePickerEmbeddedProps extends DateRangePickerBaseProps {\n ariaLabelledby?: string;\n ariaDescribedby?: string;\n}\n\nexport function DateRangePickerEmbedded({\n value,\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n relativeOptions,\n i18nStrings,\n dateOnly = false,\n timeInputFormat = 'hh:mm:ss',\n rangeSelectorMode = 'default',\n onChange,\n timeOffset = getBrowserTimezoneOffset(),\n}: DateRangePickerEmbeddedProps) {\n const {\n fillMissingTime,\n rangeSelectionMode,\n setRangeSelectionMode,\n selectedAbsoluteRange,\n setSelectedAbsoluteRange,\n selectedRelativeRange,\n setSelectedRelativeRange,\n } = useDateRangePicker({\n value,\n relativeOptions,\n rangeSelectorMode,\n });\n\n const isSingleGrid = useMobile();\n\n function updateRange(value: DateRangePickerProps.AbsoluteValue | DateRangePickerProps.RelativeValue) {\n const newValue = value.type === 'relative' ? value : fillMissingTime(value);\n\n fireNonCancelableEvent(onChange, { value: formatValue(newValue, { dateOnly, timeOffset }) });\n }\n\n const focusRefs = {\n default: useRef<Focusable>(null),\n 'absolute-only': useRef<Focusable>(null),\n 'relative-only': useRef<Focusable>(null),\n };\n\n return (\n <SpaceBetween size=\"l\">\n <InternalBox padding={{ top: 'm', horizontal: 'l' }}>\n <SpaceBetween direction=\"vertical\" size=\"s\">\n {rangeSelectorMode === 'default' && (\n <ModeSwitcher\n ref={focusRefs.default}\n mode={rangeSelectionMode}\n onChange={(mode: 'absolute' | 'relative') => {\n setRangeSelectionMode(mode);\n }}\n i18nStrings={i18nStrings}\n />\n )}\n\n {rangeSelectionMode === 'absolute' && (\n <Calendar\n ref={focusRefs['absolute-only']}\n isSingleGrid={isSingleGrid}\n initialEndDate={selectedAbsoluteRange?.endDate}\n initialStartDate={selectedAbsoluteRange?.startDate}\n locale={locale}\n startOfWeek={startOfWeek}\n isDateEnabled={isDateEnabled}\n i18nStrings={i18nStrings}\n onSelectDateRange={range => {\n setSelectedAbsoluteRange(range);\n updateRange(range);\n }}\n dateOnly={dateOnly}\n timeInputFormat={timeInputFormat}\n />\n )}\n\n {rangeSelectionMode === 'relative' && (\n <RelativeRangePicker\n ref={focusRefs['relative-only']}\n isSingleGrid={isSingleGrid}\n options={relativeOptions}\n dateOnly={dateOnly}\n initialSelection={selectedRelativeRange}\n onChange={range => {\n setSelectedRelativeRange(range);\n updateRange(range);\n }}\n i18nStrings={i18nStrings}\n />\n )}\n </SpaceBetween>\n </InternalBox>\n </SpaceBetween>\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-range-picker/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAyBpD,OAAO,EAAE,oBAAoB,EAAE,CAAC;AA0EhC,QAAA,MAAM,eAAe,uGAgMpB,CAAC;AAGF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-range-picker/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AA2BpD,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAwDhC,QAAA,MAAM,eAAe,uGAgMpB,CAAC;AAGF,eAAe,eAAe,CAAC"}
@@ -18,7 +18,7 @@ import { useMobile } from '../internal/hooks/use-mobile';
18
18
  import ButtonTrigger from '../internal/components/button-trigger';
19
19
  import { useFormFieldContext } from '../internal/context/form-field-context';
20
20
  import InternalIcon from '../icon/internal';
21
- import { getBrowserTimezoneOffset, shiftTimeOffset, formatOffset, setTimeOffset } from './time-offset';
21
+ import { shiftTimeOffset } from './time-offset';
22
22
  import useBaseComponent from '../internal/hooks/use-base-component';
23
23
  import { useMergeRefs } from '../internal/hooks/use-merge-refs';
24
24
  import { fireNonCancelableEvent } from '../internal/events/index.js';
@@ -26,6 +26,8 @@ import { isDevelopment } from '../internal/is-development.js';
26
26
  import { warnOnce } from '../internal/logging.js';
27
27
  import { usePrevious } from '../internal/hooks/use-previous/index.js';
28
28
  import { useUniqueId } from '../internal/hooks/use-unique-id';
29
+ import { formatTimezoneOffset, getBrowserTimezoneOffset, isIsoDateOnly } from '../internal/utils/date-time';
30
+ import { formatValue } from './use-date-range-picker.js';
29
31
  function formatDateRange(range, placeholder, formatRelativeRange, timeOffset) {
30
32
  if (!range) {
31
33
  return (React.createElement("span", { className: styles['label-text'], "aria-disabled": true }, placeholder));
@@ -41,29 +43,14 @@ function BreakSpaces(_a) {
41
43
  token === ' ' && React.createElement("wbr", null))); })));
42
44
  }
43
45
  function formatAbsoluteRange(value, timeOffset) {
44
- var formattedOffset = isDateOnly(value) ? '' : formatOffset(timeOffset);
46
+ var formattedOffset = isDateOnly(value) ? '' : formatTimezoneOffset(timeOffset);
45
47
  return value.startDate + formattedOffset + ' ' + '—' + ' ' + value.endDate + formattedOffset;
46
48
  }
47
49
  function isDateOnly(value) {
48
50
  if (!value || value.type !== 'absolute') {
49
51
  return false;
50
52
  }
51
- var dateRegex = /^\d{4}-\d{2}-\d{2}$/;
52
- return dateRegex.test(value.startDate) && dateRegex.test(value.endDate);
53
- }
54
- function formatValue(value, _a) {
55
- var timeOffset = _a.timeOffset, dateOnly = _a.dateOnly;
56
- if (!value || value.type === 'relative') {
57
- return value;
58
- }
59
- if (dateOnly) {
60
- return {
61
- type: 'absolute',
62
- startDate: value.startDate.split('T')[0],
63
- endDate: value.endDate.split('T')[0]
64
- };
65
- }
66
- return setTimeOffset(value, timeOffset);
53
+ return isIsoDateOnly(value.startDate) && isIsoDateOnly(value.endDate);
67
54
  }
68
55
  var DateRangePicker = React.forwardRef(function (_a, ref) {
69
56
  var _b;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date-range-picker/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAO,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,YA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ChC,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,GAChC,CACH,CACQ,CACP,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;AACrD,eAAe,eAAe,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { Ref, useEffect, useRef, useState } from 'react';\nimport styles from './styles.css.js';\nimport { DateRangePickerProps } from './interfaces';\nimport { normalizeLocale } from '../date-picker/calendar/utils/locales';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { KeyCode } from '../internal/keycode';\nimport clsx from 'clsx';\nimport { getBaseProps } from '../internal/base-component';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport InternalBox from '../box/internal';\nimport { DateRangePickerDropdown } from './dropdown';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport Dropdown from '../internal/components/dropdown';\nimport { useFocusTracker } from '../internal/hooks/use-focus-tracker';\nimport { useMobile } from '../internal/hooks/use-mobile';\nimport ButtonTrigger from '../internal/components/button-trigger';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport InternalIcon from '../icon/internal';\nimport { getBrowserTimezoneOffset, shiftTimeOffset, formatOffset, setTimeOffset } from './time-offset';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport { isDevelopment } from '../internal/is-development.js';\nimport { warnOnce } from '../internal/logging.js';\nimport { usePrevious } from '../internal/hooks/use-previous/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\n\nexport { DateRangePickerProps };\n\nfunction formatDateRange(\n range: null | DateRangePickerProps.Value,\n placeholder: string,\n formatRelativeRange: DateRangePickerProps.I18nStrings['formatRelativeRange'],\n timeOffset: number\n) {\n if (!range) {\n return (\n <span className={styles['label-text']} aria-disabled={true}>\n {placeholder}\n </span>\n );\n }\n\n const formatted =\n range.type === 'relative' ? (\n formatRelativeRange(range)\n ) : (\n <BreakSpaces text={formatAbsoluteRange(range, timeOffset)} />\n );\n\n return (\n <InternalBox fontWeight=\"normal\" display=\"inline\" color=\"inherit\">\n {formatted}\n </InternalBox>\n );\n}\n\nfunction BreakSpaces({ text }: { text: string }) {\n const tokens = text.split(/( )/);\n return (\n <div style={{ whiteSpace: 'nowrap' }}>\n {tokens.map((token, index) => (\n <React.Fragment key={index}>\n {token}\n {token === ' ' && <wbr />}\n </React.Fragment>\n ))}\n </div>\n );\n}\n\nfunction formatAbsoluteRange(value: DateRangePickerProps.AbsoluteValue, timeOffset: number): string {\n const formattedOffset = isDateOnly(value) ? '' : formatOffset(timeOffset);\n return value.startDate + formattedOffset + ' ' + '—' + ' ' + value.endDate + formattedOffset;\n}\n\nfunction isDateOnly(value: null | DateRangePickerProps.Value) {\n if (!value || value.type !== 'absolute') {\n return false;\n }\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n return dateRegex.test(value.startDate) && dateRegex.test(value.endDate);\n}\n\nfunction formatValue(\n value: null | DateRangePickerProps.Value,\n { timeOffset, dateOnly }: { timeOffset: number; dateOnly: boolean }\n): null | DateRangePickerProps.Value {\n if (!value || value.type === 'relative') {\n return value;\n }\n if (dateOnly) {\n return {\n type: 'absolute',\n startDate: value.startDate.split('T')[0],\n endDate: value.endDate.split('T')[0],\n };\n }\n return setTimeOffset(value, timeOffset);\n}\n\nconst DateRangePicker = React.forwardRef(\n (\n {\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n value,\n placeholder,\n readOnly = false,\n disabled = false,\n onChange,\n onBlur,\n onFocus,\n relativeOptions = [],\n i18nStrings,\n isValidRange = () => ({ valid: true }),\n showClearButton = true,\n dateOnly = false,\n timeOffset = getBrowserTimezoneOffset(),\n timeInputFormat = 'hh:mm:ss',\n expandToViewport = false,\n rangeSelectorMode = 'default',\n ...rest\n }: DateRangePickerProps,\n ref: Ref<DateRangePickerProps.Ref>\n ) => {\n const { __internalRootRef } = useBaseComponent('DateRangePicker');\n checkControlled('DateRangePicker', 'value', value, 'onChange', onChange);\n\n value = isDateOnly(value) ? value : shiftTimeOffset(value, timeOffset);\n\n const baseProps = getBaseProps(rest);\n const { invalid, controlId, ariaDescribedby, ariaLabelledby } = useFormFieldContext({\n ariaLabelledby: rest.ariaLabelledby ?? i18nStrings.ariaLabelledby,\n ariaDescribedby: rest.ariaDescribedby ?? i18nStrings.ariaDescribedby,\n ...rest,\n });\n const isSingleGrid = useMobile();\n\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n useForwardFocus(ref, triggerRef);\n\n const rootRef = useRef<HTMLDivElement>(null);\n const dropdownId = useUniqueId('date-range-picker-dropdown');\n\n useFocusTracker({ rootRef, onBlur, onFocus, viewportId: expandToViewport ? dropdownId : '' });\n\n const [isDropDownOpen, setIsDropDownOpen] = useState<boolean>(false);\n\n const normalizedLocale = normalizeLocale('DateRangePicker', locale ?? '');\n\n const closeDropdown = (focusTrigger = false) => {\n setIsDropDownOpen(false);\n if (focusTrigger) {\n triggerRef.current?.focus();\n }\n };\n\n const onWrapperKeyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.keyCode === KeyCode.escape) {\n closeDropdown(true);\n }\n };\n\n const onClear = () => {\n fireNonCancelableEvent(onChange, { value: null });\n };\n\n const onApply = (newValue: null | DateRangePickerProps.Value): DateRangePickerProps.ValidationResult => {\n const validationResult = isValidRange(newValue);\n if (validationResult?.valid === false) {\n return validationResult;\n }\n\n if (isDevelopment) {\n if (newValue?.type === 'absolute') {\n const [startDateWithoutTime] = newValue.startDate.split('T');\n const [endDateWithoutTime] = newValue.endDate.split('T');\n if (!startDateWithoutTime || !endDateWithoutTime) {\n warnOnce(\n 'DateRangePicker',\n 'You have provided an `isValidRange` prop that did not catch a missing start or end date.'\n );\n }\n }\n }\n fireNonCancelableEvent(onChange, { value: formatValue(newValue, { dateOnly, timeOffset }) });\n return validationResult || { valid: true };\n };\n\n const prevDateOnly = usePrevious(dateOnly);\n useEffect(() => {\n if (prevDateOnly !== undefined && prevDateOnly !== dateOnly) {\n warnOnce(\n 'DateRangePicker',\n `The provided \\`dateOnly\\` flag has been changed from \"${prevDateOnly}\" to \"${dateOnly}\" which can lead to unexpected value format. Consider using separate components.`\n );\n }\n }, [prevDateOnly, dateOnly]);\n\n if (value && value.type !== 'absolute' && value.type !== 'relative') {\n warnOnce('DateRangePicker', 'You provided an invalid value. Reverting back to default.');\n value = null;\n }\n\n if (\n (value?.type === 'absolute' && rangeSelectorMode === 'relative-only') ||\n (value?.type === 'relative' && rangeSelectorMode === 'absolute-only')\n ) {\n warnOnce(\n 'DateRangePicker',\n 'The provided value does not correspond to the current range selector mode. Reverting back to default.'\n );\n value = null;\n }\n\n const trigger = (\n <div className={styles['trigger-wrapper']}>\n <ButtonTrigger\n ref={triggerRef}\n id={controlId}\n invalid={invalid}\n ariaLabel={i18nStrings.ariaLabel}\n ariaDescribedby={ariaDescribedby}\n ariaLabelledby={ariaLabelledby}\n className={clsx(styles.label, {\n [styles['label-enabled']]: !readOnly && !disabled,\n })}\n hideCaret={true}\n onClick={() => {\n if (!readOnly && !disabled) {\n setIsDropDownOpen(true);\n }\n }}\n disabled={disabled}\n readOnly={readOnly}\n ariaHasPopup=\"true\"\n >\n <span className={styles['trigger-flexbox']}>\n <span className={styles['icon-wrapper']}>\n <InternalIcon name=\"calendar\" variant={disabled || readOnly ? 'disabled' : 'normal'} />\n </span>\n {formatDateRange(value, placeholder ?? '', i18nStrings.formatRelativeRange, timeOffset)}\n </span>\n </ButtonTrigger>\n </div>\n );\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n return (\n <div\n {...baseProps}\n ref={mergedRef}\n className={clsx(baseProps.className, styles.root)}\n onKeyDown={onWrapperKeyDownHandler}\n >\n <Dropdown\n stretchWidth={true}\n stretchHeight={true}\n open={isDropDownOpen}\n onDropdownClose={() => closeDropdown()}\n trigger={trigger}\n stretchToTriggerWidth={false}\n expandToViewport={expandToViewport}\n dropdownId={dropdownId}\n >\n {isDropDownOpen && (\n <DateRangePickerDropdown\n startOfWeek={startOfWeek}\n locale={normalizedLocale}\n isSingleGrid={isSingleGrid}\n onDropdownClose={() => closeDropdown(true)}\n value={value}\n showClearButton={showClearButton}\n isDateEnabled={isDateEnabled}\n i18nStrings={i18nStrings}\n onClear={onClear}\n onApply={onApply}\n relativeOptions={relativeOptions}\n isValidRange={isValidRange}\n dateOnly={dateOnly}\n timeInputFormat={timeInputFormat}\n rangeSelectorMode={rangeSelectorMode}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n />\n )}\n </Dropdown>\n </div>\n );\n }\n);\n\napplyDisplayName(DateRangePicker, 'DateRangePicker');\nexport default DateRangePicker;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date-range-picker/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAO,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,g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,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;AACrD,eAAe,eAAe,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { Ref, useEffect, useRef, useState } from 'react';\nimport styles from './styles.css.js';\nimport { DateRangePickerProps } from './interfaces';\nimport { normalizeLocale } from '../date-picker/calendar/utils/locales';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { KeyCode } from '../internal/keycode';\nimport clsx from 'clsx';\nimport { getBaseProps } from '../internal/base-component';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport InternalBox from '../box/internal';\nimport { DateRangePickerDropdown } from './dropdown';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport Dropdown from '../internal/components/dropdown';\nimport { useFocusTracker } from '../internal/hooks/use-focus-tracker';\nimport { useMobile } from '../internal/hooks/use-mobile';\nimport ButtonTrigger from '../internal/components/button-trigger';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport InternalIcon from '../icon/internal';\nimport { shiftTimeOffset } from './time-offset';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport { isDevelopment } from '../internal/is-development.js';\nimport { warnOnce } from '../internal/logging.js';\nimport { usePrevious } from '../internal/hooks/use-previous/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { formatTimezoneOffset, getBrowserTimezoneOffset, isIsoDateOnly } from '../internal/utils/date-time';\nimport { formatValue } from './use-date-range-picker.js';\n\nexport { DateRangePickerProps };\n\nfunction formatDateRange(\n range: null | DateRangePickerProps.Value,\n placeholder: string,\n formatRelativeRange: DateRangePickerProps.I18nStrings['formatRelativeRange'],\n timeOffset: number\n) {\n if (!range) {\n return (\n <span className={styles['label-text']} aria-disabled={true}>\n {placeholder}\n </span>\n );\n }\n\n const formatted =\n range.type === 'relative' ? (\n formatRelativeRange(range)\n ) : (\n <BreakSpaces text={formatAbsoluteRange(range, timeOffset)} />\n );\n\n return (\n <InternalBox fontWeight=\"normal\" display=\"inline\" color=\"inherit\">\n {formatted}\n </InternalBox>\n );\n}\n\nfunction BreakSpaces({ text }: { text: string }) {\n const tokens = text.split(/( )/);\n return (\n <div style={{ whiteSpace: 'nowrap' }}>\n {tokens.map((token, index) => (\n <React.Fragment key={index}>\n {token}\n {token === ' ' && <wbr />}\n </React.Fragment>\n ))}\n </div>\n );\n}\n\nfunction formatAbsoluteRange(value: DateRangePickerProps.AbsoluteValue, timeOffset: number): string {\n const formattedOffset = isDateOnly(value) ? '' : formatTimezoneOffset(timeOffset);\n return value.startDate + formattedOffset + ' ' + '—' + ' ' + value.endDate + formattedOffset;\n}\n\nfunction isDateOnly(value: null | DateRangePickerProps.Value) {\n if (!value || value.type !== 'absolute') {\n return false;\n }\n return isIsoDateOnly(value.startDate) && isIsoDateOnly(value.endDate);\n}\n\nconst DateRangePicker = React.forwardRef(\n (\n {\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n value,\n placeholder,\n readOnly = false,\n disabled = false,\n onChange,\n onBlur,\n onFocus,\n relativeOptions = [],\n i18nStrings,\n isValidRange = () => ({ valid: true }),\n showClearButton = true,\n dateOnly = false,\n timeOffset = getBrowserTimezoneOffset(),\n timeInputFormat = 'hh:mm:ss',\n expandToViewport = false,\n rangeSelectorMode = 'default',\n ...rest\n }: DateRangePickerProps,\n ref: Ref<DateRangePickerProps.Ref>\n ) => {\n const { __internalRootRef } = useBaseComponent('DateRangePicker');\n checkControlled('DateRangePicker', 'value', value, 'onChange', onChange);\n\n value = isDateOnly(value) ? value : shiftTimeOffset(value, timeOffset);\n\n const baseProps = getBaseProps(rest);\n const { invalid, controlId, ariaDescribedby, ariaLabelledby } = useFormFieldContext({\n ariaLabelledby: rest.ariaLabelledby ?? i18nStrings.ariaLabelledby,\n ariaDescribedby: rest.ariaDescribedby ?? i18nStrings.ariaDescribedby,\n ...rest,\n });\n const isSingleGrid = useMobile();\n\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n useForwardFocus(ref, triggerRef);\n\n const rootRef = useRef<HTMLDivElement>(null);\n const dropdownId = useUniqueId('date-range-picker-dropdown');\n\n useFocusTracker({ rootRef, onBlur, onFocus, viewportId: expandToViewport ? dropdownId : '' });\n\n const [isDropDownOpen, setIsDropDownOpen] = useState<boolean>(false);\n\n const normalizedLocale = normalizeLocale('DateRangePicker', locale ?? '');\n\n const closeDropdown = (focusTrigger = false) => {\n setIsDropDownOpen(false);\n if (focusTrigger) {\n triggerRef.current?.focus();\n }\n };\n\n const onWrapperKeyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.keyCode === KeyCode.escape) {\n closeDropdown(true);\n }\n };\n\n const onClear = () => {\n fireNonCancelableEvent(onChange, { value: null });\n };\n\n const onApply = (newValue: null | DateRangePickerProps.Value): DateRangePickerProps.ValidationResult => {\n const validationResult = isValidRange(newValue);\n if (validationResult?.valid === false) {\n return validationResult;\n }\n\n if (isDevelopment) {\n if (newValue?.type === 'absolute') {\n const [startDateWithoutTime] = newValue.startDate.split('T');\n const [endDateWithoutTime] = newValue.endDate.split('T');\n if (!startDateWithoutTime || !endDateWithoutTime) {\n warnOnce(\n 'DateRangePicker',\n 'You have provided an `isValidRange` prop that did not catch a missing start or end date.'\n );\n }\n }\n }\n fireNonCancelableEvent(onChange, { value: formatValue(newValue, { dateOnly, timeOffset }) });\n return validationResult || { valid: true };\n };\n\n const prevDateOnly = usePrevious(dateOnly);\n useEffect(() => {\n if (prevDateOnly !== undefined && prevDateOnly !== dateOnly) {\n warnOnce(\n 'DateRangePicker',\n `The provided \\`dateOnly\\` flag has been changed from \"${prevDateOnly}\" to \"${dateOnly}\" which can lead to unexpected value format. Consider using separate components.`\n );\n }\n }, [prevDateOnly, dateOnly]);\n\n if (value && value.type !== 'absolute' && value.type !== 'relative') {\n warnOnce('DateRangePicker', 'You provided an invalid value. Reverting back to default.');\n value = null;\n }\n\n if (\n (value?.type === 'absolute' && rangeSelectorMode === 'relative-only') ||\n (value?.type === 'relative' && rangeSelectorMode === 'absolute-only')\n ) {\n warnOnce(\n 'DateRangePicker',\n 'The provided value does not correspond to the current range selector mode. Reverting back to default.'\n );\n value = null;\n }\n\n const trigger = (\n <div className={styles['trigger-wrapper']}>\n <ButtonTrigger\n ref={triggerRef}\n id={controlId}\n invalid={invalid}\n ariaLabel={i18nStrings.ariaLabel}\n ariaDescribedby={ariaDescribedby}\n ariaLabelledby={ariaLabelledby}\n className={clsx(styles.label, {\n [styles['label-enabled']]: !readOnly && !disabled,\n })}\n hideCaret={true}\n onClick={() => {\n if (!readOnly && !disabled) {\n setIsDropDownOpen(true);\n }\n }}\n disabled={disabled}\n readOnly={readOnly}\n ariaHasPopup=\"true\"\n >\n <span className={styles['trigger-flexbox']}>\n <span className={styles['icon-wrapper']}>\n <InternalIcon name=\"calendar\" variant={disabled || readOnly ? 'disabled' : 'normal'} />\n </span>\n {formatDateRange(value, placeholder ?? '', i18nStrings.formatRelativeRange, timeOffset)}\n </span>\n </ButtonTrigger>\n </div>\n );\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n return (\n <div\n {...baseProps}\n ref={mergedRef}\n className={clsx(baseProps.className, styles.root)}\n onKeyDown={onWrapperKeyDownHandler}\n >\n <Dropdown\n stretchWidth={true}\n stretchHeight={true}\n open={isDropDownOpen}\n onDropdownClose={() => closeDropdown()}\n trigger={trigger}\n stretchToTriggerWidth={false}\n expandToViewport={expandToViewport}\n dropdownId={dropdownId}\n >\n {isDropDownOpen && (\n <DateRangePickerDropdown\n startOfWeek={startOfWeek}\n locale={normalizedLocale}\n isSingleGrid={isSingleGrid}\n onDropdownClose={() => closeDropdown(true)}\n value={value}\n showClearButton={showClearButton}\n isDateEnabled={isDateEnabled}\n i18nStrings={i18nStrings}\n onClear={onClear}\n onApply={onApply}\n relativeOptions={relativeOptions}\n isValidRange={isValidRange}\n dateOnly={dateOnly}\n timeInputFormat={timeInputFormat}\n rangeSelectorMode={rangeSelectorMode}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n />\n )}\n </Dropdown>\n </div>\n );\n }\n);\n\napplyDisplayName(DateRangePicker, 'DateRangePicker');\nexport default DateRangePicker;\n"]}
@@ -3,7 +3,7 @@ import { FormFieldValidationControlProps } from '../internal/context/form-field-
3
3
  import { NonCancelableEventHandler } from '../internal/events';
4
4
  import { TimeInputProps } from '../time-input/interfaces';
5
5
  import { ExpandToViewport } from '../internal/components/dropdown/interfaces';
6
- export interface DateRangePickerProps extends BaseComponentProps, FormFieldValidationControlProps, ExpandToViewport {
6
+ export interface DateRangePickerBaseProps {
7
7
  /**
8
8
  * The current date range value. Can be either an absolute time range
9
9
  * or a relative time range.
@@ -13,10 +13,6 @@ export interface DateRangePickerProps extends BaseComponentProps, FormFieldValid
13
13
  * A list of relative time ranges that are shown as suggestions.
14
14
  */
15
15
  relativeOptions: ReadonlyArray<DateRangePickerProps.RelativeOption>;
16
- /**
17
- * Specifies the placeholder text that is rendered when the value is empty.
18
- */
19
- placeholder?: string;
20
16
  /**
21
17
  * A function that defines whether a particular date should be enabled
22
18
  * in the calendar or not. Note that disabling a date in the calendar
@@ -38,44 +34,10 @@ export interface DateRangePickerProps extends BaseComponentProps, FormFieldValid
38
34
  * but you can override it using this property.
39
35
  */
40
36
  startOfWeek?: number;
41
- /**
42
- * Specifies that the component is disabled, preventing the user from
43
- * modifying the value. A disabled component cannot receive focus.
44
- */
45
- disabled?: boolean;
46
- /**
47
- * Specifies that the component is read-only, preventing the user from
48
- * modifying the value. A read-only component can receive focus.
49
- */
50
- readOnly?: boolean;
51
- /**
52
- * Fired when keyboard focus is set onto the UI control.
53
- */
54
- onFocus?: NonCancelableEventHandler<null>;
55
- /**
56
- * Fired when keyboard focus is removed from the UI control.
57
- */
58
- onBlur?: NonCancelableEventHandler<null>;
59
- /**
60
- * Fired whenever a user changes the component's value.
61
- * The event `detail` contains the current value of the field.
62
- */
63
- onChange?: NonCancelableEventHandler<DateRangePickerProps.ChangeDetail>;
64
- /**
65
- * A function that defines whether a particular range is valid or not.
66
- *
67
- * Ensure that your function checks for missing fields in the value.
68
- */
69
- isValidRange: DateRangePickerProps.ValidationFunction;
70
37
  /**
71
38
  * An object containing all the necessary localized strings required by the component.
72
39
  */
73
40
  i18nStrings: DateRangePickerProps.I18nStrings;
74
- /**
75
- * Specifies whether the component should show a button that
76
- * allows the user to clear the selected value.
77
- */
78
- showClearButton?: boolean;
79
41
  /**
80
42
  * Hides time inputs and changes the input format to date-only, e.g. 2021-04-06.
81
43
  *
@@ -94,6 +56,19 @@ export interface DateRangePickerProps extends BaseComponentProps, FormFieldValid
94
56
  * By default, the range selector mode is `default`.
95
57
  */
96
58
  rangeSelectorMode?: DateRangePickerProps.RangeSelectorMode;
59
+ /**
60
+ * Specifies the format of the time input for absolute ranges.
61
+ *
62
+ * Use to restrict the granularity of time that the user can enter.
63
+ *
64
+ * Has no effect when `dateOnly` is true.
65
+ */
66
+ timeInputFormat?: TimeInputProps.Format;
67
+ /**
68
+ * Fired whenever a user changes the component's value.
69
+ * The event `detail` contains the current value of the field.
70
+ */
71
+ onChange?: NonCancelableEventHandler<DateRangePickerProps.ChangeDetail>;
97
72
  /**
98
73
  * The time offset from UTC in minutes that should be used to
99
74
  * display and produce values.
@@ -103,14 +78,41 @@ export interface DateRangePickerProps extends BaseComponentProps, FormFieldValid
103
78
  * Default: the user's current time offset as provided by the browser.
104
79
  */
105
80
  timeOffset?: number;
81
+ }
82
+ export interface DateRangePickerProps extends BaseComponentProps, FormFieldValidationControlProps, ExpandToViewport, DateRangePickerBaseProps {
106
83
  /**
107
- * Specifies the format of the time input for absolute ranges.
108
- *
109
- * Use to restrict the granularity of time that the user can enter.
84
+ * Specifies the placeholder text that is rendered when the value is empty.
85
+ */
86
+ placeholder?: string;
87
+ /**
88
+ * Specifies that the component is disabled, preventing the user from
89
+ * modifying the value. A disabled component cannot receive focus.
90
+ */
91
+ disabled?: boolean;
92
+ /**
93
+ * Specifies that the component is read-only, preventing the user from
94
+ * modifying the value. A read-only component can receive focus.
95
+ */
96
+ readOnly?: boolean;
97
+ /**
98
+ * Fired when keyboard focus is set onto the UI control.
99
+ */
100
+ onFocus?: NonCancelableEventHandler<null>;
101
+ /**
102
+ * Fired when keyboard focus is removed from the UI control.
103
+ */
104
+ onBlur?: NonCancelableEventHandler<null>;
105
+ /**
106
+ * A function that defines whether a particular range is valid or not.
110
107
  *
111
- * Has no effect when `dateOnly` is true.
108
+ * Ensure that your function checks for missing fields in the value.
112
109
  */
113
- timeInputFormat?: TimeInputProps.Format;
110
+ isValidRange: DateRangePickerProps.ValidationFunction;
111
+ /**
112
+ * Specifies whether the component should show a button that
113
+ * allows the user to clear the selected value.
114
+ */
115
+ showClearButton?: boolean;
114
116
  }
115
117
  export declare namespace DateRangePickerProps {
116
118
  type Value = AbsoluteValue | RelativeValue;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/date-range-picker/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB,EAAE,+BAA+B,EAAE,gBAAgB;IACjH;;;OAGG;IACH,KAAK,EAAE,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC;IAEzC;;OAEG;IACH,eAAe,EAAE,aAAa,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;IAEpE;;OAEG;IACH,WA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;;WAGG;QACH,cAAc,EAAE,MAAM,CAAC;QACvB;;;WAGG;QACH,YAAY,EAAE,MAAM,CAAC;QACrB;;;WAGG;QACH,YAAY,EAAE,MAAM,CAAC;QAErB;;;WAGG;QACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;QAEhC;;WAEG;QACH,mCAAmC,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;KACtF;CACF;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/date-range-picker/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport { FormFieldValidationControlProps } from '../internal/context/form-field-context';\nimport { NonCancelableEventHandler } from '../internal/events';\nimport { TimeInputProps } from '../time-input/interfaces';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\n\nexport interface DateRangePickerProps extends BaseComponentProps, FormFieldValidationControlProps, ExpandToViewport {\n /**\n * The current date range value. Can be either an absolute time range\n * or a relative time range.\n */\n value: null | DateRangePickerProps.Value;\n\n /**\n * A list of relative time ranges that are shown as suggestions.\n */\n relativeOptions: ReadonlyArray<DateRangePickerProps.RelativeOption>;\n\n /**\n * Specifies the placeholder text that is rendered when the value is empty.\n */\n placeholder?: string;\n\n /**\n * A function that defines whether a particular date should be enabled\n * in the calendar or not. Note that disabling a date in the calendar\n * still allows users to enter this date via keyboard. We therefore\n * recommend that you also validate these constraints client- and\n * server-side, in the same way as for other form elements.\n */\n isDateEnabled?: DateRangePickerProps.IsDateEnabledFunction;\n\n /**\n * The locale to be used for rendering month names and defining the\n * starting date of the week. If not provided, it will be determined\n * from the page and browser locales. Supported values and formats\n * are as-per the [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).\n */\n locale?: string;\n\n /**\n * Starting day of the week. [0-6] maps to [Sunday-Saturday].\n * By default the starting day of the week is defined by the locale,\n * but you can override it using this property.\n */\n startOfWeek?: number;\n\n /**\n * Specifies that the component is disabled, preventing the user from\n * modifying the value. A disabled component cannot receive focus.\n */\n disabled?: boolean;\n\n /**\n * Specifies that the component is read-only, preventing the user from\n * modifying the value. A read-only component can receive focus.\n */\n readOnly?: boolean;\n\n /**\n * Fired when keyboard focus is set onto the UI control.\n */\n onFocus?: NonCancelableEventHandler<null>;\n\n /**\n * Fired when keyboard focus is removed from the UI control.\n */\n onBlur?: NonCancelableEventHandler<null>;\n\n /**\n * Fired whenever a user changes the component's value.\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<DateRangePickerProps.ChangeDetail>;\n\n /**\n * A function that defines whether a particular range is valid or not.\n *\n * Ensure that your function checks for missing fields in the value.\n */\n isValidRange: DateRangePickerProps.ValidationFunction;\n\n /**\n * An object containing all the necessary localized strings required by the component.\n */\n i18nStrings: DateRangePickerProps.I18nStrings;\n\n /**\n * Specifies whether the component should show a button that\n * allows the user to clear the selected value.\n */\n showClearButton?: boolean;\n\n /**\n * Hides time inputs and changes the input format to date-only, e.g. 2021-04-06.\n *\n * Do not use `dateOnly` flag conditionally. The component does not trigger the value update\n * when the flag changes which means the value format can become inconsistent.\n *\n * Default: `false`.\n */\n dateOnly?: boolean;\n\n /**\n * Determines the range selector mode as follows:\n * * `default` for combined absolute/relative range selector.\n * * `absolute-only` for absolute-only range selector.\n * * `relative-only` for relative-only range selector.\n *\n * By default, the range selector mode is `default`.\n */\n rangeSelectorMode?: DateRangePickerProps.RangeSelectorMode;\n\n /**\n * The time offset from UTC in minutes that should be used to\n * display and produce values.\n *\n * Has no effect when `dateOnly` is true.\n *\n * Default: the user's current time offset as provided by the browser.\n */\n timeOffset?: number;\n\n /**\n * Specifies the format of the time input for absolute ranges.\n *\n * Use to restrict the granularity of time that the user can enter.\n *\n * Has no effect when `dateOnly` is true.\n */\n timeInputFormat?: TimeInputProps.Format;\n}\n\nexport namespace DateRangePickerProps {\n export type Value = AbsoluteValue | RelativeValue;\n export interface AbsoluteValue {\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n startDate: string;\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n endDate: string;\n type: 'absolute';\n }\n\n export interface RelativeValue {\n /**\n * If provided, used to match this value\n * to a provided relative option.\n */\n key?: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n export interface RelativeOption {\n /**\n * Used to uniquely identify this relative option.\n */\n key: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n\n export type TimeUnit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';\n\n export type ValidationFunction = (value: Value | null) => ValidationResult;\n\n export type ValidationResult = ValidRangeResult | InvalidRangeResult;\n\n export interface ValidRangeResult {\n valid: true;\n }\n\n export interface InvalidRangeResult {\n valid: false;\n errorMessage: string;\n }\n\n export interface ChangeDetail {\n /**\n * The newly selected range of this date range picker.\n */\n value: null | Value;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export type RangeSelectorMode = 'default' | 'absolute-only' | 'relative-only';\n\n export interface Ref {\n /**\n * Sets the browser focus on the UI control\n */\n focus(): void;\n }\n\n export interface I18nStrings {\n /**\n * Adds `aria-label` to the trigger and dropdown.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the trigger and dropdown.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the trigger and dropdown.\n */\n ariaDescribedby?: string;\n\n /**\n * Segment title of the relative range selection mode\n */\n relativeModeTitle: string;\n\n /**\n * Segment title of the absolute range selection mode\n */\n absoluteModeTitle: string;\n\n /**\n * Heading for the relative range selection area\n */\n relativeRangeSelectionHeading: string;\n\n /**\n * Visible label of the Cancel button\n */\n cancelButtonLabel: string;\n /**\n * Visible label of the Clear and dismiss button\n */\n clearButtonLabel: string;\n /**\n * Visible label of the Apply button\n */\n applyButtonLabel: string;\n\n /**\n * Formatting function for relative ranges.\n * This function must convert a relative range to a human-readable string.\n */\n formatRelativeRange: (value: RelativeValue) => string;\n\n /**\n * Formatting function for time units.\n *\n * This function must return a localized form of the unit that fits the provided time value.\n */\n formatUnit: (unit: TimeUnit, value: number) => string;\n\n /**\n * Visible label for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionLabel: string;\n\n /**\n * Visible description for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionDescription: string;\n\n /**\n * Visible label for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationLabel: string;\n /**\n * Placeholder for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationPlaceholder: string;\n /**\n * Visible label for the unit selector for the\n * custom relative range.\n */\n customRelativeRangeUnitLabel: string;\n\n /**\n * Used as part of the aria label for today's date in the calendar.\n */\n todayAriaLabel: string;\n\n /**\n * An aria label for the 'next month' button.\n */\n nextMonthAriaLabel: string;\n\n /**\n * An aria label for the 'previous month' button.\n */\n previousMonthAriaLabel: string;\n\n /**\n * Visible label for the Start Date input for the\n * absolute range.\n */\n startDateLabel: string;\n /**\n * Visible label for the Start Time input for the\n * absolute range.\n */\n startTimeLabel: string;\n /**\n * Visible label for the End Date input for the\n * absolute range.\n */\n endDateLabel: string;\n /**\n * Visible label for the End Time input for the\n * absolute range.\n */\n endTimeLabel: string;\n\n /**\n * Constraint text for the input fields for the\n * absolute range.\n */\n dateTimeConstraintText?: string;\n\n /**\n * When the property is set, screen readers announce the selected range when the absolute range gets selected.\n */\n renderSelectedAbsoluteRangeAriaLive?: (startDate: string, endDate: string) => string;\n }\n}\n\nexport interface Focusable {\n focus(): void;\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/date-range-picker/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport { FormFieldValidationControlProps } from '../internal/context/form-field-context';\nimport { NonCancelableEventHandler } from '../internal/events';\nimport { TimeInputProps } from '../time-input/interfaces';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\n\nexport interface DateRangePickerBaseProps {\n /**\n * The current date range value. Can be either an absolute time range\n * or a relative time range.\n */\n value: null | DateRangePickerProps.Value;\n\n /**\n * A list of relative time ranges that are shown as suggestions.\n */\n relativeOptions: ReadonlyArray<DateRangePickerProps.RelativeOption>;\n\n /**\n * A function that defines whether a particular date should be enabled\n * in the calendar or not. Note that disabling a date in the calendar\n * still allows users to enter this date via keyboard. We therefore\n * recommend that you also validate these constraints client- and\n * server-side, in the same way as for other form elements.\n */\n isDateEnabled?: DateRangePickerProps.IsDateEnabledFunction;\n\n /**\n * The locale to be used for rendering month names and defining the\n * starting date of the week. If not provided, it will be determined\n * from the page and browser locales. Supported values and formats\n * are as-per the [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).\n */\n locale?: string;\n\n /**\n * Starting day of the week. [0-6] maps to [Sunday-Saturday].\n * By default the starting day of the week is defined by the locale,\n * but you can override it using this property.\n */\n startOfWeek?: number;\n\n /**\n * An object containing all the necessary localized strings required by the component.\n */\n i18nStrings: DateRangePickerProps.I18nStrings;\n\n /**\n * Hides time inputs and changes the input format to date-only, e.g. 2021-04-06.\n *\n * Do not use `dateOnly` flag conditionally. The component does not trigger the value update\n * when the flag changes which means the value format can become inconsistent.\n *\n * Default: `false`.\n */\n dateOnly?: boolean;\n\n /**\n * Determines the range selector mode as follows:\n * * `default` for combined absolute/relative range selector.\n * * `absolute-only` for absolute-only range selector.\n * * `relative-only` for relative-only range selector.\n *\n * By default, the range selector mode is `default`.\n */\n rangeSelectorMode?: DateRangePickerProps.RangeSelectorMode;\n\n /**\n * Specifies the format of the time input for absolute ranges.\n *\n * Use to restrict the granularity of time that the user can enter.\n *\n * Has no effect when `dateOnly` is true.\n */\n timeInputFormat?: TimeInputProps.Format;\n\n /**\n * Fired whenever a user changes the component's value.\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<DateRangePickerProps.ChangeDetail>;\n\n /**\n * The time offset from UTC in minutes that should be used to\n * display and produce values.\n *\n * Has no effect when `dateOnly` is true.\n *\n * Default: the user's current time offset as provided by the browser.\n */\n timeOffset?: number;\n}\nexport interface DateRangePickerProps\n extends BaseComponentProps,\n FormFieldValidationControlProps,\n ExpandToViewport,\n DateRangePickerBaseProps {\n /**\n * Specifies the placeholder text that is rendered when the value is empty.\n */\n placeholder?: string;\n\n /**\n * Specifies that the component is disabled, preventing the user from\n * modifying the value. A disabled component cannot receive focus.\n */\n disabled?: boolean;\n\n /**\n * Specifies that the component is read-only, preventing the user from\n * modifying the value. A read-only component can receive focus.\n */\n readOnly?: boolean;\n\n /**\n * Fired when keyboard focus is set onto the UI control.\n */\n onFocus?: NonCancelableEventHandler<null>;\n\n /**\n * Fired when keyboard focus is removed from the UI control.\n */\n onBlur?: NonCancelableEventHandler<null>;\n\n /**\n * A function that defines whether a particular range is valid or not.\n *\n * Ensure that your function checks for missing fields in the value.\n */\n isValidRange: DateRangePickerProps.ValidationFunction;\n\n /**\n * Specifies whether the component should show a button that\n * allows the user to clear the selected value.\n */\n showClearButton?: boolean;\n}\n\nexport namespace DateRangePickerProps {\n export type Value = AbsoluteValue | RelativeValue;\n export interface AbsoluteValue {\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n startDate: string;\n /**\n * In ISO8601 format, e.g.: 2021-04-06T17:23:50+02:00 (or 2021-04-06 when `dateOnly` is true)\n */\n endDate: string;\n type: 'absolute';\n }\n\n export interface RelativeValue {\n /**\n * If provided, used to match this value\n * to a provided relative option.\n */\n key?: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n export interface RelativeOption {\n /**\n * Used to uniquely identify this relative option.\n */\n key: string;\n amount: number;\n unit: TimeUnit;\n type: 'relative';\n }\n\n export type TimeUnit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';\n\n export type ValidationFunction = (value: Value | null) => ValidationResult;\n\n export type ValidationResult = ValidRangeResult | InvalidRangeResult;\n\n export interface ValidRangeResult {\n valid: true;\n }\n\n export interface InvalidRangeResult {\n valid: false;\n errorMessage: string;\n }\n\n export interface ChangeDetail {\n /**\n * The newly selected range of this date range picker.\n */\n value: null | Value;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export type RangeSelectorMode = 'default' | 'absolute-only' | 'relative-only';\n\n export interface Ref {\n /**\n * Sets the browser focus on the UI control\n */\n focus(): void;\n }\n\n export interface I18nStrings {\n /**\n * Adds `aria-label` to the trigger and dropdown.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the trigger and dropdown.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the trigger and dropdown.\n */\n ariaDescribedby?: string;\n\n /**\n * Segment title of the relative range selection mode\n */\n relativeModeTitle: string;\n\n /**\n * Segment title of the absolute range selection mode\n */\n absoluteModeTitle: string;\n\n /**\n * Heading for the relative range selection area\n */\n relativeRangeSelectionHeading: string;\n\n /**\n * Visible label of the Cancel button\n */\n cancelButtonLabel: string;\n /**\n * Visible label of the Clear and dismiss button\n */\n clearButtonLabel: string;\n /**\n * Visible label of the Apply button\n */\n applyButtonLabel: string;\n\n /**\n * Formatting function for relative ranges.\n * This function must convert a relative range to a human-readable string.\n */\n formatRelativeRange: (value: RelativeValue) => string;\n\n /**\n * Formatting function for time units.\n *\n * This function must return a localized form of the unit that fits the provided time value.\n */\n formatUnit: (unit: TimeUnit, value: number) => string;\n\n /**\n * Visible label for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionLabel: string;\n\n /**\n * Visible description for the option for selecting\n * a custom relative range.\n */\n customRelativeRangeOptionDescription: string;\n\n /**\n * Visible label for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationLabel: string;\n /**\n * Placeholder for the duration selector for\n * the custom relative range.\n */\n customRelativeRangeDurationPlaceholder: string;\n /**\n * Visible label for the unit selector for the\n * custom relative range.\n */\n customRelativeRangeUnitLabel: string;\n\n /**\n * Used as part of the aria label for today's date in the calendar.\n */\n todayAriaLabel: string;\n\n /**\n * An aria label for the 'next month' button.\n */\n nextMonthAriaLabel: string;\n\n /**\n * An aria label for the 'previous month' button.\n */\n previousMonthAriaLabel: string;\n\n /**\n * Visible label for the Start Date input for the\n * absolute range.\n */\n startDateLabel: string;\n /**\n * Visible label for the Start Time input for the\n * absolute range.\n */\n startTimeLabel: string;\n /**\n * Visible label for the End Date input for the\n * absolute range.\n */\n endDateLabel: string;\n /**\n * Visible label for the End Time input for the\n * absolute range.\n */\n endTimeLabel: string;\n\n /**\n * Constraint text for the input fields for the\n * absolute range.\n */\n dateTimeConstraintText?: string;\n\n /**\n * When the property is set, screen readers announce the selected range when the absolute range gets selected.\n */\n renderSelectedAbsoluteRangeAriaLive?: (startDate: string, endDate: string) => string;\n }\n}\n\nexport interface Focusable {\n focus(): void;\n}\n"]}
@@ -1,15 +1,8 @@
1
1
  import { DateRangePickerProps } from './interfaces';
2
- /**
3
- * Returns the time offset of the browser.
4
- *
5
- * I.e. determines the `x` in `current offset = UTC + x`
6
- */
7
- export declare function getBrowserTimezoneOffset(): number;
8
2
  /**
9
3
  * Appends a time zone offset to an offset-less date string.
10
4
  */
11
5
  export declare function setTimeOffset(value: DateRangePickerProps.Value | null, timeOffsetInMinutes: number): DateRangePickerProps.Value | null;
12
- export declare function formatOffset(offsetInMinutes: number): string;
13
6
  /**
14
7
  * Re-formats an absolute date range so that it is expressed using the
15
8
  * target time offset. The returned value still represents the same range
@@ -1 +1 @@
1
- {"version":3,"file":"time-offset.d.ts","sourceRoot":"","sources":["../../../src/date-range-picker/time-offset.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAMpD;;;;GAIG;AACH,wBAAgB,wBAAwB,WAEvC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,oBAAoB,CAAC,KAAK,GAAG,IAAI,EACxC,mBAAmB,EAAE,MAAM,GAC1B,oBAAoB,CAAC,KAAK,GAAG,IAAI,CAcnC;AAED,wBAAgB,YAAY,CAAC,eAAe,EAAE,MAAM,UAQnD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,IAAI,GAAG,oBAAoB,CAAC,KAAK,EACxC,mBAAmB,EAAE,MAAM,GAC1B,oBAAoB,CAAC,KAAK,GAAG,IAAI,CA2BnC"}
1
+ {"version":3,"file":"time-offset.d.ts","sourceRoot":"","sources":["../../../src/date-range-picker/time-offset.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAIpD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,oBAAoB,CAAC,KAAK,GAAG,IAAI,EACxC,mBAAmB,EAAE,MAAM,GAC1B,oBAAoB,CAAC,KAAK,GAAG,IAAI,CAcnC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,IAAI,GAAG,oBAAoB,CAAC,KAAK,EACxC,mBAAmB,EAAE,MAAM,GAC1B,oBAAoB,CAAC,KAAK,GAAG,IAAI,CA2BnC"}
@@ -1,15 +1,5 @@
1
- import { padLeftZeros } from '../internal/components/masked-input/utils/strings';
2
- import { addMinutes } from 'date-fns';
3
- import { formatTime, formatDate } from '../date-picker/calendar/utils/date';
4
1
  import { warnOnce } from '../internal/logging';
5
- /**
6
- * Returns the time offset of the browser.
7
- *
8
- * I.e. determines the `x` in `current offset = UTC + x`
9
- */
10
- export function getBrowserTimezoneOffset() {
11
- return 0 - new Date().getTimezoneOffset();
12
- }
2
+ import { formatTimezoneOffset, shiftTimezoneOffset } from '../internal/utils/date-time';
13
3
  /**
14
4
  * Appends a time zone offset to an offset-less date string.
15
5
  */
@@ -17,7 +7,7 @@ export function setTimeOffset(value, timeOffsetInMinutes) {
17
7
  if (!((value === null || value === void 0 ? void 0 : value.type) === 'absolute')) {
18
8
  return value;
19
9
  }
20
- var offsetSuffix = formatOffset(timeOffsetInMinutes);
10
+ var offsetSuffix = formatTimezoneOffset(timeOffsetInMinutes);
21
11
  var startDate = value.startDate, endDate = value.endDate;
22
12
  return {
23
13
  type: 'absolute',
@@ -25,13 +15,6 @@ export function setTimeOffset(value, timeOffsetInMinutes) {
25
15
  endDate: endDate + offsetSuffix
26
16
  };
27
17
  }
28
- export function formatOffset(offsetInMinutes) {
29
- var hoursOffset = padLeftZeros(Math.floor(Math.abs(offsetInMinutes) / 60).toFixed(0), 2);
30
- var minuteOffset = padLeftZeros(Math.abs(offsetInMinutes % 60).toFixed(0), 2);
31
- var sign = offsetInMinutes < 0 ? '-' : '+';
32
- var offsetSuffix = "".concat(sign).concat(hoursOffset, ":").concat(minuteOffset);
33
- return offsetSuffix;
34
- }
35
18
  /**
36
19
  * Re-formats an absolute date range so that it is expressed using the
37
20
  * target time offset. The returned value still represents the same range
@@ -55,47 +38,8 @@ export function shiftTimeOffset(value, timeOffsetInMinutes) {
55
38
  }
56
39
  return {
57
40
  type: 'absolute',
58
- startDate: doShiftTimeOffset(value.startDate, timeOffsetInMinutes),
59
- endDate: doShiftTimeOffset(value.endDate, timeOffsetInMinutes)
41
+ startDate: shiftTimezoneOffset(value.startDate, timeOffsetInMinutes),
42
+ endDate: shiftTimezoneOffset(value.endDate, timeOffsetInMinutes)
60
43
  };
61
44
  }
62
- /**
63
- * Re-formats an ISO8601 date string so that it is expressed using the
64
- * target time offset. The returned date string still represents the
65
- * same instant in time, but contains no visible offset.
66
- *
67
- * Example:
68
- * ```
69
- * doShiftTimeOffset("2020-01-01T09:00:00+03:00", 2 * 60)
70
- * = "2020-01-01T08:00:00"
71
- * ```
72
- */
73
- function doShiftTimeOffset(value, targetOffsetInMinutes) {
74
- var _a = splitOffset(value), valueWithoutOffset = _a[0], offsetInMinutes = _a[1];
75
- var differenceBetweenValueAndTarget = targetOffsetInMinutes - offsetInMinutes;
76
- var date = new Date(valueWithoutOffset);
77
- var adjustedDate = addMinutes(date, differenceBetweenValueAndTarget);
78
- var formattedDate = formatDate(adjustedDate);
79
- var formattedTime = formatTime(adjustedDate);
80
- return "".concat(formattedDate, "T").concat(formattedTime);
81
- }
82
- /**
83
- * Splits an ISO8601 date string into its timezone-independent part
84
- * and its time offset in minutes.
85
- */
86
- function splitOffset(value) {
87
- var _a = value.split('T'), datePart = _a[0], timePart = _a[1];
88
- var _b = timePart.split(/(-|\+)/), time = _b[0], signCharacter = _b[1], offsetPart = _b[2];
89
- if (signCharacter && offsetPart) {
90
- var _c = offsetPart.split(':'), offsetHours = _c[0], offsetMinutes = _c[1];
91
- var offset = Number(offsetHours) * 60 + Number(offsetMinutes);
92
- var sign = signCharacter === '-' ? -1 : 1;
93
- return ["".concat(datePart, "T").concat(time), offset * sign];
94
- }
95
- var utcTimezoneIndicator = value.indexOf('Z');
96
- if (utcTimezoneIndicator !== -1) {
97
- return [value.substring(0, utcTimezoneIndicator), 0];
98
- }
99
- return [value, getBrowserTimezoneOffset()];
100
- }
101
45
  //# sourceMappingURL=time-offset.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"time-offset.js","sourceRoot":"","sources":["../../../src/date-range-picker/time-offset.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,QAAQ,E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;IACxC,IAAA,KAAoC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,EAA3D,IAAI,QAAA,EAAE,aAAa,QAAA,EAAE,UAAU,QAA4B,CAAC;IAEnE,IAAI,aAAa,IAAI,UAAU,EAAE;QACzB,IAAA,KAA+B,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,EAAnD,WAAW,QAAA,EAAE,aAAa,QAAyB,CAAC;QAE3D,IAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;QAEhE,IAAM,IAAI,GAAG,aAAa,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAE5C,OAAO,CAAC,UAAG,QAAQ,cAAI,IAAI,CAAE,EAAE,MAAM,GAAG,IAAI,CAAU,CAAC;KACxD;IAED,IAAM,oBAAoB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,oBAAoB,KAAK,CAAC,CAAC,EAAE;QAC/B,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,oBAAoB,CAAC,EAAE,CAAC,CAAU,CAAC;KAC/D;IAED,OAAO,CAAC,KAAK,EAAE,wBAAwB,EAAE,CAAU,CAAC;AACtD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DateRangePickerProps } from './interfaces';\nimport { padLeftZeros } from '../internal/components/masked-input/utils/strings';\nimport { addMinutes } from 'date-fns';\nimport { formatTime, formatDate } from '../date-picker/calendar/utils/date';\nimport { warnOnce } from '../internal/logging';\n\n/**\n * Returns the time offset of the browser.\n *\n * I.e. determines the `x` in `current offset = UTC + x`\n */\nexport function getBrowserTimezoneOffset() {\n return 0 - new Date().getTimezoneOffset();\n}\n\n/**\n * Appends a time zone offset to an offset-less date string.\n */\nexport function setTimeOffset(\n value: DateRangePickerProps.Value | null,\n timeOffsetInMinutes: number\n): DateRangePickerProps.Value | null {\n if (!(value?.type === 'absolute')) {\n return value;\n }\n\n const offsetSuffix = formatOffset(timeOffsetInMinutes);\n\n const { startDate, endDate } = value;\n\n return {\n type: 'absolute',\n startDate: startDate + offsetSuffix,\n endDate: endDate + offsetSuffix,\n };\n}\n\nexport function formatOffset(offsetInMinutes: number) {\n const hoursOffset = padLeftZeros(Math.floor(Math.abs(offsetInMinutes) / 60).toFixed(0), 2);\n const minuteOffset = padLeftZeros(Math.abs(offsetInMinutes % 60).toFixed(0), 2);\n\n const sign = offsetInMinutes < 0 ? '-' : '+';\n const offsetSuffix = `${sign}${hoursOffset}:${minuteOffset}`;\n\n return offsetSuffix;\n}\n\n/**\n * Re-formats an absolute date range so that it is expressed using the\n * target time offset. The returned value still represents the same range\n * in time, but contains no visible offset.\n */\nexport function shiftTimeOffset(\n value: null | DateRangePickerProps.Value,\n timeOffsetInMinutes: number\n): DateRangePickerProps.Value | null {\n if (!value || value.type !== 'absolute') {\n return value;\n }\n\n /*\n This regex matches an ISO date-time with\n - optional seconds;\n - optional milliseconds;\n - optional time offset or 'Z'.\n */\n const dateTimeRegex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2})?(\\.\\d{1,3})?(((\\+|-)\\d{2}(:\\d{2})?)|Z)?$/;\n\n if (!dateTimeRegex.test(value.startDate) || !dateTimeRegex.test(value.endDate)) {\n warnOnce(\n 'DateRangePicker',\n 'You have provided a misformatted start or end date. The component will fall back to an empty value. ' +\n 'Dates have to be ISO8601-formatted with an optional time zone offset.'\n );\n return null;\n }\n\n return {\n type: 'absolute',\n startDate: doShiftTimeOffset(value.startDate, timeOffsetInMinutes),\n endDate: doShiftTimeOffset(value.endDate, timeOffsetInMinutes),\n };\n}\n\n/**\n * Re-formats an ISO8601 date string so that it is expressed using the\n * target time offset. The returned date string still represents the\n * same instant in time, but contains no visible offset.\n *\n * Example:\n * ```\n * doShiftTimeOffset(\"2020-01-01T09:00:00+03:00\", 2 * 60)\n * = \"2020-01-01T08:00:00\"\n * ```\n */\nfunction doShiftTimeOffset(value: string, targetOffsetInMinutes: number) {\n const [valueWithoutOffset, offsetInMinutes] = splitOffset(value);\n\n const differenceBetweenValueAndTarget = targetOffsetInMinutes - offsetInMinutes;\n\n const date = new Date(valueWithoutOffset);\n const adjustedDate = addMinutes(date, differenceBetweenValueAndTarget);\n\n const formattedDate = formatDate(adjustedDate);\n const formattedTime = formatTime(adjustedDate);\n\n return `${formattedDate}T${formattedTime}`;\n}\n\n/**\n * Splits an ISO8601 date string into its timezone-independent part\n * and its time offset in minutes.\n */\nfunction splitOffset(value: string) {\n const [datePart, timePart] = value.split('T');\n const [time, signCharacter, offsetPart] = timePart.split(/(-|\\+)/);\n\n if (signCharacter && offsetPart) {\n const [offsetHours, offsetMinutes] = offsetPart.split(':');\n\n const offset = Number(offsetHours) * 60 + Number(offsetMinutes);\n\n const sign = signCharacter === '-' ? -1 : 1;\n\n return [`${datePart}T${time}`, offset * sign] as const;\n }\n\n const utcTimezoneIndicator = value.indexOf('Z');\n if (utcTimezoneIndicator !== -1) {\n return [value.substring(0, utcTimezoneIndicator), 0] as const;\n }\n\n return [value, getBrowserTimezoneOffset()] as const;\n}\n"]}
1
+ {"version":3,"file":"time-offset.js","sourceRoot":"","sources":["../../../src/date-range-picker/time-offset.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAExF;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAwC,EACxC,mBAA2B;IAE3B,IAAI,CAAC,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,UAAU,CAAC,EAAE;QACjC,OAAO,KAAK,CAAC;KACd;IAED,IAAM,YAAY,GAAG,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;IAEvD,IAAA,SAAS,GAAc,KAAK,UAAnB,EAAE,OAAO,GAAK,KAAK,QAAV,CAAW;IAErC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,SAAS,EAAE,SAAS,GAAG,YAAY;QACnC,OAAO,EAAE,OAAO,GAAG,YAAY;KAChC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAwC,EACxC,mBAA2B;IAE3B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE;QACvC,OAAO,KAAK,CAAC;KACd;IAED;;;;;MAKE;IACF,IAAM,aAAa,GAAG,iFAAiF,CAAC;IAExG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;QAC9E,QAAQ,CACN,iBAAiB,EACjB,sGAAsG;YACpG,uEAAuE,CAC1E,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,SAAS,EAAE,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,mBAAmB,CAAC;QACpE,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,mBAAmB,CAAC;KACjE,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DateRangePickerProps } from './interfaces';\nimport { warnOnce } from '../internal/logging';\nimport { formatTimezoneOffset, shiftTimezoneOffset } from '../internal/utils/date-time';\n\n/**\n * Appends a time zone offset to an offset-less date string.\n */\nexport function setTimeOffset(\n value: DateRangePickerProps.Value | null,\n timeOffsetInMinutes: number\n): DateRangePickerProps.Value | null {\n if (!(value?.type === 'absolute')) {\n return value;\n }\n\n const offsetSuffix = formatTimezoneOffset(timeOffsetInMinutes);\n\n const { startDate, endDate } = value;\n\n return {\n type: 'absolute',\n startDate: startDate + offsetSuffix,\n endDate: endDate + offsetSuffix,\n };\n}\n\n/**\n * Re-formats an absolute date range so that it is expressed using the\n * target time offset. The returned value still represents the same range\n * in time, but contains no visible offset.\n */\nexport function shiftTimeOffset(\n value: null | DateRangePickerProps.Value,\n timeOffsetInMinutes: number\n): DateRangePickerProps.Value | null {\n if (!value || value.type !== 'absolute') {\n return value;\n }\n\n /*\n This regex matches an ISO date-time with\n - optional seconds;\n - optional milliseconds;\n - optional time offset or 'Z'.\n */\n const dateTimeRegex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2})?(\\.\\d{1,3})?(((\\+|-)\\d{2}(:\\d{2})?)|Z)?$/;\n\n if (!dateTimeRegex.test(value.startDate) || !dateTimeRegex.test(value.endDate)) {\n warnOnce(\n 'DateRangePicker',\n 'You have provided a misformatted start or end date. The component will fall back to an empty value. ' +\n 'Dates have to be ISO8601-formatted with an optional time zone offset.'\n );\n return null;\n }\n\n return {\n type: 'absolute',\n startDate: shiftTimezoneOffset(value.startDate, timeOffsetInMinutes),\n endDate: shiftTimezoneOffset(value.endDate, timeOffsetInMinutes),\n };\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import { DateRangePickerProps } from './interfaces';
2
+ /**
3
+ * This function fills in a start and end time if they are missing.
4
+ */
5
+ declare function fillMissingTime(value: DateRangePickerProps.AbsoluteValue | null): {
6
+ startDate: string;
7
+ endDate: string;
8
+ type: "absolute";
9
+ } | null;
10
+ export declare function formatValue(value: null | DateRangePickerProps.Value, { timeOffset, dateOnly }: {
11
+ timeOffset: number;
12
+ dateOnly: boolean;
13
+ }): null | DateRangePickerProps.Value;
14
+ export declare function useDateRangePicker({ value, relativeOptions, rangeSelectorMode }: UseDateRangePickerProps): {
15
+ fillMissingTime: typeof fillMissingTime;
16
+ rangeSelectionMode: "absolute" | "relative";
17
+ setRangeSelectionMode: import("react").Dispatch<import("react").SetStateAction<"absolute" | "relative">>;
18
+ selectedAbsoluteRange: DateRangePickerProps.AbsoluteValue | null;
19
+ setSelectedAbsoluteRange: import("react").Dispatch<import("react").SetStateAction<DateRangePickerProps.AbsoluteValue | null>>;
20
+ selectedRelativeRange: DateRangePickerProps.RelativeValue | null;
21
+ setSelectedRelativeRange: import("react").Dispatch<import("react").SetStateAction<DateRangePickerProps.RelativeValue | null>>;
22
+ };
23
+ export interface UseDateRangePickerProps {
24
+ value: null | DateRangePickerProps.Value;
25
+ relativeOptions: ReadonlyArray<DateRangePickerProps.RelativeOption>;
26
+ rangeSelectorMode: DateRangePickerProps.RangeSelectorMode;
27
+ }
28
+ export {};
29
+ //# sourceMappingURL=use-date-range-picker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-date-range-picker.d.ts","sourceRoot":"","sources":["../../../src/date-range-picker/use-date-range-picker.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD;;GAEG;AACH,iBAAS,eAAe,CAAC,KAAK,EAAE,oBAAoB,CAAC,aAAa,GAAG,IAAI;;;;SAWxE;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,IAAI,GAAG,oBAAoB,CAAC,KAAK,EACxC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAClE,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAYnC;AAmBD,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,EAAE,uBAAuB;;;;;;;;EAsBxG;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC;IACzC,eAAe,EAAE,aAAa,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;IACpE,iBAAiB,EAAE,oBAAoB,CAAC,iBAAiB,CAAC;CAC3D"}