grommet 2.54.0 → 2.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/components/Button/Button.js +7 -4
  2. package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
  3. package/components/Calendar/Calendar.js +24 -16
  4. package/components/Calendar/index.d.ts +1 -1
  5. package/components/Calendar/stories/CustomHeader.stories.js +6 -1
  6. package/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  7. package/components/Calendar/stories/Dual.stories.js +23 -11
  8. package/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  9. package/components/Calendar/stories/Multiple.stories.js +8 -3
  10. package/components/Calendar/stories/Simple.stories.js +6 -1
  11. package/components/Cards/Cards.js +164 -10
  12. package/components/Cards/StyledCellContainer.js +29 -0
  13. package/components/Cards/index.d.ts +4 -1
  14. package/components/Cards/propTypes.js +2 -0
  15. package/components/Cards/stories/Sizable.stories.js +70 -0
  16. package/components/Cards/stories/onOrder.stories.js +69 -0
  17. package/components/DataFilter/DataFilter.js +21 -28
  18. package/components/DateInput/DateInput.js +57 -24
  19. package/components/DateInput/index.d.ts +1 -0
  20. package/components/DateInput/utils.js +2 -2
  21. package/components/Drop/DropContainer.js +59 -3
  22. package/components/FileInput/FileInput.js +3 -0
  23. package/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  24. package/components/Form/stories/FieldStates.stories.js +7 -1
  25. package/components/FormField/FormField.js +1 -1
  26. package/components/Grommet/Grommet.js +2 -1
  27. package/components/Grommet/index.d.ts +27 -0
  28. package/components/Grommet/propTypes.js +33 -1
  29. package/components/Layer/LayerContainer.d.ts +40 -0
  30. package/components/Select/stories/ChildrenRender.stories.js +28 -55
  31. package/components/SelectMultiple/stories/typescript/Children.stories.tsx +24 -48
  32. package/components/SelectMultiple/stories/typescript/ValueLabel.stories.tsx +88 -0
  33. package/components/Stepper/StepConnector.js +68 -0
  34. package/components/Stepper/Stepper.js +309 -0
  35. package/components/Stepper/StepperContext.js +43 -0
  36. package/components/Stepper/StepperDescription.js +26 -0
  37. package/components/Stepper/StepperHelperText.js +44 -0
  38. package/components/Stepper/StepperIndicator.js +74 -0
  39. package/components/Stepper/StepperLabel.js +41 -0
  40. package/components/Stepper/StepperStep.js +127 -0
  41. package/components/Stepper/StyledStepper.js +124 -0
  42. package/components/Stepper/index.d.ts +80 -0
  43. package/components/Stepper/index.js +18 -0
  44. package/components/Stepper/propTypes.js +35 -0
  45. package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
  46. package/components/Stepper/stories/ErrorStates.stories.js +45 -0
  47. package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
  48. package/components/Stepper/stories/Interactive.stories.js +60 -0
  49. package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
  50. package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
  51. package/components/Stepper/stories/ReadOnly.stories.js +43 -0
  52. package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
  53. package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
  54. package/components/Tab/Tab.js +19 -6
  55. package/components/Tabs/Tabs.js +156 -22
  56. package/components/Tag/Tag.js +4 -3
  57. package/components/Tag/index.d.ts +5 -4
  58. package/components/Tag/propTypes.js +3 -2
  59. package/components/TextInput/StyledTextInput.js +4 -2
  60. package/components/TextInput/TextInput.js +1 -0
  61. package/components/TimeInput/README.md +2 -0
  62. package/components/TimeInput/StyledTimeInput.js +73 -0
  63. package/components/TimeInput/TimeInput.js +689 -0
  64. package/components/TimeInput/TimeInputPopup.js +393 -0
  65. package/components/TimeInput/index.d.ts +41 -0
  66. package/components/TimeInput/index.js +6 -0
  67. package/components/TimeInput/propTypes.js +35 -0
  68. package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  69. package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  70. package/components/TimeInput/stories/Form.stories.tsx +38 -0
  71. package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  72. package/components/TimeInput/stories/Simple.stories.tsx +19 -0
  73. package/components/TimeInput/stories/Step.stories.tsx +14 -0
  74. package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  75. package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  76. package/components/TimeInput/useSectionedTimeField.js +359 -0
  77. package/components/TimeInput/utils.js +187 -0
  78. package/components/index.d.ts +2 -0
  79. package/components/index.js +12 -0
  80. package/es6/components/Button/Button.js +7 -4
  81. package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
  82. package/es6/components/Calendar/Calendar.js +24 -16
  83. package/es6/components/Calendar/index.d.ts +1 -1
  84. package/es6/components/Calendar/stories/CustomHeader.stories.js +6 -1
  85. package/es6/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  86. package/es6/components/Calendar/stories/Dual.stories.js +23 -11
  87. package/es6/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  88. package/es6/components/Calendar/stories/Multiple.stories.js +8 -3
  89. package/es6/components/Calendar/stories/Simple.stories.js +6 -1
  90. package/es6/components/Cards/Cards.js +165 -12
  91. package/es6/components/Cards/StyledCellContainer.js +24 -0
  92. package/es6/components/Cards/index.d.ts +4 -1
  93. package/es6/components/Cards/propTypes.js +2 -0
  94. package/es6/components/Cards/stories/Sizable.stories.js +65 -0
  95. package/es6/components/Cards/stories/onOrder.stories.js +64 -0
  96. package/es6/components/DataFilter/DataFilter.js +21 -28
  97. package/es6/components/DateInput/DateInput.js +57 -24
  98. package/es6/components/DateInput/index.d.ts +1 -0
  99. package/es6/components/DateInput/utils.js +2 -2
  100. package/es6/components/Drop/DropContainer.js +59 -3
  101. package/es6/components/FileInput/FileInput.js +3 -0
  102. package/es6/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  103. package/es6/components/Form/stories/FieldStates.stories.js +7 -1
  104. package/es6/components/FormField/FormField.js +1 -1
  105. package/es6/components/Grommet/Grommet.js +2 -1
  106. package/es6/components/Grommet/index.d.ts +27 -0
  107. package/es6/components/Grommet/propTypes.js +33 -1
  108. package/es6/components/Layer/LayerContainer.d.ts +40 -0
  109. package/es6/components/Select/stories/ChildrenRender.stories.js +29 -56
  110. package/es6/components/SelectMultiple/stories/typescript/Children.stories.tsx +24 -48
  111. package/es6/components/SelectMultiple/stories/typescript/ValueLabel.stories.tsx +88 -0
  112. package/es6/components/Stepper/StepConnector.js +63 -0
  113. package/es6/components/Stepper/Stepper.js +306 -0
  114. package/es6/components/Stepper/StepperContext.js +39 -0
  115. package/es6/components/Stepper/StepperDescription.js +21 -0
  116. package/es6/components/Stepper/StepperHelperText.js +39 -0
  117. package/es6/components/Stepper/StepperIndicator.js +69 -0
  118. package/es6/components/Stepper/StepperLabel.js +36 -0
  119. package/es6/components/Stepper/StepperStep.js +122 -0
  120. package/es6/components/Stepper/StyledStepper.js +120 -0
  121. package/es6/components/Stepper/index.d.ts +80 -0
  122. package/es6/components/Stepper/index.js +6 -0
  123. package/es6/components/Stepper/propTypes.js +30 -0
  124. package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
  125. package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
  126. package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
  127. package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
  128. package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
  129. package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
  130. package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
  131. package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
  132. package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
  133. package/es6/components/Tab/Tab.js +19 -6
  134. package/es6/components/Tabs/Tabs.js +157 -23
  135. package/es6/components/Tag/Tag.js +4 -3
  136. package/es6/components/Tag/index.d.ts +5 -4
  137. package/es6/components/Tag/propTypes.js +3 -2
  138. package/es6/components/TextInput/StyledTextInput.js +4 -2
  139. package/es6/components/TextInput/TextInput.js +1 -0
  140. package/es6/components/TimeInput/README.md +2 -0
  141. package/es6/components/TimeInput/StyledTimeInput.js +68 -0
  142. package/es6/components/TimeInput/TimeInput.js +685 -0
  143. package/es6/components/TimeInput/TimeInputPopup.js +389 -0
  144. package/es6/components/TimeInput/index.d.ts +41 -0
  145. package/es6/components/TimeInput/index.js +1 -0
  146. package/es6/components/TimeInput/propTypes.js +30 -0
  147. package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  148. package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  149. package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
  150. package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  151. package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
  152. package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
  153. package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  154. package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  155. package/es6/components/TimeInput/useSectionedTimeField.js +356 -0
  156. package/es6/components/TimeInput/utils.js +183 -0
  157. package/es6/components/index.d.ts +2 -0
  158. package/es6/components/index.js +2 -0
  159. package/es6/index.d.ts +2 -0
  160. package/es6/languages/default.json +27 -1
  161. package/es6/themes/base.d.ts +109 -0
  162. package/es6/themes/base.js +208 -0
  163. package/es6/utils/index.d.ts +1 -0
  164. package/es6/utils/styles.js +23 -12
  165. package/grommet.min.js +1 -1
  166. package/grommet.min.js.map +1 -1
  167. package/index.d.ts +2 -0
  168. package/languages/default.json +27 -1
  169. package/package.json +51 -53
  170. package/themes/base.d.ts +109 -0
  171. package/themes/base.js +208 -0
  172. package/utils/index.d.ts +1 -0
  173. package/utils/styles.js +23 -12
  174. package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  175. package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
  176. package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  177. package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
