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,489 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.TimeInputPopup = void 0;
5
+ var _react = _interopRequireWildcard(require("react"));
6
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
7
+ var _useIsomorphicLayoutEffect = require("../../utils/use-isomorphic-layout-effect");
8
+ var _utils = require("../../utils");
9
+ var _useThemeValue2 = require("../../utils/useThemeValue");
10
+ var _Box = require("../Box");
11
+ var _Drop = require("../Drop");
12
+ var _Text = require("../Text");
13
+ var _utils2 = require("./utils");
14
+ var _excluded = ["activeSection", "align", "format", "formatMessage", "hoursOptions", "id", "incrementSection", "messages", "minuteOptions", "onClose", "onFocusLeave", "secondOptions", "sectionOrder", "sections", "setActiveSection", "setSectionValue", "target", "dropProps", "label", "inline", "onKeyDown"]; // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
15
+ // SPDX-License-Identifier: Apache-2.0
16
+ /* eslint-disable max-len */
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
18
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
19
+ 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); }
20
+ 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; }
21
+ var PopupColumnBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
22
+ displayName: "TimeInputPopup__PopupColumnBox",
23
+ componentId: "sc-r2j8uh-0"
24
+ })(["scrollbar-gutter:stable;scrollbar-width:thin;"]);
25
+ var PopupOption = _styledComponents["default"].div.withConfig({
26
+ displayName: "TimeInputPopup__PopupOption",
27
+ componentId: "sc-r2j8uh-1"
28
+ })(["box-sizing:border-box;cursor:pointer;display:flex;padding:", ";border-radius:", ";background:", ";&:hover{background:", ";}&:focus-visible{", "}"], function (props) {
29
+ return props.theme.global.edgeSize.xxsmall + " " + props.theme.global.edgeSize.xsmall;
30
+ }, function (props) {
31
+ var _props$theme$global$c;
32
+ 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;
33
+ }, function (props) {
34
+ var _props$theme$timeInpu3;
35
+ if (props.$selected) {
36
+ var _props$theme$timeInpu;
37
+ return (0, _utils.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);
38
+ }
39
+ if (props.$active) {
40
+ var _props$theme$timeInpu2;
41
+ return (0, _utils.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);
42
+ }
43
+ return (0, _utils.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);
44
+ }, function (props) {
45
+ var _props$theme$timeInpu6;
46
+ if (props.$selected) {
47
+ var _props$theme$timeInpu4, _props$theme$timeInpu5;
48
+ return (0, _utils.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);
49
+ }
50
+ return (0, _utils.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);
51
+ }, (0, _utils.focusStyle)({
52
+ inset: true
53
+ }));
54
+ var optionKey = function optionKey(label, option) {
55
+ return label.toLowerCase() + "-" + option;
56
+ };
57
+ var getDefaultPopupOption = function getDefaultPopupOption(_ref) {
58
+ var section = _ref.section,
59
+ format = _ref.format,
60
+ options = _ref.options;
61
+ if (section === _utils2.SECTION_HOUR) {
62
+ var defaultHour = (0, _utils2.defaultHourForFormat)(format);
63
+ return options.includes(defaultHour) ? defaultHour : options[0];
64
+ }
65
+ if (section === _utils2.SECTION_PERIOD) return 'AM';
66
+ return options[0];
67
+ };
68
+ var PopupColumn = function PopupColumn(_ref2) {
69
+ var _theme$global$size, _theme$timeInput;
70
+ var activeSection = _ref2.activeSection,
71
+ format = _ref2.format,
72
+ formatMessage = _ref2.formatMessage,
73
+ inline = _ref2.inline,
74
+ label = _ref2.label,
75
+ messages = _ref2.messages,
76
+ onClickCommitOption = _ref2.onClickCommitOption,
77
+ onPointerCommitOption = _ref2.onPointerCommitOption,
78
+ onSetSection = _ref2.onSetSection,
79
+ options = _ref2.options,
80
+ section = _ref2.section,
81
+ sections = _ref2.sections,
82
+ theme = _ref2.theme;
83
+ // When inline (in DateTimeInput), use 'medium' to match Calendar height.
84
+ // Otherwise use timeInput drop maxHeight with fallback to 'small'.
85
+ var maxHeightToken = inline ? 'medium' : null;
86
+ 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;
87
+ return /*#__PURE__*/_react["default"].createElement(PopupColumnBox, {
88
+ role: "listbox",
89
+ "aria-label": label,
90
+ gap: "xxsmall",
91
+ height: {
92
+ max: maxHeight
93
+ },
94
+ overflow: "auto",
95
+ flex: {
96
+ grow: 0,
97
+ shrink: 0
98
+ }
99
+ }, options.map(function (option) {
100
+ var _theme$timeInput2;
101
+ var key = optionKey(label, option);
102
+ var sectionHasValue = section === _utils2.SECTION_HOUR && sections.hour !== undefined || section === _utils2.SECTION_MINUTE && sections.minute !== undefined || section === _utils2.SECTION_SECOND && sections.second !== undefined || section === _utils2.SECTION_PERIOD && sections.period !== undefined;
103
+
104
+ // In empty state, keep focus defaults but avoid visually selecting
105
+ // options until the user makes an explicit choice.
106
+ var selected = section === _utils2.SECTION_HOUR && sections.hour === option || section === _utils2.SECTION_MINUTE && sections.minute === option || section === _utils2.SECTION_SECOND && sections.second === option || section === _utils2.SECTION_PERIOD && sections.period === option;
107
+ 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';
108
+ var isActive = selected && activeSection === section;
109
+ var optionTabIndex = -1;
110
+ if (inline) {
111
+ // In inline mode each column needs exactly one tabbable option so Tab
112
+ // key lands on the option (with Grommet focus style) instead of the
113
+ // listbox container (which has no theme focus style). Use the selected
114
+ // value when set, otherwise fall back to the column's first option.
115
+ var defaultOption = getDefaultPopupOption({
116
+ section: section,
117
+ format: format,
118
+ options: options
119
+ });
120
+ optionTabIndex = selected || !sectionHasValue && option === defaultOption ? 0 : -1;
121
+ } else if (isActive) {
122
+ optionTabIndex = 0;
123
+ }
124
+ return /*#__PURE__*/_react["default"].createElement(PopupOption, {
125
+ key: key,
126
+ "data-option-key": key,
127
+ role: "option",
128
+ "aria-selected": selected,
129
+ tabIndex: optionTabIndex,
130
+ "aria-label": (section === _utils2.SECTION_PERIOD ? option : (0, _utils2.pad)(option)) + " " + (0, _utils2.getSectionName)(section, format, formatMessage, messages),
131
+ $active: isActive,
132
+ $selected: selected,
133
+ onMouseDown: function onMouseDown(event) {
134
+ if (event.button !== 0) return;
135
+ // Commit on pointer press so momentum scroll does not swallow
136
+ // the first click commit on some trackpad/mouse flows.
137
+ event.preventDefault();
138
+ onPointerCommitOption(section, option);
139
+ },
140
+ onClick: function onClick() {
141
+ return onClickCommitOption(section, option);
142
+ },
143
+ onFocus: function onFocus() {
144
+ return onSetSection(section);
145
+ }
146
+ }, /*#__PURE__*/_react["default"].createElement(_Text.Text, {
147
+ size: theme.global.input.font.size || 'small',
148
+ color: optionColor
149
+ }, section === _utils2.SECTION_PERIOD ? option : (0, _utils2.pad)(option)));
150
+ }));
151
+ };
152
+ var TimeInputPopup = exports.TimeInputPopup = function TimeInputPopup(_ref3) {
153
+ var _theme$timeInput3, _theme$timeInput4, _theme$timeInput5;
154
+ var activeSection = _ref3.activeSection,
155
+ align = _ref3.align,
156
+ format = _ref3.format,
157
+ formatMessage = _ref3.formatMessage,
158
+ hoursOptions = _ref3.hoursOptions,
159
+ id = _ref3.id,
160
+ incrementSection = _ref3.incrementSection,
161
+ messages = _ref3.messages,
162
+ minuteOptions = _ref3.minuteOptions,
163
+ onClose = _ref3.onClose,
164
+ onFocusLeave = _ref3.onFocusLeave,
165
+ secondOptions = _ref3.secondOptions,
166
+ sectionOrder = _ref3.sectionOrder,
167
+ sections = _ref3.sections,
168
+ setActiveSection = _ref3.setActiveSection,
169
+ setSectionValue = _ref3.setSectionValue,
170
+ target = _ref3.target,
171
+ dropProps = _ref3.dropProps,
172
+ label = _ref3.label,
173
+ _ref3$inline = _ref3.inline,
174
+ inline = _ref3$inline === void 0 ? false : _ref3$inline,
175
+ onKeyDownProp = _ref3.onKeyDown,
176
+ rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
177
+ var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
178
+ theme = _useThemeValue.theme;
179
+ var dialogRef = (0, _react.useRef)();
180
+ var pointerDownInsideRef = (0, _react.useRef)(false);
181
+ var pointerSelectionCommittedRef = (0, _react.useRef)(false);
182
+ var suppressNextAutoScrollRef = (0, _react.useRef)(false);
183
+ var wheelInteractionTimeoutRef = (0, _react.useRef)();
184
+ var pointerReleaseTimeoutRef = (0, _react.useRef)();
185
+ var clearPointerReleaseTimeout = (0, _react.useCallback)(function () {
186
+ if (pointerReleaseTimeoutRef.current) {
187
+ window.clearTimeout(pointerReleaseTimeoutRef.current);
188
+ pointerReleaseTimeoutRef.current = undefined;
189
+ }
190
+ }, []);
191
+ var clearInteractionInProgress = (0, _react.useCallback)(function () {
192
+ clearPointerReleaseTimeout();
193
+ pointerDownInsideRef.current = false;
194
+ if (wheelInteractionTimeoutRef.current) {
195
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
196
+ wheelInteractionTimeoutRef.current = undefined;
197
+ }
198
+ }, [clearPointerReleaseTimeout]);
199
+ var releaseInteractionAfterClick = (0, _react.useCallback)(function () {
200
+ clearPointerReleaseTimeout();
201
+ // Keep lock through click handler + resulting render/effect cycle.
202
+ pointerReleaseTimeoutRef.current = window.setTimeout(function () {
203
+ pointerDownInsideRef.current = false;
204
+ pointerReleaseTimeoutRef.current = undefined;
205
+ }, 0);
206
+ }, [clearPointerReleaseTimeout]);
207
+ var markInteractionInProgress = (0, _react.useCallback)(function () {
208
+ pointerDownInsideRef.current = true;
209
+ }, []);
210
+ var suppressNextAutoScroll = (0, _react.useCallback)(function () {
211
+ suppressNextAutoScrollRef.current = true;
212
+ }, []);
213
+ var commitOptionSelection = (0, _react.useCallback)(function (section, option) {
214
+ setActiveSection(section);
215
+ setSectionValue(section, option);
216
+ }, [setActiveSection, setSectionValue]);
217
+ var commitPointerOptionSelection = (0, _react.useCallback)(function (section, option) {
218
+ pointerSelectionCommittedRef.current = true;
219
+ suppressNextAutoScroll();
220
+ commitOptionSelection(section, option);
221
+ }, [commitOptionSelection, suppressNextAutoScroll]);
222
+ var commitClickOptionSelection = (0, _react.useCallback)(function (section, option) {
223
+ if (pointerSelectionCommittedRef.current) {
224
+ pointerSelectionCommittedRef.current = false;
225
+ return;
226
+ }
227
+ commitOptionSelection(section, option);
228
+ }, [commitOptionSelection]);
229
+ var onPopupWheelCapture = (0, _react.useCallback)(function () {
230
+ pointerDownInsideRef.current = true;
231
+ if (wheelInteractionTimeoutRef.current) {
232
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
233
+ }
234
+
235
+ // Trackpad and wheel events can continue after the pointer sequence.
236
+ // Keep interaction lock briefly so refocus does not steal first selection.
237
+ wheelInteractionTimeoutRef.current = window.setTimeout(function () {
238
+ pointerDownInsideRef.current = false;
239
+ wheelInteractionTimeoutRef.current = undefined;
240
+ }, 120);
241
+ }, []);
242
+ (0, _react.useEffect)(function () {
243
+ return function () {
244
+ clearPointerReleaseTimeout();
245
+ if (wheelInteractionTimeoutRef.current) {
246
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
247
+ }
248
+ };
249
+ }, [clearPointerReleaseTimeout]);
250
+ var popupSections = [{
251
+ section: _utils2.SECTION_HOUR,
252
+ label: 'hour',
253
+ options: hoursOptions
254
+ }, {
255
+ section: _utils2.SECTION_MINUTE,
256
+ label: 'minute',
257
+ options: minuteOptions
258
+ }, {
259
+ section: _utils2.SECTION_SECOND,
260
+ label: 'second',
261
+ options: secondOptions
262
+ }, {
263
+ section: _utils2.SECTION_PERIOD,
264
+ label: 'period',
265
+ options: ['AM', 'PM']
266
+ }];
267
+ var visiblePopupSections = popupSections.filter(function (_ref4) {
268
+ var section = _ref4.section;
269
+ return sectionOrder.includes(section);
270
+ });
271
+ var getSectionFromLabel = (0, _react.useCallback)(function (listboxLabel) {
272
+ if (listboxLabel === 'hour') return _utils2.SECTION_HOUR;
273
+ if (listboxLabel === 'minute') return _utils2.SECTION_MINUTE;
274
+ if (listboxLabel === 'second') return _utils2.SECTION_SECOND;
275
+ if (listboxLabel === 'period') return _utils2.SECTION_PERIOD;
276
+ return undefined;
277
+ }, []);
278
+ var getSectionFromEventTarget = (0, _react.useCallback)(function (eventTarget) {
279
+ var listboxNode = eventTarget == null || eventTarget.closest == null ? void 0 : eventTarget.closest('[role="listbox"]');
280
+ var ariaLabel = listboxNode == null || listboxNode.getAttribute == null ? void 0 : listboxNode.getAttribute('aria-label');
281
+ return getSectionFromLabel(ariaLabel);
282
+ }, [getSectionFromLabel]);
283
+ var getAdjacentSection = (0, _react.useCallback)(function (section, delta) {
284
+ var _sectionOrder$, _sectionOrder$nextInd;
285
+ var currentIndex = sectionOrder.indexOf(section);
286
+ if (currentIndex === -1) return (_sectionOrder$ = sectionOrder[0]) != null ? _sectionOrder$ : section;
287
+ var nextIndex = (currentIndex + delta + sectionOrder.length) % sectionOrder.length;
288
+ return (_sectionOrder$nextInd = sectionOrder[nextIndex]) != null ? _sectionOrder$nextInd : section;
289
+ }, [sectionOrder]);
290
+ var scrollSelectedOptionsIntoView = (0, _react.useCallback)(function () {
291
+ var _sectionLabel, _sectionValue;
292
+ if (pointerDownInsideRef.current) return;
293
+ if (suppressNextAutoScrollRef.current) {
294
+ suppressNextAutoScrollRef.current = false;
295
+ return;
296
+ }
297
+ var popupNode = dialogRef.current;
298
+ if (!popupNode) return;
299
+ var sectionLabel = (_sectionLabel = {}, _sectionLabel[_utils2.SECTION_HOUR] = 'hour', _sectionLabel[_utils2.SECTION_MINUTE] = 'minute', _sectionLabel[_utils2.SECTION_SECOND] = 'second', _sectionLabel[_utils2.SECTION_PERIOD] = 'period', _sectionLabel);
300
+ var sectionValue = (_sectionValue = {}, _sectionValue[_utils2.SECTION_HOUR] = sections.hour !== undefined ? sections.hour : getDefaultPopupOption({
301
+ section: _utils2.SECTION_HOUR,
302
+ format: format,
303
+ options: hoursOptions
304
+ }), _sectionValue[_utils2.SECTION_MINUTE] = sections.minute !== undefined ? sections.minute : getDefaultPopupOption({
305
+ section: _utils2.SECTION_MINUTE,
306
+ format: format,
307
+ options: minuteOptions
308
+ }), _sectionValue[_utils2.SECTION_SECOND] = sections.second !== undefined ? sections.second : getDefaultPopupOption({
309
+ section: _utils2.SECTION_SECOND,
310
+ format: format,
311
+ options: secondOptions
312
+ }), _sectionValue[_utils2.SECTION_PERIOD] = sections.period || 'AM', _sectionValue);
313
+ visiblePopupSections.forEach(function (_ref5) {
314
+ var section = _ref5.section;
315
+ var labelValue = sectionLabel[section];
316
+ if (!labelValue) return;
317
+ var listboxNode = popupNode.querySelector("[role=\"listbox\"][aria-label=\"" + labelValue + "\"]");
318
+ if (!listboxNode) return;
319
+ var selectedNode = popupNode.querySelector("[data-option-key=\"" + optionKey(labelValue, sectionValue[section]) + "\"]") || listboxNode.querySelector('[role="option"][aria-selected="true"]');
320
+ if (selectedNode) {
321
+ if (selectedNode.scrollIntoView) {
322
+ selectedNode.scrollIntoView({
323
+ block: 'nearest'
324
+ });
325
+ }
326
+
327
+ // Center selected value in each listbox so all sections (hh/mm/ss)
328
+ // are consistently aligned on open, not just the focused section.
329
+ var selectedOffsetTop = selectedNode.offsetTop;
330
+ var selectedHeight = selectedNode.offsetHeight;
331
+ var targetScrollTop = selectedOffsetTop - (listboxNode.clientHeight / 2 - selectedHeight / 2);
332
+ listboxNode.scrollTop = Math.max(0, targetScrollTop);
333
+ }
334
+ });
335
+ }, [format, hoursOptions, minuteOptions, secondOptions, sections, visiblePopupSections]);
336
+ var focusCurrentPopupOption = (0, _react.useCallback)(function () {
337
+ var _labelMap, _keyMap, _dialogRef$current, _dialogRef$current2;
338
+ var labelMap = (_labelMap = {}, _labelMap[_utils2.SECTION_HOUR] = 'hour', _labelMap[_utils2.SECTION_MINUTE] = 'minute', _labelMap[_utils2.SECTION_SECOND] = 'second', _labelMap[_utils2.SECTION_PERIOD] = 'period', _labelMap);
339
+ var keyMap = (_keyMap = {}, _keyMap[_utils2.SECTION_HOUR] = optionKey('hour', sections.hour !== undefined ? sections.hour : getDefaultPopupOption({
340
+ section: _utils2.SECTION_HOUR,
341
+ format: format,
342
+ options: hoursOptions
343
+ })), _keyMap[_utils2.SECTION_MINUTE] = optionKey('minute', sections.minute !== undefined ? sections.minute : getDefaultPopupOption({
344
+ section: _utils2.SECTION_MINUTE,
345
+ format: format,
346
+ options: minuteOptions
347
+ })), _keyMap[_utils2.SECTION_SECOND] = optionKey('second', sections.second !== undefined ? sections.second : getDefaultPopupOption({
348
+ section: _utils2.SECTION_SECOND,
349
+ format: format,
350
+ options: secondOptions
351
+ })), _keyMap[_utils2.SECTION_PERIOD] = optionKey('period', sections.period || 'AM'), _keyMap);
352
+ var selector = "[data-option-key=\"" + keyMap[activeSection] + "\"]";
353
+ var node = (_dialogRef$current = dialogRef.current) == null ? void 0 : _dialogRef$current.querySelector(selector);
354
+ if (node) {
355
+ node.focus();
356
+ return true;
357
+ }
358
+
359
+ // Fallback: if current section value has no matching option
360
+ // (e.g., minute=31 with minuteStep=15), focus first option in section.
361
+ var sectionLabel = labelMap[activeSection];
362
+ if (!sectionLabel) return false;
363
+ var fallbackNode = (_dialogRef$current2 = dialogRef.current) == null ? void 0 : _dialogRef$current2.querySelector("[role=\"listbox\"][aria-label=\"" + sectionLabel + "\"] [role=\"option\"]");
364
+ if (fallbackNode) {
365
+ fallbackNode.focus();
366
+ return true;
367
+ }
368
+ return false;
369
+ }, [activeSection, format, hoursOptions, minuteOptions, secondOptions, sections]);
370
+ (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
371
+ // Avoid stealing pointer interactions: while the user is actively
372
+ // clicking inside the popup, let that click settle before refocusing.
373
+ if (pointerDownInsideRef.current) return undefined;
374
+ var scrollRaf = requestAnimationFrame(function () {
375
+ scrollSelectedOptionsIntoView();
376
+ });
377
+ var rafB;
378
+ var rafA = requestAnimationFrame(function () {
379
+ scrollSelectedOptionsIntoView();
380
+ var focused = focusCurrentPopupOption();
381
+ // Retry one more frame to handle occasional mount timing races.
382
+ if (!focused) {
383
+ rafB = requestAnimationFrame(function () {
384
+ scrollSelectedOptionsIntoView();
385
+ focusCurrentPopupOption();
386
+ });
387
+ }
388
+ });
389
+ return function () {
390
+ window.cancelAnimationFrame(scrollRaf);
391
+ window.cancelAnimationFrame(rafA);
392
+ if (rafB) window.cancelAnimationFrame(rafB);
393
+ };
394
+ }, [focusCurrentPopupOption, scrollSelectedOptionsIntoView]);
395
+ var popupContent = /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({
396
+ ref: dialogRef,
397
+ role: inline ? undefined : 'dialog',
398
+ "aria-label": inline ? undefined : label,
399
+ direction: "row",
400
+ width: {
401
+ width: (_theme$timeInput3 = theme.timeInput) == null || (_theme$timeInput3 = _theme$timeInput3.drop) == null ? void 0 : _theme$timeInput3.width,
402
+ max: '100%'
403
+ },
404
+ minHeight: (_theme$timeInput4 = theme.timeInput) == null || (_theme$timeInput4 = _theme$timeInput4.drop) == null ? void 0 : _theme$timeInput4.minHeight,
405
+ gap: "xsmall",
406
+ pad: inline ? 'none' : ((_theme$timeInput5 = theme.timeInput) == null || (_theme$timeInput5 = _theme$timeInput5.drop) == null ? void 0 : _theme$timeInput5.pad) || 'small',
407
+ onPointerDownCapture: markInteractionInProgress,
408
+ onPointerUpCapture: releaseInteractionAfterClick,
409
+ onPointerCancelCapture: clearInteractionInProgress,
410
+ onWheelCapture: onPopupWheelCapture,
411
+ onKeyDown: function onKeyDown(event) {
412
+ var _ref6;
413
+ var eventSectionFromTarget = getSectionFromEventTarget(event.target);
414
+ var eventSectionFromActiveElement = getSectionFromEventTarget(document.activeElement);
415
+ var eventSection = (_ref6 = eventSectionFromTarget != null ? eventSectionFromTarget : eventSectionFromActiveElement) != null ? _ref6 : activeSection;
416
+ if (event.key === 'Escape') {
417
+ if (onClose) {
418
+ event.preventDefault();
419
+ onClose();
420
+ }
421
+ } else if (event.key === 'Enter') {
422
+ var _event$target, _document$activeEleme;
423
+ event.preventDefault();
424
+ 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"]'));
425
+ focusedOption == null || focusedOption.click == null || focusedOption.click();
426
+ } else if (event.key === ' ' || event.key === 'Spacebar') {
427
+ var _event$target2, _document$activeEleme2;
428
+ event.preventDefault();
429
+ 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"]'));
430
+ _focusedOption == null || _focusedOption.click == null || _focusedOption.click();
431
+ } else if (event.key === 'Tab') {
432
+ if (!inline) {
433
+ event.preventDefault();
434
+ setActiveSection(getAdjacentSection(eventSection, event.shiftKey ? -1 : 1));
435
+ }
436
+ } else if (event.key === 'ArrowLeft') {
437
+ event.preventDefault();
438
+ setActiveSection(getAdjacentSection(eventSection, -1));
439
+ } else if (event.key === 'ArrowRight') {
440
+ event.preventDefault();
441
+ setActiveSection(getAdjacentSection(eventSection, 1));
442
+ } else if (event.key === 'ArrowUp') {
443
+ event.preventDefault();
444
+ incrementSection(eventSection, -1);
445
+ } else if (event.key === 'ArrowDown') {
446
+ event.preventDefault();
447
+ incrementSection(eventSection, 1);
448
+ }
449
+ onKeyDownProp == null || onKeyDownProp(event);
450
+ },
451
+ onBlurCapture: function onBlurCapture(event) {
452
+ var nextFocusTarget = event.relatedTarget;
453
+ // Clicking the scrollbar blurs the focused option with
454
+ // relatedTarget = null. Keep the popup open for that interaction.
455
+ if (!nextFocusTarget) return;
456
+ if (!event.currentTarget.contains(nextFocusTarget)) {
457
+ onFocusLeave == null || onFocusLeave();
458
+ }
459
+ }
460
+ }, rest), visiblePopupSections.map(function (_ref7) {
461
+ var section = _ref7.section,
462
+ sectionLabel = _ref7.label,
463
+ options = _ref7.options;
464
+ return /*#__PURE__*/_react["default"].createElement(PopupColumn, {
465
+ key: sectionLabel,
466
+ activeSection: activeSection,
467
+ format: format,
468
+ formatMessage: formatMessage,
469
+ inline: inline,
470
+ label: sectionLabel,
471
+ messages: messages,
472
+ onClickCommitOption: commitClickOptionSelection,
473
+ onPointerCommitOption: commitPointerOptionSelection,
474
+ onSetSection: setActiveSection,
475
+ options: options,
476
+ section: section,
477
+ sections: sections,
478
+ theme: theme
479
+ });
480
+ }));
481
+ if (inline) return popupContent;
482
+ return /*#__PURE__*/_react["default"].createElement(_Drop.Drop, _extends({
483
+ id: id ? id + "__drop" : undefined,
484
+ target: target,
485
+ align: align,
486
+ onEsc: onClose,
487
+ onClickOutside: onClose
488
+ }, dropProps), popupContent);
489
+ };
@@ -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,6 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.TimeInput = void 0;
5
+ var _TimeInput = require("./TimeInput");
6
+ exports.TimeInput = _TimeInput.TimeInput;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.TimeInputPropTypes = void 0;
5
+ var _propTypes = _interopRequireDefault(require("prop-types"));
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
7
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ var PropType = {};
11
+ if (process.env.NODE_ENV !== 'production') {
12
+ PropType = {
13
+ defaultValue: _propTypes["default"].string,
14
+ disabled: _propTypes["default"].bool,
15
+ format: _propTypes["default"].oneOf(['12', '24']),
16
+ id: _propTypes["default"].string,
17
+ messages: _propTypes["default"].shape({
18
+ activePeriodValue: _propTypes["default"].string,
19
+ activeSection: _propTypes["default"].string,
20
+ activeSectionValue: _propTypes["default"].string,
21
+ chooseTime: _propTypes["default"].string,
22
+ currentValue: _propTypes["default"].string,
23
+ inputLabel: _propTypes["default"].string,
24
+ invalidTime: _propTypes["default"].string,
25
+ openDrop: _propTypes["default"].string,
26
+ sectionHours: _propTypes["default"].string,
27
+ sectionMeridiem: _propTypes["default"].string,
28
+ sectionMinutes: _propTypes["default"].string,
29
+ sectionSeconds: _propTypes["default"].string
30
+ }),
31
+ minuteStep: _propTypes["default"].number,
32
+ name: _propTypes["default"].string,
33
+ onChange: _propTypes["default"].func,
34
+ readOnly: _propTypes["default"].bool,
35
+ showSeconds: _propTypes["default"].bool,
36
+ value: _propTypes["default"].string
37
+ };
38
+ }
39
+ var TimeInputPropTypes = exports.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
+ };