@hitachivantara/uikit-react-core 3.62.6 → 3.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/AppSwitcher/Action/Action.d.ts +75 -0
  3. package/dist/AppSwitcher/Action/Action.js +304 -0
  4. package/dist/AppSwitcher/Action/Action.js.map +1 -0
  5. package/dist/AppSwitcher/Action/index.d.ts +2 -0
  6. package/dist/AppSwitcher/Action/index.js +14 -0
  7. package/dist/AppSwitcher/Action/index.js.map +1 -0
  8. package/dist/AppSwitcher/Action/styles.js +60 -0
  9. package/dist/AppSwitcher/Action/styles.js.map +1 -0
  10. package/dist/AppSwitcher/AppSwitcher.d.ts +67 -0
  11. package/dist/AppSwitcher/AppSwitcher.js +282 -0
  12. package/dist/AppSwitcher/AppSwitcher.js.map +1 -0
  13. package/dist/AppSwitcher/TitleWithTooltip.js +76 -0
  14. package/dist/AppSwitcher/TitleWithTooltip.js.map +1 -0
  15. package/dist/AppSwitcher/index.d.ts +5 -0
  16. package/dist/AppSwitcher/index.js +24 -0
  17. package/dist/AppSwitcher/index.js.map +1 -0
  18. package/dist/AppSwitcher/styles.js +95 -0
  19. package/dist/AppSwitcher/styles.js.map +1 -0
  20. package/dist/Chart/chartPlotlyOverrides.js +2 -2
  21. package/dist/Chart/chartPlotlyOverrides.js.map +1 -1
  22. package/dist/FileUploader/File/styles.js +2 -1
  23. package/dist/FileUploader/File/styles.js.map +1 -1
  24. package/dist/SimpleGrid/SimpleGrid.d.ts +17 -0
  25. package/dist/SimpleGrid/SimpleGrid.js +73 -0
  26. package/dist/SimpleGrid/SimpleGrid.js.map +1 -0
  27. package/dist/SimpleGrid/index.d.ts +2 -0
  28. package/dist/SimpleGrid/index.js +16 -0
  29. package/dist/SimpleGrid/index.js.map +1 -0
  30. package/dist/SimpleGrid/styles.js +99 -0
  31. package/dist/SimpleGrid/styles.js.map +1 -0
  32. package/dist/TimePicker/PeriodPicker/PeriodPicker.js +112 -0
  33. package/dist/TimePicker/PeriodPicker/PeriodPicker.js.map +1 -0
  34. package/dist/TimePicker/PeriodPicker/index.js +21 -0
  35. package/dist/TimePicker/PeriodPicker/index.js.map +1 -0
  36. package/dist/TimePicker/PeriodPicker/styles.js +32 -0
  37. package/dist/TimePicker/PeriodPicker/styles.js.map +1 -0
  38. package/dist/TimePicker/TimePicker.d.ts +140 -0
  39. package/dist/TimePicker/TimePicker.js +748 -0
  40. package/dist/TimePicker/TimePicker.js.map +1 -0
  41. package/dist/TimePicker/UnitTimePicker/UnitTimePicker.js +243 -0
  42. package/dist/TimePicker/UnitTimePicker/UnitTimePicker.js.map +1 -0
  43. package/dist/TimePicker/UnitTimePicker/index.js +21 -0
  44. package/dist/TimePicker/UnitTimePicker/index.js.map +1 -0
  45. package/dist/TimePicker/UnitTimePicker/styles.js +75 -0
  46. package/dist/TimePicker/UnitTimePicker/styles.js.map +1 -0
  47. package/dist/TimePicker/enums.js +43 -0
  48. package/dist/TimePicker/enums.js.map +1 -0
  49. package/dist/TimePicker/index.d.ts +2 -0
  50. package/dist/TimePicker/index.js +16 -0
  51. package/dist/TimePicker/index.js.map +1 -0
  52. package/dist/TimePicker/styles.js +134 -0
  53. package/dist/TimePicker/styles.js.map +1 -0
  54. package/dist/TimePicker/timePickerConverter.js +90 -0
  55. package/dist/TimePicker/timePickerConverter.js.map +1 -0
  56. package/dist/TimePicker/timePickerFormatter.js +81 -0
  57. package/dist/TimePicker/timePickerFormatter.js.map +1 -0
  58. package/dist/TimePicker/timePickerUtils.js +39 -0
  59. package/dist/TimePicker/timePickerUtils.js.map +1 -0
  60. package/dist/index.d.ts +3 -0
  61. package/dist/index.js +9 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/legacy/AppSwitcher/Action/Action.d.ts +75 -0
  64. package/dist/legacy/AppSwitcher/Action/Action.js +259 -0
  65. package/dist/legacy/AppSwitcher/Action/Action.js.map +1 -0
  66. package/dist/legacy/AppSwitcher/Action/index.d.ts +2 -0
  67. package/dist/legacy/AppSwitcher/Action/index.js +3 -0
  68. package/dist/legacy/AppSwitcher/Action/index.js.map +1 -0
  69. package/dist/legacy/AppSwitcher/Action/styles.js +52 -0
  70. package/dist/legacy/AppSwitcher/Action/styles.js.map +1 -0
  71. package/dist/legacy/AppSwitcher/AppSwitcher.d.ts +67 -0
  72. package/dist/legacy/AppSwitcher/AppSwitcher.js +260 -0
  73. package/dist/legacy/AppSwitcher/AppSwitcher.js.map +1 -0
  74. package/dist/legacy/AppSwitcher/TitleWithTooltip.js +45 -0
  75. package/dist/legacy/AppSwitcher/TitleWithTooltip.js.map +1 -0
  76. package/dist/legacy/AppSwitcher/index.d.ts +5 -0
  77. package/dist/legacy/AppSwitcher/index.js +3 -0
  78. package/dist/legacy/AppSwitcher/index.js.map +1 -0
  79. package/dist/legacy/AppSwitcher/styles.js +78 -0
  80. package/dist/legacy/AppSwitcher/styles.js.map +1 -0
  81. package/dist/legacy/Chart/chartPlotlyOverrides.js +2 -2
  82. package/dist/legacy/Chart/chartPlotlyOverrides.js.map +1 -1
  83. package/dist/legacy/FileUploader/File/styles.js +2 -1
  84. package/dist/legacy/FileUploader/File/styles.js.map +1 -1
  85. package/dist/legacy/SimpleGrid/SimpleGrid.d.ts +17 -0
  86. package/dist/legacy/SimpleGrid/SimpleGrid.js +59 -0
  87. package/dist/legacy/SimpleGrid/SimpleGrid.js.map +1 -0
  88. package/dist/legacy/SimpleGrid/index.d.ts +2 -0
  89. package/dist/legacy/SimpleGrid/index.js +2 -0
  90. package/dist/legacy/SimpleGrid/index.js.map +1 -0
  91. package/dist/legacy/SimpleGrid/styles.js +81 -0
  92. package/dist/legacy/SimpleGrid/styles.js.map +1 -0
  93. package/dist/legacy/TimePicker/PeriodPicker/PeriodPicker.js +78 -0
  94. package/dist/legacy/TimePicker/PeriodPicker/PeriodPicker.js.map +1 -0
  95. package/dist/legacy/TimePicker/PeriodPicker/index.js +7 -0
  96. package/dist/legacy/TimePicker/PeriodPicker/index.js.map +1 -0
  97. package/dist/legacy/TimePicker/PeriodPicker/styles.js +24 -0
  98. package/dist/legacy/TimePicker/PeriodPicker/styles.js.map +1 -0
  99. package/dist/legacy/TimePicker/TimePicker.d.ts +140 -0
  100. package/dist/legacy/TimePicker/TimePicker.js +696 -0
  101. package/dist/legacy/TimePicker/TimePicker.js.map +1 -0
  102. package/dist/legacy/TimePicker/UnitTimePicker/UnitTimePicker.js +206 -0
  103. package/dist/legacy/TimePicker/UnitTimePicker/UnitTimePicker.js.map +1 -0
  104. package/dist/legacy/TimePicker/UnitTimePicker/index.js +7 -0
  105. package/dist/legacy/TimePicker/UnitTimePicker/index.js.map +1 -0
  106. package/dist/legacy/TimePicker/UnitTimePicker/styles.js +58 -0
  107. package/dist/legacy/TimePicker/UnitTimePicker/styles.js.map +1 -0
  108. package/dist/legacy/TimePicker/enums.js +33 -0
  109. package/dist/legacy/TimePicker/enums.js.map +1 -0
  110. package/dist/legacy/TimePicker/index.d.ts +2 -0
  111. package/dist/legacy/TimePicker/index.js +2 -0
  112. package/dist/legacy/TimePicker/index.js.map +1 -0
  113. package/dist/legacy/TimePicker/styles.js +117 -0
  114. package/dist/legacy/TimePicker/styles.js.map +1 -0
  115. package/dist/legacy/TimePicker/timePickerConverter.js +71 -0
  116. package/dist/legacy/TimePicker/timePickerConverter.js.map +1 -0
  117. package/dist/legacy/TimePicker/timePickerFormatter.js +66 -0
  118. package/dist/legacy/TimePicker/timePickerFormatter.js.map +1 -0
  119. package/dist/legacy/TimePicker/timePickerUtils.js +29 -0
  120. package/dist/legacy/TimePicker/timePickerUtils.js.map +1 -0
  121. package/dist/legacy/index.d.ts +3 -0
  122. package/dist/legacy/index.js +1 -0
  123. package/dist/legacy/index.js.map +1 -1
  124. package/dist/modern/AppSwitcher/Action/Action.d.ts +75 -0
  125. package/dist/modern/AppSwitcher/Action/Action.js +242 -0
  126. package/dist/modern/AppSwitcher/Action/Action.js.map +1 -0
  127. package/dist/modern/AppSwitcher/Action/index.d.ts +2 -0
  128. package/dist/modern/AppSwitcher/Action/index.js +3 -0
  129. package/dist/modern/AppSwitcher/Action/index.js.map +1 -0
  130. package/dist/modern/AppSwitcher/Action/styles.js +50 -0
  131. package/dist/modern/AppSwitcher/Action/styles.js.map +1 -0
  132. package/dist/modern/AppSwitcher/AppSwitcher.d.ts +67 -0
  133. package/dist/modern/AppSwitcher/AppSwitcher.js +254 -0
  134. package/dist/modern/AppSwitcher/AppSwitcher.js.map +1 -0
  135. package/dist/modern/AppSwitcher/TitleWithTooltip.js +41 -0
  136. package/dist/modern/AppSwitcher/TitleWithTooltip.js.map +1 -0
  137. package/dist/modern/AppSwitcher/index.d.ts +5 -0
  138. package/dist/modern/AppSwitcher/index.js +3 -0
  139. package/dist/modern/AppSwitcher/index.js.map +1 -0
  140. package/dist/modern/AppSwitcher/styles.js +67 -0
  141. package/dist/modern/AppSwitcher/styles.js.map +1 -0
  142. package/dist/modern/Chart/chartPlotlyOverrides.js +2 -2
  143. package/dist/modern/Chart/chartPlotlyOverrides.js.map +1 -1
  144. package/dist/modern/FileUploader/File/styles.js +2 -1
  145. package/dist/modern/FileUploader/File/styles.js.map +1 -1
  146. package/dist/modern/SimpleGrid/SimpleGrid.d.ts +17 -0
  147. package/dist/modern/SimpleGrid/SimpleGrid.js +60 -0
  148. package/dist/modern/SimpleGrid/SimpleGrid.js.map +1 -0
  149. package/dist/modern/SimpleGrid/index.d.ts +2 -0
  150. package/dist/modern/SimpleGrid/index.js +2 -0
  151. package/dist/modern/SimpleGrid/index.js.map +1 -0
  152. package/dist/modern/SimpleGrid/styles.js +68 -0
  153. package/dist/modern/SimpleGrid/styles.js.map +1 -0
  154. package/dist/modern/TimePicker/PeriodPicker/PeriodPicker.js +75 -0
  155. package/dist/modern/TimePicker/PeriodPicker/PeriodPicker.js.map +1 -0
  156. package/dist/modern/TimePicker/PeriodPicker/index.js +7 -0
  157. package/dist/modern/TimePicker/PeriodPicker/index.js.map +1 -0
  158. package/dist/modern/TimePicker/PeriodPicker/styles.js +22 -0
  159. package/dist/modern/TimePicker/PeriodPicker/styles.js.map +1 -0
  160. package/dist/modern/TimePicker/TimePicker.d.ts +140 -0
  161. package/dist/modern/TimePicker/TimePicker.js +659 -0
  162. package/dist/modern/TimePicker/TimePicker.js.map +1 -0
  163. package/dist/modern/TimePicker/UnitTimePicker/UnitTimePicker.js +191 -0
  164. package/dist/modern/TimePicker/UnitTimePicker/UnitTimePicker.js.map +1 -0
  165. package/dist/modern/TimePicker/UnitTimePicker/index.js +7 -0
  166. package/dist/modern/TimePicker/UnitTimePicker/index.js.map +1 -0
  167. package/dist/modern/TimePicker/UnitTimePicker/styles.js +49 -0
  168. package/dist/modern/TimePicker/UnitTimePicker/styles.js.map +1 -0
  169. package/dist/modern/TimePicker/enums.js +32 -0
  170. package/dist/modern/TimePicker/enums.js.map +1 -0
  171. package/dist/modern/TimePicker/index.d.ts +2 -0
  172. package/dist/modern/TimePicker/index.js +2 -0
  173. package/dist/modern/TimePicker/index.js.map +1 -0
  174. package/dist/modern/TimePicker/styles.js +108 -0
  175. package/dist/modern/TimePicker/styles.js.map +1 -0
  176. package/dist/modern/TimePicker/timePickerConverter.js +66 -0
  177. package/dist/modern/TimePicker/timePickerConverter.js.map +1 -0
  178. package/dist/modern/TimePicker/timePickerFormatter.js +65 -0
  179. package/dist/modern/TimePicker/timePickerFormatter.js.map +1 -0
  180. package/dist/modern/TimePicker/timePickerUtils.js +27 -0
  181. package/dist/modern/TimePicker/timePickerUtils.js.map +1 -0
  182. package/dist/modern/index.d.ts +3 -0
  183. package/dist/modern/index.js +1 -0
  184. package/dist/modern/index.js.map +1 -1
  185. package/package.json +4 -4
