@carbon/react 1.0.0-rc.0 → 1.0.2

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 (98) hide show
  1. package/README.md +2 -2
  2. package/es/components/Accordion/Accordion.Skeleton.js +1 -7
  3. package/es/components/Accordion/AccordionItem.js +0 -5
  4. package/es/components/Button/Button.Skeleton.js +1 -3
  5. package/es/components/Button/Button.js +51 -113
  6. package/es/components/Checkbox/Checkbox.js +8 -21
  7. package/es/components/CodeSnippet/CodeSnippet.js +3 -11
  8. package/es/components/ComboBox/ComboBox.js +2 -4
  9. package/es/components/ContentSwitcher/index.js +13 -0
  10. package/es/components/DataTable/DataTable.js +5 -14
  11. package/es/components/DataTable/Table.js +3 -11
  12. package/es/components/DataTable/TableBatchAction.js +2 -1
  13. package/es/components/DataTable/TableExpandHeader.js +1 -1
  14. package/es/components/DataTable/TableToolbar.js +1 -2
  15. package/es/components/DataTable/TableToolbarSearch.js +4 -13
  16. package/es/components/DatePickerInput/next/DatePickerInput.js +6 -31
  17. package/es/components/Dropdown/Dropdown.Skeleton.js +4 -13
  18. package/es/components/Dropdown/Dropdown.js +4 -9
  19. package/es/components/ExpandableSearch/ExpandableSearch.js +16 -22
  20. package/es/components/FormGroup/FormGroup.js +4 -14
  21. package/es/components/IconButton/index.js +0 -1
  22. package/es/components/InlineLoading/InlineLoading.js +2 -9
  23. package/es/components/ListBox/ListBox.js +10 -0
  24. package/es/components/Modal/next/Modal.js +5 -8
  25. package/es/components/MultiSelect/FilterableMultiSelect.js +1 -2
  26. package/es/components/MultiSelect/MultiSelect.js +2 -3
  27. package/es/components/MultiSelect/next/FilterableMultiSelect.js +1 -2
  28. package/es/components/Notification/next/Notification.js +18 -39
  29. package/es/components/OverflowMenuItem/OverflowMenuItem.js +1 -9
  30. package/es/components/RadioTile/RadioTile.js +6 -13
  31. package/es/components/Search/index.js +3 -3
  32. package/es/components/Search/next/Search.js +25 -20
  33. package/es/components/Select/Select.js +6 -14
  34. package/es/components/Slider/Slider.js +4 -14
  35. package/es/components/StructuredList/next/StructuredList.js +7 -11
  36. package/es/components/TextInput/ControlledPasswordInput.js +2 -2
  37. package/es/components/Tile/next/Tile.js +12 -51
  38. package/es/components/TileGroup/index.js +13 -0
  39. package/es/components/TimePickerSelect/next/TimePickerSelect.js +0 -6
  40. package/es/components/Toggletip/index.js +252 -0
  41. package/es/components/Tooltip/next/DefinitionTooltip.js +1 -1
  42. package/es/index.js +6 -10
  43. package/es/internal/useEvent.js +29 -0
  44. package/icons/package.json +2 -1
  45. package/lib/components/Accordion/Accordion.Skeleton.js +1 -7
  46. package/lib/components/Accordion/AccordionItem.js +0 -5
  47. package/lib/components/Button/Button.Skeleton.js +1 -3
  48. package/lib/components/Button/Button.js +49 -130
  49. package/lib/components/Checkbox/Checkbox.js +8 -21
  50. package/lib/components/CodeSnippet/CodeSnippet.js +3 -11
  51. package/lib/components/ComboBox/ComboBox.js +2 -4
  52. package/lib/components/ContentSwitcher/index.js +17 -0
  53. package/lib/components/DataTable/DataTable.js +5 -33
  54. package/lib/components/DataTable/Table.js +3 -30
  55. package/lib/components/DataTable/TableBatchAction.js +2 -1
  56. package/lib/components/DataTable/TableExpandHeader.js +1 -1
  57. package/lib/components/DataTable/TableToolbar.js +1 -21
  58. package/lib/components/DataTable/TableToolbarSearch.js +4 -13
  59. package/lib/components/DatePickerInput/next/DatePickerInput.js +5 -30
  60. package/lib/components/Dropdown/Dropdown.Skeleton.js +4 -13
  61. package/lib/components/Dropdown/Dropdown.js +4 -9
  62. package/lib/components/ExpandableSearch/ExpandableSearch.js +15 -21
  63. package/lib/components/FormGroup/FormGroup.js +3 -13
  64. package/lib/components/IconButton/index.js +0 -1
  65. package/lib/components/InlineLoading/InlineLoading.js +2 -9
  66. package/lib/components/ListBox/ListBox.js +10 -0
  67. package/lib/components/Modal/next/Modal.js +5 -8
  68. package/lib/components/MultiSelect/FilterableMultiSelect.js +1 -2
  69. package/lib/components/MultiSelect/MultiSelect.js +2 -3
  70. package/lib/components/MultiSelect/next/FilterableMultiSelect.js +1 -2
  71. package/lib/components/Notification/next/Notification.js +18 -39
  72. package/lib/components/OverflowMenuItem/OverflowMenuItem.js +1 -9
  73. package/lib/components/RadioTile/RadioTile.js +6 -13
  74. package/lib/components/Search/next/Search.js +25 -20
  75. package/lib/components/Select/Select.js +6 -33
  76. package/lib/components/Slider/Slider.js +4 -14
  77. package/lib/components/StructuredList/next/StructuredList.js +7 -11
  78. package/lib/components/TextInput/ControlledPasswordInput.js +2 -2
  79. package/lib/components/Tile/next/Tile.js +12 -51
  80. package/lib/components/TileGroup/index.js +17 -0
  81. package/lib/components/TimePickerSelect/next/TimePickerSelect.js +0 -6
  82. package/lib/components/Toggletip/index.js +266 -0
  83. package/lib/components/Tooltip/next/DefinitionTooltip.js +1 -1
  84. package/lib/index.js +102 -110
  85. package/lib/internal/useEvent.js +33 -0
  86. package/package.json +9 -9
  87. package/es/components/ToggleSmall/ToggleSmall.js +0 -104
  88. package/es/components/Toolbar/Toolbar.js +0 -121
  89. package/es/components/ToolbarSearch/ToolbarSearch.js +0 -168
  90. package/es/components/TooltipDefinition/TooltipDefinition.js +0 -167
  91. package/es/components/TooltipIcon/TooltipIcon.js +0 -235
  92. package/es/tools/createPropAdapter.js +0 -63
  93. package/lib/components/ToggleSmall/ToggleSmall.js +0 -114
  94. package/lib/components/Toolbar/Toolbar.js +0 -135
  95. package/lib/components/ToolbarSearch/ToolbarSearch.js +0 -178
  96. package/lib/components/TooltipDefinition/TooltipDefinition.js +0 -178
  97. package/lib/components/TooltipIcon/TooltipIcon.js +0 -245
  98. package/lib/tools/createPropAdapter.js +0 -67
