@planningcenter/tapestry-react 2.1.2 → 2.3.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 (88) hide show
  1. package/dist/cjs/Badge/Badge.js +5 -1
  2. package/dist/cjs/Button/Button.js +6 -3
  3. package/dist/cjs/Card/Card.js +5 -2
  4. package/dist/cjs/Combobox/Combobox.js +16 -43
  5. package/dist/cjs/Combobox/ComboboxInput.js +112 -146
  6. package/dist/cjs/Combobox/ComboboxItem.js +38 -53
  7. package/dist/cjs/Combobox/ComboboxItems.js +41 -58
  8. package/dist/cjs/Combobox/index.js +12 -0
  9. package/dist/cjs/DateField/DateField.js +109 -128
  10. package/dist/cjs/Field/Field.js +80 -106
  11. package/dist/cjs/Menu/Item.js +1 -0
  12. package/dist/cjs/Popover/utils.js +1 -0
  13. package/dist/cjs/SegmentedControl/SegmentedControl.js +89 -111
  14. package/dist/cjs/SegmentedTabs/SegmentedTabs.js +54 -84
  15. package/dist/cjs/Tabs/Tab.js +9 -6
  16. package/dist/cjs/Tabs/TabList.js +49 -64
  17. package/dist/cjs/Tabs/TabPanel.js +6 -2
  18. package/dist/cjs/Tabs/TabPanels.js +14 -27
  19. package/dist/cjs/Tabs/Tabs.js +72 -106
  20. package/dist/cjs/Tabs/index.js +12 -0
  21. package/dist/cjs/ThemeProvider/ThemeProvider.js +1 -1
  22. package/dist/cjs/Tooltip/Tooltip.js +158 -182
  23. package/dist/cjs/Wizard/Wizard.js +143 -193
  24. package/dist/cjs/Wizard/index.js +3 -0
  25. package/dist/esm/Badge/Badge.js +5 -1
  26. package/dist/esm/Button/Button.js +6 -3
  27. package/dist/esm/Card/Card.js +5 -2
  28. package/dist/esm/Combobox/Combobox.js +18 -43
  29. package/dist/esm/Combobox/ComboboxInput.js +111 -149
  30. package/dist/esm/Combobox/ComboboxItem.js +38 -52
  31. package/dist/esm/Combobox/ComboboxItems.js +38 -56
  32. package/dist/esm/Combobox/index.js +8 -0
  33. package/dist/esm/DateField/DateField.js +106 -133
  34. package/dist/esm/Field/Field.js +76 -103
  35. package/dist/esm/Menu/Item.js +1 -0
  36. package/dist/esm/Popover/utils.js +1 -0
  37. package/dist/esm/SegmentedControl/SegmentedControl.js +90 -114
  38. package/dist/esm/SegmentedTabs/SegmentedTabs.js +51 -83
  39. package/dist/esm/Tabs/Tab.js +8 -6
  40. package/dist/esm/Tabs/TabList.js +49 -66
  41. package/dist/esm/Tabs/TabPanel.js +4 -2
  42. package/dist/esm/Tabs/TabPanels.js +14 -28
  43. package/dist/esm/Tabs/Tabs.js +76 -120
  44. package/dist/esm/Tabs/index.js +8 -0
  45. package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
  46. package/dist/esm/Tooltip/Tooltip.js +154 -195
  47. package/dist/esm/Wizard/Wizard.js +144 -201
  48. package/dist/esm/Wizard/index.js +2 -0
  49. package/dist/types/Popover/utils.d.ts +3 -0
  50. package/package.json +1 -1
  51. package/src/.DS_Store +0 -0
  52. package/src/Badge/Badge.js +5 -0
  53. package/src/Button/Button.tsx +6 -3
  54. package/src/Card/Card.tsx +22 -1
  55. package/src/Combobox/Combobox.js +18 -32
  56. package/src/Combobox/Combobox.mdx +1 -0
  57. package/src/Combobox/Combobox.test.js +1 -1
  58. package/src/Combobox/ComboboxInput.js +111 -105
  59. package/src/Combobox/ComboboxItem.js +27 -27
  60. package/src/Combobox/ComboboxItems.js +38 -60
  61. package/src/Combobox/index.js +8 -0
  62. package/src/DateField/DateField.js +109 -105
  63. package/src/DateField/DateField.mdx +1 -0
  64. package/src/Field/Field.js +85 -93
  65. package/src/Field/Field.mdx +1 -0
  66. package/src/Menu/Heading.js +5 -1
  67. package/src/Menu/Heading.mdx +20 -0
  68. package/src/Menu/Item.js +13 -1
  69. package/src/Menu/Item.mdx +18 -0
  70. package/src/Menu/Menu.mdx +1 -0
  71. package/src/Popover/utils.ts +1 -0
  72. package/src/SegmentedControl/SegmentedControl.js +88 -92
  73. package/src/SegmentedControl/SegmentedControl.mdx +1 -0
  74. package/src/SegmentedTabs/SegmentedTabs.js +51 -71
  75. package/src/SegmentedTabs/SegmentedTabs.mdx +1 -0
  76. package/src/Tabs/Tab.js +3 -1
  77. package/src/Tabs/TabList.js +56 -62
  78. package/src/Tabs/TabPanel.js +2 -1
  79. package/src/Tabs/TabPanels.js +14 -15
  80. package/src/Tabs/Tabs.js +63 -84
  81. package/src/Tabs/Tabs.mdx +16 -17
  82. package/src/Tabs/index.js +8 -0
  83. package/src/ThemeProvider/ThemeProvider.tsx +1 -1
  84. package/src/Tooltip/Tooltip.js +142 -160
  85. package/src/Tooltip/Tooltip.mdx +1 -0
  86. package/src/Wizard/Wizard.js +141 -170
  87. package/src/Wizard/Wizard.mdx +3 -2
  88. package/src/Wizard/index.js +2 -0
