@planningcenter/tapestry-react 2.1.2 → 2.2.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.
- package/dist/cjs/Badge/Badge.js +5 -1
- package/dist/cjs/Card/Card.js +5 -2
- package/dist/cjs/Combobox/Combobox.js +16 -43
- package/dist/cjs/Combobox/ComboboxInput.js +112 -146
- package/dist/cjs/Combobox/ComboboxItem.js +38 -53
- package/dist/cjs/Combobox/ComboboxItems.js +41 -58
- package/dist/cjs/Combobox/index.js +12 -0
- package/dist/cjs/DateField/DateField.js +109 -128
- package/dist/cjs/Field/Field.js +80 -106
- package/dist/cjs/Menu/Item.js +1 -0
- package/dist/cjs/Popover/utils.js +1 -0
- package/dist/cjs/SegmentedControl/SegmentedControl.js +89 -111
- package/dist/cjs/SegmentedTabs/SegmentedTabs.js +54 -84
- package/dist/cjs/Tabs/Tab.js +9 -6
- package/dist/cjs/Tabs/TabList.js +49 -64
- package/dist/cjs/Tabs/TabPanel.js +6 -2
- package/dist/cjs/Tabs/TabPanels.js +14 -27
- package/dist/cjs/Tabs/Tabs.js +72 -106
- package/dist/cjs/Tabs/index.js +12 -0
- package/dist/cjs/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.js +158 -182
- package/dist/cjs/Wizard/Wizard.js +143 -193
- package/dist/cjs/Wizard/index.js +3 -0
- package/dist/esm/Badge/Badge.js +5 -1
- package/dist/esm/Card/Card.js +5 -2
- package/dist/esm/Combobox/Combobox.js +18 -43
- package/dist/esm/Combobox/ComboboxInput.js +111 -149
- package/dist/esm/Combobox/ComboboxItem.js +38 -52
- package/dist/esm/Combobox/ComboboxItems.js +38 -56
- package/dist/esm/Combobox/index.js +8 -0
- package/dist/esm/DateField/DateField.js +106 -133
- package/dist/esm/Field/Field.js +76 -103
- package/dist/esm/Menu/Item.js +1 -0
- package/dist/esm/Popover/utils.js +1 -0
- package/dist/esm/SegmentedControl/SegmentedControl.js +90 -114
- package/dist/esm/SegmentedTabs/SegmentedTabs.js +51 -83
- package/dist/esm/Tabs/Tab.js +8 -6
- package/dist/esm/Tabs/TabList.js +49 -66
- package/dist/esm/Tabs/TabPanel.js +4 -2
- package/dist/esm/Tabs/TabPanels.js +14 -28
- package/dist/esm/Tabs/Tabs.js +76 -120
- package/dist/esm/Tabs/index.js +8 -0
- package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/esm/Tooltip/Tooltip.js +154 -195
- package/dist/esm/Wizard/Wizard.js +144 -201
- package/dist/esm/Wizard/index.js +2 -0
- package/dist/types/Popover/utils.d.ts +3 -0
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/Badge/Badge.js +5 -0
- package/src/Card/Card.tsx +22 -1
- package/src/Combobox/Combobox.js +18 -32
- package/src/Combobox/Combobox.mdx +1 -0
- package/src/Combobox/Combobox.test.js +1 -1
- package/src/Combobox/ComboboxInput.js +111 -105
- package/src/Combobox/ComboboxItem.js +27 -27
- package/src/Combobox/ComboboxItems.js +38 -60
- package/src/Combobox/index.js +8 -0
- package/src/DateField/DateField.js +109 -105
- package/src/DateField/DateField.mdx +1 -0
- package/src/Field/Field.js +85 -93
- package/src/Field/Field.mdx +1 -0
- package/src/Menu/Heading.js +5 -1
- package/src/Menu/Heading.mdx +20 -0
- package/src/Menu/Item.js +13 -1
- package/src/Menu/Item.mdx +18 -0
- package/src/Menu/Menu.mdx +1 -0
- package/src/Popover/utils.ts +1 -0
- package/src/SegmentedControl/SegmentedControl.js +88 -92
- package/src/SegmentedControl/SegmentedControl.mdx +1 -0
- package/src/SegmentedTabs/SegmentedTabs.js +51 -71
- package/src/SegmentedTabs/SegmentedTabs.mdx +1 -0
- package/src/Tabs/Tab.js +3 -1
- package/src/Tabs/TabList.js +56 -62
- package/src/Tabs/TabPanel.js +2 -1
- package/src/Tabs/TabPanels.js +14 -15
- package/src/Tabs/Tabs.js +63 -84
- package/src/Tabs/Tabs.mdx +16 -17
- package/src/Tabs/index.js +8 -0
- package/src/ThemeProvider/ThemeProvider.tsx +1 -1
- package/src/Tooltip/Tooltip.js +142 -160
- package/src/Tooltip/Tooltip.mdx +1 -0
- package/src/Wizard/Wizard.js +141 -170
- package/src/Wizard/Wizard.mdx +3 -2
- package/src/Wizard/index.js +2 -0
package/dist/esm/Tabs/Tabs.js
CHANGED
|
@@ -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
|
|
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
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
+
var nextTab = tabListRef.current.children[nextIndex];
|
|
27
50
|
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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;
|
package/dist/esm/Tabs/index.js
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
76
|
+
var close = function close() {
|
|
77
|
+
clearTimeout(openTimeoutId);
|
|
78
|
+
openTimeoutId = null;
|
|
79
|
+
setIsPopoverOpen(false);
|
|
146
80
|
};
|
|
147
81
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
clearTimeout(this.openTimeoutId);
|
|
151
|
-
clearTimeout(this.closeTimeoutId);
|
|
152
|
-
this.cleanupPageViewChange();
|
|
82
|
+
var toggle = function toggle() {
|
|
83
|
+
setIsPopoverOpen(!isPopoverOpen);
|
|
153
84
|
};
|
|
154
85
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
219
|
-
|
|
161
|
+
if (triggerOnHover) {
|
|
162
|
+
childProps.onMouseEnter = composeEvents(createOpenTimeout, onMouseEnter);
|
|
163
|
+
childProps.onMouseLeave = composeEvents(createCloseTimeout, onMouseLeave);
|
|
164
|
+
}
|
|
220
165
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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;
|