@@ -1,168 +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 { inherits as _inherits, createSuper as _createSuper, classCallCheck as _classCallCheck, defineProperty as _defineProperty, assertThisInitialized as _assertThisInitialized, createClass as _createClass, objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { Component } from 'react';
10
- import PropTypes from 'prop-types';
11
- import cx from 'classnames';
12
- import { Search } from '@carbon/icons-react';
13
- import ClickListener from '../../internal/ClickListener.js';
14
- import { warning } from '../../internal/warning.js';
15
- import { PrefixContext } from '../../internal/usePrefix.js';
16
-
17
- var _excluded = ["className", "type", "id", "placeHolderText", "labelText", "role", "labelId"];
18
- var didWarnAboutDeprecation = false;
19
-
20
- var ToolbarSearch = /*#__PURE__*/function (_Component) {
21
- _inherits(ToolbarSearch, _Component);
22
-
23
- var _super = _createSuper(ToolbarSearch);
24
-
25
- function ToolbarSearch(props) {
26
- var _this;
27
-
28
- _classCallCheck(this, ToolbarSearch);
29
-
30
- _this = _super.call(this, props);
31
-
32
- _defineProperty(_assertThisInitialized(_this), "state", {
33
- expanded: false
34
- });
35
-
36
- _defineProperty(_assertThisInitialized(_this), "expandSearch", function () {
37
- _this.setState({
38
- expanded: !_this.state.expanded
39
- });
40
-
41
- _this.input.focus();
42
- });
43
-
44
- _defineProperty(_assertThisInitialized(_this), "handleClickOutside", function () {
45
- _this.setState({
46
- expanded: false
47
- });
48
- });
49
-
50
- if (process.env.NODE_ENV !== "production") {
51
- process.env.NODE_ENV !== "production" ? warning(didWarnAboutDeprecation, 'The ToolbarSearch component has been deprecated and will be removed in the next major release of `carbon-components-react`') : void 0;
52
- didWarnAboutDeprecation = true;
53
- }
54
-
55
- return _this;
56
- }
57
-
58
- _createClass(ToolbarSearch, [{
59
- key: "render",
60
- value: function render() {
61
- var _classNames,
62
- _this2 = this;
63
-
64
- var prefix = this.context;
65
-
66
- var _this$props = this.props,
67
- className = _this$props.className,
68
- type = _this$props.type,
69
- id = _this$props.id,
70
- placeHolderText = _this$props.placeHolderText,
71
- labelText = _this$props.labelText,
72
- role = _this$props.role,
73
- labelId = _this$props.labelId,
74
- other = _objectWithoutProperties(_this$props, _excluded);
75
-
76
- var searchClasses = cx((_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "--search ").concat(prefix, "--search--sm ").concat(prefix, "--toolbar-search"), true), _defineProperty(_classNames, "".concat(prefix, "--toolbar-search--active"), this.state.expanded), _defineProperty(_classNames, className, className), _classNames));
77
- return /*#__PURE__*/React__default.createElement(ClickListener, {
78
- onClickOutside: this.handleClickOutside
79
- }, /*#__PURE__*/React__default.createElement("div", {
80
- className: searchClasses,
81
- role: role
82
- }, /*#__PURE__*/React__default.createElement("label", {
83
- htmlFor: id,
84
- className: "".concat(prefix, "--label"),
85
- id: labelId
86
- }, labelText), /*#__PURE__*/React__default.createElement("input", _extends({}, other, {
87
- type: type,
88
- className: "".concat(prefix, "--search-input"),
89
- id: id,
90
- "aria-labelledby": labelId,
91
- placeholder: placeHolderText,
92
- ref: function ref(input) {
93
- _this2.input = input;
94
- }
95
- })), /*#__PURE__*/React__default.createElement("button", {
96
- type: "button",
97
- className: "".concat(prefix, "--toolbar-search__btn"),
98
- title: labelText,
99
- onClick: this.expandSearch
100
- }, /*#__PURE__*/React__default.createElement(Search, {
101
- className: "".concat(prefix, "--search-magnifier"),
102
- "aria-label": labelText
103
- }))));
104
- }
105
- }]);
106
-
107
- return ToolbarSearch;
108
- }(Component);
109
-
110
- _defineProperty(ToolbarSearch, "contextType", PrefixContext);
111
-
112
- _defineProperty(ToolbarSearch, "propTypes", {
113
- /**
114
- * The child nodes.
115
- */
116
- children: PropTypes.node,
117
-
118
- /**
119
- * The CSS class names.
120
- */
121
- className: PropTypes.string,
122
-
123
- /**
124
- * The ID of the `<input>`.
125
- */
126
- id: PropTypes.string,
127
-
128
- /**
129
- * The ID of the `<label>`.
130
- */
131
- labelId: PropTypes.string,
132
-
133
- /**
134
- * The text in the `<label>`.
135
- */
136
- labelText: PropTypes.node,
137
-
138
- /**
139
- * The placeholder text of the `<input>`.
140
- */
141
- placeHolderText: PropTypes.string,
142
-
143
- /**
144
- * Optional prop to specify the role of the ToolbarSearch
145
- */
146
- role: PropTypes.string,
147
-
148
- /**
149
- * `true` to use the small version of the UI.
150
- */
151
- small: PropTypes.bool,
152
-
153
- /**
154
- * The `type` of the `<input>`.
155
- */
156
- type: PropTypes.string
157
- });
158
-
159
- _defineProperty(ToolbarSearch, "defaultProps", {
160
- type: 'search',
161
- id: 'search__input',
162
- labelText: '',
163
- placeHolderText: '',
164
- role: 'search',
165
- labelId: 'search__label'
166
- });
167
-
168
- export { ToolbarSearch as default };
@@ -1,167 +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 } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import cx from 'classnames';
10
- import React__default, { useState, useEffect } from 'react';
11
- import PropTypes from 'prop-types';
12
- import debounce from 'lodash.debounce';
13
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
14
- import { composeEventHandlers } from '../../tools/events.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", "triggerClassName", "children", "direction", "align", "onBlur", "onFocus", "onMouseEnter", "onMouseLeave", "tooltipText"];
20
- var getInstanceId = setupGetInstanceId();
21
-
22
- var TooltipDefinition = function TooltipDefinition(_ref) {
23
- var _cx;
24
-
25
- var id = _ref.id,
26
- className = _ref.className,
27
- triggerClassName = _ref.triggerClassName,
28
- children = _ref.children,
29
- direction = _ref.direction,
30
- align = _ref.align,
31
- onBlur = _ref.onBlur,
32
- onFocus = _ref.onFocus,
33
- onMouseEnter = _ref.onMouseEnter,
34
- onMouseLeave = _ref.onMouseLeave,
35
- tooltipText = _ref.tooltipText,
36
- rest = _objectWithoutProperties(_ref, _excluded);
37
-
38
- var prefix = usePrefix();
39
-
40
- var _useState = useState(true),
41
- _useState2 = _slicedToArray(_useState, 2),
42
- allowTooltipVisibility = _useState2[0],
43
- setAllowTooltipVisibility = _useState2[1];
44
-
45
- var _useState3 = useState(false),
46
- _useState4 = _slicedToArray(_useState3, 2),
47
- tooltipVisible = _useState4[0],
48
- setTooltipVisible = _useState4[1];
49
-
50
- var tooltipId = id || "definition-tooltip-".concat(getInstanceId());
51
- var tooltipClassName = cx("".concat(prefix, "--tooltip--definition"), "".concat(prefix, "--tooltip--a11y"), className);
52
- var tooltipTriggerClasses = cx("".concat(prefix, "--tooltip__trigger"), "".concat(prefix, "--tooltip--a11y"), "".concat(prefix, "--tooltip__trigger--definition"), triggerClassName, (_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), _defineProperty(_cx, "".concat(prefix, "--tooltip--visible"), tooltipVisible), _cx));
53
- var debounceTooltipVisible = debounce(function () {
54
- return setTooltipVisible(false);
55
- }, 100);
56
-
57
- var handleFocus = function handleFocus() {
58
- debounceTooltipVisible.cancel();
59
- setAllowTooltipVisibility(true);
60
- setTooltipVisible(true);
61
- };
62
-
63
- var handleBlur = debounceTooltipVisible;
64
-
65
- var handleMouseEnter = function handleMouseEnter() {
66
- debounceTooltipVisible.cancel();
67
- setAllowTooltipVisibility(true);
68
- setTooltipVisible(true);
69
- };
70
-
71
- var handleMouseLeave = debounceTooltipVisible;
72
- useEffect(function () {
73
- var handleEscKeyDown = function handleEscKeyDown(event) {
74
- if (matches(event, [Escape])) {
75
- setAllowTooltipVisibility(false);
76
- }
77
- };
78
-
79
- document.addEventListener('keydown', handleEscKeyDown);
80
- return function () {
81
- return document.removeEventListener('keydown', handleEscKeyDown);
82
- };
83
- }, []);
84
- return /*#__PURE__*/React__default.createElement("span", _extends({}, rest, {
85
- className: tooltipClassName,
86
- onMouseEnter: composeEventHandlers([onMouseEnter, handleMouseEnter]),
87
- onMouseLeave: composeEventHandlers([onMouseLeave, handleMouseLeave])
88
- }), /*#__PURE__*/React__default.createElement("button", {
89
- type: "button",
90
- className: tooltipTriggerClasses,
91
- "aria-describedby": tooltipId,
92
- onFocus: composeEventHandlers([onFocus, handleFocus]),
93
- onBlur: composeEventHandlers([onBlur, handleBlur])
94
- }, children), /*#__PURE__*/React__default.createElement("span", {
95
- className: "".concat(prefix, "--assistive-text"),
96
- id: tooltipId,
97
- role: "tooltip"
98
- }, tooltipText));
99
- };
100
-
101
- TooltipDefinition.propTypes = {
102
- /**
103
- * Specify the alignment (to the trigger button) of the tooltip.
104
- * Can be one of: start, center, or end.
105
- */
106
- align: PropTypes.oneOf(['start', 'center', 'end']),
107
-
108
- /**
109
- * Specify the tooltip trigger text that is rendered to the UI for the user to
110
- * interact with in order to display the tooltip.
111
- */
112
- children: PropTypes.node.isRequired,
113
-
114
- /**
115
- * Specify an optional className to be applied to the container node
116
- */
117
- className: PropTypes.string,
118
-
119
- /**
120
- * Specify the direction of the tooltip. Can be either top or bottom.
121
- */
122
- direction: PropTypes.oneOf(['top', 'bottom']),
123
-
124
- /**
125
- * Optionally specify a custom id for the tooltip. If one is not provided, we
126
- * generate a unique id for you.
127
- */
128
- id: PropTypes.string,
129
-
130
- /**
131
- * The event handler for the `blur` event.
132
- */
133
- onBlur: PropTypes.func,
134
-
135
- /**
136
- * The event handler for the `focus` event.
137
- */
138
- onFocus: PropTypes.func,
139
-
140
- /**
141
- * The event handler for the `mouseenter` event.
142
- */
143
- onMouseEnter: PropTypes.func,
144
-
145
- /**
146
- * The event handler for the `mouseleave` event.
147
- */
148
- onMouseLeave: PropTypes.func,
149
-
150
- /**
151
- * Provide the text that will be displayed in the tooltip when it is rendered.
152
- * TODO: rename this prop (will be a breaking change)
153
- */
154
- tooltipText: PropTypes.node.isRequired,
155
-
156
- /**
157
- * The CSS class name of the trigger element
158
- */
159
- triggerClassName: PropTypes.string
160
- };
161
- TooltipDefinition.defaultProps = {
162
- direction: 'bottom',
163
- align: 'start'
164
- };
165
- var TooltipDefinition$1 = TooltipDefinition;
166
-
167
- export { TooltipDefinition$1 as default };
@@ -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 };