@@ -0,0 +1,393 @@
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
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
+ 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); }
16
+ 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); } /* eslint-disable max-len */
17
+ var PopupColumnBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
18
+ displayName: "TimeInputPopup__PopupColumnBox",
19
+ componentId: "sc-r2j8uh-0"
20
+ })(["scrollbar-gutter:stable;scrollbar-width:thin;"]);
21
+ var PopupOption = _styledComponents["default"].div.withConfig({
22
+ displayName: "TimeInputPopup__PopupOption",
23
+ componentId: "sc-r2j8uh-1"
24
+ })(["box-sizing:border-box;cursor:pointer;display:flex;padding:", ";border-radius:", ";background:", ";&:hover{background:", ";}&:focus-visible{", "}"], function (props) {
25
+ return props.theme.global.edgeSize.xxsmall + " " + props.theme.global.edgeSize.xsmall;
26
+ }, function (props) {
27
+ var _props$theme$global$c;
28
+ 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;
29
+ }, function (props) {
30
+ var _props$theme$timeInpu3;
31
+ if (props.$selected) {
32
+ var _props$theme$timeInpu;
33
+ 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);
34
+ }
35
+ if (props.$active) {
36
+ var _props$theme$timeInpu2;
37
+ 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);
38
+ }
39
+ 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);
40
+ }, function (props) {
41
+ var _props$theme$timeInpu6;
42
+ if (props.$selected) {
43
+ var _props$theme$timeInpu4, _props$theme$timeInpu5;
44
+ 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);
45
+ }
46
+ 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);
47
+ }, (0, _utils.focusStyle)({
48
+ inset: true
49
+ }));
50
+ var optionKey = function optionKey(label, option) {
51
+ return label.toLowerCase() + "-" + option;
52
+ };
53
+ var PopupColumn = function PopupColumn(_ref) {
54
+ var _theme$timeInput;
55
+ var activeSection = _ref.activeSection,
56
+ format = _ref.format,
57
+ formatMessage = _ref.formatMessage,
58
+ label = _ref.label,
59
+ messages = _ref.messages,
60
+ onClickCommitOption = _ref.onClickCommitOption,
61
+ onPointerCommitOption = _ref.onPointerCommitOption,
62
+ onSetSection = _ref.onSetSection,
63
+ options = _ref.options,
64
+ section = _ref.section,
65
+ sections = _ref.sections,
66
+ theme = _ref.theme;
67
+ return /*#__PURE__*/_react["default"].createElement(PopupColumnBox, {
68
+ role: "listbox",
69
+ "aria-label": label,
70
+ gap: "xxsmall",
71
+ height: {
72
+ 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
73
+ },
74
+ overflow: "auto",
75
+ flex: {
76
+ grow: 0,
77
+ shrink: 0
78
+ }
79
+ }, options.map(function (option) {
80
+ var _theme$timeInput2;
81
+ var key = optionKey(label, option);
82
+ 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;
83
+ 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';
84
+ var isActive = selected && activeSection === section;
85
+ return /*#__PURE__*/_react["default"].createElement(PopupOption, {
86
+ key: key,
87
+ "data-option-key": key,
88
+ role: "option",
89
+ "aria-selected": selected,
90
+ tabIndex: isActive ? 0 : -1,
91
+ "aria-label": (section === _utils2.SECTION_PERIOD ? option : (0, _utils2.pad)(option)) + " " + (0, _utils2.getSectionName)(section, format, formatMessage, messages),
92
+ $active: isActive,
93
+ $selected: selected,
94
+ onMouseDown: function onMouseDown(event) {
95
+ if (event.button !== 0) return;
96
+ // Commit on pointer press so momentum scroll does not swallow
97
+ // the first click commit on some trackpad/mouse flows.
98
+ event.preventDefault();
99
+ onPointerCommitOption(section, option);
100
+ },
101
+ onClick: function onClick() {
102
+ return onClickCommitOption(section, option);
103
+ },
104
+ onFocus: function onFocus() {
105
+ return onSetSection(section);
106
+ }
107
+ }, /*#__PURE__*/_react["default"].createElement(_Text.Text, {
108
+ size: theme.global.input.font.size || 'small',
109
+ weight: selected ? 'bold' : 'normal',
110
+ color: optionColor
111
+ }, section === _utils2.SECTION_PERIOD ? option : (0, _utils2.pad)(option)));
112
+ }));
113
+ };
114
+ var TimeInputPopup = exports.TimeInputPopup = function TimeInputPopup(_ref2) {
115
+ var _theme$timeInput3, _theme$timeInput4;
116
+ var activeSection = _ref2.activeSection,
117
+ align = _ref2.align,
118
+ format = _ref2.format,
119
+ formatMessage = _ref2.formatMessage,
120
+ hoursOptions = _ref2.hoursOptions,
121
+ id = _ref2.id,
122
+ incrementSection = _ref2.incrementSection,
123
+ messages = _ref2.messages,
124
+ minuteOptions = _ref2.minuteOptions,
125
+ moveSection = _ref2.moveSection,
126
+ onAccept = _ref2.onAccept,
127
+ onClose = _ref2.onClose,
128
+ onFocusLeave = _ref2.onFocusLeave,
129
+ secondOptions = _ref2.secondOptions,
130
+ sectionOrder = _ref2.sectionOrder,
131
+ sections = _ref2.sections,
132
+ setActiveSection = _ref2.setActiveSection,
133
+ setSectionValue = _ref2.setSectionValue,
134
+ target = _ref2.target,
135
+ dropProps = _ref2.dropProps,
136
+ label = _ref2.label;
137
+ var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
138
+ theme = _useThemeValue.theme;
139
+ var dialogRef = (0, _react.useRef)();
140
+ var pointerDownInsideRef = (0, _react.useRef)(false);
141
+ var pointerSelectionCommittedRef = (0, _react.useRef)(false);
142
+ var suppressNextAutoScrollRef = (0, _react.useRef)(false);
143
+ var wheelInteractionTimeoutRef = (0, _react.useRef)();
144
+ var pointerReleaseTimeoutRef = (0, _react.useRef)();
145
+ var clearPointerReleaseTimeout = (0, _react.useCallback)(function () {
146
+ if (pointerReleaseTimeoutRef.current) {
147
+ window.clearTimeout(pointerReleaseTimeoutRef.current);
148
+ pointerReleaseTimeoutRef.current = undefined;
149
+ }
150
+ }, []);
151
+ var clearInteractionInProgress = (0, _react.useCallback)(function () {
152
+ clearPointerReleaseTimeout();
153
+ pointerDownInsideRef.current = false;
154
+ if (wheelInteractionTimeoutRef.current) {
155
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
156
+ wheelInteractionTimeoutRef.current = undefined;
157
+ }
158
+ }, [clearPointerReleaseTimeout]);
159
+ var releaseInteractionAfterClick = (0, _react.useCallback)(function () {
160
+ clearPointerReleaseTimeout();
161
+ // Keep lock through click handler + resulting render/effect cycle.
162
+ pointerReleaseTimeoutRef.current = window.setTimeout(function () {
163
+ pointerDownInsideRef.current = false;
164
+ pointerReleaseTimeoutRef.current = undefined;
165
+ }, 0);
166
+ }, [clearPointerReleaseTimeout]);
167
+ var markInteractionInProgress = (0, _react.useCallback)(function () {
168
+ pointerDownInsideRef.current = true;
169
+ }, []);
170
+ var suppressNextAutoScroll = (0, _react.useCallback)(function () {
171
+ suppressNextAutoScrollRef.current = true;
172
+ }, []);
173
+ var commitOptionSelection = (0, _react.useCallback)(function (section, option) {
174
+ setActiveSection(section);
175
+ setSectionValue(section, option);
176
+ }, [setActiveSection, setSectionValue]);
177
+ var commitPointerOptionSelection = (0, _react.useCallback)(function (section, option) {
178
+ pointerSelectionCommittedRef.current = true;
179
+ suppressNextAutoScroll();
180
+ commitOptionSelection(section, option);
181
+ }, [commitOptionSelection, suppressNextAutoScroll]);
182
+ var commitClickOptionSelection = (0, _react.useCallback)(function (section, option) {
183
+ if (pointerSelectionCommittedRef.current) {
184
+ pointerSelectionCommittedRef.current = false;
185
+ return;
186
+ }
187
+ commitOptionSelection(section, option);
188
+ }, [commitOptionSelection]);
189
+ var onPopupWheelCapture = (0, _react.useCallback)(function () {
190
+ pointerDownInsideRef.current = true;
191
+ if (wheelInteractionTimeoutRef.current) {
192
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
193
+ }
194
+
195
+ // Trackpad and wheel events can continue after the pointer sequence.
196
+ // Keep interaction lock briefly so refocus does not steal first selection.
197
+ wheelInteractionTimeoutRef.current = window.setTimeout(function () {
198
+ pointerDownInsideRef.current = false;
199
+ wheelInteractionTimeoutRef.current = undefined;
200
+ }, 120);
201
+ }, []);
202
+ (0, _react.useEffect)(function () {
203
+ return function () {
204
+ clearPointerReleaseTimeout();
205
+ if (wheelInteractionTimeoutRef.current) {
206
+ window.clearTimeout(wheelInteractionTimeoutRef.current);
207
+ }
208
+ };
209
+ }, [clearPointerReleaseTimeout]);
210
+ var popupSections = [{
211
+ section: _utils2.SECTION_HOUR,
212
+ label: 'hour',
213
+ options: hoursOptions
214
+ }, {
215
+ section: _utils2.SECTION_MINUTE,
216
+ label: 'minute',
217
+ options: minuteOptions
218
+ }, {
219
+ section: _utils2.SECTION_SECOND,
220
+ label: 'second',
221
+ options: secondOptions
222
+ }, {
223
+ section: _utils2.SECTION_PERIOD,
224
+ label: 'period',
225
+ options: ['AM', 'PM']
226
+ }];
227
+ var visiblePopupSections = popupSections.filter(function (_ref3) {
228
+ var section = _ref3.section;
229
+ return sectionOrder.includes(section);
230
+ });
231
+ var scrollSelectedOptionsIntoView = (0, _react.useCallback)(function () {
232
+ var _sectionLabel, _sectionValue;
233
+ if (pointerDownInsideRef.current) return;
234
+ if (suppressNextAutoScrollRef.current) {
235
+ suppressNextAutoScrollRef.current = false;
236
+ return;
237
+ }
238
+ var popupNode = dialogRef.current;
239
+ if (!popupNode) return;
240
+ var sectionLabel = (_sectionLabel = {}, _sectionLabel[_utils2.SECTION_HOUR] = 'hour', _sectionLabel[_utils2.SECTION_MINUTE] = 'minute', _sectionLabel[_utils2.SECTION_SECOND] = 'second', _sectionLabel[_utils2.SECTION_PERIOD] = 'period', _sectionLabel);
241
+ var sectionValue = (_sectionValue = {}, _sectionValue[_utils2.SECTION_HOUR] = sections.hour !== undefined ? sections.hour : hoursOptions[0], _sectionValue[_utils2.SECTION_MINUTE] = sections.minute !== undefined ? sections.minute : minuteOptions[0], _sectionValue[_utils2.SECTION_SECOND] = sections.second !== undefined ? sections.second : secondOptions[0], _sectionValue[_utils2.SECTION_PERIOD] = sections.period || 'AM', _sectionValue);
242
+ visiblePopupSections.forEach(function (_ref4) {
243
+ var section = _ref4.section;
244
+ var labelValue = sectionLabel[section];
245
+ if (!labelValue) return;
246
+ var listboxNode = popupNode.querySelector("[role=\"listbox\"][aria-label=\"" + labelValue + "\"]");
247
+ if (!listboxNode) return;
248
+ var selectedNode = popupNode.querySelector("[data-option-key=\"" + optionKey(labelValue, sectionValue[section]) + "\"]") || listboxNode.querySelector('[role="option"][aria-selected="true"]');
249
+ if (selectedNode) {
250
+ if (selectedNode.scrollIntoView) {
251
+ selectedNode.scrollIntoView({
252
+ block: 'nearest'
253
+ });
254
+ }
255
+
256
+ // Center selected value in each listbox so all sections (hh/mm/ss)
257
+ // are consistently aligned on open, not just the focused section.
258
+ var selectedOffsetTop = selectedNode.offsetTop;
259
+ var selectedHeight = selectedNode.offsetHeight;
260
+ var targetScrollTop = selectedOffsetTop - (listboxNode.clientHeight / 2 - selectedHeight / 2);
261
+ listboxNode.scrollTop = Math.max(0, targetScrollTop);
262
+ }
263
+ });
264
+ }, [hoursOptions, minuteOptions, secondOptions, sections, visiblePopupSections]);
265
+ var focusCurrentPopupOption = (0, _react.useCallback)(function () {
266
+ var _labelMap, _keyMap, _dialogRef$current, _dialogRef$current2;
267
+ var labelMap = (_labelMap = {}, _labelMap[_utils2.SECTION_HOUR] = 'hour', _labelMap[_utils2.SECTION_MINUTE] = 'minute', _labelMap[_utils2.SECTION_SECOND] = 'second', _labelMap[_utils2.SECTION_PERIOD] = 'period', _labelMap);
268
+ var keyMap = (_keyMap = {}, _keyMap[_utils2.SECTION_HOUR] = optionKey('hour', sections.hour !== undefined ? sections.hour : hoursOptions[0]), _keyMap[_utils2.SECTION_MINUTE] = optionKey('minute', sections.minute !== undefined ? sections.minute : minuteOptions[0]), _keyMap[_utils2.SECTION_SECOND] = optionKey('second', sections.second !== undefined ? sections.second : secondOptions[0]), _keyMap[_utils2.SECTION_PERIOD] = optionKey('period', sections.period || 'AM'), _keyMap);
269
+ var selector = "[data-option-key=\"" + keyMap[activeSection] + "\"]";
270
+ var node = (_dialogRef$current = dialogRef.current) == null ? void 0 : _dialogRef$current.querySelector(selector);
271
+ if (node) {
272
+ node.focus();
273
+ return true;
274
+ }
275
+
276
+ // Fallback: if current section value has no matching option
277
+ // (e.g., minute=31 with minuteStep=15), focus first option in section.
278
+ var sectionLabel = labelMap[activeSection];
279
+ if (!sectionLabel) return false;
280
+ var fallbackNode = (_dialogRef$current2 = dialogRef.current) == null ? void 0 : _dialogRef$current2.querySelector("[role=\"listbox\"][aria-label=\"" + sectionLabel + "\"] [role=\"option\"]");
281
+ if (fallbackNode) {
282
+ fallbackNode.focus();
283
+ return true;
284
+ }
285
+ return false;
286
+ }, [activeSection, hoursOptions, minuteOptions, secondOptions, sections]);
287
+ (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
288
+ // Avoid stealing pointer interactions: while the user is actively
289
+ // clicking inside the popup, let that click settle before refocusing.
290
+ if (pointerDownInsideRef.current) return undefined;
291
+ var scrollRaf = requestAnimationFrame(function () {
292
+ scrollSelectedOptionsIntoView();
293
+ });
294
+ var rafB;
295
+ var rafA = requestAnimationFrame(function () {
296
+ scrollSelectedOptionsIntoView();
297
+ var focused = focusCurrentPopupOption();
298
+ // Retry one more frame to handle occasional mount timing races.
299
+ if (!focused) {
300
+ rafB = requestAnimationFrame(function () {
301
+ scrollSelectedOptionsIntoView();
302
+ focusCurrentPopupOption();
303
+ });
304
+ }
305
+ });
306
+ return function () {
307
+ window.cancelAnimationFrame(scrollRaf);
308
+ window.cancelAnimationFrame(rafA);
309
+ if (rafB) window.cancelAnimationFrame(rafB);
310
+ };
311
+ }, [focusCurrentPopupOption, scrollSelectedOptionsIntoView]);
312
+ return /*#__PURE__*/_react["default"].createElement(_Drop.Drop, _extends({
313
+ id: id ? id + "__drop" : undefined,
314
+ target: target,
315
+ align: align,
316
+ onEsc: onClose,
317
+ onClickOutside: onClose
318
+ }, dropProps), /*#__PURE__*/_react["default"].createElement(_Box.Box, {
319
+ ref: dialogRef,
320
+ role: "dialog",
321
+ "aria-label": label,
322
+ direction: "row",
323
+ width: {
324
+ width: (_theme$timeInput3 = theme.timeInput) == null || (_theme$timeInput3 = _theme$timeInput3.drop) == null ? void 0 : _theme$timeInput3.width,
325
+ max: '100%'
326
+ },
327
+ minHeight: (_theme$timeInput4 = theme.timeInput) == null || (_theme$timeInput4 = _theme$timeInput4.drop) == null ? void 0 : _theme$timeInput4.minHeight,
328
+ gap: "xsmall",
329
+ pad: "small",
330
+ onPointerDownCapture: markInteractionInProgress,
331
+ onPointerUpCapture: releaseInteractionAfterClick,
332
+ onPointerCancelCapture: clearInteractionInProgress,
333
+ onWheelCapture: onPopupWheelCapture,
334
+ onKeyDown: function onKeyDown(event) {
335
+ if (event.key === 'Escape') {
336
+ event.preventDefault();
337
+ onClose();
338
+ } else if (event.key === ' ' || event.key === 'Spacebar') {
339
+ var _event$target, _document$activeEleme;
340
+ event.preventDefault();
341
+ 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"]'));
342
+ focusedOption == null || focusedOption.click == null || focusedOption.click();
343
+ } else if (event.key === 'Tab') {
344
+ event.preventDefault();
345
+ setActiveSection(moveSection(event.shiftKey ? -1 : 1));
346
+ } else if (event.key === 'ArrowLeft') {
347
+ event.preventDefault();
348
+ setActiveSection(moveSection(-1));
349
+ } else if (event.key === 'ArrowRight') {
350
+ event.preventDefault();
351
+ setActiveSection(moveSection(1));
352
+ } else if (event.key === 'ArrowUp') {
353
+ event.preventDefault();
354
+ incrementSection(activeSection, -1);
355
+ } else if (event.key === 'ArrowDown') {
356
+ event.preventDefault();
357
+ incrementSection(activeSection, 1);
358
+ } else if (event.key === 'Enter') {
359
+ event.preventDefault();
360
+ onAccept == null || onAccept();
361
+ onClose();
362
+ }
363
+ },
364
+ onBlurCapture: function onBlurCapture(event) {
365
+ var nextFocusTarget = event.relatedTarget;
366
+ // Clicking the scrollbar blurs the focused option with
367
+ // relatedTarget = null. Keep the popup open for that interaction.
368
+ if (!nextFocusTarget) return;
369
+ if (!event.currentTarget.contains(nextFocusTarget)) {
370
+ onFocusLeave == null || onFocusLeave();
371
+ }
372
+ }
373
+ }, visiblePopupSections.map(function (_ref5) {
374
+ var section = _ref5.section,
375
+ sectionLabel = _ref5.label,
376
+ options = _ref5.options;
377
+ return /*#__PURE__*/_react["default"].createElement(PopupColumn, {
378
+ key: sectionLabel,
379
+ activeSection: activeSection,
380
+ format: format,
381
+ formatMessage: formatMessage,
382
+ label: sectionLabel,
383
+ messages: messages,
384
+ onClickCommitOption: commitClickOptionSelection,
385
+ onPointerCommitOption: commitPointerOptionSelection,
386
+ onSetSection: setActiveSection,
387
+ options: options,
388
+ section: section,
389
+ sections: sections,
390
+ theme: theme
391
+ });
392
+ })));
393
+ };
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+
3
+ export interface TimeInputProps {
4
+ defaultValue?: string;
5
+ disabled?: boolean;
6
+ format?: '12' | '24';
7
+ id?: string;
8
+ messages?: {
9
+ activePeriodValue?: string;
10
+ activeSection?: string;
11
+ activeSectionValue?: string;
12
+ chooseTime?: string;
13
+ currentValue?: string;
14
+ inputLabel?: string;
15
+ invalidTime?: string;
16
+ openDrop?: string;
17
+ sectionHours?: string;
18
+ sectionMeridiem?: string;
19
+ sectionMinutes?: string;
20
+ sectionSeconds?: string;
21
+ };
22
+ minuteStep?: number;
23
+ name?: string;
24
+ onChange?: (event: { value?: string }) => void;
25
+ readOnly?: boolean;
26
+ value?: string;
27
+ }
28
+
29
+ export interface TimeInputExtendedProps
30
+ extends TimeInputProps,
31
+ Omit<
32
+ React.DetailedHTMLProps<
33
+ React.InputHTMLAttributes<HTMLInputElement>,
34
+ HTMLInputElement
35
+ >,
36
+ 'defaultValue' | 'onChange' | 'onError' | 'size' | 'value'
37
+ > {}
38
+
39
+ declare const TimeInput: React.FC<TimeInputExtendedProps>;
40
+
41
+ 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,35 @@
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
+ var PropType = {};
8
+ if (process.env.NODE_ENV !== 'production') {
9
+ PropType = {
10
+ defaultValue: _propTypes["default"].string,
11
+ disabled: _propTypes["default"].bool,
12
+ format: _propTypes["default"].oneOf(['12', '24']),
13
+ id: _propTypes["default"].string,
14
+ messages: _propTypes["default"].shape({
15
+ activePeriodValue: _propTypes["default"].string,
16
+ activeSection: _propTypes["default"].string,
17
+ activeSectionValue: _propTypes["default"].string,
18
+ chooseTime: _propTypes["default"].string,
19
+ currentValue: _propTypes["default"].string,
20
+ inputLabel: _propTypes["default"].string,
21
+ invalidTime: _propTypes["default"].string,
22
+ openDrop: _propTypes["default"].string,
23
+ sectionHours: _propTypes["default"].string,
24
+ sectionMeridiem: _propTypes["default"].string,
25
+ sectionMinutes: _propTypes["default"].string,
26
+ sectionSeconds: _propTypes["default"].string
27
+ }),
28
+ minuteStep: _propTypes["default"].number,
29
+ name: _propTypes["default"].string,
30
+ onChange: _propTypes["default"].func,
31
+ readOnly: _propTypes["default"].bool,
32
+ value: _propTypes["default"].string
33
+ };
34
+ }
35
+ 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
+ };
@@ -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
+ };
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+
3
+ import { Box, TimeInput } from 'grommet';
4
+
5
+ export const Simple = () => {
6
+ const onChange = ({ value }: { value?: string }) => {
7
+ console.log('onChange iso time:', value);
8
+ };
9
+
10
+ return (
11
+ <Box pad="large" width="medium">
12
+ <TimeInput format="12" onChange={onChange} />
13
+ </Box>
14
+ );
15
+ };
16
+
17
+ export default {
18
+ title: 'Input/TimeInput/Simple',
19
+ };
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Text, TimeInput } from 'grommet';
4
+
5
+ export const Step = () => (
6
+ <Box pad="large" width="medium" gap="small">
7
+ <Text size="small">Minute options increment by 15 (00, 15, 30, 45).</Text>
8
+ <TimeInput format="24" defaultValue="10:30:00" minuteStep={15} />
9
+ </Box>
10
+ );
11
+
12
+ export default {
13
+ title: 'Input/TimeInput/Step',
14
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Heading, ThemeContext, TimeInput } from 'grommet';
4
+
5
+ export const ThemingLightDark = () => (
6
+ <Box gap="xlarge">
7
+ <Box pad="xlarge" background="background-front">
8
+ <Heading level={3}>Light Theme</Heading>
9
+ <TimeInput format="12" defaultValue="12:34:56" />
10
+ </Box>
11
+ <ThemeContext.Extend value={{ dark: true }}>
12
+ <Box pad="xlarge" background="background-front">
13
+ <Heading level={3}>Dark Theme</Heading>
14
+ <TimeInput format="12" defaultValue="12:34:56" />
15
+ </Box>
16
+ </ThemeContext.Extend>
17
+ </Box>
18
+ );
19
+
20
+ export default {
21
+ title: 'Input/TimeInput/Theming Light Dark',
22
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+
3
+ import { Box, Text, TimeInput } from 'grommet';
4
+
5
+ export const Uncontrolled = () => {
6
+ const onChange = ({ value }: { value?: string }) => {
7
+ console.log('onChange iso time:', value);
8
+ };
9
+
10
+ return (
11
+ <Box pad="large" width="medium" gap="small">
12
+ <Text size="small">
13
+ Uncontrolled input (manages its own internal state).
14
+ </Text>
15
+ <TimeInput format="12" defaultValue="12:34:56" onChange={onChange} />
16
+ </Box>
17
+ );
18
+ };
19
+
20
+ export default {
21
+ title: 'Input/TimeInput/Uncontrolled',
22
+ };