grommet 2.55.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 (109) hide show
  1. package/components/Button/Button.js +7 -4
  2. package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
  3. package/components/FormField/FormField.js +1 -1
  4. package/components/Grommet/index.d.ts +21 -0
  5. package/components/Grommet/propTypes.js +26 -0
  6. package/components/Stepper/StepConnector.js +68 -0
  7. package/components/Stepper/Stepper.js +309 -0
  8. package/components/Stepper/StepperContext.js +43 -0
  9. package/components/Stepper/StepperDescription.js +26 -0
  10. package/components/Stepper/StepperHelperText.js +44 -0
  11. package/components/Stepper/StepperIndicator.js +74 -0
  12. package/components/Stepper/StepperLabel.js +41 -0
  13. package/components/Stepper/StepperStep.js +127 -0
  14. package/components/Stepper/StyledStepper.js +124 -0
  15. package/components/Stepper/index.d.ts +80 -0
  16. package/components/Stepper/index.js +18 -0
  17. package/components/Stepper/propTypes.js +35 -0
  18. package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
  19. package/components/Stepper/stories/ErrorStates.stories.js +45 -0
  20. package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
  21. package/components/Stepper/stories/Interactive.stories.js +60 -0
  22. package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
  23. package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
  24. package/components/Stepper/stories/ReadOnly.stories.js +43 -0
  25. package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
  26. package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
  27. package/components/Tab/Tab.js +19 -6
  28. package/components/Tabs/Tabs.js +156 -22
  29. package/components/TimeInput/README.md +2 -0
  30. package/components/TimeInput/StyledTimeInput.js +73 -0
  31. package/components/TimeInput/TimeInput.js +689 -0
  32. package/components/TimeInput/TimeInputPopup.js +393 -0
  33. package/components/TimeInput/index.d.ts +41 -0
  34. package/components/TimeInput/index.js +6 -0
  35. package/components/TimeInput/propTypes.js +35 -0
  36. package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  37. package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  38. package/components/TimeInput/stories/Form.stories.tsx +38 -0
  39. package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  40. package/components/TimeInput/stories/Simple.stories.tsx +19 -0
  41. package/components/TimeInput/stories/Step.stories.tsx +14 -0
  42. package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  43. package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  44. package/components/TimeInput/useSectionedTimeField.js +359 -0
  45. package/components/TimeInput/utils.js +187 -0
  46. package/components/index.d.ts +2 -0
  47. package/components/index.js +12 -0
  48. package/es6/components/Button/Button.js +7 -4
  49. package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
  50. package/es6/components/FormField/FormField.js +1 -1
  51. package/es6/components/Grommet/index.d.ts +21 -0
  52. package/es6/components/Grommet/propTypes.js +26 -0
  53. package/es6/components/Stepper/StepConnector.js +63 -0
  54. package/es6/components/Stepper/Stepper.js +306 -0
  55. package/es6/components/Stepper/StepperContext.js +39 -0
  56. package/es6/components/Stepper/StepperDescription.js +21 -0
  57. package/es6/components/Stepper/StepperHelperText.js +39 -0
  58. package/es6/components/Stepper/StepperIndicator.js +69 -0
  59. package/es6/components/Stepper/StepperLabel.js +36 -0
  60. package/es6/components/Stepper/StepperStep.js +122 -0
  61. package/es6/components/Stepper/StyledStepper.js +120 -0
  62. package/es6/components/Stepper/index.d.ts +80 -0
  63. package/es6/components/Stepper/index.js +6 -0
  64. package/es6/components/Stepper/propTypes.js +30 -0
  65. package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
  66. package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
  67. package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
  68. package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
  69. package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
  70. package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
  71. package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
  72. package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
  73. package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
  74. package/es6/components/Tab/Tab.js +19 -6
  75. package/es6/components/Tabs/Tabs.js +157 -23
  76. package/es6/components/TimeInput/README.md +2 -0
  77. package/es6/components/TimeInput/StyledTimeInput.js +68 -0
  78. package/es6/components/TimeInput/TimeInput.js +685 -0
  79. package/es6/components/TimeInput/TimeInputPopup.js +389 -0
  80. package/es6/components/TimeInput/index.d.ts +41 -0
  81. package/es6/components/TimeInput/index.js +1 -0
  82. package/es6/components/TimeInput/propTypes.js +30 -0
  83. package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  84. package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  85. package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
  86. package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  87. package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
  88. package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
  89. package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  90. package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  91. package/es6/components/TimeInput/useSectionedTimeField.js +356 -0
  92. package/es6/components/TimeInput/utils.js +183 -0
  93. package/es6/components/index.d.ts +2 -0
  94. package/es6/components/index.js +2 -0
  95. package/es6/index.d.ts +2 -0
  96. package/es6/languages/default.json +20 -0
  97. package/es6/themes/base.d.ts +108 -0
  98. package/es6/themes/base.js +208 -0
  99. package/grommet.min.js +1 -1
  100. package/grommet.min.js.map +1 -1
  101. package/index.d.ts +2 -0
  102. package/languages/default.json +20 -0
  103. package/package.json +41 -40
  104. package/themes/base.d.ts +108 -0
  105. package/themes/base.js +208 -0
  106. package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  107. package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
  108. package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  109. package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
