grommet 2.55.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 (190) hide show
  1. package/COPYRIGHT.md +3 -1
  2. package/components/Button/Button.js +7 -4
  3. package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
  4. package/components/Calendar/Calendar.js +2 -1
  5. package/components/Cards/Cards.js +1 -2
  6. package/components/DateTimeInput/DateTimeInput.js +1093 -0
  7. package/components/DateTimeInput/README.md +2 -0
  8. package/components/DateTimeInput/StyledDateTimeInput.js +74 -0
  9. package/components/DateTimeInput/index.d.ts +47 -0
  10. package/components/DateTimeInput/index.js +6 -0
  11. package/components/DateTimeInput/propTypes.js +42 -0
  12. package/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  13. package/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  14. package/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  15. package/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  16. package/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  17. package/components/Form/Form.js +7 -4
  18. package/components/Form/index.d.ts +3 -0
  19. package/components/Form/stories/AggregateValidation.stories.js +6 -8
  20. package/components/FormField/FormField.js +164 -91
  21. package/components/Grommet/index.d.ts +21 -0
  22. package/components/Grommet/propTypes.js +26 -0
  23. package/components/Stepper/StepConnector.js +38 -0
  24. package/components/Stepper/Stepper.js +303 -0
  25. package/components/Stepper/StepperContext.js +43 -0
  26. package/components/Stepper/StepperDescription.js +26 -0
  27. package/components/Stepper/StepperHelperText.js +44 -0
  28. package/components/Stepper/StepperIndicator.js +74 -0
  29. package/components/Stepper/StepperLabel.js +41 -0
  30. package/components/Stepper/StepperStep.js +137 -0
  31. package/components/Stepper/StyledStepper.js +162 -0
  32. package/components/Stepper/index.d.ts +80 -0
  33. package/components/Stepper/index.js +18 -0
  34. package/components/Stepper/propTypes.js +35 -0
  35. package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
  36. package/components/Stepper/stories/ErrorStates.stories.js +45 -0
  37. package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
  38. package/components/Stepper/stories/Interactive.stories.js +60 -0
  39. package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
  40. package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
  41. package/components/Stepper/stories/ReadOnly.stories.js +43 -0
  42. package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
  43. package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
  44. package/components/Tab/Tab.js +19 -6
  45. package/components/Tabs/Tabs.js +156 -22
  46. package/components/TimeInput/README.md +2 -0
  47. package/components/TimeInput/StyledTimeInput.js +73 -0
  48. package/components/TimeInput/TimeInput.js +692 -0
  49. package/components/TimeInput/TimeInputPopup.js +489 -0
  50. package/components/TimeInput/index.d.ts +44 -0
  51. package/components/TimeInput/index.js +6 -0
  52. package/components/TimeInput/propTypes.js +39 -0
  53. package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  54. package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  55. package/components/TimeInput/stories/Form.stories.tsx +38 -0
  56. package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  57. package/components/TimeInput/stories/Simple.stories.tsx +19 -0
  58. package/components/TimeInput/stories/Step.stories.tsx +14 -0
  59. package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  60. package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  61. package/components/TimeInput/useSectionedTimeField.js +358 -0
  62. package/components/TimeInput/utils.js +192 -0
  63. package/components/Wizard/StyledWizard.js +16 -0
  64. package/components/Wizard/Wizard.js +770 -0
  65. package/components/Wizard/WizardContent.js +90 -0
  66. package/components/Wizard/WizardContext.js +35 -0
  67. package/components/Wizard/WizardFooter.js +123 -0
  68. package/components/Wizard/WizardHeader.js +63 -0
  69. package/components/Wizard/WizardProgress.js +84 -0
  70. package/components/Wizard/WizardStepHeader.js +55 -0
  71. package/components/Wizard/index.d.ts +171 -0
  72. package/components/Wizard/index.js +19 -0
  73. package/components/Wizard/propTypes.js +56 -0
  74. package/components/Wizard/stories/BasicLinear.stories.js +71 -0
  75. package/components/Wizard/stories/Branching.stories.js +96 -0
  76. package/components/Wizard/stories/Composable.stories.js +75 -0
  77. package/components/Wizard/stories/Controlled.stories.js +136 -0
  78. package/components/Wizard/stories/LongContent.stories.js +118 -0
  79. package/components/Wizard/stories/Modal.stories.js +143 -0
  80. package/components/Wizard/stories/NestedSubSteps.stories.js +79 -0
  81. package/components/Wizard/stories/Validation.stories.js +123 -0
  82. package/components/index.d.ts +6 -0
  83. package/components/index.js +24 -0
  84. package/es6/components/Button/Button.js +7 -4
  85. package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
  86. package/es6/components/Calendar/Calendar.js +2 -0
  87. package/es6/components/Cards/Cards.js +1 -2
  88. package/es6/components/DateTimeInput/DateTimeInput.js +1090 -0
  89. package/es6/components/DateTimeInput/README.md +2 -0
  90. package/es6/components/DateTimeInput/StyledDateTimeInput.js +68 -0
  91. package/es6/components/DateTimeInput/index.d.ts +47 -0
  92. package/es6/components/DateTimeInput/index.js +3 -0
  93. package/es6/components/DateTimeInput/propTypes.js +36 -0
  94. package/es6/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  95. package/es6/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  96. package/es6/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  97. package/es6/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  98. package/es6/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  99. package/es6/components/Form/Form.js +7 -3
  100. package/es6/components/Form/index.d.ts +3 -0
  101. package/es6/components/Form/stories/AggregateValidation.stories.js +6 -9
  102. package/es6/components/FormField/FormField.js +165 -91
  103. package/es6/components/Grommet/index.d.ts +21 -0
  104. package/es6/components/Grommet/propTypes.js +26 -0
  105. package/es6/components/Stepper/StepConnector.js +33 -0
  106. package/es6/components/Stepper/Stepper.js +301 -0
  107. package/es6/components/Stepper/StepperContext.js +39 -0
  108. package/es6/components/Stepper/StepperDescription.js +21 -0
  109. package/es6/components/Stepper/StepperHelperText.js +39 -0
  110. package/es6/components/Stepper/StepperIndicator.js +69 -0
  111. package/es6/components/Stepper/StepperLabel.js +36 -0
  112. package/es6/components/Stepper/StepperStep.js +133 -0
  113. package/es6/components/Stepper/StyledStepper.js +156 -0
  114. package/es6/components/Stepper/index.d.ts +80 -0
  115. package/es6/components/Stepper/index.js +6 -0
  116. package/es6/components/Stepper/propTypes.js +30 -0
  117. package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
  118. package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
  119. package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
  120. package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
  121. package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
  122. package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
  123. package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
  124. package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
  125. package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
  126. package/es6/components/Tab/Tab.js +19 -6
  127. package/es6/components/Tabs/Tabs.js +157 -23
  128. package/es6/components/TimeInput/README.md +2 -0
  129. package/es6/components/TimeInput/StyledTimeInput.js +68 -0
  130. package/es6/components/TimeInput/TimeInput.js +689 -0
  131. package/es6/components/TimeInput/TimeInputPopup.js +485 -0
  132. package/es6/components/TimeInput/index.d.ts +44 -0
  133. package/es6/components/TimeInput/index.js +1 -0
  134. package/es6/components/TimeInput/propTypes.js +33 -0
  135. package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  136. package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  137. package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
  138. package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  139. package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
  140. package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
  141. package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  142. package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  143. package/es6/components/TimeInput/useSectionedTimeField.js +355 -0
  144. package/es6/components/TimeInput/utils.js +187 -0
  145. package/es6/components/Wizard/StyledWizard.js +11 -0
  146. package/es6/components/Wizard/Wizard.js +768 -0
  147. package/es6/components/Wizard/WizardContent.js +87 -0
  148. package/es6/components/Wizard/WizardContext.js +31 -0
  149. package/es6/components/Wizard/WizardFooter.js +120 -0
  150. package/es6/components/Wizard/WizardHeader.js +60 -0
  151. package/es6/components/Wizard/WizardProgress.js +80 -0
  152. package/es6/components/Wizard/WizardStepHeader.js +51 -0
  153. package/es6/components/Wizard/index.d.ts +171 -0
  154. package/es6/components/Wizard/index.js +7 -0
  155. package/es6/components/Wizard/propTypes.js +51 -0
  156. package/es6/components/Wizard/stories/BasicLinear.stories.js +67 -0
  157. package/es6/components/Wizard/stories/Branching.stories.js +93 -0
  158. package/es6/components/Wizard/stories/Composable.stories.js +72 -0
  159. package/es6/components/Wizard/stories/Controlled.stories.js +133 -0
  160. package/es6/components/Wizard/stories/LongContent.stories.js +115 -0
  161. package/es6/components/Wizard/stories/Modal.stories.js +141 -0
  162. package/es6/components/Wizard/stories/NestedSubSteps.stories.js +76 -0
  163. package/es6/components/Wizard/stories/Validation.stories.js +118 -0
  164. package/es6/components/index.d.ts +6 -0
  165. package/es6/components/index.js +6 -0
  166. package/es6/index.d.ts +6 -0
  167. package/es6/languages/default.json +48 -0
  168. package/es6/themes/base.d.ts +223 -0
  169. package/es6/themes/base.js +366 -0
  170. package/es6/utils/DOM.js +11 -2
  171. package/es6/utils/dates.js +10 -0
  172. package/es6/utils/sectionHelpers.js +57 -0
  173. package/es6/utils/useSectionedField.js +45 -0
  174. package/grommet.min.js +2 -1
  175. package/grommet.min.js.LICENSE.txt +1 -0
  176. package/grommet.min.js.map +1 -1
  177. package/index.d.ts +6 -0
  178. package/languages/default.json +48 -0
  179. package/package.json +57 -52
  180. package/themes/base.d.ts +223 -0
  181. package/themes/base.js +366 -1
  182. package/tools/license-header.js +2 -0
  183. package/utils/DOM.js +11 -2
  184. package/utils/dates.js +11 -1
  185. package/utils/sectionHelpers.js +61 -0
  186. package/utils/useSectionedField.js +50 -0
  187. package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  188. package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
  189. package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  190. package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