@@ -1,133 +1,89 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
- import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
5
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
- import React, { Component, Children } from 'react';
3
+ import React, { useState, useRef, useCallback, Children } from 'react';
7
4
  import StackView from '../StackView';
8
5
  import { generateId } from '../utils';
9
- import Tab from './Tab';
10
- import TabList, { TABLIST_DISPLAY_NAME } from './TabList';
11
- import TabPanel from './TabPanel';
12
- import TabPanels, { TABPANELS_DISPLAY_NAME } from './TabPanels';
13
-
14
- var Tabs = /*#__PURE__*/function (_Component) {
15
- _inheritsLoose(Tabs, _Component);
16
-
17
- function Tabs() {
18
- var _this;
19
-
20
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
21
- args[_key] = arguments[_key];
6
+ import { useThemeProps } from '../system';
7
+ import { TABLIST_DISPLAY_NAME } from './TabList';
8
+ import { TABPANELS_DISPLAY_NAME } from './TabPanels';
9
+
10
+ function Tabs(props) {
11
+ var _useThemeProps = useThemeProps('tabs', props),
12
+ _useThemeProps$active = _useThemeProps.activeIndex,
13
+ activeIndex = _useThemeProps$active === void 0 ? null : _useThemeProps$active,
14
+ children = _useThemeProps.children,
15
+ _useThemeProps$defaul = _useThemeProps.defaultActiveIndex,
16
+ defaultActiveIndex = _useThemeProps$defaul === void 0 ? 0 : _useThemeProps$defaul,
17
+ onChange = _useThemeProps.onChange,
18
+ restProps = _objectWithoutPropertiesLoose(_useThemeProps, ["activeIndex", "children", "defaultActiveIndex", "onChange"]);
19
+
20
+ var id = generateId('tabs');
21
+
22
+ var _useState = useState(defaultActiveIndex),
23
+ localActiveIndex = _useState[0],
24
+ setLocalActiveIndex = _useState[1];
25
+
26
+ var tabListRef = useRef(null);
27
+ var setActiveIndex = useCallback(function (index) {
28
+ if (onChange) {
29
+ onChange(index);
22
30
  }
23
31
 
24
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
32
+ if (activeIndex === null) {
33
+ setLocalActiveIndex(index);
34
+ }
35
+ });
36
+ var getActiveIndex = useCallback(function () {
37
+ return activeIndex === null ? localActiveIndex : activeIndex;
38
+ });
39
+ var getNextTab = useCallback(function (startIndex, direction) {
40
+ var tabCount = tabListRef.current.children.length;
41
+ var nextIndex = startIndex + direction;
42
+
43
+ if (nextIndex < 0) {
44
+ nextIndex = tabCount - 1;
45
+ } else if (nextIndex >= tabCount) {
46
+ nextIndex = 0;
47
+ }
25
48
 
26
- _defineProperty(_assertThisInitialized(_this), "id", generateId('tabs'));
49
+ var nextTab = tabListRef.current.children[nextIndex];
27
50
 
28
- _defineProperty(_assertThisInitialized(_this), "state", {
29
- activeIndex: _this.props.defaultActiveIndex
30
- });
51
+ if (nextTab.getAttribute('aria-disabled') === 'true') {
52
+ return getNextTab(nextIndex, direction);
53
+ } else {
54
+ return nextTab;
55
+ }
56
+ });
57
+ var moveTabFocus = useCallback(function (direction) {
58
+ var nextTab = getNextTab(getActiveIndex(), direction);
31
59
 
32
- _defineProperty(_assertThisInitialized(_this), "setTabList", function (node) {
60
+ if (nextTab) {
61
+ nextTab.focus();
62
+ }
63
+ });
64
+ return /*#__PURE__*/React.createElement(StackView, _extends({
65
+ innerRef: function innerRef(node) {
33
66
  if (node) {
34
- _this.tabList = node.querySelector('[role="tablist"]');
35
- }
36
- });
37
-
38
- _defineProperty(_assertThisInitialized(_this), "setActiveIndex", function (activeIndex) {
39
- if (_this.props.onChange) {
40
- _this.props.onChange(activeIndex);
41
- }
42
-
43
- if (_this.props.activeIndex === null) {
44
- _this.setState({
45
- activeIndex: activeIndex
46
- });
47
- }
48
- });
49
-
50
- _defineProperty(_assertThisInitialized(_this), "getActiveIndex", function () {
51
- return _this.props.activeIndex === null ? _this.state.activeIndex : _this.props.activeIndex;
52
- });
53
-
54
- _defineProperty(_assertThisInitialized(_this), "getNextTab", function (startIndex, direction) {
55
- var tabCount = _this.tabList.children.length;
56
- var nextIndex = startIndex + direction;
57
-
58
- if (nextIndex < 0) {
59
- nextIndex = tabCount - 1;
60
- } else if (nextIndex >= tabCount) {
61
- nextIndex = 0;
62
- }
63
-
64
- var nextTab = _this.tabList.children[nextIndex];
65
-
66
- if (nextTab.getAttribute('aria-disabled') === 'true') {
67
- return _this.getNextTab(nextIndex, direction);
68
- } else {
69
- return nextTab;
67
+ tabListRef.current = node.querySelector('[role="tablist"]');
70
68
  }
71
- });
72
-
73
- _defineProperty(_assertThisInitialized(_this), "moveTabFocus", function (direction) {
74
- var nextTab = _this.getNextTab(_this.getActiveIndex(), direction);
75
-
76
- if (nextTab) {
77
- nextTab.focus();
78
- }
79
- });
80
-
81
- return _this;
82
- }
83
-
84
- var _proto = Tabs.prototype;
85
-
86
- _proto.render = function render() {
87
- var _this2 = this;
88
-
89
- var _this$props = this.props,
90
- activeIndex = _this$props.activeIndex,
91
- children = _this$props.children,
92
- defaultActiveIndex = _this$props.defaultActiveIndex,
93
- onChange = _this$props.onChange,
94
- restProps = _objectWithoutPropertiesLoose(_this$props, ["activeIndex", "children", "defaultActiveIndex", "onChange"]);
95
-
96
- return /*#__PURE__*/React.createElement(StackView, _extends({
97
- innerRef: this.setTabList
98
- }, restProps), Children.map(children, function (child, index) {
99
- if (child && child.type.displayName === TABLIST_DISPLAY_NAME) {
100
- return /*#__PURE__*/React.cloneElement(child, {
101
- id: _this2.id,
102
- activeIndex: _this2.getActiveIndex(),
103
- moveTabFocus: _this2.moveTabFocus,
104
- setActiveIndex: _this2.setActiveIndex
105
- });
106
- } else if (child && child.type.displayName === TABPANELS_DISPLAY_NAME) {
107
- return /*#__PURE__*/React.cloneElement(child, {
108
- id: _this2.id,
109
- activeIndex: _this2.getActiveIndex()
110
- });
111
- } else {
112
- return child;
113
- }
114
- }));
115
- };
116
-
117
- return Tabs;
118
- }(Component);
119
-
120
- _defineProperty(Tabs, "Tab", Tab);
121
-
122
- _defineProperty(Tabs, "TabList", TabList);
123
-
124
- _defineProperty(Tabs, "TabPanel", TabPanel);
125
-
126
- _defineProperty(Tabs, "TabPanels", TabPanels);
127
-
128
- _defineProperty(Tabs, "defaultProps", {
129
- activeIndex: null,
130
- defaultActiveIndex: 0
131
- });
69
+ }
70
+ }, restProps), Children.map(children, function (child, index) {
71
+ if (child && child.type.displayName === TABLIST_DISPLAY_NAME) {
72
+ return /*#__PURE__*/React.cloneElement(child, {
73
+ id: id,
74
+ activeIndex: getActiveIndex(),
75
+ moveTabFocus: moveTabFocus,
76
+ setActiveIndex: setActiveIndex
77
+ });
78
+ } else if (child && child.type.displayName === TABPANELS_DISPLAY_NAME) {
79
+ return /*#__PURE__*/React.cloneElement(child, {
80
+ id: id,
81
+ activeIndex: getActiveIndex()
82
+ });
83
+ } else {
84
+ return child;
85
+ }
86
+ }));
87
+ }
132
88
 