@@ -0,0 +1,696 @@
1
+ import "core-js/modules/es.object.keys.js";
2
+ import "core-js/modules/es.array.filter.js";
3
+ import "core-js/modules/es.object.get-own-property-descriptor.js";
4
+ import "core-js/modules/web.dom-collections.for-each.js";
5
+ import "core-js/modules/es.object.get-own-property-descriptors.js";
6
+ import _extends from "@babel/runtime/helpers/esm/extends";
7
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
9
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
10
+ var _excluded = ["classes", "className", "id", "name", "required", "disabled", "label", "aria-label", "aria-labelledby", "description", "aria-describedby", "onChange", "status", "statusMessage", "aria-errormessage", "placeholder", "hoursPlaceholder", "minutesPlaceholder", "secondsPlaceholder", "value", "defaultValue", "timeFormat", "locale", "disableDefaultValue", "onToggle", "hours", "minutes", "seconds", "period", "disablePortal", "escapeWithReference", "dropdownProps"];
11
+
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+
16
+ import "core-js/modules/es.function.name.js";
17
+ import "core-js/modules/es.symbol.js";
18
+ import "core-js/modules/es.symbol.description.js";
19
+ import "core-js/modules/es.object.to-string.js";
20
+ import "core-js/modules/es.regexp.to-string.js";
21
+ import "core-js/modules/es.string.trim.js";
22
+ import "core-js/modules/es.array.join.js";
23
+ import React, { useState, useEffect, useRef, useMemo } from "react";
24
+ import PropTypes from "prop-types";
25
+ import clsx from "clsx";
26
+ import { withStyles } from "@material-ui/core";
27
+ import { Time as TimeIcon } from "@hitachivantara/uikit-react-icons";
28
+ import { HvFormElement, HvBaseDropdown, HvLabel, HvWarningText, HvInfoMessage, setId, useUniqueId, useControlled, useLocale, HvTypography, useSavedState } from "..";
29
+ import { TimePickerUnits, TimeFormat, PeriodPickerOptions } from "./enums";
30
+ import { getFormattedTime, getTimeFormatForLocale } from "./timePickerFormatter";
31
+ import { getHoursForTimeFormat, getTimeWithFormat24 } from "./timePickerConverter";
32
+ import UnitTimePicker from "./UnitTimePicker";
33
+ import PeriodPicker from "./PeriodPicker";
34
+ import styles from "./styles";
35
+
36
+ var setFocusToContent = function setFocusToContent(containerRef) {
37
+ var _containerRef$getElem;
38
+
39
+ containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$getElem = containerRef.getElementsByTagName("input")[0]) === null || _containerRef$getElem === void 0 ? void 0 : _containerRef$getElem.focus();
40
+ };
41
+
42
+ var timeIsEqual = function timeIsEqual(timeA, timeB) {
43
+ return timeA === timeB || timeA == null && timeB == null || timeA != null && timeB != null && timeA.hours === timeB.hours && timeA.minutes === timeB.minutes && timeA.seconds === timeB.seconds && timeA.period === timeB.period;
44
+ };
45
+
46
+ var timeIsValid = function timeIsValid(time, timeFormat) {
47
+ var hourInputState = (time === null || time === void 0 ? void 0 : time.hours) != null && time.hours !== "" && time.hours >= 0 && (timeFormat === TimeFormat.H24 && time.hours <= 24 || timeFormat === TimeFormat.H12 && time.hours <= 12);
48
+ var minutesInputState = (time === null || time === void 0 ? void 0 : time.minutes) != null && time.minutes !== "" && time.minutes >= 0 && time.minutes <= 59;
49
+ var secondsInputState = (time === null || time === void 0 ? void 0 : time.seconds) != null && time.seconds !== "" && time.seconds >= 0 && time.seconds <= 59;
50
+ return hourInputState && minutesInputState && secondsInputState;
51
+ };
52
+ /**
53
+ * A TimePicker component used to choose the time.
54
+ */
55
+
56
+
57
+ var HvTimePicker = function HvTimePicker(_ref) {
58
+ var classes = _ref.classes,
59
+ className = _ref.className,
60
+ id = _ref.id,
61
+ name = _ref.name,
62
+ _ref$required = _ref.required,
63
+ required = _ref$required === void 0 ? false : _ref$required,
64
+ _ref$disabled = _ref.disabled,
65
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
66
+ label = _ref.label,
67
+ ariaLabel = _ref["aria-label"],
68
+ ariaLabelledBy = _ref["aria-labelledby"],
69
+ description = _ref.description,
70
+ ariaDescribedBy = _ref["aria-describedby"],
71
+ onChange = _ref.onChange,
72
+ status = _ref.status,
73
+ statusMessage = _ref.statusMessage,
74
+ ariaErrorMessage = _ref["aria-errormessage"],
75
+ placeholder = _ref.placeholder,
76
+ _ref$hoursPlaceholder = _ref.hoursPlaceholder,
77
+ hoursPlaceholder = _ref$hoursPlaceholder === void 0 ? "hh" : _ref$hoursPlaceholder,
78
+ _ref$minutesPlacehold = _ref.minutesPlaceholder,
79
+ minutesPlaceholder = _ref$minutesPlacehold === void 0 ? "mm" : _ref$minutesPlacehold,
80
+ _ref$secondsPlacehold = _ref.secondsPlaceholder,
81
+ secondsPlaceholder = _ref$secondsPlacehold === void 0 ? "ss" : _ref$secondsPlacehold,
82
+ valueProp = _ref.value,
83
+ defaultValueProp = _ref.defaultValue,
84
+ chosenTimeFormat = _ref.timeFormat,
85
+ localeProp = _ref.locale,
86
+ disableDefaultValue = _ref.disableDefaultValue,
87
+ onToggleCallback = _ref.onToggle,
88
+ _ref$hours = _ref.hours,
89
+ hours = _ref$hours === void 0 ? new Date().getHours() : _ref$hours,
90
+ _ref$minutes = _ref.minutes,
91
+ minutes = _ref$minutes === void 0 ? new Date().getMinutes() : _ref$minutes,
92
+ _ref$seconds = _ref.seconds,
93
+ seconds = _ref$seconds === void 0 ? 0 : _ref$seconds,
94
+ chosenTimePeriod = _ref.period,
95
+ _ref$disablePortal = _ref.disablePortal,
96
+ disablePortal = _ref$disablePortal === void 0 ? true : _ref$disablePortal,
97
+ _ref$escapeWithRefere = _ref.escapeWithReference,
98
+ escapeWithReference = _ref$escapeWithRefere === void 0 ? true : _ref$escapeWithRefere,
99
+ dropdownProps = _ref.dropdownProps,
100
+ others = _objectWithoutProperties(_ref, _excluded);
101
+
102
+ // #region STATE
103
+ var elementId = useUniqueId(id, "hvtimepicker");
104
+ var localeFromProvider = useLocale();
105
+ var locale = localeProp || localeFromProvider;
106
+ var timeFormat = useMemo(function () {
107
+ return chosenTimeFormat != null ? chosenTimeFormat.toString() : getTimeFormatForLocale(locale);
108
+ }, [chosenTimeFormat, locale]);
109
+
110
+ var _useSavedState = useSavedState(function () {
111
+ // fallback to the deprecated properties
112
+ // we shouldn't do that when promoting to core
113
+ // as it makes impossible to start with an empty value
114
+ var defaultValue = defaultValueProp !== null && defaultValueProp !== void 0 ? defaultValueProp : disableDefaultValue ? null : {
115
+ hours: hours,
116
+ minutes: minutes,
117
+ seconds: seconds
118
+ };
119
+ var v = valueProp !== null && valueProp !== void 0 ? valueProp : defaultValue;
120
+ return v != null ? {
121
+ hours: (v === null || v === void 0 ? void 0 : v.hours) != null ? getHoursForTimeFormat(v.hours, timeFormat) : null,
122
+ minutes: v === null || v === void 0 ? void 0 : v.minutes,
123
+ seconds: v === null || v === void 0 ? void 0 : v.seconds,
124
+ period: timeFormat === TimeFormat.H12 ? chosenTimePeriod !== null && chosenTimePeriod !== void 0 ? chosenTimePeriod : (v === null || v === void 0 ? void 0 : v.hours) == null || v.hours < 12 ? PeriodPickerOptions.AM : PeriodPickerOptions.PM : null
125
+ } : null;
126
+ }),
127
+ _useSavedState2 = _slicedToArray(_useSavedState, 4),
128
+ value = _useSavedState2[0],
129
+ setValue = _useSavedState2[1],
130
+ rollbackValue = _useSavedState2[2],
131
+ lastValidValue = _useSavedState2[3];
132
+
133
+ var _useControlled = useControlled(statusMessage, "Required"),
134
+ _useControlled2 = _slicedToArray(_useControlled, 1),
135
+ validationMessage = _useControlled2[0];
136
+
137
+ var _useControlled3 = useControlled(status, "standBy"),
138
+ _useControlled4 = _slicedToArray(_useControlled3, 2),
139
+ validationState = _useControlled4[0],
140
+ setValidationState = _useControlled4[1];
141
+
142
+ var _useState = useState(false),
143
+ _useState2 = _slicedToArray(_useState, 2),
144
+ isOpen = _useState2[0],
145
+ setOpen = _useState2[1]; // #endregion
146
+ // #region SIDE EFFECTS
147
+
148
+
149
+ var firstRender = useRef(true);
150
+ var currentValue = useRef(value);
151
+ useEffect(function () {
152
+ currentValue.current = value;
153
+ });
154
+ var currentTimeFormat = useRef(timeFormat);
155
+ useEffect(function () {
156
+ currentTimeFormat.current = timeFormat;
157
+ });
158
+ useEffect(function () {
159
+ // allow external changes to the time format (via timeFormat or locale properties)
160
+ if (!firstRender.current && currentValue.current != null) {
161
+ var to12 = timeFormat === TimeFormat.H12;
162
+ var _currentValue$current = currentValue.current,
163
+ h = _currentValue$current.hours,
164
+ p = _currentValue$current.period;
165
+
166
+ if (to12) {
167
+ if (h == null || h < 12) {
168
+ p = PeriodPickerOptions.AM;
169
+ } else {
170
+ p = PeriodPickerOptions.PM;
171
+
172
+ if (h > 12) {
173
+ h -= 12;
174
+ }
175
+ }
176
+ } else {
177
+ if (p === PeriodPickerOptions.AM) {
178
+ if (h === 12) {
179
+ h = 0;
180
+ }
181
+ } else if (h < 12) {
182
+ h += 12;
183
+ }
184
+
185
+ p = undefined;
186
+ }
187
+
188
+ setValue({
189
+ hours: h,
190
+ minutes: currentValue.current.minutes,
191
+ seconds: currentValue.current.seconds,
192
+ period: p
193
+ }, true);
194
+ }
195
+ }, [setValue, timeFormat]);
196
+ useEffect(function () {
197
+ // allow control of value property
198
+ if (!firstRender.current) {
199
+ var dayPeriod = (valueProp === null || valueProp === void 0 ? void 0 : valueProp.hours) == null || valueProp.hours < 12 ? PeriodPickerOptions.AM : PeriodPickerOptions.PM;
200
+ setValue(valueProp != null ? {
201
+ hours: (valueProp === null || valueProp === void 0 ? void 0 : valueProp.hours) != null ? getHoursForTimeFormat(valueProp.hours, currentTimeFormat.current) : null,
202
+ minutes: valueProp === null || valueProp === void 0 ? void 0 : valueProp.minutes,
203
+ seconds: valueProp === null || valueProp === void 0 ? void 0 : valueProp.seconds,
204
+ period: currentTimeFormat.current === TimeFormat.H12 ? dayPeriod : null
205
+ } : null, true);
206
+ }
207
+ }, [setValue, valueProp]);
208
+ useEffect(function () {
209
+ // on close, make sure to restore the last valid value
210
+ // (in the case the user closed with some time part invalid)
211
+ if (!firstRender.current && !isOpen) {
212
+ rollbackValue();
213
+ }
214
+ }, [isOpen, rollbackValue]);
215
+ useEffect(function () {
216
+ // run validations on each render
217
+ // (except on the first, remaining in the standBy/untouched state)
218
+ if (!firstRender.current) {
219
+ setValidationState(function () {
220
+ // this will only run if status is uncontrolled
221
+ if (required && lastValidValue == null) {
222
+ return "invalid";
223
+ }
224
+
225
+ return "valid";
226
+ });
227
+ }
228
+ });
229
+ useEffect(function () {
230
+ firstRender.current = false;
231
+ }, []); // #endregion
232
+ // #region EVENT HANDLERS
233
+
234
+ var handleTimeChange = function handleTimeChange(updatedTimeObject) {
235
+ if (!timeIsEqual(value, updatedTimeObject)) {
236
+ var valid = timeIsValid(updatedTimeObject, timeFormat); // the value only is commited if valid
237
+
238
+ setValue(updatedTimeObject, valid);
239
+
240
+ if (valid) {
241
+ // always output in 24h format
242
+ onChange === null || onChange === void 0 ? void 0 : onChange(getTimeWithFormat24(updatedTimeObject, timeFormat));
243
+ }
244
+ }
245
+ };
246
+ /**
247
+ * Handles the change of the hours value
248
+ * @param {Number} hours - selected hours
249
+ * @memberof HvTimePicker
250
+ */
251
+
252
+
253
+ var handleHoursChange = function handleHoursChange(updatedHours) {
254
+ var newSelectedTime = _objectSpread(_objectSpread({}, value), {}, {
255
+ hours: updatedHours
256
+ });
257
+
258
+ handleTimeChange(newSelectedTime);
259
+ };
260
+ /**
261
+ * Handles the change of the minutes value
262
+ * @param {Number} minutes - selected minutes
263
+ * @memberof HvTimePicker
264
+ */
265
+
266
+
267
+ var handleMinutesChange = function handleMinutesChange(updatedMinutes) {
268
+ var newSelectedTime = _objectSpread(_objectSpread({}, value), {}, {
269
+ minutes: updatedMinutes
270
+ });
271
+
272
+ handleTimeChange(newSelectedTime);
273
+ };
274
+ /**
275
+ * Handles the change of the seconds value
276
+ * @param {Number} seconds - selected seconds
277
+ * @memberof HvTimePicker
278
+ */
279
+
280
+
281
+ var handleSecondsChange = function handleSecondsChange(updatedSeconds) {
282
+ var newSelectedTime = _objectSpread(_objectSpread({}, value), {}, {
283
+ seconds: updatedSeconds
284
+ });
285
+
286
+ handleTimeChange(newSelectedTime);
287
+ };
288
+ /**
289
+ * Handles the change of the period (am/pm)
290
+ * @param {String} period - selected period
291
+ * @memberof HvTimePicker
292
+ */
293
+
294
+
295
+ var handleChangePeriod = function handleChangePeriod(updatedPeriod) {
296
+ var newSelectedTime = _objectSpread(_objectSpread({}, value), {}, {
297
+ period: updatedPeriod
298
+ });
299
+
300
+ handleTimeChange(newSelectedTime);
301
+ };
302
+
303
+ var onToggle = function onToggle(evt, open) {
304
+ /*
305
+ If evt is null this toggle wasn't triggered by the user.
306
+ instead it was triggered by the baseDropdown useEffect after
307
+ the change of the expanded property.
308
+ */
309
+ if (evt === null) return;
310
+ onToggleCallback === null || onToggleCallback === void 0 ? void 0 : onToggleCallback(evt, open);
311
+ setOpen(open);
312
+ }; // #endregion
313
+
314
+
315
+ var hasLabels = label != null;
316
+ var hasDescription = description != null; // the error message area will only be created if:
317
+ // - an external element that provides an error message isn't identified via aria-errormessage AND
318
+ // - both status and statusMessage properties are being controlled OR
319
+ // - status is uncontrolled and required is true
320
+
321
+ var canShowError = ariaErrorMessage == null && (status !== undefined && statusMessage !== undefined || status === undefined && required);
322
+ var isStateInvalid = validationState === "invalid";
323
+ var errorMessageId;
324
+
325
+ if (isStateInvalid) {
326
+ errorMessageId = canShowError ? setId(elementId, "error") : ariaErrorMessage;
327
+ }
328
+
329
+ return /*#__PURE__*/React.createElement(HvFormElement, _extends({
330
+ id: id,
331
+ name: name,
332
+ locale: locale,
333
+ required: required,
334
+ disabled: disabled,
335
+ status: validationState,
336
+ classes: {
337
+ root: classes.formElementRoot
338
+ },
339
+ className: clsx(className, classes.root)
340
+ }, others), (hasLabels || hasDescription) && /*#__PURE__*/React.createElement("div", {
341
+ className: classes.labelContainer
342
+ }, hasLabels && /*#__PURE__*/React.createElement(HvLabel, {
343
+ id: setId(elementId, "label"),
344
+ label: label,
345
+ className: classes.label
346
+ }), hasDescription && /*#__PURE__*/React.createElement(HvInfoMessage, {
347
+ id: setId(elementId, "description"),
348
+ className: classes.description
349
+ }, description)), /*#__PURE__*/React.createElement(HvBaseDropdown, _extends({
350
+ id: setId(elementId, "timepicker-dropdown"),
351
+ role: "combobox",
352
+ placeholder: lastValidValue != null ? getFormattedTime(lastValidValue, timeFormat) : /*#__PURE__*/React.createElement(HvTypography, {
353
+ variant: "placeholderText"
354
+ }, placeholder),
355
+ classes: {
356
+ placeholder: disabled ? classes.dropdownPlaceholderDisabled : classes.dropdownPlaceholder,
357
+ header: isStateInvalid ? classes.dropdownHeaderInvalid : undefined,
358
+ headerOpen: classes.dropdownHeaderOpen
359
+ },
360
+ variableWidth: true,
361
+ placement: "right",
362
+ adornment: /*#__PURE__*/React.createElement(TimeIcon, {
363
+ color: disabled ? "atmo5" : "acce1",
364
+ className: classes.iconBaseRoot
365
+ }),
366
+ expanded: isOpen,
367
+ onToggle: onToggle,
368
+ onContainerCreation: setFocusToContent,
369
+ "aria-haspopup": "dialog",
370
+ "aria-label": ariaLabel,
371
+ "aria-labelledby": [label && setId(elementId, "label"), ariaLabelledBy].join(" ").trim() || undefined,
372
+ "aria-invalid": isStateInvalid ? true : undefined,
373
+ "aria-errormessage": errorMessageId,
374
+ "aria-describedby": [description && setId(elementId, "description"), ariaDescribedBy].join(" ").trim() || undefined,
375
+ disablePortal: disablePortal,
376
+ disabled: disabled,
377
+ popperProps: {
378
+ modifiers: [{
379
+ name: "preventOverflow",
380
+ enabled: escapeWithReference
381
+ }]
382
+ }
383
+ }, dropdownProps), /*#__PURE__*/React.createElement("div", {
384
+ className: classes.timePopperContainer
385
+ }, /*#__PURE__*/React.createElement(UnitTimePicker, {
386
+ id: setId(elementId, "hours"),
387
+ placeholder: hoursPlaceholder,
388
+ unit: timeFormat === TimeFormat.H24 ? TimePickerUnits.HOUR_24.type : TimePickerUnits.HOUR_12.type,
389
+ unitValue: value === null || value === void 0 ? void 0 : value.hours,
390
+ onChangeUnitTimeValue: handleHoursChange
391
+ }), /*#__PURE__*/React.createElement("span", {
392
+ className: classes.separator
393
+ }, ":"), /*#__PURE__*/React.createElement(UnitTimePicker, {
394
+ id: setId(elementId, "minutes"),
395
+ placeholder: minutesPlaceholder,
396
+ unit: TimePickerUnits.MINUTE.type,
397
+ unitValue: value === null || value === void 0 ? void 0 : value.minutes,
398
+ onChangeUnitTimeValue: handleMinutesChange
399
+ }), /*#__PURE__*/React.createElement("span", {
400
+ className: classes.separator
401
+ }, ":"), /*#__PURE__*/React.createElement(UnitTimePicker, {
402
+ id: setId(elementId, "seconds"),
403
+ placeholder: secondsPlaceholder,
404
+ unit: TimePickerUnits.SECOND.type,
405
+ unitValue: value === null || value === void 0 ? void 0 : value.seconds,
406
+ onChangeUnitTimeValue: handleSecondsChange
407
+ }), timeFormat === TimeFormat.H12 && /*#__PURE__*/React.createElement(PeriodPicker, {
408
+ onChangePeriod: handleChangePeriod,
409
+ period: value === null || value === void 0 ? void 0 : value.period
410
+ }))), canShowError && /*#__PURE__*/React.createElement(HvWarningText, {
411
+ id: setId(elementId, "error"),
412
+ disableBorder: true,
413
+ className: classes.error
414
+ }, validationMessage));
415
+ };
416
+
417
+ process.env.NODE_ENV !== "production" ? HvTimePicker.propTypes = {
418
+ /**
419
+ * A Jss Object used to override or extend the styles applied to the input/popper
420
+ */
421
+ classes: PropTypes.shape({
422
+ /**
423
+ * Styles applied to the root element.
424
+ */
425
+ root: PropTypes.string,
426
+
427
+ /**
428
+ * Styles applied to the input.
429
+ */
430
+ input: PropTypes.string,
431
+
432
+ /**
433
+ * Styles applied to the label.
434
+ */
435
+ label: PropTypes.string,
436
+
437
+ /**
438
+ * Styles applied to the timePopperContainer.
439
+ */
440
+ timePopperContainer: PropTypes.string,
441
+
442
+ /**
443
+ * Styles applied to the separator.
444
+ */
445
+ separator: PropTypes.string,
446
+
447
+ /**
448
+ * Styles applied to the period container.
449
+ */
450
+ periodContainer: PropTypes.string,
451
+
452
+ /**
453
+ * Styles applied to the form element.
454
+ */
455
+ formElementRoot: PropTypes.string,
456
+
457
+ /**
458
+ * Styles applied to the dropdown placeholder.
459
+ */
460
+ dropdownPlaceholder: PropTypes.string,
461
+
462
+ /**
463
+ * Styles applied to the icon base.
464
+ */
465
+ iconBaseRoot: PropTypes.string,
466
+
467
+ /**
468
+ * Styles applied to the error area.
469
+ */
470
+ error: PropTypes.string,
471
+
472
+ /**
473
+ * Styles applied to the container of the labels elements.
474
+ */
475
+ labelContainer: PropTypes.string,
476
+
477
+ /**
478
+ * Styles applied to the icon information text.
479
+ */
480
+ description: PropTypes.string,
481
+
482
+ /**
483
+ * Styles applied to the dropdown when invalid information text.
484
+ */
485
+ dropdownHeaderInvalid: PropTypes.string,
486
+
487
+ /**
488
+ * Styles applied to the dropdown text when invalid.
489
+ */
490
+ dropdownPlaceholderDisabled: PropTypes.string,
491
+
492
+ /**
493
+ * Styles applied to the dropdown border when invalid.
494
+ */
495
+ dropdownHeaderOpen: PropTypes.string
496
+ }).isRequired,
497
+
498
+ /**
499
+ * Class names to be applied.
500
+ */
501
+ className: PropTypes.string,
502
+
503
+ /**
504
+ * Id to be applied to the form element root node.
505
+ */
506
+ id: PropTypes.string,
507
+
508
+ /**
509
+ * The form element name.
510
+ */
511
+ name: PropTypes.string,
512
+
513
+ /**
514
+ * The value of the form element.
515
+ */
516
+ value: PropTypes.shape({
517
+ hours: PropTypes.number,
518
+ minutes: PropTypes.number,
519
+ seconds: PropTypes.number,
520
+ period: PropTypes.string
521
+ }),
522
+
523
+ /**
524
+ * When uncontrolled, defines the initial input value.
525
+ */
526
+ defaultValue: PropTypes.shape({
527
+ hours: PropTypes.number,
528
+ minutes: PropTypes.number,
529
+ seconds: PropTypes.number,
530
+ period: PropTypes.string
531
+ }),
532
+
533
+ /**
534
+ * Indicates that user input is required on the form element.
535
+ */
536
+ required: PropTypes.bool,
537
+
538
+ /**
539
+ * Indicates that the form element is disabled.
540
+ */
541
+ disabled: PropTypes.bool,
542
+
543
+ /**
544
+ * The label of the form element.
545
+ *
546
+ * The form element must be labeled for accessibility reasons.
547
+ * If not provided, an aria-label or aria-labelledby must be provided instead.
548
+ */
549
+ label: PropTypes.string,
550
+
551
+ /**
552
+ * @ignore
553
+ */
554
+ "aria-label": PropTypes.string,
555
+
556
+ /**
557
+ * @ignore
558
+ */
559
+ "aria-labelledby": PropTypes.string,
560
+
561
+ /**
562
+ * Provide additional descriptive text for the form element.
563
+ */
564
+ description: PropTypes.node,
565
+
566
+ /**
567
+ * @ignore
568
+ */
569
+ "aria-describedby": PropTypes.string,
570
+
571
+ /**
572
+ * The placeholder value when no time is selected.
573
+ */
574
+ placeholder: PropTypes.string,
575
+
576
+ /**
577
+ * The placeholder of the hours input.
578
+ */
579
+ hoursPlaceholder: PropTypes.string,
580
+
581
+ /**
582
+ * The placeholder of the minutes input.
583
+ */
584
+ minutesPlaceholder: PropTypes.string,
585
+
586
+ /**
587
+ * The placeholder of the seconds input.
588
+ */
589
+ secondsPlaceholder: PropTypes.string,
590
+
591
+ /**
592
+ * The status of the form element.
593
+ *
594
+ * Valid is correct, invalid is incorrect and standBy means no validations have run.
595
+ *
596
+ * When uncontrolled and unspecified it will default to "standBy" and change to either "valid"
597
+ * or "invalid" after any change to the state.
598
+ */
599
+ status: PropTypes.oneOf(["standBy", "valid", "invalid"]),
600
+
601
+ /**
602
+ * The error message to show when the validation status is "invalid".
603
+ *
604
+ * Defaults to "Required" when the status is uncontrolled and no `aria-errormessage` is provided.
605
+ */
606
+ statusMessage: PropTypes.node,
607
+
608
+ /**
609
+ * Identifies the element that provides an error message for the time picker.
610
+ *
611
+ * Will only be used when the validation status is invalid.
612
+ */
613
+ "aria-errormessage": PropTypes.string,
614
+
615
+ /**
616
+ * If the time should be presented in 12 or 24 hour format.
617
+ * If undefined, the component will use a format according to the passed locale.
618
+ * If defined, it will "override" the default value given by the locale
619
+ */
620
+ timeFormat: PropTypes.oneOf([TimeFormat.H12, TimeFormat.H24, 12, 24, undefined]),
621
+
622
+ /**
623
+ * Locale that will provide the time format(12 or 24 hour format)
624
+ * It is "overwritten" by the timeFormat prop
625
+ */
626
+ locale: PropTypes.string,
627
+
628
+ /**
629
+ * Callback function to be triggered when the input value is changed.
630
+ * It is invoked with a object param with the following props:
631
+ * - hours (in a 24h format)
632
+ * - minutes
633
+ * - seconds
634
+ * - period
635
+ *
636
+ * It is always invoked with the hours in a 24h format
637
+ */
638
+ onChange: PropTypes.func,
639
+
640
+ /**
641
+ * Callback called when dropdown changes the expanded state.
642
+ *
643
+ * @param {object} event The event source of the callback.
644
+ * @param {boolean} open If the dropdown new state is open (`true`) or closed (`false`).
645
+ */
646
+ onToggle: PropTypes.func,
647
+
648
+ /**
649
+ * Allow starting with an empty value by not defaulting to the current time.
650
+ * This should become the default behavior when the component is promoted to core.
651
+ */
652
+ disableDefaultValue: PropTypes.bool,
653
+
654
+ /**
655
+ * Default value for the hours picker
656
+ * @deprecated use defaultValue instead
657
+ */
658
+ hours: PropTypes.number,
659
+
660
+ /**
661
+ * Default value for the minutes picker
662
+ * @deprecated use defaultValue instead
663
+ */
664
+ minutes: PropTypes.number,
665
+
666
+ /**
667
+ * Default value for the seconds picker
668
+ * @deprecated use defaultValue instead
669
+ */
670
+ seconds: PropTypes.number,
671
+
672
+ /**
673
+ * Default value for the period picker
674
+ * @deprecated use defaultValue instead
675
+ */
676
+ period: PropTypes.string,
677
+
678
+ /**
679
+ * Disable the portal behavior. The children stay within it's parent DOM hierarchy.
680
+ */
681
+ disablePortal: PropTypes.bool,
682
+
683
+ /**
684
+ * Sets if the calendar container should follow the date picker input out of the screen or stay visible.
685
+ */
686
+ escapeWithReference: PropTypes.bool,
687
+
688
+ /**
689
+ * Extra properties to be passed to the timepicker dropdown.
690
+ */
691
+ dropdownProps: PropTypes.instanceOf(Object)
692
+ } : void 0;
693
+ export default withStyles(styles, {
694
+ name: "HvTimePicker"
695
+ })(HvTimePicker);
696
+ //# sourceMappingURL=TimePicker.js.map