@carbon/react 1.0.0-rc.0 → 1.0.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/es/components/Accordion/Accordion.Skeleton.js +1 -7
- package/es/components/Accordion/AccordionItem.js +0 -5
- package/es/components/Button/Button.Skeleton.js +1 -3
- package/es/components/Button/Button.js +51 -113
- package/es/components/Checkbox/Checkbox.js +8 -21
- package/es/components/CodeSnippet/CodeSnippet.js +3 -11
- package/es/components/ComboBox/ComboBox.js +2 -4
- package/es/components/ContentSwitcher/index.js +13 -0
- package/es/components/DataTable/DataTable.js +5 -14
- package/es/components/DataTable/Table.js +3 -11
- package/es/components/DataTable/TableBatchAction.js +2 -1
- package/es/components/DataTable/TableExpandHeader.js +1 -1
- package/es/components/DataTable/TableToolbar.js +1 -2
- package/es/components/DataTable/TableToolbarSearch.js +4 -13
- package/es/components/DatePickerInput/next/DatePickerInput.js +6 -31
- package/es/components/Dropdown/Dropdown.Skeleton.js +4 -13
- package/es/components/Dropdown/Dropdown.js +4 -9
- package/es/components/ExpandableSearch/ExpandableSearch.js +16 -22
- package/es/components/FormGroup/FormGroup.js +4 -14
- package/es/components/IconButton/index.js +0 -1
- package/es/components/InlineLoading/InlineLoading.js +2 -9
- package/es/components/ListBox/ListBox.js +10 -0
- package/es/components/Modal/next/Modal.js +5 -8
- package/es/components/MultiSelect/FilterableMultiSelect.js +1 -2
- package/es/components/MultiSelect/MultiSelect.js +2 -3
- package/es/components/MultiSelect/next/FilterableMultiSelect.js +1 -2
- package/es/components/Notification/next/Notification.js +18 -39
- package/es/components/OverflowMenuItem/OverflowMenuItem.js +1 -9
- package/es/components/RadioTile/RadioTile.js +6 -13
- package/es/components/Search/index.js +3 -3
- package/es/components/Search/next/Search.js +25 -20
- package/es/components/Select/Select.js +6 -14
- package/es/components/Slider/Slider.js +4 -14
- package/es/components/StructuredList/next/StructuredList.js +7 -11
- package/es/components/TextInput/ControlledPasswordInput.js +2 -2
- package/es/components/Tile/next/Tile.js +12 -51
- package/es/components/TileGroup/index.js +13 -0
- package/es/components/TimePickerSelect/next/TimePickerSelect.js +0 -6
- package/es/components/Tooltip/next/DefinitionTooltip.js +1 -1
- package/es/index.js +4 -6
- package/es/internal/ComponentToggle.js +1 -0
- package/lib/components/Accordion/Accordion.Skeleton.js +1 -7
- package/lib/components/Accordion/AccordionItem.js +0 -5
- package/lib/components/Button/Button.Skeleton.js +1 -3
- package/lib/components/Button/Button.js +49 -130
- package/lib/components/Checkbox/Checkbox.js +8 -21
- package/lib/components/CodeSnippet/CodeSnippet.js +3 -11
- package/lib/components/ComboBox/ComboBox.js +2 -4
- package/lib/components/ContentSwitcher/index.js +17 -0
- package/lib/components/DataTable/DataTable.js +5 -33
- package/lib/components/DataTable/Table.js +3 -30
- package/lib/components/DataTable/TableBatchAction.js +2 -1
- package/lib/components/DataTable/TableExpandHeader.js +1 -1
- package/lib/components/DataTable/TableToolbar.js +1 -21
- package/lib/components/DataTable/TableToolbarSearch.js +4 -13
- package/lib/components/DatePickerInput/next/DatePickerInput.js +5 -30
- package/lib/components/Dropdown/Dropdown.Skeleton.js +4 -13
- package/lib/components/Dropdown/Dropdown.js +4 -9
- package/lib/components/ExpandableSearch/ExpandableSearch.js +15 -21
- package/lib/components/FormGroup/FormGroup.js +3 -13
- package/lib/components/IconButton/index.js +0 -1
- package/lib/components/InlineLoading/InlineLoading.js +2 -9
- package/lib/components/ListBox/ListBox.js +10 -0
- package/lib/components/Modal/next/Modal.js +5 -8
- package/lib/components/MultiSelect/FilterableMultiSelect.js +1 -2
- package/lib/components/MultiSelect/MultiSelect.js +2 -3
- package/lib/components/MultiSelect/next/FilterableMultiSelect.js +1 -2
- package/lib/components/Notification/next/Notification.js +18 -39
- package/lib/components/OverflowMenuItem/OverflowMenuItem.js +1 -9
- package/lib/components/RadioTile/RadioTile.js +6 -13
- package/lib/components/Search/next/Search.js +25 -20
- package/lib/components/Select/Select.js +6 -33
- package/lib/components/Slider/Slider.js +4 -14
- package/lib/components/StructuredList/next/StructuredList.js +7 -11
- package/lib/components/TextInput/ControlledPasswordInput.js +2 -2
- package/lib/components/Tile/next/Tile.js +12 -51
- package/lib/components/TileGroup/index.js +17 -0
- package/lib/components/TimePickerSelect/next/TimePickerSelect.js +0 -6
- package/lib/components/Tooltip/next/DefinitionTooltip.js +1 -1
- package/lib/index.js +94 -98
- package/lib/internal/ComponentToggle.js +1 -0
- package/package.json +9 -9
- package/es/components/TooltipDefinition/TooltipDefinition.js +0 -167
- package/es/components/TooltipIcon/TooltipIcon.js +0 -235
- package/es/tools/createPropAdapter.js +0 -63
- package/lib/components/TooltipDefinition/TooltipDefinition.js +0 -178
- package/lib/components/TooltipIcon/TooltipIcon.js +0 -245
- package/lib/tools/createPropAdapter.js +0 -67
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2021
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import cx from 'classnames';
|
|
10
|
-
import React__default, { useState, useRef, useEffect } from 'react';
|
|
11
|
-
import PropTypes from 'prop-types';
|
|
12
|
-
import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
|
|
13
|
-
import { composeEventHandlers } from '../../tools/events.js';
|
|
14
|
-
import toggleClass from '../../tools/toggleClass.js';
|
|
15
|
-
import { usePrefix } from '../../internal/usePrefix.js';
|
|
16
|
-
import { matches } from '../../internal/keyboard/match.js';
|
|
17
|
-
import { Escape } from '../../internal/keyboard/keys.js';
|
|
18
|
-
|
|
19
|
-
var _excluded = ["id", "className", "children", "direction", "disabled", "align", "onClick", "onBlur", "onFocus", "onMouseEnter", "onMouseLeave", "renderIcon", "tooltipText"];
|
|
20
|
-
var getInstanceId = setupGetInstanceId();
|
|
21
|
-
|
|
22
|
-
var TooltipIcon = function TooltipIcon(_ref) {
|
|
23
|
-
var _cx;
|
|
24
|
-
|
|
25
|
-
var id = _ref.id,
|
|
26
|
-
className = _ref.className,
|
|
27
|
-
children = _ref.children,
|
|
28
|
-
direction = _ref.direction,
|
|
29
|
-
disabled = _ref.disabled,
|
|
30
|
-
align = _ref.align,
|
|
31
|
-
onClick = _ref.onClick,
|
|
32
|
-
onBlur = _ref.onBlur,
|
|
33
|
-
onFocus = _ref.onFocus,
|
|
34
|
-
onMouseEnter = _ref.onMouseEnter,
|
|
35
|
-
onMouseLeave = _ref.onMouseLeave,
|
|
36
|
-
IconElement = _ref.renderIcon,
|
|
37
|
-
tooltipText = _ref.tooltipText,
|
|
38
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
39
|
-
|
|
40
|
-
var prefix = usePrefix();
|
|
41
|
-
|
|
42
|
-
var _useState = useState(true),
|
|
43
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
44
|
-
allowTooltipVisibility = _useState2[0],
|
|
45
|
-
setAllowTooltipVisibility = _useState2[1];
|
|
46
|
-
|
|
47
|
-
var _useState3 = useState(false),
|
|
48
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
49
|
-
isHovered = _useState4[0],
|
|
50
|
-
setIsHovered = _useState4[1];
|
|
51
|
-
|
|
52
|
-
var _useState5 = useState(false),
|
|
53
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
54
|
-
isFocused = _useState6[0],
|
|
55
|
-
setIsFocused = _useState6[1];
|
|
56
|
-
|
|
57
|
-
var tooltipRef = useRef(null);
|
|
58
|
-
var tooltipTimeout = useRef(null);
|
|
59
|
-
var tooltipId = id || "icon-tooltip-".concat(getInstanceId());
|
|
60
|
-
var tooltipTriggerClasses = cx("".concat(prefix, "--tooltip__trigger"), "".concat(prefix, "--tooltip--a11y"), className, (_cx = {}, _defineProperty(_cx, "".concat(prefix, "--tooltip--").concat(direction), direction), _defineProperty(_cx, "".concat(prefix, "--tooltip--align-").concat(align), align), _defineProperty(_cx, "".concat(prefix, "--tooltip--hidden"), !allowTooltipVisibility || disabled), _defineProperty(_cx, "".concat(prefix, "--tooltip--visible"), isHovered), _cx));
|
|
61
|
-
|
|
62
|
-
var closeTooltips = function closeTooltips(evt) {
|
|
63
|
-
var _document;
|
|
64
|
-
|
|
65
|
-
var tooltipNode = (_document = document) === null || _document === void 0 ? void 0 : _document.querySelectorAll(".".concat(prefix, "--tooltip--a11y"));
|
|
66
|
-
|
|
67
|
-
_toConsumableArray(tooltipNode).map(function (node) {
|
|
68
|
-
toggleClass(node, "".concat(prefix, "--tooltip--hidden"), node !== evt.currentTarget);
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
var handleFocus = function handleFocus(evt) {
|
|
73
|
-
closeTooltips(evt);
|
|
74
|
-
setIsFocused(true);
|
|
75
|
-
setAllowTooltipVisibility(true);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
var handleBlur = function handleBlur() {
|
|
79
|
-
setIsHovered(false);
|
|
80
|
-
setIsFocused(false);
|
|
81
|
-
setAllowTooltipVisibility(false);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
var handleMouseEnter = function handleMouseEnter(evt) {
|
|
85
|
-
if (!disabled) {
|
|
86
|
-
tooltipTimeout.current && clearTimeout(tooltipTimeout.current);
|
|
87
|
-
|
|
88
|
-
if (evt.target === tooltipRef.current) {
|
|
89
|
-
setAllowTooltipVisibility(true);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
closeTooltips(evt);
|
|
94
|
-
setAllowTooltipVisibility(true);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
var handleMouseLeave = function handleMouseLeave() {
|
|
99
|
-
if (!isFocused) {
|
|
100
|
-
tooltipTimeout.current = setTimeout(function () {
|
|
101
|
-
setAllowTooltipVisibility(false);
|
|
102
|
-
setIsHovered(false);
|
|
103
|
-
}, 100);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
var handleClick = function handleClick(evt) {
|
|
108
|
-
setAllowTooltipVisibility(false); // Prevent clicks on the tooltip from triggering the button click event
|
|
109
|
-
|
|
110
|
-
if (evt.target === tooltipRef.current) {
|
|
111
|
-
evt.preventDefault();
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
useEffect(function () {
|
|
117
|
-
var handleEscKeyDown = function handleEscKeyDown(event) {
|
|
118
|
-
if (matches(event, [Escape])) {
|
|
119
|
-
setAllowTooltipVisibility(false);
|
|
120
|
-
setIsHovered(false);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
document.addEventListener('keydown', handleEscKeyDown);
|
|
125
|
-
return function () {
|
|
126
|
-
return document.removeEventListener('keydown', handleEscKeyDown);
|
|
127
|
-
};
|
|
128
|
-
}, []);
|
|
129
|
-
var cursorStyle;
|
|
130
|
-
|
|
131
|
-
if (disabled) {
|
|
132
|
-
cursorStyle = 'not-allowed';
|
|
133
|
-
} else {
|
|
134
|
-
cursorStyle = onClick ? 'pointer' : 'default';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return /*#__PURE__*/React__default.createElement("button", _extends({
|
|
138
|
-
disabled: disabled,
|
|
139
|
-
style: {
|
|
140
|
-
cursor: cursorStyle
|
|
141
|
-
}
|
|
142
|
-
}, rest, {
|
|
143
|
-
type: "button",
|
|
144
|
-
className: tooltipTriggerClasses,
|
|
145
|
-
"aria-describedby": tooltipId,
|
|
146
|
-
onMouseEnter: composeEventHandlers([onMouseEnter, handleMouseEnter]),
|
|
147
|
-
onMouseLeave: composeEventHandlers([onMouseLeave, handleMouseLeave]),
|
|
148
|
-
onFocus: composeEventHandlers([onFocus, handleFocus]),
|
|
149
|
-
onBlur: composeEventHandlers([onBlur, handleBlur]),
|
|
150
|
-
onClick: composeEventHandlers([handleClick, onClick])
|
|
151
|
-
}), /*#__PURE__*/React__default.createElement("span", {
|
|
152
|
-
ref: tooltipRef,
|
|
153
|
-
onMouseEnter: handleMouseEnter,
|
|
154
|
-
className: "".concat(prefix, "--assistive-text"),
|
|
155
|
-
id: tooltipId
|
|
156
|
-
}, tooltipText), IconElement && /*#__PURE__*/React__default.createElement(IconElement, null), !IconElement && children);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
TooltipIcon.propTypes = {
|
|
160
|
-
/**
|
|
161
|
-
* Specify the alignment (to the trigger button) of the tooltip.
|
|
162
|
-
* Can be one of: start, center, or end.
|
|
163
|
-
*/
|
|
164
|
-
align: PropTypes.oneOf(['start', 'center', 'end']),
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Specify an icon as children that will be used as the tooltip trigger. This
|
|
168
|
-
* can be an icon from our Icon component, or a custom SVG element.
|
|
169
|
-
*/
|
|
170
|
-
children: PropTypes.node,
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Specify an optional className to be applied to the trigger node
|
|
174
|
-
*/
|
|
175
|
-
className: PropTypes.string,
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Specify the direction of the tooltip. Can be either top or bottom.
|
|
179
|
-
*/
|
|
180
|
-
direction: PropTypes.oneOf(['top', 'right', 'left', 'bottom']),
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Specify whether the `<TooltipIcon>` should be disabled
|
|
184
|
-
*/
|
|
185
|
-
disabled: PropTypes.bool,
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Optionally specify a custom id for the tooltip. If one is not provided, we
|
|
189
|
-
* generate a unique id for you.
|
|
190
|
-
*/
|
|
191
|
-
id: PropTypes.string,
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* The event handler for the `blur` event.
|
|
195
|
-
*/
|
|
196
|
-
onBlur: PropTypes.func,
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* The event handler for the `click` event.
|
|
200
|
-
*/
|
|
201
|
-
onClick: PropTypes.func,
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* The event handler for the `focus` event.
|
|
205
|
-
*/
|
|
206
|
-
onFocus: PropTypes.func,
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* The event handler for the `mouseenter` event.
|
|
210
|
-
*/
|
|
211
|
-
onMouseEnter: PropTypes.func,
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* The event handler for the `mouseleave` event.
|
|
215
|
-
*/
|
|
216
|
-
onMouseLeave: PropTypes.func,
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Function called to override icon rendering.
|
|
220
|
-
*/
|
|
221
|
-
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Provide the ARIA label for the tooltip.
|
|
225
|
-
* TODO: rename this prop (will be a breaking change)
|
|
226
|
-
*/
|
|
227
|
-
tooltipText: PropTypes.node.isRequired
|
|
228
|
-
};
|
|
229
|
-
TooltipIcon.defaultProps = {
|
|
230
|
-
direction: 'bottom',
|
|
231
|
-
align: 'center'
|
|
232
|
-
};
|
|
233
|
-
var TooltipIcon$1 = TooltipIcon;
|
|
234
|
-
|
|
235
|
-
export { TooltipIcon$1 as default };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2021
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Copyright IBM Corp. 2016, 2018
|
|
12
|
-
*
|
|
13
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
14
|
-
* LICENSE file in the root directory of this source tree.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Create an adapter that converts an object of props with potentially deprecated
|
|
19
|
-
* prop names to the replacement prop names in a newer version. Useful for guarding
|
|
20
|
-
* against breaking changes when a prop has been renamed
|
|
21
|
-
*
|
|
22
|
-
* @param {Array} spec - an array of options which specify a text or regex
|
|
23
|
-
* matcher alongside a replacement if there is a match
|
|
24
|
-
* @returns {Function}
|
|
25
|
-
*/
|
|
26
|
-
function createPropAdapter(spec) {
|
|
27
|
-
// if props aren't passed in we should default the prop to empty object
|
|
28
|
-
return function () {
|
|
29
|
-
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
-
var output = {};
|
|
31
|
-
Object.keys(input).forEach(function (key) {
|
|
32
|
-
var match = spec.find(function (_ref) {
|
|
33
|
-
var _ref2 = _slicedToArray(_ref, 1),
|
|
34
|
-
regex = _ref2[0];
|
|
35
|
-
|
|
36
|
-
return key.match(regex);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
if (match) {
|
|
40
|
-
var _match = _slicedToArray(match, 2),
|
|
41
|
-
regex = _match[0],
|
|
42
|
-
replacer = _match[1];
|
|
43
|
-
|
|
44
|
-
output[key.replace(regex, replacer)] = input[key];
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
output[key] = input[key];
|
|
49
|
-
});
|
|
50
|
-
return output;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* TODO: REMOVE IN v11
|
|
55
|
-
* props staring with "default..." were changed to "initial..." in Downshift v3
|
|
56
|
-
*
|
|
57
|
-
* @see https://github.com/downshift-js/downshift/releases/tag/v3.0.0
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var mapDownshiftProps = createPropAdapter([[/^default/g, 'initial']]);
|
|
62
|
-
|
|
63
|
-
export { mapDownshiftProps };
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2021
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
-
|
|
12
|
-
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
-
var cx = require('classnames');
|
|
14
|
-
var React = require('react');
|
|
15
|
-
var PropTypes = require('prop-types');
|
|
16
|
-
var debounce = require('lodash.debounce');
|
|
17
|
-
var setupGetInstanceId = require('../../tools/setupGetInstanceId.js');
|
|
18
|
-
var events = require('../../tools/events.js');
|
|
19
|
-
var usePrefix = require('../../internal/usePrefix.js');
|
|
20
|
-
var match = require('../../internal/keyboard/match.js');
|
|
21
|
-
var keys = require('../../internal/keyboard/keys.js');
|
|
22
|
-
|
|
23
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
24
|
-
|
|
25
|
-
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
26
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
27
|
-
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
28
|
-
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
29
|
-
|
|
30
|
-
var _excluded = ["id", "className", "triggerClassName", "children", "direction", "align", "onBlur", "onFocus", "onMouseEnter", "onMouseLeave", "tooltipText"];
|
|
31
|
-
var getInstanceId = setupGetInstanceId["default"]();
|
|
32
|
-
|
|
33
|
-
var TooltipDefinition = function TooltipDefinition(_ref) {
|
|
34
|
-
var _cx;
|
|
35
|
-
|
|
36
|
-
var id = _ref.id,
|
|
37
|
-
className = _ref.className,
|
|
38
|
-
triggerClassName = _ref.triggerClassName,
|
|
39
|
-
children = _ref.children,
|
|
40
|
-
direction = _ref.direction,
|
|
41
|
-
align = _ref.align,
|
|
42
|
-
onBlur = _ref.onBlur,
|
|
43
|
-
onFocus = _ref.onFocus,
|
|
44
|
-
onMouseEnter = _ref.onMouseEnter,
|
|
45
|
-
onMouseLeave = _ref.onMouseLeave,
|
|
46
|
-
tooltipText = _ref.tooltipText,
|
|
47
|
-
rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
|
|
48
|
-
|
|
49
|
-
var prefix = usePrefix.usePrefix();
|
|
50
|
-
|
|
51
|
-
var _useState = React.useState(true),
|
|
52
|
-
_useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
|
|
53
|
-
allowTooltipVisibility = _useState2[0],
|
|
54
|
-
setAllowTooltipVisibility = _useState2[1];
|
|
55
|
-
|
|
56
|
-
var _useState3 = React.useState(false),
|
|
57
|
-
_useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
|
|
58
|
-
tooltipVisible = _useState4[0],
|
|
59
|
-
setTooltipVisible = _useState4[1];
|
|
60
|
-
|
|
61
|
-
var tooltipId = id || "definition-tooltip-".concat(getInstanceId());
|
|
62
|
-
var tooltipClassName = cx__default["default"]("".concat(prefix, "--tooltip--definition"), "".concat(prefix, "--tooltip--a11y"), className);
|
|
63
|
-
var tooltipTriggerClasses = cx__default["default"]("".concat(prefix, "--tooltip__trigger"), "".concat(prefix, "--tooltip--a11y"), "".concat(prefix, "--tooltip__trigger--definition"), triggerClassName, (_cx = {}, _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--tooltip--").concat(direction), direction), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--tooltip--align-").concat(align), align), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--tooltip--hidden"), !allowTooltipVisibility), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--tooltip--visible"), tooltipVisible), _cx));
|
|
64
|
-
var debounceTooltipVisible = debounce__default["default"](function () {
|
|
65
|
-
return setTooltipVisible(false);
|
|
66
|
-
}, 100);
|
|
67
|
-
|
|
68
|
-
var handleFocus = function handleFocus() {
|
|
69
|
-
debounceTooltipVisible.cancel();
|
|
70
|
-
setAllowTooltipVisibility(true);
|
|
71
|
-
setTooltipVisible(true);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
var handleBlur = debounceTooltipVisible;
|
|
75
|
-
|
|
76
|
-
var handleMouseEnter = function handleMouseEnter() {
|
|
77
|
-
debounceTooltipVisible.cancel();
|
|
78
|
-
setAllowTooltipVisibility(true);
|
|
79
|
-
setTooltipVisible(true);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
var handleMouseLeave = debounceTooltipVisible;
|
|
83
|
-
React.useEffect(function () {
|
|
84
|
-
var handleEscKeyDown = function handleEscKeyDown(event) {
|
|
85
|
-
if (match.matches(event, [keys.Escape])) {
|
|
86
|
-
setAllowTooltipVisibility(false);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
document.addEventListener('keydown', handleEscKeyDown);
|
|
91
|
-
return function () {
|
|
92
|
-
return document.removeEventListener('keydown', handleEscKeyDown);
|
|
93
|
-
};
|
|
94
|
-
}, []);
|
|
95
|
-
return /*#__PURE__*/React__default["default"].createElement("span", _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
96
|
-
className: tooltipClassName,
|
|
97
|
-
onMouseEnter: events.composeEventHandlers([onMouseEnter, handleMouseEnter]),
|
|
98
|
-
onMouseLeave: events.composeEventHandlers([onMouseLeave, handleMouseLeave])
|
|
99
|
-
}), /*#__PURE__*/React__default["default"].createElement("button", {
|
|
100
|
-
type: "button",
|
|
101
|
-
className: tooltipTriggerClasses,
|
|
102
|
-
"aria-describedby": tooltipId,
|
|
103
|
-
onFocus: events.composeEventHandlers([onFocus, handleFocus]),
|
|
104
|
-
onBlur: events.composeEventHandlers([onBlur, handleBlur])
|
|
105
|
-
}, children), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
106
|
-
className: "".concat(prefix, "--assistive-text"),
|
|
107
|
-
id: tooltipId,
|
|
108
|
-
role: "tooltip"
|
|
109
|
-
}, tooltipText));
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
TooltipDefinition.propTypes = {
|
|
113
|
-
/**
|
|
114
|
-
* Specify the alignment (to the trigger button) of the tooltip.
|
|
115
|
-
* Can be one of: start, center, or end.
|
|
116
|
-
*/
|
|
117
|
-
align: PropTypes__default["default"].oneOf(['start', 'center', 'end']),
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Specify the tooltip trigger text that is rendered to the UI for the user to
|
|
121
|
-
* interact with in order to display the tooltip.
|
|
122
|
-
*/
|
|
123
|
-
children: PropTypes__default["default"].node.isRequired,
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Specify an optional className to be applied to the container node
|
|
127
|
-
*/
|
|
128
|
-
className: PropTypes__default["default"].string,
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Specify the direction of the tooltip. Can be either top or bottom.
|
|
132
|
-
*/
|
|
133
|
-
direction: PropTypes__default["default"].oneOf(['top', 'bottom']),
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Optionally specify a custom id for the tooltip. If one is not provided, we
|
|
137
|
-
* generate a unique id for you.
|
|
138
|
-
*/
|
|
139
|
-
id: PropTypes__default["default"].string,
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* The event handler for the `blur` event.
|
|
143
|
-
*/
|
|
144
|
-
onBlur: PropTypes__default["default"].func,
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* The event handler for the `focus` event.
|
|
148
|
-
*/
|
|
149
|
-
onFocus: PropTypes__default["default"].func,
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The event handler for the `mouseenter` event.
|
|
153
|
-
*/
|
|
154
|
-
onMouseEnter: PropTypes__default["default"].func,
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* The event handler for the `mouseleave` event.
|
|
158
|
-
*/
|
|
159
|
-
onMouseLeave: PropTypes__default["default"].func,
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Provide the text that will be displayed in the tooltip when it is rendered.
|
|
163
|
-
* TODO: rename this prop (will be a breaking change)
|
|
164
|
-
*/
|
|
165
|
-
tooltipText: PropTypes__default["default"].node.isRequired,
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The CSS class name of the trigger element
|
|
169
|
-
*/
|
|
170
|
-
triggerClassName: PropTypes__default["default"].string
|
|
171
|
-
};
|
|
172
|
-
TooltipDefinition.defaultProps = {
|
|
173
|
-
direction: 'bottom',
|
|
174
|
-
align: 'start'
|
|
175
|
-
};
|
|
176
|
-
var TooltipDefinition$1 = TooltipDefinition;
|
|
177
|
-
|
|
178
|
-
exports["default"] = TooltipDefinition$1;
|