grommet 2.56.0 → 2.56.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/COPYRIGHT.md +3 -1
  2. package/components/Calendar/Calendar.js +2 -1
  3. package/components/Cards/Cards.js +1 -2
  4. package/components/DateTimeInput/DateTimeInput.js +1093 -0
  5. package/components/DateTimeInput/README.md +2 -0
  6. package/components/DateTimeInput/StyledDateTimeInput.js +74 -0
  7. package/components/DateTimeInput/index.d.ts +47 -0
  8. package/components/DateTimeInput/index.js +6 -0
  9. package/components/DateTimeInput/propTypes.js +42 -0
  10. package/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  11. package/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  12. package/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  13. package/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  14. package/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  15. package/components/Form/Form.js +7 -4
  16. package/components/Form/index.d.ts +3 -0
  17. package/components/Form/stories/AggregateValidation.stories.js +6 -8
  18. package/components/FormField/FormField.js +164 -91
  19. package/components/Stepper/StepConnector.js +19 -49
  20. package/components/Stepper/Stepper.js +5 -11
  21. package/components/Stepper/StepperStep.js +14 -4
  22. package/components/Stepper/StyledStepper.js +59 -21
  23. package/components/TimeInput/TimeInput.js +50 -47
  24. package/components/TimeInput/TimeInputPopup.js +172 -76
  25. package/components/TimeInput/index.d.ts +3 -0
  26. package/components/TimeInput/propTypes.js +4 -0
  27. package/components/TimeInput/useSectionedTimeField.js +33 -34
  28. package/components/TimeInput/utils.js +31 -26
  29. package/components/Wizard/StyledWizard.js +16 -0
  30. package/components/Wizard/Wizard.js +770 -0
  31. package/components/Wizard/WizardContent.js +90 -0
  32. package/components/Wizard/WizardContext.js +35 -0
  33. package/components/Wizard/WizardFooter.js +123 -0
  34. package/components/Wizard/WizardHeader.js +63 -0
  35. package/components/Wizard/WizardProgress.js +84 -0
  36. package/components/Wizard/WizardStepHeader.js +55 -0
  37. package/components/Wizard/index.d.ts +171 -0
  38. package/components/Wizard/index.js +19 -0
  39. package/components/Wizard/propTypes.js +56 -0
  40. package/components/Wizard/stories/BasicLinear.stories.js +71 -0
  41. package/components/Wizard/stories/Branching.stories.js +96 -0
  42. package/components/Wizard/stories/Composable.stories.js +75 -0
  43. package/components/Wizard/stories/Controlled.stories.js +136 -0
  44. package/components/Wizard/stories/LongContent.stories.js +118 -0
  45. package/components/Wizard/stories/Modal.stories.js +143 -0
  46. package/components/Wizard/stories/NestedSubSteps.stories.js +79 -0
  47. package/components/Wizard/stories/Validation.stories.js +123 -0
  48. package/components/index.d.ts +4 -0
  49. package/components/index.js +12 -0
  50. package/es6/components/Calendar/Calendar.js +2 -0
  51. package/es6/components/Cards/Cards.js +1 -2
  52. package/es6/components/DateTimeInput/DateTimeInput.js +1090 -0
  53. package/es6/components/DateTimeInput/README.md +2 -0
  54. package/es6/components/DateTimeInput/StyledDateTimeInput.js +68 -0
  55. package/es6/components/DateTimeInput/index.d.ts +47 -0
  56. package/es6/components/DateTimeInput/index.js +3 -0
  57. package/es6/components/DateTimeInput/propTypes.js +36 -0
  58. package/es6/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  59. package/es6/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  60. package/es6/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  61. package/es6/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  62. package/es6/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  63. package/es6/components/Form/Form.js +7 -3
  64. package/es6/components/Form/index.d.ts +3 -0
  65. package/es6/components/Form/stories/AggregateValidation.stories.js +6 -9
  66. package/es6/components/FormField/FormField.js +165 -91
  67. package/es6/components/Stepper/StepConnector.js +18 -48
  68. package/es6/components/Stepper/Stepper.js +5 -10
  69. package/es6/components/Stepper/StepperStep.js +15 -4
  70. package/es6/components/Stepper/StyledStepper.js +57 -21
  71. package/es6/components/TimeInput/TimeInput.js +50 -46
  72. package/es6/components/TimeInput/TimeInputPopup.js +172 -76
  73. package/es6/components/TimeInput/index.d.ts +3 -0
  74. package/es6/components/TimeInput/propTypes.js +3 -0
  75. package/es6/components/TimeInput/useSectionedTimeField.js +34 -35
  76. package/es6/components/TimeInput/utils.js +25 -21
  77. package/es6/components/Wizard/StyledWizard.js +11 -0
  78. package/es6/components/Wizard/Wizard.js +768 -0
  79. package/es6/components/Wizard/WizardContent.js +87 -0
  80. package/es6/components/Wizard/WizardContext.js +31 -0
  81. package/es6/components/Wizard/WizardFooter.js +120 -0
  82. package/es6/components/Wizard/WizardHeader.js +60 -0
  83. package/es6/components/Wizard/WizardProgress.js +80 -0
  84. package/es6/components/Wizard/WizardStepHeader.js +51 -0
  85. package/es6/components/Wizard/index.d.ts +171 -0
  86. package/es6/components/Wizard/index.js +7 -0
  87. package/es6/components/Wizard/propTypes.js +51 -0
  88. package/es6/components/Wizard/stories/BasicLinear.stories.js +67 -0
  89. package/es6/components/Wizard/stories/Branching.stories.js +93 -0
  90. package/es6/components/Wizard/stories/Composable.stories.js +72 -0
  91. package/es6/components/Wizard/stories/Controlled.stories.js +133 -0
  92. package/es6/components/Wizard/stories/LongContent.stories.js +115 -0
  93. package/es6/components/Wizard/stories/Modal.stories.js +141 -0
  94. package/es6/components/Wizard/stories/NestedSubSteps.stories.js +76 -0
  95. package/es6/components/Wizard/stories/Validation.stories.js +118 -0
  96. package/es6/components/index.d.ts +4 -0
  97. package/es6/components/index.js +4 -0
  98. package/es6/index.d.ts +4 -0
  99. package/es6/languages/default.json +28 -0
  100. package/es6/themes/base.d.ts +115 -0
  101. package/es6/themes/base.js +158 -0
  102. package/es6/utils/DOM.js +11 -2
  103. package/es6/utils/dates.js +10 -0
  104. package/es6/utils/sectionHelpers.js +57 -0
  105. package/es6/utils/useSectionedField.js +45 -0
  106. package/grommet.min.js +2 -1
  107. package/grommet.min.js.LICENSE.txt +1 -0
  108. package/grommet.min.js.map +1 -1
  109. package/index.d.ts +4 -0
  110. package/languages/default.json +28 -0
  111. package/package.json +35 -31
  112. package/themes/base.d.ts +115 -0
  113. package/themes/base.js +158 -1
  114. package/tools/license-header.js +2 -0
  115. package/utils/DOM.js +11 -2
  116. package/utils/dates.js +11 -1
  117. package/utils/sectionHelpers.js +61 -0
  118. package/utils/useSectionedField.js +50 -0