@@ -0,0 +1,485 @@
1
+ var _excluded = ["activeSection", "align", "format", "formatMessage", "hoursOptions", "id", "incrementSection", "messages", "minuteOptions", "onClose", "onFocusLeave", "secondOptions", "sectionOrder", "sections", "setActiveSection", "setSectionValue", "target", "dropProps", "label", "inline", "onKeyDown"];
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
6
+ /* eslint-disable max-len */
7
+ import React, { useCallback, useEffect, useRef } from 'react';
8
+ import styled from 'styled-components';
9
+ import { useLayoutEffect } from '../../utils/use-isomorphic-layout-effect';
10
+ import { focusStyle, normalizeColor } from '../../utils';
11
+ import { useThemeValue } from '../../utils/useThemeValue';
12
+ import { Box } from '../Box';
13
+ import { Drop } from '../Drop';
14
+ import { Text } from '../Text';
15
+ import { defaultHourForFormat, pad, getSectionName, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
16
+ var PopupColumnBox = styled(Box).withConfig({
17
+ displayName: "TimeInputPopup__PopupColumnBox",
18
+ componentId: "sc-r2j8uh-0"
19
+ })(["scrollbar-gutter:stable;scrollbar-width:thin;"]);
20
+ var PopupOption = styled.div.withConfig({
21
+ displayName: "TimeInputPopup__PopupOption",
22
+ componentId: "sc-r2j8uh-1"
23
+ })(["box-sizing:border-box;cursor:pointer;display:flex;padding:", ";border-radius:", ";background:", ";&:hover{background:", ";}&:focus-visible{", "}"], function (props) {
24
+ return props.theme.global.edgeSize.xxsmall + " " + props.theme.global.edgeSize.xsmall;
25
+ }, function (props) {
26
+ var _props$theme$global$c;
27
+ return (_props$theme$global$c = props.theme.global.control) == null || (_props$theme$global$c = _props$theme$global$c.border) == null ? void 0 : _props$theme$global$c.radius;
28
+ }, function (props) {
29
+ var _props$theme$timeInpu3;
30
+ if (props.$selected) {
31
+ var _props$theme$timeInpu;
32
+ return normalizeColor((_props$theme$timeInpu = props.theme.timeInput) == null || (_props$theme$timeInpu = _props$theme$timeInpu.drop) == null || (_props$theme$timeInpu = _props$theme$timeInpu.option) == null || (_props$theme$timeInpu = _props$theme$timeInpu.selected) == null ? void 0 : _props$theme$timeInpu.background, props.theme);
33
+ }
34
+ if (props.$active) {
35
+ var _props$theme$timeInpu2;
36
+ return normalizeColor((_props$theme$timeInpu2 = props.theme.timeInput) == null || (_props$theme$timeInpu2 = _props$theme$timeInpu2.drop) == null || (_props$theme$timeInpu2 = _props$theme$timeInpu2.option) == null || (_props$theme$timeInpu2 = _props$theme$timeInpu2.hover) == null ? void 0 : _props$theme$timeInpu2.background, props.theme);
37
+ }
38
+ return normalizeColor((_props$theme$timeInpu3 = props.theme.timeInput) == null || (_props$theme$timeInpu3 = _props$theme$timeInpu3.drop) == null || (_props$theme$timeInpu3 = _props$theme$timeInpu3.option) == null ? void 0 : _props$theme$timeInpu3.background, props.theme);
39
+ }, function (props) {
40
+ var _props$theme$timeInpu6;
41
+ if (props.$selected) {
42
+ var _props$theme$timeInpu4, _props$theme$timeInpu5;
43
+ return normalizeColor(((_props$theme$timeInpu4 = props.theme.timeInput) == null || (_props$theme$timeInpu4 = _props$theme$timeInpu4.drop) == null || (_props$theme$timeInpu4 = _props$theme$timeInpu4.option) == null || (_props$theme$timeInpu4 = _props$theme$timeInpu4.selected) == null || (_props$theme$timeInpu4 = _props$theme$timeInpu4.hover) == null ? void 0 : _props$theme$timeInpu4.background) || ((_props$theme$timeInpu5 = props.theme.timeInput) == null || (_props$theme$timeInpu5 = _props$theme$timeInpu5.drop) == null || (_props$theme$timeInpu5 = _props$theme$timeInpu5.option) == null || (_props$theme$timeInpu5 = _props$theme$timeInpu5.selected) == null ? void 0 : _props$theme$timeInpu5.background), props.theme);
44
+ }
45
+ return normalizeColor((_props$theme$timeInpu6 = props.theme.timeInput) == null || (_props$theme$timeInpu6 = _props$theme$timeInpu6.drop) == null || (_props$theme$timeInpu6 = _props$theme$timeInpu6.option) == null || (_props$theme$timeInpu6 = _props$theme$timeInpu6.hover) == null ? void 0 : _props$theme$timeInpu6.background, props.theme);
46
+ }, focusStyle({
47
+ inset: true
48
+ }));
49
+ var optionKey = function optionKey(label, option) {
50
+ return label.toLowerCase() + "-" + option;
51
+ };
52
+ var getDefaultPopupOption = function getDefaultPopupOption(_ref) {
53
+ var section = _ref.section,
54
+ format = _ref.format,
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;
82
+ return /*#__PURE__*/React.createElement(PopupColumnBox, {
83
+ role: "listbox",
84
+ "aria-label": label,
85
+ gap: "xxsmall",
86
+ height: {
87
+ max: maxHeight
88
+ },
89
+ overflow: "auto",
90
+ flex: {
91
+ grow: 0,
92
+ shrink: 0
93
+ }
94
+ }, options.map(function (option) {
95
+ var _theme$timeInput2;
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.
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;
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';
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
+ }
119
+ return /*#__PURE__*/React.createElement(PopupOption, {
120
+ key: key,
121
+ "data-option-key": key,
122
+ role: "option",
123
+ "aria-selected": selected,
124
+ tabIndex: optionTabIndex,
125
+ "aria-label": (section === SECTION_PERIOD ? option : pad(option)) + " " + getSectionName(section, format, formatMessage, messages),
126
+ $active: isActive,
127
+ $selected: selected,
128
+ onMouseDown: function onMouseDown(event) {
129
+ if (event.button !== 0) return;
130
+ // Commit on pointer press so momentum scroll does not swallow
131
+ // the first click commit on some trackpad/mouse flows.
132
+ event.preventDefault();
133
+ onPointerCommitOption(section, option);
134
+ },
135
+ onClick: function onClick() {
136
+ return onClickCommitOption(section, option);
137
+ },
138
+ onFocus: function onFocus() {
139
+ return onSetSection(section);
140
+ }
141
+ }, /*#__PURE__*/React.createElement(Text, {
142
+ size: theme.global.input.font.size || 'small',
143
+ color: optionColor
144
+ }, section === SECTION_PERIOD ? option : pad(option)));
145
+ }));
146
+ };
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);
172
+ var _useThemeValue = useThemeValue(),
173
+ theme = _useThemeValue.theme;
174
+ var dialogRef = useRef();
175
+ var pointerDownInsideRef = useRef(false);
176
+ var pointerSelectionCommittedRef = useRef(false);
177
+ var suppressNextAutoScrollRef = useRef(false);
178
+ var wheelInteractionTimeoutRef = useRef();
179
+ var pointerReleaseTimeoutRef = useRef();
180
+ var clearPointerReleaseTimeout = useCallback(function () {
181
+ if (pointerReleaseTimeoutRef.current) {
182
+ window.clearTimeout(pointerReleaseTimeoutRef.current);
183
+ pointerReleaseTimeoutRef.current = undefined;
184
+ }
185
+ }, []);
186
+ var clearInteractionInProgress = useCallback(function () {
187
+ clearPointerReleaseTimeout();
188
+ pointerDownInsideRef.current = false;
189
+ if (wheelInteractionTimeoutRef.current) {
190
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
191
+ wheelInteractionTimeoutRef.current = undefined;
192
+ }
193
+ }, [clearPointerReleaseTimeout]);
194
+ var releaseInteractionAfterClick = useCallback(function () {
195
+ clearPointerReleaseTimeout();
196
+ // Keep lock through click handler + resulting render/effect cycle.
197
+ pointerReleaseTimeoutRef.current = window.setTimeout(function () {
198
+ pointerDownInsideRef.current = false;
199
+ pointerReleaseTimeoutRef.current = undefined;
200
+ }, 0);
201
+ }, [clearPointerReleaseTimeout]);
202
+ var markInteractionInProgress = useCallback(function () {
203
+ pointerDownInsideRef.current = true;
204
+ }, []);
205
+ var suppressNextAutoScroll = useCallback(function () {
206
+ suppressNextAutoScrollRef.current = true;
207
+ }, []);
208
+ var commitOptionSelection = useCallback(function (section, option) {
209
+ setActiveSection(section);
210
+ setSectionValue(section, option);
211
+ }, [setActiveSection, setSectionValue]);
212
+ var commitPointerOptionSelection = useCallback(function (section, option) {
213
+ pointerSelectionCommittedRef.current = true;
214
+ suppressNextAutoScroll();
215
+ commitOptionSelection(section, option);
216
+ }, [commitOptionSelection, suppressNextAutoScroll]);
217
+ var commitClickOptionSelection = useCallback(function (section, option) {
218
+ if (pointerSelectionCommittedRef.current) {
219
+ pointerSelectionCommittedRef.current = false;
220
+ return;
221
+ }
222
+ commitOptionSelection(section, option);
223
+ }, [commitOptionSelection]);
224
+ var onPopupWheelCapture = useCallback(function () {
225
+ pointerDownInsideRef.current = true;
226
+ if (wheelInteractionTimeoutRef.current) {
227
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
228
+ }
229
+
230
+ // Trackpad and wheel events can continue after the pointer sequence.
231
+ // Keep interaction lock briefly so refocus does not steal first selection.
232
+ wheelInteractionTimeoutRef.current = window.setTimeout(function () {
233
+ pointerDownInsideRef.current = false;
234
+ wheelInteractionTimeoutRef.current = undefined;
235
+ }, 120);
236
+ }, []);
237
+ useEffect(function () {
238
+ return function () {
239
+ clearPointerReleaseTimeout();
240
+ if (wheelInteractionTimeoutRef.current) {
241
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
242
+ }
243
+ };
244
+ }, [clearPointerReleaseTimeout]);
245
+ var popupSections = [{
246
+ section: SECTION_HOUR,
247
+ label: 'hour',
248
+ options: hoursOptions
249
+ }, {
250
+ section: SECTION_MINUTE,
251
+ label: 'minute',
252
+ options: minuteOptions
253
+ }, {
254
+ section: SECTION_SECOND,
255
+ label: 'second',
256
+ options: secondOptions
257
+ }, {
258
+ section: SECTION_PERIOD,
259
+ label: 'period',
260
+ options: ['AM', 'PM']
261
+ }];
262
+ var visiblePopupSections = popupSections.filter(function (_ref4) {
263
+ var section = _ref4.section;
264
+ return sectionOrder.includes(section);
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]);
285
+ var scrollSelectedOptionsIntoView = useCallback(function () {
286
+ var _sectionLabel, _sectionValue;
287
+ if (pointerDownInsideRef.current) return;
288
+ if (suppressNextAutoScrollRef.current) {
289
+ suppressNextAutoScrollRef.current = false;
290
+ return;
291
+ }
292
+ var popupNode = dialogRef.current;
293
+ if (!popupNode) return;
294
+ var sectionLabel = (_sectionLabel = {}, _sectionLabel[SECTION_HOUR] = 'hour', _sectionLabel[SECTION_MINUTE] = 'minute', _sectionLabel[SECTION_SECOND] = 'second', _sectionLabel[SECTION_PERIOD] = 'period', _sectionLabel);
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;
310
+ var labelValue = sectionLabel[section];
311
+ if (!labelValue) return;
312
+ var listboxNode = popupNode.querySelector("[role=\"listbox\"][aria-label=\"" + labelValue + "\"]");
313
+ if (!listboxNode) return;
314
+ var selectedNode = popupNode.querySelector("[data-option-key=\"" + optionKey(labelValue, sectionValue[section]) + "\"]") || listboxNode.querySelector('[role="option"][aria-selected="true"]');
315
+ if (selectedNode) {
316
+ if (selectedNode.scrollIntoView) {
317
+ selectedNode.scrollIntoView({
318
+ block: 'nearest'
319
+ });
320
+ }
321
+
322
+ // Center selected value in each listbox so all sections (hh/mm/ss)
323
+ // are consistently aligned on open, not just the focused section.
324
+ var selectedOffsetTop = selectedNode.offsetTop;
325
+ var selectedHeight = selectedNode.offsetHeight;
326
+ var targetScrollTop = selectedOffsetTop - (listboxNode.clientHeight / 2 - selectedHeight / 2);
327
+ listboxNode.scrollTop = Math.max(0, targetScrollTop);
328
+ }
329
+ });
330
+ }, [format, hoursOptions, minuteOptions, secondOptions, sections, visiblePopupSections]);
331
+ var focusCurrentPopupOption = useCallback(function () {
332
+ var _labelMap, _keyMap, _dialogRef$current, _dialogRef$current2;
333
+ var labelMap = (_labelMap = {}, _labelMap[SECTION_HOUR] = 'hour', _labelMap[SECTION_MINUTE] = 'minute', _labelMap[SECTION_SECOND] = 'second', _labelMap[SECTION_PERIOD] = 'period', _labelMap);
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);
347
+ var selector = "[data-option-key=\"" + keyMap[activeSection] + "\"]";
348
+ var node = (_dialogRef$current = dialogRef.current) == null ? void 0 : _dialogRef$current.querySelector(selector);
349
+ if (node) {
350
+ node.focus();
351
+ return true;
352
+ }
353
+
354
+ // Fallback: if current section value has no matching option
355
+ // (e.g., minute=31 with minuteStep=15), focus first option in section.
356
+ var sectionLabel = labelMap[activeSection];
357
+ if (!sectionLabel) return false;
358
+ var fallbackNode = (_dialogRef$current2 = dialogRef.current) == null ? void 0 : _dialogRef$current2.querySelector("[role=\"listbox\"][aria-label=\"" + sectionLabel + "\"] [role=\"option\"]");
359
+ if (fallbackNode) {
360
+ fallbackNode.focus();
361
+ return true;
362
+ }
363
+ return false;
364
+ }, [activeSection, format, hoursOptions, minuteOptions, secondOptions, sections]);
365
+ useLayoutEffect(function () {
366
+ // Avoid stealing pointer interactions: while the user is actively
367
+ // clicking inside the popup, let that click settle before refocusing.
368
+ if (pointerDownInsideRef.current) return undefined;
369
+ var scrollRaf = requestAnimationFrame(function () {
370
+ scrollSelectedOptionsIntoView();
371
+ });
372
+ var rafB;
373
+ var rafA = requestAnimationFrame(function () {
374
+ scrollSelectedOptionsIntoView();
375
+ var focused = focusCurrentPopupOption();
376
+ // Retry one more frame to handle occasional mount timing races.
377
+ if (!focused) {
378
+ rafB = requestAnimationFrame(function () {
379
+ scrollSelectedOptionsIntoView();
380
+ focusCurrentPopupOption();
381
+ });
382
+ }
383
+ });
384
+ return function () {
385
+ window.cancelAnimationFrame(scrollRaf);
386
+ window.cancelAnimationFrame(rafA);
387
+ if (rafB) window.cancelAnimationFrame(rafB);
388
+ };
389
+ }, [focusCurrentPopupOption, scrollSelectedOptionsIntoView]);
390
+ var popupContent = /*#__PURE__*/React.createElement(Box, _extends({
391
+ ref: dialogRef,
392
+ role: inline ? undefined : 'dialog',
393
+ "aria-label": inline ? undefined : label,
394
+ direction: "row",
395
+ width: {
396
+ width: (_theme$timeInput3 = theme.timeInput) == null || (_theme$timeInput3 = _theme$timeInput3.drop) == null ? void 0 : _theme$timeInput3.width,
397
+ max: '100%'
398
+ },
399
+ minHeight: (_theme$timeInput4 = theme.timeInput) == null || (_theme$timeInput4 = _theme$timeInput4.drop) == null ? void 0 : _theme$timeInput4.minHeight,
400
+ gap: "xsmall",
401
+ pad: inline ? 'none' : ((_theme$timeInput5 = theme.timeInput) == null || (_theme$timeInput5 = _theme$timeInput5.drop) == null ? void 0 : _theme$timeInput5.pad) || 'small',
402
+ onPointerDownCapture: markInteractionInProgress,
403
+ onPointerUpCapture: releaseInteractionAfterClick,
404
+ onPointerCancelCapture: clearInteractionInProgress,
405
+ onWheelCapture: onPopupWheelCapture,
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;
411
+ if (event.key === 'Escape') {
412
+ if (onClose) {
413
+ event.preventDefault();
414
+ onClose();
415
+ }
416
+ } else if (event.key === 'Enter') {
417
+ var _event$target, _document$activeEleme;
418
+ event.preventDefault();
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"]'));
420
+ focusedOption == null || focusedOption.click == null || focusedOption.click();
421
+ } else if (event.key === ' ' || event.key === 'Spacebar') {
422
+ var _event$target2, _document$activeEleme2;
423
+ event.preventDefault();
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
+ }
431
+ } else if (event.key === 'ArrowLeft') {
432
+ event.preventDefault();
433
+ setActiveSection(getAdjacentSection(eventSection, -1));
434
+ } else if (event.key === 'ArrowRight') {
435
+ event.preventDefault();
436
+ setActiveSection(getAdjacentSection(eventSection, 1));
437
+ } else if (event.key === 'ArrowUp') {
438
+ event.preventDefault();
439
+ incrementSection(eventSection, -1);
440
+ } else if (event.key === 'ArrowDown') {
441
+ event.preventDefault();
442
+ incrementSection(eventSection, 1);
443
+ }
444
+ onKeyDownProp == null || onKeyDownProp(event);
445
+ },
446
+ onBlurCapture: function onBlurCapture(event) {
447
+ var nextFocusTarget = event.relatedTarget;
448
+ // Clicking the scrollbar blurs the focused option with
449
+ // relatedTarget = null. Keep the popup open for that interaction.
450
+ if (!nextFocusTarget) return;
451
+ if (!event.currentTarget.contains(nextFocusTarget)) {
452
+ onFocusLeave == null || onFocusLeave();
453
+ }
454
+ }
455
+ }, rest), visiblePopupSections.map(function (_ref7) {
456
+ var section = _ref7.section,
457
+ sectionLabel = _ref7.label,
458
+ options = _ref7.options;
459
+ return /*#__PURE__*/React.createElement(PopupColumn, {
460
+ key: sectionLabel,
461
+ activeSection: activeSection,
462
+ format: format,
463
+ formatMessage: formatMessage,
464
+ inline: inline,
465
+ label: sectionLabel,
466
+ messages: messages,
467
+ onClickCommitOption: commitClickOptionSelection,
468
+ onPointerCommitOption: commitPointerOptionSelection,
469
+ onSetSection: setActiveSection,
470
+ options: options,
471
+ section: section,
472
+ sections: sections,
473
+ theme: theme
474
+ });
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);
484
+ };
485
+ export { TimeInputPopup };
@@ -0,0 +1,44 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import * as React from 'react';
4
+
5
+ export interface TimeInputProps {
6
+ defaultValue?: string;
7
+ disabled?: boolean;
8
+ format?: '12' | '24';
9
+ id?: string;
10
+ messages?: {
11
+ activePeriodValue?: string;
12
+ activeSection?: string;
13
+ activeSectionValue?: string;
14
+ chooseTime?: string;
15
+ currentValue?: string;
16
+ inputLabel?: string;
17
+ invalidTime?: string;
18
+ openDrop?: string;
19
+ sectionHours?: string;
20
+ sectionMeridiem?: string;
21
+ sectionMinutes?: string;
22
+ sectionSeconds?: string;
23
+ };
24
+ minuteStep?: number;
25
+ name?: string;
26
+ onChange?: (event: { value?: string }) => void;
27
+ readOnly?: boolean;
28
+ showSeconds?: boolean;
29
+ value?: string;
30
+ }
31
+
32
+ export interface TimeInputExtendedProps
33
+ extends TimeInputProps,
34
+ Omit<
35
+ React.DetailedHTMLProps<
36
+ React.InputHTMLAttributes<HTMLInputElement>,
37
+ HTMLInputElement
38
+ >,
39
+ 'defaultValue' | 'onChange' | 'onError' | 'size' | 'value'
40
+ > {}
41
+
42
+ declare const TimeInput: React.FC<TimeInputExtendedProps>;
43
+
44
+ export { TimeInput };
@@ -0,0 +1 @@
1
+ export { TimeInput } from './TimeInput';
@@ -0,0 +1,33 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import PropTypes from 'prop-types';
4
+ var PropType = {};
5
+ if (process.env.NODE_ENV !== 'production') {
6
+ PropType = {
7
+ defaultValue: PropTypes.string,
8
+ disabled: PropTypes.bool,
9
+ format: PropTypes.oneOf(['12', '24']),
10
+ id: PropTypes.string,
11
+ messages: PropTypes.shape({
12
+ activePeriodValue: PropTypes.string,
13
+ activeSection: PropTypes.string,
14
+ activeSectionValue: PropTypes.string,
15
+ chooseTime: PropTypes.string,
16
+ currentValue: PropTypes.string,
17
+ inputLabel: PropTypes.string,
18
+ invalidTime: PropTypes.string,
19
+ openDrop: PropTypes.string,
20
+ sectionHours: PropTypes.string,
21
+ sectionMeridiem: PropTypes.string,
22
+ sectionMinutes: PropTypes.string,
23
+ sectionSeconds: PropTypes.string
24
+ }),
25
+ minuteStep: PropTypes.number,
26
+ name: PropTypes.string,
27
+ onChange: PropTypes.func,
28
+ readOnly: PropTypes.bool,
29
+ showSeconds: PropTypes.bool,
30
+ value: PropTypes.string
31
+ };
32
+ }
33
+ export var TimeInputPropTypes = PropType;
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Button, Text, TimeInput } from 'grommet';
4
+
5
+ export const Controlled = () => {
6
+ const [value, setValue] = React.useState('12:34:56');
7
+
8
+ const onChange = ({ value: next }: { value?: string }) => {
9
+ console.log('onChange iso time:', next);
10
+ setValue(next || '');
11
+ };
12
+
13
+ return (
14
+ <Box pad="large" width="medium" gap="small">
15
+ <Text size="small">
16
+ Controlled input (value is driven by React state).
17
+ </Text>
18
+ <TimeInput format="12" value={value} onChange={onChange} />
19
+ <Box direction="row" gap="small">
20
+ <Button label="Set 01:02:03 PM" onClick={() => setValue('13:02:03')} />
21
+ <Button label="Clear" onClick={() => setValue('')} />
22
+ </Box>
23
+ </Box>
24
+ );
25
+ };
26
+
27
+ export default {
28
+ title: 'Input/TimeInput/Controlled',
29
+ };
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ import { Box, TimeInput } from 'grommet';
4
+
5
+ export const Disabled = () => (
6
+ <Box pad="large" width="medium" gap="small">
7
+ <TimeInput format="12" defaultValue="09:45:10" disabled />
8
+ </Box>
9
+ );
10
+
11
+ export default {
12
+ title: 'Input/TimeInput/Disabled',
13
+ };
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Button, Form, FormField, TimeInput } from 'grommet';
4
+
5
+ export const TimeForm = () => {
6
+ const [value, setValue] = React.useState({ value: '' });
7
+ const onChange = (nextValue: { value: string }) => {
8
+ setValue(nextValue);
9
+ };
10
+
11
+ return (
12
+ <Box align="center" pad="large">
13
+ <Form
14
+ value={value}
15
+ onChange={onChange}
16
+ onSubmit={() => {
17
+ setValue({ value: '' });
18
+ }}
19
+ >
20
+ <FormField
21
+ htmlFor="appointment-time"
22
+ name="value"
23
+ label="Choose an appointment time"
24
+ required
25
+ >
26
+ <TimeInput id="appointment-time" name="value" format="24" />
27
+ </FormField>
28
+ <Button type="submit" label="submit" />
29
+ </Form>
30
+ </Box>
31
+ );
32
+ };
33
+
34
+ TimeForm.storyName = 'Form';
35
+
36
+ export default {
37
+ title: 'Input/TimeInput',
38
+ };
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ import { Box, TimeInput } from 'grommet';
4
+
5
+ export const ReadOnly = () => (
6
+ <Box pad="large" width="medium" gap="small">
7
+ <TimeInput format="12" defaultValue="09:45:10" readOnly />
8
+ </Box>
9
+ );
10
+
11
+ export default {
12
+ title: 'Input/TimeInput/ReadOnly',
13
+ };