@@ -0,0 +1,60 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { Box, Text } from 'grommet';
3
+ import { Stepper } from '../Stepper';
4
+ var KeyboardNavigation = function KeyboardNavigation() {
5
+ var _useState = useState('step1'),
6
+ currentStep = _useState[0],
7
+ setCurrentStep = _useState[1];
8
+ var stepperRef = useRef();
9
+ var steps = [{
10
+ id: 'step1',
11
+ title: 'Step 1',
12
+ status: 'completed'
13
+ }, {
14
+ id: 'step2',
15
+ title: 'Step 2',
16
+ status: 'pending'
17
+ }, {
18
+ id: 'step3',
19
+ title: 'Step 3',
20
+ status: 'pending'
21
+ }, {
22
+ id: 'step4',
23
+ title: 'Step 4',
24
+ status: 'disabled',
25
+ disabledReason: 'Complete all prior steps.'
26
+ }, {
27
+ id: 'step5',
28
+ title: 'Step 5',
29
+ status: 'pending'
30
+ }];
31
+ useEffect(function () {
32
+ var _stepperRef$current;
33
+ // Auto-focus the first step button so the focus ring is visible immediately
34
+ var firstButton = (_stepperRef$current = stepperRef.current) == null ? void 0 : _stepperRef$current.querySelector('button');
35
+ if (firstButton) firstButton.focus();
36
+ }, []);
37
+ return (
38
+ /*#__PURE__*/
39
+ // Uncomment <Grommet> lines when using outside of storybook
40
+ // <Grommet theme={...}>
41
+ React.createElement(Box, {
42
+ pad: "large",
43
+ gap: "medium"
44
+ }, /*#__PURE__*/React.createElement(Text, {
45
+ weight: "bold"
46
+ }, "Use Arrow keys to navigate and Enter/Space to select."), /*#__PURE__*/React.createElement(Stepper, {
47
+ ref: stepperRef,
48
+ steps: steps,
49
+ currentStep: currentStep,
50
+ onStepClick: function onStepClick(id) {
51
+ setCurrentStep(id);
52
+ }
53
+ }), /*#__PURE__*/React.createElement(Text, null, "Selected : ", currentStep))
54
+ // </Grommet>
55
+ );
56
+ };
57
+ export default {
58
+ title: 'Visualizations/Stepper/Keyboard Navigation'
59
+ };
60
+ export { KeyboardNavigation };
@@ -0,0 +1,66 @@
1
+ import React, { useState } from 'react';
2
+ import { Box, Text } from 'grommet';
3
+ import { Stepper } from '../Stepper';
4
+ var NestedSubSteps = function NestedSubSteps() {
5
+ var _steps$find;
6
+ var _useState = useState('email'),
7
+ currentStep = _useState[0],
8
+ setCurrentStep = _useState[1];
9
+ var steps = [{
10
+ id: 'account',
11
+ title: 'Account Setup',
12
+ children: [{
13
+ id: 'email',
14
+ title: 'Email',
15
+ status: 'completed'
16
+ }, {
17
+ id: 'password',
18
+ title: 'Password',
19
+ status: 'pending'
20
+ }]
21
+ }, {
22
+ id: 'profile',
23
+ title: 'Profile Setup',
24
+ children: [{
25
+ id: 'name',
26
+ title: 'Name',
27
+ status: 'pending'
28
+ }, {
29
+ id: 'photo',
30
+ title: 'Photo',
31
+ status: 'error',
32
+ errorMessage: 'Please upload a valid photo.'
33
+ }]
34
+ }, {
35
+ id: 'confirm',
36
+ title: 'Confirm',
37
+ status: 'pending'
38
+ }];
39
+ return (
40
+ /*#__PURE__*/
41
+ // Uncomment <Grommet> lines when using outside of storybook
42
+ // <Grommet theme={...}>
43
+ React.createElement(Box, {
44
+ pad: "large",
45
+ gap: "medium"
46
+ }, /*#__PURE__*/React.createElement(Stepper, {
47
+ steps: steps,
48
+ currentStep: currentStep,
49
+ direction: "vertical",
50
+ "aria-label": "Account setup progress",
51
+ onStepClick: function onStepClick(id) {
52
+ return setCurrentStep(id);
53
+ }
54
+ }), /*#__PURE__*/React.createElement(Text, null, "Parent:", ' ', ((_steps$find = steps.find(function (s) {
55
+ var _s$children;
56
+ return (_s$children = s.children) == null ? void 0 : _s$children.some(function (c) {
57
+ return c.id === currentStep;
58
+ });
59
+ })) == null ? void 0 : _steps$find.title) || 'None'), /*#__PURE__*/React.createElement(Text, null, "Current Step: ", currentStep))
60
+ // </Grommet>
61
+ );
62
+ };
63
+ export default {
64
+ title: 'Visualizations/Stepper/Nested Sub-Steps'
65
+ };
66
+ export { NestedSubSteps };
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { Box } from 'grommet';
3
+ import { Stepper } from '../Stepper';
4
+ var ReadOnly = function ReadOnly() {
5
+ var steps = [{
6
+ id: 'step1',
7
+ title: 'Step 1',
8
+ status: 'completed'
9
+ }, {
10
+ id: 'step2',
11
+ title: 'Step 2',
12
+ status: 'completed'
13
+ }, {
14
+ id: 'step3',
15
+ title: 'Step 3',
16
+ status: 'pending'
17
+ }, {
18
+ id: 'step4',
19
+ title: 'Step 4',
20
+ status: 'pending'
21
+ }];
22
+ return (
23
+ /*#__PURE__*/
24
+ // Uncomment <Grommet> lines when using outside of storybook
25
+ // <Grommet theme={...}>
26
+ React.createElement(Box, {
27
+ pad: "large"
28
+ }, /*#__PURE__*/React.createElement(Stepper, {
29
+ steps: steps,
30
+ currentStep: "step3",
31
+ clickableSteps: false
32
+ }))
33
+ // </Grommet>
34
+ );
35
+ };
36
+ export default {
37
+ title: 'Visualizations/Stepper/Read-Only'
38
+ };
39
+ export { ReadOnly };
@@ -0,0 +1,54 @@
1
+ import React, { useState } from 'react';
2
+ import { Box, Heading, ThemeContext } from 'grommet';
3
+ import { Stepper } from '../Stepper';
4
+ var ThemingLightDark = function ThemingLightDark() {
5
+ var _useState = useState('step1'),
6
+ currentStep = _useState[0],
7
+ setCurrentStep = _useState[1];
8
+ var steps = [{
9
+ id: 'step1',
10
+ title: 'Account',
11
+ status: 'completed'
12
+ }, {
13
+ id: 'step2',
14
+ title: 'Profile',
15
+ status: 'pending'
16
+ }, {
17
+ id: 'step3',
18
+ title: 'Review',
19
+ status: 'pending'
20
+ }];
21
+ return /*#__PURE__*/React.createElement(Box, {
22
+ gap: "large"
23
+ }, /*#__PURE__*/React.createElement(Box, {
24
+ pad: "large",
25
+ background: "background-front"
26
+ }, /*#__PURE__*/React.createElement(Heading, {
27
+ level: 3
28
+ }, "Light Theme"), /*#__PURE__*/React.createElement(Stepper, {
29
+ steps: steps,
30
+ currentStep: currentStep,
31
+ onStepClick: function onStepClick(id) {
32
+ return setCurrentStep(id);
33
+ }
34
+ })), /*#__PURE__*/React.createElement(ThemeContext.Extend, {
35
+ value: {
36
+ dark: true
37
+ }
38
+ }, /*#__PURE__*/React.createElement(Box, {
39
+ pad: "large",
40
+ background: "background-front"
41
+ }, /*#__PURE__*/React.createElement(Heading, {
42
+ level: 3
43
+ }, "Dark Theme"), /*#__PURE__*/React.createElement(Stepper, {
44
+ steps: steps,
45
+ currentStep: currentStep,
46
+ onStepClick: function onStepClick(id) {
47
+ return setCurrentStep(id);
48
+ }
49
+ }))));
50
+ };
51
+ export default {
52
+ title: 'Visualizations/Stepper/Theming Light Dark'
53
+ };
54
+ export { ThemingLightDark };
@@ -0,0 +1,63 @@
1
+ import React, { useState } from 'react';
2
+ import { Box, Text, Heading, Paragraph } from 'grommet';
3
+ import { Stepper } from '../Stepper';
4
+ var VerticalSteps = function VerticalSteps() {
5
+ var _steps$find, _steps$find2;
6
+ var _useState = useState('deploy'),
7
+ currentStep = _useState[0],
8
+ setCurrentStep = _useState[1];
9
+ var steps = [{
10
+ id: 'setup',
11
+ title: 'Setup',
12
+ description: 'Configure your environment.',
13
+ status: 'completed'
14
+ }, {
15
+ id: 'deploy',
16
+ title: 'Deploy',
17
+ status: 'pending'
18
+ }, {
19
+ id: 'verify',
20
+ title: 'Verify',
21
+ description: 'Run post-deployment checks.',
22
+ status: 'pending'
23
+ }];
24
+ return (
25
+ /*#__PURE__*/
26
+ // Uncomment <Grommet> lines when using outside of storybook
27
+ // <Grommet theme={...}>
28
+ React.createElement(Box, {
29
+ direction: "row",
30
+ gap: "medium",
31
+ pad: "medium"
32
+ }, /*#__PURE__*/React.createElement(Stepper, {
33
+ steps: steps,
34
+ currentStep: currentStep,
35
+ direction: "vertical",
36
+ onStepClick: function onStepClick(id) {
37
+ return setCurrentStep(id);
38
+ }
39
+ }), /*#__PURE__*/React.createElement(Box, {
40
+ flex: true,
41
+ pad: "medium",
42
+ background: "background-contrast",
43
+ round: "small",
44
+ height: {
45
+ min: 'medium'
46
+ },
47
+ gap: "none"
48
+ }, /*#__PURE__*/React.createElement(Heading, {
49
+ level: 2
50
+ }, (_steps$find = steps.find(function (s) {
51
+ return s.id === currentStep;
52
+ })) == null ? void 0 : _steps$find.title), /*#__PURE__*/React.createElement(Text, {
53
+ color: "text-strong"
54
+ }, (_steps$find2 = steps.find(function (s) {
55
+ return s.id === currentStep;
56
+ })) == null ? void 0 : _steps$find2.description), /*#__PURE__*/React.createElement(Paragraph, null, "Step content")))
57
+ // </Grommet>
58
+ );
59
+ };
60
+ export default {
61
+ title: 'Visualizations/Stepper/Vertical Steps'
62
+ };
63
+ export { VerticalSteps };
@@ -1,4 +1,4 @@
1
- var _excluded = ["active", "disabled", "children", "icon", "plain", "title", "onBlur", "onFocus", "onMouseOver", "onMouseOut", "reverse", "onClick"];
1
+ var _excluded = ["active", "disabled", "children", "icon", "plain", "title", "onBlur", "onFocus", "onMouseOver", "onMouseOut", "reverse", "onClick", "onKeyDown"];
2
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
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
4
  import React, { forwardRef, useContext, useState } from 'react';