@@ -1,4 +1,8 @@
1
+ var _excluded = ["activeSection", "align", "format", "formatMessage", "hoursOptions", "id", "incrementSection", "messages", "minuteOptions", "onClose", "onFocusLeave", "secondOptions", "sectionOrder", "sections", "setActiveSection", "setSectionValue", "target", "dropProps", "label", "inline", "onKeyDown"];
1
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
5
+ // SPDX-License-Identifier: Apache-2.0
2
6
  /* eslint-disable max-len */
3
7
  import React, { useCallback, useEffect, useRef } from 'react';
4
8
  import styled from 'styled-components';
@@ -8,7 +12,7 @@ import { useThemeValue } from '../../utils/useThemeValue';
8
12
  import { Box } from '../Box';
9
13
  import { Drop } from '../Drop';
10
14
  import { Text } from '../Text';
11
- import { pad, getSectionName, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
15
+ import { defaultHourForFormat, pad, getSectionName, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
12
16
  var PopupColumnBox = styled(Box).withConfig({
13
17
  displayName: "TimeInputPopup__PopupColumnBox",
14
18
  componentId: "sc-r2j8uh-0"
@@ -45,26 +49,42 @@ var PopupOption = styled.div.withConfig({
45
49
  var optionKey = function optionKey(label, option) {
46
50
  return label.toLowerCase() + "-" + option;
47
51
  };
48
- var PopupColumn = function PopupColumn(_ref) {
49
- var _theme$timeInput;
50
- var activeSection = _ref.activeSection,
52
+ var getDefaultPopupOption = function getDefaultPopupOption(_ref) {
53
+ var section = _ref.section,
51
54
  format = _ref.format,
52
- formatMessage = _ref.formatMessage,
53
- label = _ref.label,
54
- messages = _ref.messages,
55
- onClickCommitOption = _ref.onClickCommitOption,
56
- onPointerCommitOption = _ref.onPointerCommitOption,
57
- onSetSection = _ref.onSetSection,
58
- options = _ref.options,
59
- section = _ref.section,
60
- sections = _ref.sections,
61
- theme = _ref.theme;
55
+ options = _ref.options;
56
+ if (section === SECTION_HOUR) {
57
+ var defaultHour = defaultHourForFormat(format);
58
+ return options.includes(defaultHour) ? defaultHour : options[0];
59
+ }
60
+ if (section === SECTION_PERIOD) return 'AM';
61
+ return options[0];
62
+ };
63
+ var PopupColumn = function PopupColumn(_ref2) {
64
+ var _theme$global$size, _theme$timeInput;
65
+ var activeSection = _ref2.activeSection,
66
+ format = _ref2.format,
67
+ formatMessage = _ref2.formatMessage,
68
+ inline = _ref2.inline,
69
+ label = _ref2.label,
70
+ messages = _ref2.messages,
71
+ onClickCommitOption = _ref2.onClickCommitOption,
72
+ onPointerCommitOption = _ref2.onPointerCommitOption,
73
+ onSetSection = _ref2.onSetSection,
74
+ options = _ref2.options,
75
+ section = _ref2.section,
76
+ sections = _ref2.sections,
77
+ theme = _ref2.theme;
78
+ // When inline (in DateTimeInput), use 'medium' to match Calendar height.
79
+ // Otherwise use timeInput drop maxHeight with fallback to 'small'.
80
+ var maxHeightToken = inline ? 'medium' : null;
81
+ var maxHeight = maxHeightToken && ((_theme$global$size = theme.global.size) == null ? void 0 : _theme$global$size[maxHeightToken]) || ((_theme$timeInput = theme.timeInput) == null || (_theme$timeInput = _theme$timeInput.drop) == null || (_theme$timeInput = _theme$timeInput.column) == null ? void 0 : _theme$timeInput.maxHeight) || theme.global.size.small;
62
82
  return /*#__PURE__*/React.createElement(PopupColumnBox, {
63
83
  role: "listbox",
64
84
  "aria-label": label,
65
85
  gap: "xxsmall",
66
86
  height: {
67
- max: ((_theme$timeInput = theme.timeInput) == null || (_theme$timeInput = _theme$timeInput.drop) == null || (_theme$timeInput = _theme$timeInput.column) == null ? void 0 : _theme$timeInput.maxHeight) || theme.global.size.small
87
+ max: maxHeight
68
88
  },
69
89
  overflow: "auto",
70
90
  flex: {
@@ -74,15 +94,34 @@ var PopupColumn = function PopupColumn(_ref) {
74
94
  }, options.map(function (option) {
75
95
  var _theme$timeInput2;
76
96
  var key = optionKey(label, option);
97
+ var sectionHasValue = section === SECTION_HOUR && sections.hour !== undefined || section === SECTION_MINUTE && sections.minute !== undefined || section === SECTION_SECOND && sections.second !== undefined || section === SECTION_PERIOD && sections.period !== undefined;
98
+
99
+ // In empty state, keep focus defaults but avoid visually selecting
100
+ // options until the user makes an explicit choice.
77
101
  var selected = section === SECTION_HOUR && sections.hour === option || section === SECTION_MINUTE && sections.minute === option || section === SECTION_SECOND && sections.second === option || section === SECTION_PERIOD && sections.period === option;
78
102
  var optionColor = selected ? ((_theme$timeInput2 = theme.timeInput) == null || (_theme$timeInput2 = _theme$timeInput2.drop) == null || (_theme$timeInput2 = _theme$timeInput2.option) == null || (_theme$timeInput2 = _theme$timeInput2.selected) == null ? void 0 : _theme$timeInput2.color) || 'text' : 'text';
79
103
  var isActive = selected && activeSection === section;
104
+ var optionTabIndex = -1;
105
+ if (inline) {
106
+ // In inline mode each column needs exactly one tabbable option so Tab
107
+ // key lands on the option (with Grommet focus style) instead of the
108
+ // listbox container (which has no theme focus style). Use the selected
109
+ // value when set, otherwise fall back to the column's first option.
110
+ var defaultOption = getDefaultPopupOption({
111
+ section: section,
112
+ format: format,
113
+ options: options
114
+ });
115
+ optionTabIndex = selected || !sectionHasValue && option === defaultOption ? 0 : -1;
116
+ } else if (isActive) {
117
+ optionTabIndex = 0;
118
+ }
80
119
  return /*#__PURE__*/React.createElement(PopupOption, {
81
120
  key: key,
82
121
  "data-option-key": key,
83
122
  role: "option",
84
123
  "aria-selected": selected,
85
- tabIndex: isActive ? 0 : -1,
124
+ tabIndex: optionTabIndex,
86
125
  "aria-label": (section === SECTION_PERIOD ? option : pad(option)) + " " + getSectionName(section, format, formatMessage, messages),
87
126
  $active: isActive,
88
127
  $selected: selected,
@@ -101,34 +140,35 @@ var PopupColumn = function PopupColumn(_ref) {
101
140
  }
102
141
  }, /*#__PURE__*/React.createElement(Text, {
103
142
  size: theme.global.input.font.size || 'small',
104
- weight: selected ? 'bold' : 'normal',
105
143
  color: optionColor
106
144
  }, section === SECTION_PERIOD ? option : pad(option)));
107
145
  }));
108
146
  };
109
- var TimeInputPopup = function TimeInputPopup(_ref2) {
110
- var _theme$timeInput3, _theme$timeInput4;
111
- var activeSection = _ref2.activeSection,
112
- align = _ref2.align,
113
- format = _ref2.format,
114
- formatMessage = _ref2.formatMessage,
115
- hoursOptions = _ref2.hoursOptions,
116
- id = _ref2.id,
117
- incrementSection = _ref2.incrementSection,
118
- messages = _ref2.messages,
119
- minuteOptions = _ref2.minuteOptions,
120
- moveSection = _ref2.moveSection,
121
- onAccept = _ref2.onAccept,
122
- onClose = _ref2.onClose,
123
- onFocusLeave = _ref2.onFocusLeave,
124
- secondOptions = _ref2.secondOptions,
125
- sectionOrder = _ref2.sectionOrder,
126
- sections = _ref2.sections,
127
- setActiveSection = _ref2.setActiveSection,
128
- setSectionValue = _ref2.setSectionValue,
129
- target = _ref2.target,
130
- dropProps = _ref2.dropProps,
131
- label = _ref2.label;
147
+ var TimeInputPopup = function TimeInputPopup(_ref3) {
148
+ var _theme$timeInput3, _theme$timeInput4, _theme$timeInput5;
149
+ var activeSection = _ref3.activeSection,
150
+ align = _ref3.align,
151
+ format = _ref3.format,
152
+ formatMessage = _ref3.formatMessage,
153
+ hoursOptions = _ref3.hoursOptions,
154
+ id = _ref3.id,
155
+ incrementSection = _ref3.incrementSection,
156
+ messages = _ref3.messages,
157
+ minuteOptions = _ref3.minuteOptions,
158
+ onClose = _ref3.onClose,
159
+ onFocusLeave = _ref3.onFocusLeave,
160
+ secondOptions = _ref3.secondOptions,
161
+ sectionOrder = _ref3.sectionOrder,
162
+ sections = _ref3.sections,
163
+ setActiveSection = _ref3.setActiveSection,
164
+ setSectionValue = _ref3.setSectionValue,
165
+ target = _ref3.target,
166
+ dropProps = _ref3.dropProps,
167
+ label = _ref3.label,
168
+ _ref3$inline = _ref3.inline,
169
+ inline = _ref3$inline === void 0 ? false : _ref3$inline,
170
+ onKeyDownProp = _ref3.onKeyDown,
171
+ rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
132
172
  var _useThemeValue = useThemeValue(),
133
173
  theme = _useThemeValue.theme;
134
174
  var dialogRef = useRef();
@@ -219,10 +259,29 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
219
259
  label: 'period',
220
260
  options: ['AM', 'PM']
221
261
  }];
222
- var visiblePopupSections = popupSections.filter(function (_ref3) {
223
- var section = _ref3.section;
262
+ var visiblePopupSections = popupSections.filter(function (_ref4) {
263
+ var section = _ref4.section;
224
264
  return sectionOrder.includes(section);
225
265
  });
266
+ var getSectionFromLabel = useCallback(function (listboxLabel) {
267
+ if (listboxLabel === 'hour') return SECTION_HOUR;
268
+ if (listboxLabel === 'minute') return SECTION_MINUTE;
269
+ if (listboxLabel === 'second') return SECTION_SECOND;
270
+ if (listboxLabel === 'period') return SECTION_PERIOD;
271
+ return undefined;
272
+ }, []);
273
+ var getSectionFromEventTarget = useCallback(function (eventTarget) {
274
+ var listboxNode = eventTarget == null || eventTarget.closest == null ? void 0 : eventTarget.closest('[role="listbox"]');
275
+ var ariaLabel = listboxNode == null || listboxNode.getAttribute == null ? void 0 : listboxNode.getAttribute('aria-label');
276
+ return getSectionFromLabel(ariaLabel);
277
+ }, [getSectionFromLabel]);
278
+ var getAdjacentSection = useCallback(function (section, delta) {
279
+ var _sectionOrder$, _sectionOrder$nextInd;
280
+ var currentIndex = sectionOrder.indexOf(section);
281
+ if (currentIndex === -1) return (_sectionOrder$ = sectionOrder[0]) != null ? _sectionOrder$ : section;
282
+ var nextIndex = (currentIndex + delta + sectionOrder.length) % sectionOrder.length;
283
+ return (_sectionOrder$nextInd = sectionOrder[nextIndex]) != null ? _sectionOrder$nextInd : section;
284
+ }, [sectionOrder]);
226
285
  var scrollSelectedOptionsIntoView = useCallback(function () {
227
286
  var _sectionLabel, _sectionValue;
228
287
  if (pointerDownInsideRef.current) return;
@@ -233,9 +292,21 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
233
292
  var popupNode = dialogRef.current;
234
293
  if (!popupNode) return;
235
294
  var sectionLabel = (_sectionLabel = {}, _sectionLabel[SECTION_HOUR] = 'hour', _sectionLabel[SECTION_MINUTE] = 'minute', _sectionLabel[SECTION_SECOND] = 'second', _sectionLabel[SECTION_PERIOD] = 'period', _sectionLabel);
236
- var sectionValue = (_sectionValue = {}, _sectionValue[SECTION_HOUR] = sections.hour !== undefined ? sections.hour : hoursOptions[0], _sectionValue[SECTION_MINUTE] = sections.minute !== undefined ? sections.minute : minuteOptions[0], _sectionValue[SECTION_SECOND] = sections.second !== undefined ? sections.second : secondOptions[0], _sectionValue[SECTION_PERIOD] = sections.period || 'AM', _sectionValue);
237
- visiblePopupSections.forEach(function (_ref4) {
238
- var section = _ref4.section;
295
+ var sectionValue = (_sectionValue = {}, _sectionValue[SECTION_HOUR] = sections.hour !== undefined ? sections.hour : getDefaultPopupOption({
296
+ section: SECTION_HOUR,
297
+ format: format,
298
+ options: hoursOptions
299
+ }), _sectionValue[SECTION_MINUTE] = sections.minute !== undefined ? sections.minute : getDefaultPopupOption({
300
+ section: SECTION_MINUTE,
301
+ format: format,
302
+ options: minuteOptions
303
+ }), _sectionValue[SECTION_SECOND] = sections.second !== undefined ? sections.second : getDefaultPopupOption({
304
+ section: SECTION_SECOND,
305
+ format: format,
306
+ options: secondOptions
307
+ }), _sectionValue[SECTION_PERIOD] = sections.period || 'AM', _sectionValue);
308
+ visiblePopupSections.forEach(function (_ref5) {
309
+ var section = _ref5.section;
239
310
  var labelValue = sectionLabel[section];
240
311
  if (!labelValue) return;
241
312
  var listboxNode = popupNode.querySelector("[role=\"listbox\"][aria-label=\"" + labelValue + "\"]");
@@ -256,11 +327,23 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
256
327
  listboxNode.scrollTop = Math.max(0, targetScrollTop);
257
328
  }
258
329
  });
259
- }, [hoursOptions, minuteOptions, secondOptions, sections, visiblePopupSections]);
330
+ }, [format, hoursOptions, minuteOptions, secondOptions, sections, visiblePopupSections]);
260
331
  var focusCurrentPopupOption = useCallback(function () {
261
332
  var _labelMap, _keyMap, _dialogRef$current, _dialogRef$current2;
262
333
  var labelMap = (_labelMap = {}, _labelMap[SECTION_HOUR] = 'hour', _labelMap[SECTION_MINUTE] = 'minute', _labelMap[SECTION_SECOND] = 'second', _labelMap[SECTION_PERIOD] = 'period', _labelMap);
263
- var keyMap = (_keyMap = {}, _keyMap[SECTION_HOUR] = optionKey('hour', sections.hour !== undefined ? sections.hour : hoursOptions[0]), _keyMap[SECTION_MINUTE] = optionKey('minute', sections.minute !== undefined ? sections.minute : minuteOptions[0]), _keyMap[SECTION_SECOND] = optionKey('second', sections.second !== undefined ? sections.second : secondOptions[0]), _keyMap[SECTION_PERIOD] = optionKey('period', sections.period || 'AM'), _keyMap);
334
+ var keyMap = (_keyMap = {}, _keyMap[SECTION_HOUR] = optionKey('hour', sections.hour !== undefined ? sections.hour : getDefaultPopupOption({
335
+ section: SECTION_HOUR,
336
+ format: format,
337
+ options: hoursOptions
338
+ })), _keyMap[SECTION_MINUTE] = optionKey('minute', sections.minute !== undefined ? sections.minute : getDefaultPopupOption({
339
+ section: SECTION_MINUTE,
340
+ format: format,
341
+ options: minuteOptions
342
+ })), _keyMap[SECTION_SECOND] = optionKey('second', sections.second !== undefined ? sections.second : getDefaultPopupOption({
343
+ section: SECTION_SECOND,
344
+ format: format,
345
+ options: secondOptions
346
+ })), _keyMap[SECTION_PERIOD] = optionKey('period', sections.period || 'AM'), _keyMap);
264
347
  var selector = "[data-option-key=\"" + keyMap[activeSection] + "\"]";
265
348
  var node = (_dialogRef$current = dialogRef.current) == null ? void 0 : _dialogRef$current.querySelector(selector);
266
349
  if (node) {
@@ -278,7 +361,7 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
278
361
  return true;
279
362
  }
280
363
  return false;
281
- }, [activeSection, hoursOptions, minuteOptions, secondOptions, sections]);
364
+ }, [activeSection, format, hoursOptions, minuteOptions, secondOptions, sections]);
282
365
  useLayoutEffect(function () {
283
366
  // Avoid stealing pointer interactions: while the user is actively
284
367
  // clicking inside the popup, let that click settle before refocusing.
@@ -304,16 +387,10 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
304
387
  if (rafB) window.cancelAnimationFrame(rafB);
305
388
  };
306
389
  }, [focusCurrentPopupOption, scrollSelectedOptionsIntoView]);
307
- return /*#__PURE__*/React.createElement(Drop, _extends({
308
- id: id ? id + "__drop" : undefined,
309
- target: target,
310
- align: align,
311
- onEsc: onClose,
312
- onClickOutside: onClose
313
- }, dropProps), /*#__PURE__*/React.createElement(Box, {
390
+ var popupContent = /*#__PURE__*/React.createElement(Box, _extends({
314
391
  ref: dialogRef,
315
- role: "dialog",
316
- "aria-label": label,
392
+ role: inline ? undefined : 'dialog',
393
+ "aria-label": inline ? undefined : label,
317
394
  direction: "row",
318
395
  width: {
319
396
  width: (_theme$timeInput3 = theme.timeInput) == null || (_theme$timeInput3 = _theme$timeInput3.drop) == null ? void 0 : _theme$timeInput3.width,
@@ -321,40 +398,50 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
321
398
  },
322
399
  minHeight: (_theme$timeInput4 = theme.timeInput) == null || (_theme$timeInput4 = _theme$timeInput4.drop) == null ? void 0 : _theme$timeInput4.minHeight,
323
400
  gap: "xsmall",
324
- pad: "small",
401
+ pad: inline ? 'none' : ((_theme$timeInput5 = theme.timeInput) == null || (_theme$timeInput5 = _theme$timeInput5.drop) == null ? void 0 : _theme$timeInput5.pad) || 'small',
325
402
  onPointerDownCapture: markInteractionInProgress,
326
403
  onPointerUpCapture: releaseInteractionAfterClick,
327
404
  onPointerCancelCapture: clearInteractionInProgress,
328
405
  onWheelCapture: onPopupWheelCapture,
329
406
  onKeyDown: function onKeyDown(event) {
407
+ var _ref6;
408
+ var eventSectionFromTarget = getSectionFromEventTarget(event.target);
409
+ var eventSectionFromActiveElement = getSectionFromEventTarget(document.activeElement);
410
+ var eventSection = (_ref6 = eventSectionFromTarget != null ? eventSectionFromTarget : eventSectionFromActiveElement) != null ? _ref6 : activeSection;
330
411
  if (event.key === 'Escape') {
331
- event.preventDefault();
332
- onClose();
333
- } else if (event.key === ' ' || event.key === 'Spacebar') {
412
+ if (onClose) {
413
+ event.preventDefault();
414
+ onClose();
415
+ }
416
+ } else if (event.key === 'Enter') {
334
417
  var _event$target, _document$activeEleme;
335
418
  event.preventDefault();
336
419
  var focusedOption = ((_event$target = event.target) == null || _event$target.closest == null ? void 0 : _event$target.closest('[role="option"]')) || ((_document$activeEleme = document.activeElement) == null || _document$activeEleme.closest == null ? void 0 : _document$activeEleme.closest('[role="option"]'));
337
420
  focusedOption == null || focusedOption.click == null || focusedOption.click();
338
- } else if (event.key === 'Tab') {
421
+ } else if (event.key === ' ' || event.key === 'Spacebar') {
422
+ var _event$target2, _document$activeEleme2;
339
423
  event.preventDefault();
340
- setActiveSection(moveSection(event.shiftKey ? -1 : 1));
424
+ var _focusedOption = ((_event$target2 = event.target) == null || _event$target2.closest == null ? void 0 : _event$target2.closest('[role="option"]')) || ((_document$activeEleme2 = document.activeElement) == null || _document$activeEleme2.closest == null ? void 0 : _document$activeEleme2.closest('[role="option"]'));
425
+ _focusedOption == null || _focusedOption.click == null || _focusedOption.click();
426
+ } else if (event.key === 'Tab') {
427
+ if (!inline) {
428
+ event.preventDefault();
429
+ setActiveSection(getAdjacentSection(eventSection, event.shiftKey ? -1 : 1));
430
+ }
341
431
  } else if (event.key === 'ArrowLeft') {
342
432
  event.preventDefault();
343
- setActiveSection(moveSection(-1));
433
+ setActiveSection(getAdjacentSection(eventSection, -1));
344
434
  } else if (event.key === 'ArrowRight') {
345
435
  event.preventDefault();
346
- setActiveSection(moveSection(1));
436
+ setActiveSection(getAdjacentSection(eventSection, 1));
347
437
  } else if (event.key === 'ArrowUp') {
348
438
  event.preventDefault();
349
- incrementSection(activeSection, -1);
439
+ incrementSection(eventSection, -1);
350
440
  } else if (event.key === 'ArrowDown') {
351
441
  event.preventDefault();
352
- incrementSection(activeSection, 1);
353
- } else if (event.key === 'Enter') {
354
- event.preventDefault();
355
- onAccept == null || onAccept();
356
- onClose();
442
+ incrementSection(eventSection, 1);
357
443
  }
444
+ onKeyDownProp == null || onKeyDownProp(event);
358
445
  },
359
446
  onBlurCapture: function onBlurCapture(event) {
360
447
  var nextFocusTarget = event.relatedTarget;
@@ -365,15 +452,16 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
365
452
  onFocusLeave == null || onFocusLeave();
366
453
  }
367
454
  }
368
- }, visiblePopupSections.map(function (_ref5) {
369
- var section = _ref5.section,
370
- sectionLabel = _ref5.label,
371
- options = _ref5.options;
455
+ }, rest), visiblePopupSections.map(function (_ref7) {
456
+ var section = _ref7.section,
457
+ sectionLabel = _ref7.label,
458
+ options = _ref7.options;
372
459
  return /*#__PURE__*/React.createElement(PopupColumn, {
373
460
  key: sectionLabel,
374
461
  activeSection: activeSection,
375
462
  format: format,
376
463
  formatMessage: formatMessage,
464
+ inline: inline,
377
465
  label: sectionLabel,
378
466
  messages: messages,
379
467
  onClickCommitOption: commitClickOptionSelection,
@@ -384,6 +472,14 @@ var TimeInputPopup = function TimeInputPopup(_ref2) {
384
472
  sections: sections,
385
473
  theme: theme
386
474
  });
387
- })));
475
+ }));
476
+ if (inline) return popupContent;
477
+ return /*#__PURE__*/React.createElement(Drop, _extends({
478
+ id: id ? id + "__drop" : undefined,
479
+ target: target,
480
+ align: align,
481
+ onEsc: onClose,
482
+ onClickOutside: onClose
483
+ }, dropProps), popupContent);
388
484
  };
389
485
  export { TimeInputPopup };
@@ -1,3 +1,5 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import * as React from 'react';
2
4
 
3
5
  export interface TimeInputProps {
@@ -23,6 +25,7 @@ export interface TimeInputProps {
23
25
  name?: string;
24
26
  onChange?: (event: { value?: string }) => void;
25
27
  readOnly?: boolean;
28
+ showSeconds?: boolean;
26
29
  value?: string;
27
30
  }
28
31
 
@@ -1,3 +1,5 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
  import PropTypes from 'prop-types';
2
4
  var PropType = {};
3
5
  if (process.env.NODE_ENV !== 'production') {
@@ -24,6 +26,7 @@ if (process.env.NODE_ENV !== 'production') {
24
26
  name: PropTypes.string,
25
27
  onChange: PropTypes.func,
26
28
  readOnly: PropTypes.bool,
29
+ showSeconds: PropTypes.bool,
27
30
  value: PropTypes.string
28
31
  };
29
32
  }
@@ -1,7 +1,10 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
3
+ // SPDX-License-Identifier: Apache-2.0
2
4
  /* eslint-disable no-nested-ternary */
3
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
- import { defaultSections, hasAnyValue, isoTimeToSections, normalizeToIsoTime, pad, sectionKey, sectionMax, sectionMin, sectionsToIsoTime, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
5
+ import { useCallback, useMemo, useRef } from 'react';
6
+ import { useSectionedField } from '../../utils/useSectionedField';
7
+ import { defaultSections, hasAnyValue, isoTimeToSections, normalizeToIsoTime, pad, sectionKey, sectionMax, sectionMin, sectionsToIsoTime, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND, defaultHourForFormat } from './utils';
5
8
  var separatorBeforeSection = function separatorBeforeSection(section) {
6
9
  return section === SECTION_PERIOD ? ' ' : ':';
7
10
  };
@@ -80,32 +83,25 @@ export var useSectionedTimeField = function useSectionedTimeField(_ref2) {
80
83
  previousValue: undefined,
81
84
  firstDigit: undefined
82
85
  });
83
- var preserveIncompleteSectionsRef = useRef(false);
84
- // Track pending single digit for display without committing
85
- var _useState = useState({}),
86
- pendingDigits = _useState[0],
87
- setPendingDigits = _useState[1];
88
- var parsedValue = useMemo(function () {
89
- return isoTimeToSections(normalizeToIsoTime(value), format);
90
- }, [format, value]);
91
- var _useState2 = useState(parsedValue || defaultSections(format)),
92
- sections = _useState2[0],
93
- setSections = _useState2[1];
94
- var _useState3 = useState(sectionOrder[0] || SECTION_HOUR),
95
- activeSection = _useState3[0],
96
- setActiveSection = _useState3[1];
97
- useEffect(function () {
98
- if (!sectionOrder.includes(activeSection)) {
99
- setActiveSection(sectionOrder[0] || SECTION_HOUR);
100
- }
101
- }, [activeSection, sectionOrder]);
102
- useEffect(function () {
103
- if (!parsedValue && preserveIncompleteSectionsRef.current) {
104
- preserveIncompleteSectionsRef.current = false;
105
- return;
106
- }
107
- setSections(parsedValue || defaultSections(format));
108
- }, [parsedValue, format]);
86
+ var parseValue = useCallback(function (nextValue) {
87
+ return isoTimeToSections(normalizeToIsoTime(nextValue), format);
88
+ }, [format]);
89
+ var getDefaultValue = useCallback(function () {
90
+ return defaultSections(format);
91
+ }, [format]);
92
+ var _useSectionedField = useSectionedField({
93
+ value: value,
94
+ parseValue: parseValue,
95
+ defaultValue: getDefaultValue,
96
+ sectionOrder: sectionOrder
97
+ }),
98
+ activeSection = _useSectionedField.activeSection,
99
+ pendingDigits = _useSectionedField.pendingDigits,
100
+ preserveIncompleteSectionsRef = _useSectionedField.preserveIncompleteSectionsRef,
101
+ sections = _useSectionedField.sections,
102
+ setActiveSection = _useSectionedField.setActiveSection,
103
+ setPendingDigits = _useSectionedField.setPendingDigits,
104
+ setSections = _useSectionedField.setSections;
109
105
  var displayValue = useMemo(function () {
110
106
  if (!hasAnyValue(sections)) return '';
111
107
 
@@ -121,7 +117,7 @@ export var useSectionedTimeField = function useSectionedTimeField(_ref2) {
121
117
  includeTokens: true
122
118
  });
123
119
  }, [sectionOrder, sections, pendingDigits]);
124
- var commitSections = useCallback(function (nextSections) {
120
+ var commitSections = useCallback(function (nextSections, changedSection) {
125
121
  var _nextSections$second;
126
122
  setSections(nextSections);
127
123
  var complete = sectionOrder.every(function (section) {
@@ -144,14 +140,17 @@ export var useSectionedTimeField = function useSectionedTimeField(_ref2) {
144
140
  // Mark as incomplete if: sections incomplete OR some invalid
145
141
  var hasIncompleteSections = !complete || !allValid;
146
142
  preserveIncompleteSectionsRef.current = hasIncompleteSections && hasAnyValue(nextSections);
147
- onCommit(nextSections, nextValue);
148
- }, [onCommit, sectionOrder, format]);
143
+ onCommit(nextSections, nextValue, changedSection);
144
+ }, [format, onCommit, preserveIncompleteSectionsRef, sectionOrder, setSections]);
149
145
  var setSectionValue = useCallback(function (section, rawValue) {
150
146
  var _extends2;
151
147
  var key = sectionKey(section);
152
148
  var next = _extends({}, sections, (_extends2 = {}, _extends2[key] = rawValue, _extends2));
153
- commitSections(next);
154
- }, [commitSections, sections]);
149
+ commitSections(next, section);
150
+ // Clear any pending first-digit overlay, since it's now stale
151
+ // relative to the section value we just committed.
152
+ setPendingDigits({});
153
+ }, [commitSections, sections, setPendingDigits]);
155
154
  var moveSection = useCallback(function (direction) {
156
155
  if (!sectionOrder.length) return activeSection;
157
156
  var activeIndex = Math.max(0, sectionOrder.indexOf(activeSection));
@@ -160,7 +159,7 @@ export var useSectionedTimeField = function useSectionedTimeField(_ref2) {
160
159
  var nextSection = sectionOrder[nextIndex];
161
160
  setActiveSection(nextSection);
162
161
  return nextSection;
163
- }, [activeSection, sectionOrder]);
162
+ }, [activeSection, sectionOrder, setActiveSection]);
164
163
  var incrementSection = useCallback(function (section, delta) {
165
164
  if (section === SECTION_PERIOD) {
166
165
  setSectionValue(section, sections.period === 'AM' ? 'PM' : 'AM');
@@ -197,7 +196,7 @@ export var useSectionedTimeField = function useSectionedTimeField(_ref2) {
197
196
  })) != null ? _descending$find : options[options.length - 1];
198
197
  }
199
198
  } else {
200
- var base = current === undefined ? minValue : current;
199
+ var base = current === undefined ? section === SECTION_HOUR ? defaultHourForFormat(format) : minValue : current;
201
200
  next = base + delta;
202
201
  if (next > maxValue) next = minValue;
203
202
  if (next < minValue) next = maxValue;
@@ -1,25 +1,28 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { getSectionKeyFromType, getSectionNameFromType } from '../../utils/sectionHelpers';
4
+ import { pad } from '../../utils/dates';
1
5
  export var SECTION_HOUR = 0;
2
6
  export var SECTION_MINUTE = 1;
3
7
  export var SECTION_SECOND = 2;
4
8
  export var SECTION_PERIOD = 3;
5
- export var pad = function pad(value) {
6
- return value.toString().padStart(2, '0');
7
- };
8
- var sectionMessageId = function sectionMessageId(section) {
9
- if (section === SECTION_HOUR) return 'timeInput.sectionHours';
10
- if (section === SECTION_MINUTE) return 'timeInput.sectionMinutes';
11
- if (section === SECTION_SECOND) return 'timeInput.sectionSeconds';
12
- return 'timeInput.sectionMeridiem';
9
+ export { pad };
10
+ export var sectionTypeFromSection = function sectionTypeFromSection(section) {
11
+ if (section === SECTION_HOUR) return 'hours';
12
+ if (section === SECTION_MINUTE) return 'minutes';
13
+ if (section === SECTION_SECOND) return 'seconds';
14
+ return 'meridiem';
13
15
  };
14
16
  export var getSectionName = function getSectionName(section, format, formatMessage, messages) {
15
- if (formatMessage) {
16
- return formatMessage({
17
- id: sectionMessageId(section),
18
- messages: messages
19
- });
20
- }
21
- var names = format === '12' ? ['hours', 'minutes', 'seconds', 'meridiem'] : ['hours', 'minutes', 'seconds'];
22
- return names[section];
17
+ var sectionType = sectionTypeFromSection(section);
18
+ var sectionName = getSectionNameFromType({
19
+ sectionType: sectionType,
20
+ messagePrefix: 'timeInput',
21
+ formatMessage: formatMessage,
22
+ messages: messages
23
+ });
24
+ if (format !== '12' && sectionType === 'meridiem') return undefined;
25
+ return sectionName;
23
26
  };
24
27
  export var getRanges = function getRanges(format) {
25
28
  if (format === '12') {
@@ -143,11 +146,12 @@ export var sectionMin = function sectionMin(section, format) {
143
146
  if (section === SECTION_HOUR) return format === '12' ? 1 : 0;
144
147
  return 0;
145
148
  };
149
+ export var defaultHourForFormat = function defaultHourForFormat(format) {
150
+ return format === '12' ? 12 : 0;
151
+ };
146
152
  export var sectionKey = function sectionKey(section) {
147
- if (section === SECTION_HOUR) return 'hour';
148
- if (section === SECTION_MINUTE) return 'minute';
149
- if (section === SECTION_SECOND) return 'second';
150
- return 'period';
153
+ var sectionType = sectionTypeFromSection(section);
154
+ return getSectionKeyFromType(sectionType);
151
155
  };
152
156
  export var getSectionAriaMeta = function getSectionAriaMeta(_ref) {
153
157
  var _sections$key;
@@ -164,7 +168,7 @@ export var getSectionAriaMeta = function getSectionAriaMeta(_ref) {
164
168
  var key = sectionKey(section);
165
169
  var min = sectionMin(section, format);
166
170
  var max = sectionMax(section, format);
167
- var now = (_sections$key = sections[key]) != null ? _sections$key : min;
171
+ var now = (_sections$key = sections[key]) != null ? _sections$key : section === SECTION_HOUR ? defaultHourForFormat(format) : min;
168
172
  return {
169
173
  now: now,
170
174
  min: min,
@@ -0,0 +1,11 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import styled from 'styled-components';
4
+ import { styledComponentsConfig } from '../../utils';
5
+
6
+ // Programmatic focus target for step transitions (tabIndex={-1}); no visible
7
+ // focus indication — screen readers announce via aria-live on this element.
8
+ export var StyledWizardFocusAnchor = styled.div.withConfig(styledComponentsConfig).withConfig({
9
+ displayName: "StyledWizard__StyledWizardFocusAnchor",
10
+ componentId: "sc-1o4qqu4-0"
11
+ })(["outline:none;"]);