133
89
  export default Tabs;
@@ -1,2 +1,10 @@
1
1
  import Tabs from './Tabs';
2
+ import Tab from './Tab';
3
+ import TabList from './TabList';
4
+ import TabPanel from './TabPanel';
5
+ import TabPanels from './TabPanels';
6
+ Tabs.Tab = Tab;
7
+ Tabs.TabList = TabList;
8
+ Tabs.TabPanel = TabPanel;
9
+ Tabs.TabPanels = TabPanels;
2
10
  export default Tabs;
@@ -25,7 +25,7 @@ export var themeStorage = {
25
25
  return window.localStorage.setItem(STORAGE_KEY, value);
26
26
  }
27
27
  };
28
- export var themeInitializerScript = "\ntry {\n var theme = window.localStorage.getItem('" + STORAGE_KEY + "')\n if (theme) {\n document.body.dataset.theme = theme\n }\n} catch (e) {}\n";
28
+ export var themeInitializerScript = "\ntry {\n var theme = window.localStorage.getItem('" + STORAGE_KEY + "')\n if (theme) {\n document.documentElement.dataset.theme = theme\n }\n} catch (e) {}\n";
29
29
  var emptyTheme = {};
30
30
 
31
31
  function mergeThemes(a, b) {
@@ -1,12 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
- import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
5
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
- import React, { Component, Children, cloneElement } from 'react';
3
+ import React, { Children, cloneElement, forwardRef, useState, useCallback, useImperativeHandle, useEffect } from 'react';
7
4
  import mitt from 'mitt';
8
5
  import Popover from '../Popover';
9
6
  import { composeEvents, pageViewChange } from '../utils';
7
+ import { useThemeProps } from '../system';
10
8
  var emitter = mitt();
11
9
  var globalTimeoutId = null;
12
10
  var instantDelay = false;
@@ -22,209 +20,170 @@ function clearGlobalTimeout() {
22
20
  clearTimeout(globalTimeoutId);
23
21
  }
24
22
 
25
- var Tooltip = /*#__PURE__*/function (_Component) {
26
- _inheritsLoose(Tooltip, _Component);
27
-
28
- function Tooltip() {
29
- var _this;
30
-
31
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
32
- args[_key] = arguments[_key];
33
- }
34
-
35
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
36
-
37
- _defineProperty(_assertThisInitialized(_this), "state", {
38
- isPopoverOpen: _this.props.defaultOpen
39
- });
40
-
41
- _defineProperty(_assertThisInitialized(_this), "isPageInView", true);
42
-
43
- _defineProperty(_assertThisInitialized(_this), "isFocused", false);
44
-
45
- _defineProperty(_assertThisInitialized(_this), "isMouseDown", false);
46
-
47
- _defineProperty(_assertThisInitialized(_this), "openTimeoutId", null);
48
-
49
- _defineProperty(_assertThisInitialized(_this), "closeTimeoutId", null);
50
-
51
- _defineProperty(_assertThisInitialized(_this), "cleanupPageViewChange", pageViewChange(function (inView) {
52
- return setTimeout(function () {
53
- return _this.isPageInView = inView;
54
- });
55
- }));
56
-
57
- _defineProperty(_assertThisInitialized(_this), "handleCloseOpenTooltips", function (instance) {
58
- if (_assertThisInitialized(_this) !== instance) {
59
- _this.close();
60
- }
61
- });
62
-
63
- _defineProperty(_assertThisInitialized(_this), "createOpenTimeout", function () {
64
- clearGlobalTimeout();
65
-
66
- if (_this.openTimeoutId === null) {
67
- clearTimeout(_this.closeTimeoutId);
68
- _this.closeTimeoutId = null;
69
-
70
- if (_this.state.isPopoverOpen === false) {
71
- emitter.emit('CLOSE_OPEN_TOOLTIPS');
72
- _this.openTimeoutId = setTimeout(function () {
73
- return _this.open();
74
- }, instantDelay ? 0 : _this.props.openDelay);
75
- }
76
- }
77
- });
78
-
79
- _defineProperty(_assertThisInitialized(_this), "createCloseTimeout", function () {
80
- startGlobalTimeout();
81
-
82
- if (_this.closeTimeoutId === null) {
83
- clearTimeout(_this.openTimeoutId);
84
- _this.openTimeoutId = null;
85
- _this.closeTimeoutId = setTimeout(function () {
86
- _this.close();
87
- }, _this.props.closeDelay);
88
- }
89
- });
90
-
91
- _defineProperty(_assertThisInitialized(_this), "open", function () {
92
- clearTimeout(_this.closeTimeoutId);
93
- _this.closeTimeoutId = null;
94
-
95
- _this.setState({
96
- isPopoverOpen: true
97
- });
98
- });
99
-
100
- _defineProperty(_assertThisInitialized(_this), "close", function () {
101
- clearTimeout(_this.openTimeoutId);
102
- _this.openTimeoutId = null;
103
-
104
- _this.setState({
105
- isPopoverOpen: false
106
- });
107
- });
108
-
109
- _defineProperty(_assertThisInitialized(_this), "toggle", function () {
110
- _this.setState(function (state) {
111
- return {
112
- isPopoverOpen: !state.isPopoverOpen
113
- };
114
- });
115
- });
116
-
117
- _defineProperty(_assertThisInitialized(_this), "handleFocus", function () {
118
- if (_this.isPageInView && !_this.isMouseDown) {
119
- _this.open();
120
- }
23
+ function Tooltip(props, ref) {
24
+ var _useThemeProps = useThemeProps('tooltip', props),
25
+ children = _useThemeProps.children,
26
+ _useThemeProps$openDe = _useThemeProps.openDelay,
27
+ openDelay = _useThemeProps$openDe === void 0 ? 500 : _useThemeProps$openDe,
28
+ _useThemeProps$closeD = _useThemeProps.closeDelay,
29
+ closeDelay = _useThemeProps$closeD === void 0 ? 300 : _useThemeProps$closeD,
30
+ _useThemeProps$defaul = _useThemeProps.defaultOpen,
31
+ defaultOpen = _useThemeProps$defaul === void 0 ? false : _useThemeProps$defaul,
32
+ _useThemeProps$keepIn = _useThemeProps.keepInView,
33
+ keepInView = _useThemeProps$keepIn === void 0 ? true : _useThemeProps$keepIn,
34
+ placement = _useThemeProps.placement,
35
+ popoverProps = _useThemeProps.popoverProps,
36
+ renderTo = _useThemeProps.renderTo,
37
+ title = _useThemeProps.title,
38
+ _useThemeProps$trigge = _useThemeProps.triggerOnFocus,
39
+ triggerOnFocus = _useThemeProps$trigge === void 0 ? true : _useThemeProps$trigge,
40
+ _useThemeProps$trigge2 = _useThemeProps.triggerOnHover,
41
+ triggerOnHover = _useThemeProps$trigge2 === void 0 ? true : _useThemeProps$trigge2,
42
+ childProps = _objectWithoutPropertiesLoose(_useThemeProps, ["children", "openDelay", "closeDelay", "defaultOpen", "keepInView", "placement", "popoverProps", "renderTo", "title", "triggerOnFocus", "triggerOnHover"]);
43
+
44
+ var isPageInView = true;
45
+ var isFocused = false;
46
+ var isMouseDown = false;
47
+ var openTimeoutId = null;
48
+ var closeTimeoutId = null; // prevents tooltips showing when focused and navigating back to a page after leaving
49
+
50
+ var cleanupPageViewChange = useCallback(pageViewChange(function (inView) {
51
+ return setTimeout(function () {
52
+ return isPageInView = inView;
121
53
  });
122
-
123
- _defineProperty(_assertThisInitialized(_this), "handleMouseDown", function () {
124
- _this.isMouseDown = true;
125
-
126
- _this.close();
127
- });
128
-
129
- _defineProperty(_assertThisInitialized(_this), "handleMouseUp", function () {
130
- _this.isMouseDown = false;
131
- });
132
-
133
- return _this;
134
- }
135
-
136
- var _proto = Tooltip.prototype;
137
-
138
- _proto.componentDidMount = function componentDidMount() {
139
- emitter.on('CLOSE_OPEN_TOOLTIPS', this.handleCloseOpenTooltips);
54
+ }));
55
+
56
+ var _useState = useState(defaultOpen),
57
+ isPopoverOpen = _useState[0],
58
+ setIsPopoverOpen = _useState[1];
59
+
60
+ useEffect(function () {
61
+ emitter.on('CLOSE_OPEN_TOOLTIPS', close);
62
+ return function () {
63
+ emitter.off('CLOSE_OPEN_TOOLTIPS', close);
64
+ clearTimeout(openTimeoutId);
65
+ clearTimeout(closeTimeoutId);
66
+ cleanupPageViewChange();
67
+ };
68
+ }, []);
69
+
70
+ var open = function open() {
71
+ clearTimeout(closeTimeoutId);
72
+ closeTimeoutId = null;
73
+ setIsPopoverOpen(true);
140
74
  };
141
75
 
142
- _proto.componentDidUpdate = function componentDidUpdate(lastProps) {
143
- if (lastProps.triggerOnFocus !== this.props.triggerOnFocus && this.props.triggerOnFocus === false || lastProps.triggerOnHover !== this.props.triggerOnHover && this.triggerOnHover === false) {
144
- this.close();
145
- }
76
+ var close = function close() {
77
+ clearTimeout(openTimeoutId);
78
+ openTimeoutId = null;
79
+ setIsPopoverOpen(false);
146
80
  };
147
81
 
148
- _proto.componentWillUnmount = function componentWillUnmount() {
149
- emitter.off('CLOSE_OPEN_TOOLTIPS', this.handleCloseOpenTooltips);
150
- clearTimeout(this.openTimeoutId);
151
- clearTimeout(this.closeTimeoutId);
152
- this.cleanupPageViewChange();
82
+ var toggle = function toggle() {
83
+ setIsPopoverOpen(!isPopoverOpen);
153
84
  };
154
85
 
155
- _proto.render = function render() {
156
- var _this$props = this.props,
157
- children = _this$props.children,
158
- openDelay = _this$props.openDelay,
159
- closeDelay = _this$props.closeDelay,
160
- defaultOpen = _this$props.defaultOpen,
161
- keepInView = _this$props.keepInView,
162
- placement = _this$props.placement,
163
- popoverProps = _this$props.popoverProps,
164
- renderTo = _this$props.renderTo,
165
- title = _this$props.title,
166
- triggerOnFocus = _this$props.triggerOnFocus,
167
- triggerOnHover = _this$props.triggerOnHover,
168
- childProps = _objectWithoutPropertiesLoose(_this$props, ["children", "openDelay", "closeDelay", "defaultOpen", "keepInView", "placement", "popoverProps", "renderTo", "title", "triggerOnFocus", "triggerOnHover"]);
169
-
170
- var isPopoverOpen = this.state.isPopoverOpen;
171
- var child = Children.only(children);
172
- var _child$props = child.props,
173
- onFocus = _child$props.onFocus,
174
- onBlur = _child$props.onBlur,
175
- onMouseEnter = _child$props.onMouseEnter,
176
- onMouseLeave = _child$props.onMouseLeave,
177
- onMouseDown = _child$props.onMouseDown,
178
- onMouseUp = _child$props.onMouseUp;
179
-
180
- if (!title) {
181
- return /*#__PURE__*/cloneElement(child, childProps);
86
+ useImperativeHandle(ref, function () {
87
+ return {
88
+ open: open,
89
+ close: close,
90
+ toggle: toggle
91
+ };
92
+ });
93
+ useEffect(function () {
94
+ if (triggerOnFocus === false) {
95
+ close();
182
96
  }
183
-
184
- if (triggerOnFocus) {
185
- childProps.onFocus = composeEvents(this.handleFocus, onFocus);
186
- childProps.onBlur = composeEvents(this.close, onBlur);
187
- childProps.onMouseDown = composeEvents(this.handleMouseDown, onMouseDown);
188
- childProps.onMouseUp = composeEvents(this.handleMouseUp, onMouseUp);
97
+ }, [triggerOnFocus]);
98
+ useEffect(function () {
99
+ if (triggerOnHover === false) {
100
+ close();
189
101
  }
190
-
191
- if (triggerOnHover) {
192
- childProps.onMouseEnter = composeEvents(this.createOpenTimeout, onMouseEnter);
193
- childProps.onMouseLeave = composeEvents(this.createCloseTimeout, onMouseLeave);
102
+ }, [triggerOnHover]);
103
+ var createOpenTimeout = useCallback(function () {
104
+ clearGlobalTimeout();
105
+
106
+ if (openTimeoutId === null) {
107
+ clearTimeout(closeTimeoutId);
108
+ closeTimeoutId = null;
109
+
110
+ if (isPopoverOpen === false) {
111
+ emitter.emit('CLOSE_OPEN_TOOLTIPS');
112
+ openTimeoutId = setTimeout(function () {
113
+ return open();
114
+ }, instantDelay ? 0 : openDelay);
115
+ }
116
+ }
117
+ });
118
+ var createCloseTimeout = useCallback(function () {
119
+ startGlobalTimeout();
120
+
121
+ if (closeTimeoutId === null) {
122
+ clearTimeout(openTimeoutId);
123
+ openTimeoutId = null;
124
+ closeTimeoutId = setTimeout(function () {
125
+ close();
126
+ }, closeDelay);
194
127
  }
128
+ });
129
+ var handleFocus = useCallback(function () {
130
+ if (isPageInView && !isMouseDown) {
131
+ open();
132
+ }
133
+ });
134
+ var handleMouseDown = useCallback(function () {
135
+ isMouseDown = true;
136
+ close();
137
+ });
138
+ var handleMouseUp = useCallback(function () {
139
+ isMouseDown = false;
140
+ });
141
+ var child = Children.only(children);
142
+ var _child$props = child.props,
143
+ onFocus = _child$props.onFocus,
144
+ onBlur = _child$props.onBlur,
145
+ onMouseEnter = _child$props.onMouseEnter,
146
+ onMouseLeave = _child$props.onMouseLeave,
147
+ onMouseDown = _child$props.onMouseDown,
148
+ onMouseUp = _child$props.onMouseUp;
149
+
150
+ if (!title) {
151
+ return /*#__PURE__*/cloneElement(child, childProps);
152
+ }
195
153
 
196
- return /*#__PURE__*/React.createElement(Popover, _extends({
197
- shouldFlip: true,
198
- paddingHorizontal: 0.75,
199
- paddingVertical: 0.25,
200
- fontSize: 5,
201
- textAlign: "center",
202
- radius: 2,
203
- backgroundColor: "grey-9",
204
- color: "rgba(255,255,255,0.94)",
205
- zIndex: 9999
206
- }, popoverProps, {
207
- anchorElement: /*#__PURE__*/cloneElement(child, childProps),
208
- onMouseEnter: this.createOpenTimeout,
209
- onMouseLeave: this.createCloseTimeout,
210
- keepInView: keepInView,
211
- placement: placement,
212
- renderTo: renderTo,
213
- children: title,
214
- open: isPopoverOpen
215
- }));
216
- };
154
+ if (triggerOnFocus) {
155
+ childProps.onFocus = composeEvents(handleFocus, onFocus);
156
+ childProps.onBlur = composeEvents(close, onBlur);
157
+ childProps.onMouseDown = composeEvents(handleMouseDown, onMouseDown);
158
+ childProps.onMouseUp = composeEvents(handleMouseUp, onMouseUp);
159
+ }
217
160
 
218
- return Tooltip;
219
- }(Component);
161
+ if (triggerOnHover) {
162
+ childProps.onMouseEnter = composeEvents(createOpenTimeout, onMouseEnter);
163
+ childProps.onMouseLeave = composeEvents(createCloseTimeout, onMouseLeave);
164
+ }
220
165
 
221
- _defineProperty(Tooltip, "defaultProps", {
222
- openDelay: 500,
223
- closeDelay: 300,
224
- keepInView: true,
225
- triggerOnFocus: true,
226
- triggerOnHover: true,
227
- defaultOpen: false
228
- });
166
+ return /*#__PURE__*/React.createElement(Popover, _extends({
167
+ shouldFlip: true,
168
+ paddingHorizontal: 0.75,
169
+ paddingVertical: 0.25,
170
+ fontSize: 5,
171
+ textAlign: "center",
172
+ radius: 2,
173
+ backgroundColor: "grey-9",
174
+ color: "rgba(255,255,255,0.94)",
175
+ zIndex: 9999
176
+ }, popoverProps, {
177
+ anchorElement: /*#__PURE__*/cloneElement(child, childProps),
178
+ onMouseEnter: createOpenTimeout,
179
+ onMouseLeave: createCloseTimeout,
180
+ keepInView: keepInView,
181
+ placement: placement,
182
+ renderTo: renderTo,
183
+ children: title,
184
+ open: isPopoverOpen
185
+ }));
186
+ }
229
187
 
188
+ Tooltip = /*#__PURE__*/forwardRef(Tooltip);
230
189
  export default Tooltip;