@@ -23,13 +23,17 @@ var Tab = /*#__PURE__*/forwardRef(function (_ref, ref) {
23
23
  onMouseOut = _ref.onMouseOut,
24
24
  reverse = _ref.reverse,
25
25
  onClick = _ref.onClick,
26
+ onKeyDown = _ref.onKeyDown,
26
27
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
27
28
  var _useContext = useContext(TabsContext),
28
29
  active = _useContext.active,
29
30
  activeIndex = _useContext.activeIndex,
31
+ focusable = _useContext.focusable,
30
32
  index = _useContext.index,
33
+ panelId = _useContext.panelId,
31
34
  tabsContextRef = _useContext.ref,
32
35
  onActivate = _useContext.onActivate,
36
+ onTabsKeyDown = _useContext.onKeyDown,
33
37
  setActiveContent = _useContext.setActiveContent,
34
38
  setActiveTitle = _useContext.setActiveTitle,
35
39
  setFocusIndex = _useContext.setFocusIndex;
@@ -88,6 +92,13 @@ var Tab = /*#__PURE__*/forwardRef(function (_ref, ref) {
88
92
  onClick(event);
89
93
  }
90
94
  };
95
+ var onKeyDownTab = function onKeyDownTab(event) {
96
+ if (disabled) return;
97
+ onTabsKeyDown(event);
98
+ if (onKeyDown) {
99
+ onKeyDown(event);
100
+ }
101
+ };
91
102
  if (active && disabled) {
92
103
  console.warn(// eslint-disable-next-line max-len
93
104
  "Warning: Tab props 'active' and 'disabled' have both been set to TRUE on the same Tab resulting in an interesting Tab state. Is this your intent?");
@@ -157,19 +168,21 @@ var Tab = /*#__PURE__*/forwardRef(function (_ref, ref) {
157
168
  ref: tabRef,
158
169
  plain: true,
159
170
  role: "tab",
171
+ tabIndex: focusable ? 0 : -1,
172
+ "aria-controls": panelId,
160
173
  "aria-selected": active,
161
- "aria-expanded": active,
162
174
  disabled: disabled
163
175
  }, rest, {
164
176
  onClick: onClickTab,
177
+ onKeyDown: onKeyDownTab,
165
178
  onMouseOver: onMouseOverTab,
166
179
  onMouseOut: onMouseOutTab,
167
- onFocus: function onFocus() {
168
- if (_onFocus) _onFocus();
180
+ onFocus: function onFocus(event) {
181
+ if (_onFocus) _onFocus(event);
169
182
  setFocusIndex(index);
170
183
  },
171
- onBlur: function onBlur() {
172
- if (_onBlur) _onBlur();
184
+ onBlur: function onBlur(event) {
185
+ if (_onBlur) _onBlur(event);
173
186
  setFocusIndex(-1);
174
187
  }
175
188
  }), /*#__PURE__*/React.createElement(StyledTab, _extends({
@@ -10,7 +10,7 @@ import { Button } from '../Button';
10
10
  import { TabsContext } from './TabsContext';
11
11
  import { ResponsiveContext } from '../../contexts/ResponsiveContext';
12
12
  import { StyledTabPanel, StyledTabs, StyledTabsHeader } from './StyledTabs';
13
- import { normalizeColor } from '../../utils';
13
+ import { normalizeColor, useId } from '../../utils';
14
14
  import { MessageContext } from '../../contexts/MessageContext';
15
15
  import { TabsPropTypes } from './propTypes';
16
16
  import { useAnalytics } from '../../contexts/AnalyticsContext/AnalyticsContext';
@@ -55,6 +55,7 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
55
55
  focusIndex = _useState7[0],
56
56
  setFocusIndex = _useState7[1];
57
57
  var headerRef = useRef();
58
+ var panelId = useId();
58
59
  var size = useContext(ResponsiveContext);
59
60
  var PreviousIcon = ((_theme$tabs$header = theme.tabs.header) == null || (_theme$tabs$header = _theme$tabs$header.previousButton) == null ? void 0 : _theme$tabs$header.icon) || Previous;
60
61
  var NextIcon = ((_theme$tabs$header2 = theme.tabs.header) == null || (_theme$tabs$header2 = _theme$tabs$header2.nextButton) == null ? void 0 : _theme$tabs$header2.icon) || Next;
@@ -79,6 +80,114 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
79
80
  return /*#__PURE__*/React.createRef();
80
81
  });
81
82
  }, [children]);
83
+ var disabledIndexes = useMemo(function () {
84
+ return React.Children.map(children, function (child) {
85
+ if (! /*#__PURE__*/React.isValidElement(child)) return true;
86
+ return !!child.props.disabled;
87
+ }) || [];
88
+ }, [children]);
89
+ var focusTab = useCallback(function (index) {
90
+ var _tabRefs$index;
91
+ if (index >= 0 && (_tabRefs$index = tabRefs[index]) != null && _tabRefs$index.current) {
92
+ tabRefs[index].current.focus();
93
+ }
94
+ }, [tabRefs]);
95
+ var findEnabledIndex = useCallback(function (startIndex, direction) {
96
+ if (!disabledIndexes.length) return undefined;
97
+ var normalizeIndex = function normalizeIndex(index) {
98
+ if (index < 0) return disabledIndexes.length - 1;
99
+ if (index >= disabledIndexes.length) return 0;
100
+ return index;
101
+ };
102
+ var nextIndex = normalizeIndex(startIndex);
103
+ var attempts = 0;
104
+ while (attempts < disabledIndexes.length) {
105
+ if (!disabledIndexes[nextIndex]) {
106
+ return nextIndex;
107
+ }
108
+ nextIndex = normalizeIndex(nextIndex + direction);
109
+ attempts += 1;
110
+ }
111
+ return undefined;
112
+ }, [disabledIndexes]);
113
+ var getClosestEnabledIndex = useCallback(function (preferredIndex) {
114
+ if (!disabledIndexes.length) return undefined;
115
+ var clampedIndex = Math.min(Math.max(preferredIndex, 0), disabledIndexes.length - 1);
116
+ if (!disabledIndexes[clampedIndex]) {
117
+ return clampedIndex;
118
+ }
119
+ for (var offset = 1; offset < disabledIndexes.length; offset += 1) {
120
+ var nextIndex = clampedIndex + offset;
121
+ if (nextIndex < disabledIndexes.length && !disabledIndexes[nextIndex]) {
122
+ return nextIndex;
123
+ }
124
+ var previousIndex = clampedIndex - offset;
125
+ if (previousIndex >= 0 && !disabledIndexes[previousIndex]) {
126
+ return previousIndex;
127
+ }
128
+ }
129
+ return undefined;
130
+ }, [disabledIndexes]);
131
+ var resolvedActiveIndex = useMemo(function () {
132
+ if (!disabledIndexes.length) return undefined;
133
+ if (activeIndex < 0 || activeIndex >= disabledIndexes.length) {
134
+ return getClosestEnabledIndex(activeIndex);
135
+ }
136
+ if (disabledIndexes[activeIndex]) {
137
+ return getClosestEnabledIndex(activeIndex);
138
+ }
139
+ return activeIndex;
140
+ }, [activeIndex, disabledIndexes, getClosestEnabledIndex]);
141
+ var activateTab = useCallback(function (nextIndex) {
142
+ sendAnalytics({
143
+ type: 'activateTab',
144
+ element: tabRefs[nextIndex].current
145
+ });
146
+ if (propsActiveIndex === undefined) {
147
+ setActiveIndex(nextIndex);
148
+ }
149
+ if (onActive) {
150
+ onActive(nextIndex);
151
+ }
152
+ }, [onActive, propsActiveIndex, sendAnalytics, tabRefs]);
153
+ var moveFocus = useCallback(function (targetIndex) {
154
+ if (targetIndex === undefined) return;
155
+ focusTab(targetIndex);
156
+ }, [focusTab]);
157
+ var moveFocusByKey = useCallback(function (currentIndex, direction) {
158
+ moveFocus(findEnabledIndex(currentIndex + direction, direction));
159
+ }, [findEnabledIndex, moveFocus]);
160
+ var moveFocusToEdge = useCallback(function (direction) {
161
+ var startIndex = direction > 0 ? 0 : tabRefs.length - 1;
162
+ moveFocus(findEnabledIndex(startIndex, direction));
163
+ }, [findEnabledIndex, moveFocus, tabRefs.length]);
164
+ var handleTabKeyDown = useCallback(function (index, event) {
165
+ switch (event.key) {
166
+ case 'ArrowRight':
167
+ event.preventDefault();
168
+ moveFocusByKey(index, 1);
169
+ break;
170
+ case 'ArrowLeft':
171
+ event.preventDefault();
172
+ moveFocusByKey(index, -1);
173
+ break;
174
+ case 'Home':
175
+ event.preventDefault();
176
+ moveFocusToEdge(1);
177
+ break;
178
+ case 'End':
179
+ event.preventDefault();
180
+ moveFocusToEdge(-1);
181
+ break;
182
+ case 'Enter':
183
+ case ' ':
184
+ case 'Spacebar':
185
+ event.preventDefault();
186
+ activateTab(index);
187
+ break;
188
+ default:
189
+ }
190
+ }, [activateTab, moveFocusByKey, moveFocusToEdge]);
82
191
 
83
192
  // check if tab is in view
84
193
  var isVisible = useCallback(function (index) {
@@ -179,10 +288,10 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
179
288
  }
180
289
  };
181
290
  useEffect(function () {
182
- var _tabRefs$activeIndex;
291
+ var _tabRefs$resolvedActi;
183
292
  // if the active tab isn't visible scroll to it
184
- if (overflow && tabRefs && (_tabRefs$activeIndex = tabRefs[activeIndex]) != null && _tabRefs$activeIndex.current && !isVisible(activeIndex)) scrollTo(activeIndex, true);
185
- }, [overflow, activeIndex, tabRefs, isVisible, scrollTo]);
293
+ if (overflow && tabRefs && resolvedActiveIndex !== undefined && (_tabRefs$resolvedActi = tabRefs[resolvedActiveIndex]) != null && _tabRefs$resolvedActi.current && !isVisible(resolvedActiveIndex)) scrollTo(resolvedActiveIndex, true);
294
+ }, [overflow, resolvedActiveIndex, tabRefs, isVisible, scrollTo]);
186
295
  useEffect(function () {
187
296
  // scroll focus item into view if it is not already visible
188
297
  if (overflow && focusIndex !== -1 && !isVisible(focusIndex)) scrollTo(focusIndex, true);else if (overflow && focusIndex !== -1) {
@@ -211,33 +320,51 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
211
320
  return function () {
212
321
  return window.removeEventListener('resize', onResize);
213
322
  };
214
- }, [tabRefs, disableLeftArrow, disableRightArrow, activeIndex, headerRef, overflow, updateArrowState]);
323
+ }, [tabRefs, activeIndex, headerRef, updateArrowState]);
324
+ useLayoutEffect(function () {
325
+ if (focusIndex === -1 || !headerRef.current) return;
326
+ var _document = document,
327
+ activeElement = _document.activeElement;
328
+ if (headerRef.current.contains(activeElement)) return;
329
+ var nextFocusIndex = getClosestEnabledIndex(focusIndex);
330
+ if (nextFocusIndex === undefined) {
331
+ setFocusIndex(-1);
332
+ return;
333
+ }
334
+ setFocusIndex(nextFocusIndex);
335
+ focusTab(nextFocusIndex);
336
+ }, [children, focusIndex, focusTab, getClosestEnabledIndex]);
215
337
  var getTabsContext = useCallback(function (index) {
216
- var activateTab = function activateTab(nextIndex) {
217
- sendAnalytics({
218
- type: 'activateTab',
219
- element: tabRefs[nextIndex].current
220
- });
221
- if (propsActiveIndex === undefined) {
222
- setActiveIndex(nextIndex);
223
- }
224
- if (onActive) {
225
- onActive(nextIndex);
226
- }
227
- };
228
338
  return {
229
- activeIndex: activeIndex,
230
- active: activeIndex === index,
339
+ activeIndex: resolvedActiveIndex,
340
+ active: resolvedActiveIndex === index,
341
+ focusable: focusIndex === -1 ? resolvedActiveIndex === index : focusIndex === index,
231
342
  index: index,
343
+ panelId: panelId,
232
344
  ref: tabRefs[index],
233
345
  onActivate: function onActivate() {
234
346
  return activateTab(index);
235
347
  },
348
+ onKeyDown: function onKeyDown(event) {
349
+ return handleTabKeyDown(index, event);
350
+ },
351
+ onNext: function onNext() {
352
+ return moveFocusByKey(index, 1);
353
+ },
354
+ onPrevious: function onPrevious() {
355
+ return moveFocusByKey(index, -1);
356
+ },
357
+ onFirst: function onFirst() {
358
+ return moveFocusToEdge(1);
359
+ },
360
+ onLast: function onLast() {
361
+ return moveFocusToEdge(-1);
362
+ },
236
363
  setActiveContent: setActiveContent,
237
364
  setActiveTitle: setActiveTitle,
238
365
  setFocusIndex: setFocusIndex
239
366
  };
240
- }, [activeIndex, onActive, propsActiveIndex, sendAnalytics, tabRefs]);
367
+ }, [focusIndex, activateTab, handleTabKeyDown, moveFocusByKey, moveFocusToEdge, panelId, resolvedActiveIndex, tabRefs]);
241
368
  var tabs = React.Children.map(children, function (child, index) {
242
369
  return /*#__PURE__*/React.createElement(TabsContext.Provider, {
243
370
  value: getTabsContext(index)
@@ -247,7 +374,7 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
247
374
  // styled components that rely on props.active. We should reassess
248
375
  // if it is still necessary in our next major release.
249
376
  React.cloneElement(child, {
250
- active: activeIndex === index
377
+ active: resolvedActiveIndex === index
251
378
  }) : child);
252
379
  });
253
380
  var tabsHeaderStyles = {};
@@ -276,7 +403,10 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
276
403
  flex: false,
277
404
  direction: overflow ? 'row' : 'column'
278
405
  }, tabsHeaderStyles), overflow && /*#__PURE__*/React.createElement(Button, {
279
- a11yTitle: "Previous Tab",
406
+ a11yTitle: format({
407
+ id: 'tabs.previousTab',
408
+ messages: messages
409
+ }),
280
410
  disabled: disableLeftArrow
281
411
  // removed from tabIndex, button is redundant for keyboard users
282
412
  ,
@@ -301,7 +431,10 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
301
431
  pad: overflow ? '2px' : undefined,
302
432
  margin: overflow ? '-2px' : undefined
303
433
  }, passThemeFlag), tabs), overflow && /*#__PURE__*/React.createElement(Button, {
304
- a11yTitle: "Next Tab",
434
+ a11yTitle: format({
435
+ id: 'tabs.nextTab',
436
+ messages: messages
437
+ }),
305
438
  disabled: disableRightArrow
306
439
  // removed from tabIndex, button is redundant for keyboard users
307
440
  ,
@@ -314,6 +447,7 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
314
447
  }, /*#__PURE__*/React.createElement(NextIcon, {
315
448
  color: disableRightArrow ? theme.button.disabled.color : theme.global.colors.text
316
449
  })))), /*#__PURE__*/React.createElement(StyledTabPanel, _extends({
450
+ id: panelId,
317
451
  flex: flex,
318
452
  "aria-label": tabContentTitle,
319
453
  role: "tabpanel"
@@ -0,0 +1,2 @@
1
+ ## TimeInput
2
+ Documentation for this component: https://v2.grommet.io/timeinput
@@ -0,0 +1,68 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { disabledStyle, edgeStyle, focusStyle, inputStyle, normalizeColor, parseMetricToNum, plainInputStyle, readOnlyStyle, styledComponentsConfig } from '../../utils';
3
+ import { Box } from '../Box';
4
+ export var StyledTimeInputContainer = styled(Box).withConfig({
5
+ // Keep Box styling props like border and round flowing into Box.
6
+ shouldForwardProp: function shouldForwardProp(prop) {
7
+ return prop !== 'disabled' && prop !== 'readOnlyProp';
8
+ }
9
+ }).withConfig({
10
+ displayName: "StyledTimeInput__StyledTimeInputContainer",
11
+ componentId: "sc-xktdr3-0"
12
+ })(["", " ", " ", ""], function (props) {
13
+ return props.disabled && disabledStyle();
14
+ }, function (props) {
15
+ return props.readOnlyProp && readOnlyStyle(props.theme);
16
+ }, function (props) {
17
+ return props.focusIndicator !== false && css(["&:focus-within{", "}"], focusStyle());
18
+ });
19
+ export var StyledTimeInput = styled.input.withConfig(styledComponentsConfig).withConfig({
20
+ displayName: "StyledTimeInput",
21
+ componentId: "sc-xktdr3-1"
22
+ })(["", " ", " position:relative;pointer-events:none;color:transparent;caret-color:transparent;text-shadow:none;&::selection{background:transparent;color:transparent;}&::placeholder{color:transparent;}"], inputStyle, plainInputStyle);
23
+ export var StyledTimeInputField = styled.div.withConfig(styledComponentsConfig).withConfig({
24
+ displayName: "StyledTimeInput__StyledTimeInputField",
25
+ componentId: "sc-xktdr3-2"
26
+ })(["position:relative;flex:1 1 auto;min-width:0;"]);
27
+ export var StyledTimeInputDisplay = styled.div.withConfig(styledComponentsConfig).withConfig({
28
+ displayName: "StyledTimeInput__StyledTimeInputDisplay",
29
+ componentId: "sc-xktdr3-3"
30
+ })(["position:absolute;inset:0;display:flex;align-items:center;overflow:hidden;", ""], function (props) {
31
+ return props.theme.global.input.padding && (typeof props.theme.global.input.padding !== 'object' ? "padding: " + (parseMetricToNum(props.theme.global.edgeSize[props.theme.global.input.padding] || props.theme.global.input.padding) - parseMetricToNum(props.theme.global.control.border.width)) + "px;" : edgeStyle('padding', props.theme.global.input.padding, props.responsive, props.theme.box.responsiveBreakpoint, props.theme));
32
+ });
33
+ export var StyledTimeInputSeparator = styled.span.withConfig(styledComponentsConfig).withConfig({
34
+ displayName: "StyledTimeInput__StyledTimeInputSeparator",
35
+ componentId: "sc-xktdr3-4"
36
+ })(["display:inline-flex;align-items:center;line-height:inherit;color:", ";", ""], function (props) {
37
+ return normalizeColor(props.$filled ? 'text' : props.theme.global.colors.placeholder, props.theme);
38
+ }, function (props) {
39
+ var weight = props.theme.global.input.weight || props.theme.global.input.font.weight;
40
+ return weight && "font-weight: " + weight + ";";
41
+ });
42
+ export var StyledTimeInputSegment = styled.span.withConfig(styledComponentsConfig).withConfig({
43
+ displayName: "StyledTimeInput__StyledTimeInputSegment",
44
+ componentId: "sc-xktdr3-5"
45
+ })(["&:focus{outline:none;}display:inline-flex;align-items:center;position:relative;line-height:inherit;padding-inline:", ";color:", ";", " ", ""], function (props) {
46
+ var _props$theme$timeInpu, _props$theme$global$e;
47
+ var padToken = (_props$theme$timeInpu = props.theme.timeInput) == null || (_props$theme$timeInpu = _props$theme$timeInpu.active) == null ? void 0 : _props$theme$timeInpu.pad;
48
+ return ((_props$theme$global$e = props.theme.global.edgeSize) == null ? void 0 : _props$theme$global$e[padToken]) || padToken;
49
+ }, function (props) {
50
+ return normalizeColor(props.$filled ? 'text' : props.theme.global.colors.placeholder, props.theme);
51
+ }, function (props) {
52
+ var weight = props.theme.global.input.weight || props.theme.global.input.font.weight;
53
+ return weight && "font-weight: " + weight + ";";
54
+ }, function (props) {
55
+ var _props$theme$global$e2, _props$theme$timeInpu2, _props$theme$global$b, _props$theme$global$e3, _props$theme$timeInpu3, _props$theme$timeInpu4;
56
+ if (!props.$active) return '';
57
+
58
+ // The active indicator's corner rounding is intentionally a fixed
59
+ // "hair" edge size rather than a theme-exposed value we can expose
60
+ // theme in future.
61
+ var activeRound = (_props$theme$global$e2 = props.theme.global.edgeSize) == null ? void 0 : _props$theme$global$e2.hair;
62
+ var activeBorderToken = (_props$theme$timeInpu2 = props.theme.timeInput) == null || (_props$theme$timeInpu2 = _props$theme$timeInpu2.active) == null || (_props$theme$timeInpu2 = _props$theme$timeInpu2.indicator) == null ? void 0 : _props$theme$timeInpu2.size;
63
+ var activeBorderSize = ((_props$theme$global$b = props.theme.global.borderSize) == null ? void 0 : _props$theme$global$b[activeBorderToken]) || ((_props$theme$global$e3 = props.theme.global.edgeSize) == null ? void 0 : _props$theme$global$e3[activeBorderToken]) || activeBorderToken || props.theme.global.borderSize.small;
64
+ return css(["&::before{content:'';position:absolute;inset:0;background-color:", ";border-top-left-radius:", ";border-top-right-radius:", ";}&::after{content:'';position:absolute;left:0;right:0;bottom:0;height:", ";background-color:", ";border-bottom-left-radius:", ";border-bottom-right-radius:", ";}"], normalizeColor((_props$theme$timeInpu3 = props.theme.timeInput) == null || (_props$theme$timeInpu3 = _props$theme$timeInpu3.active) == null ? void 0 : _props$theme$timeInpu3.background, props.theme), activeRound, activeRound, activeBorderSize, normalizeColor(((_props$theme$timeInpu4 = props.theme.timeInput) == null || (_props$theme$timeInpu4 = _props$theme$timeInpu4.active) == null || (_props$theme$timeInpu4 = _props$theme$timeInpu4.indicator) == null ? void 0 : _props$theme$timeInpu4.color) || {
65
+ dark: 'white',
66
+ light: 'black'
67
+ }, props.theme), activeRound, activeRound);
68
+ });