@carbon/react 1.24.0 → 1.25.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/CodeSnippet/CodeSnippet.js +13 -115
- package/es/components/ComboBox/ComboBox.d.ts +6 -0
- package/es/components/ComboBox/ComboBox.js +19 -172
- package/es/components/ComboButton/index.js +164 -0
- package/es/components/ComposedModal/ComposedModal.js +1 -2
- package/es/components/DataTable/TableToolbar.d.ts +19 -0
- package/es/components/DataTable/TableToolbar.js +1 -1
- package/es/components/DataTable/TableToolbarAction.d.ts +21 -0
- package/es/components/DataTable/TableToolbarContent.d.ts +21 -0
- package/es/components/DataTable/TableToolbarMenu.d.ts +24 -0
- package/es/components/DataTable/TableToolbarMenu.js +3 -3
- package/es/components/DataTable/tools/sorting.js +2 -1
- package/es/components/DataTableSkeleton/DataTableSkeleton.d.ts +107 -0
- package/es/components/Dropdown/Dropdown.d.ts +6 -0
- package/es/components/Dropdown/Dropdown.js +8 -145
- package/es/components/FileUploader/FileUploader.js +1 -1
- package/es/components/FileUploader/FileUploaderDropContainer.js +30 -18
- package/es/components/FileUploader/FileUploaderItem.js +2 -1
- package/es/components/FileUploader/Filename.js +8 -2
- package/es/components/FluidTextArea/FluidTextArea.js +12 -1
- package/es/components/IconButton/index.js +1 -0
- package/es/components/ListBox/ListBoxSelection.js +4 -23
- package/es/components/ListBox/next/ListBoxSelection.js +2 -23
- package/es/components/Menu/Menu.js +50 -29
- package/es/components/Menu/MenuItem.js +1 -0
- package/es/components/MenuButton/index.js +127 -0
- package/es/components/Modal/Modal.js +4 -3
- package/es/components/MultiSelect/FilterableMultiSelect.js +31 -137
- package/es/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/es/components/MultiSelect/MultiSelect.js +48 -26
- package/es/components/Notification/Notification.js +27 -264
- package/es/components/OverflowMenu/OverflowMenu.js +13 -139
- package/es/components/OverflowMenuItem/OverflowMenuItem.d.ts +58 -0
- package/es/components/OverflowMenuItem/OverflowMenuItem.js +12 -7
- package/es/components/OverflowMenuV2/index.js +15 -51
- package/es/components/Popover/index.d.ts +5 -1
- package/es/components/Popover/index.js +37 -9
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +7 -4
- package/es/components/RadioTile/RadioTile.js +6 -6
- package/es/components/Select/Select.d.ts +89 -0
- package/es/components/SelectItem/SelectItem.d.ts +62 -0
- package/es/components/SelectItem/SelectItem.js +2 -4
- package/es/components/SelectItemGroup/SelectItemGroup.d.ts +52 -0
- package/es/components/SkeletonText/SkeletonText.js +1 -1
- package/es/components/StructuredList/StructuredList.js +10 -38
- package/es/components/Tabs/Tabs.js +3 -1
- package/es/components/TextArea/TextArea.Skeleton.d.ts +33 -0
- package/es/components/TextArea/TextArea.Skeleton.js +5 -5
- package/es/components/TextArea/TextArea.d.ts +9 -2
- package/es/components/TextArea/TextArea.js +31 -8
- package/es/components/TextArea/index.js +1 -0
- package/es/components/Toggle/Toggle.js +8 -19
- package/es/components/Tooltip/DefinitionTooltip.d.ts +52 -0
- package/es/components/Tooltip/DefinitionTooltip.js +2 -2
- package/es/components/Tooltip/Tooltip.d.ts +117 -0
- package/es/components/Tooltip/Tooltip.js +6 -4
- package/es/components/Tooltip/index.d.ts +9 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +5 -3
- package/es/internal/ClickListener.js +1 -2
- package/es/internal/keyboard/match.js +1 -1
- package/es/internal/useAttachedMenu.js +85 -0
- package/es/internal/useDelayedState.d.ts +19 -0
- package/es/internal/useDelayedState.js +7 -3
- package/es/internal/useId.js +1 -1
- package/lib/components/CodeSnippet/CodeSnippet.js +13 -115
- package/lib/components/ComboBox/ComboBox.d.ts +6 -0
- package/lib/components/ComboBox/ComboBox.js +18 -171
- package/lib/components/ComboButton/index.js +174 -0
- package/lib/components/ComposedModal/ComposedModal.js +1 -2
- package/lib/components/DataTable/TableToolbar.d.ts +19 -0
- package/lib/components/DataTable/TableToolbar.js +1 -1
- package/lib/components/DataTable/TableToolbarAction.d.ts +21 -0
- package/lib/components/DataTable/TableToolbarContent.d.ts +21 -0
- package/lib/components/DataTable/TableToolbarMenu.d.ts +24 -0
- package/lib/components/DataTable/TableToolbarMenu.js +3 -3
- package/lib/components/DataTable/tools/sorting.js +2 -1
- package/lib/components/DataTableSkeleton/DataTableSkeleton.d.ts +107 -0
- package/lib/components/Dropdown/Dropdown.d.ts +6 -0
- package/lib/components/Dropdown/Dropdown.js +7 -144
- package/lib/components/FileUploader/FileUploader.js +1 -1
- package/lib/components/FileUploader/FileUploaderDropContainer.js +30 -18
- package/lib/components/FileUploader/FileUploaderItem.js +2 -1
- package/lib/components/FileUploader/Filename.js +8 -2
- package/lib/components/FluidTextArea/FluidTextArea.js +12 -1
- package/lib/components/IconButton/index.js +1 -0
- package/lib/components/ListBox/ListBoxSelection.js +4 -23
- package/lib/components/ListBox/next/ListBoxSelection.js +2 -23
- package/lib/components/Menu/Menu.js +50 -29
- package/lib/components/Menu/MenuItem.js +1 -0
- package/lib/components/MenuButton/index.js +137 -0
- package/lib/components/Modal/Modal.js +4 -3
- package/lib/components/MultiSelect/FilterableMultiSelect.js +29 -135
- package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/lib/components/MultiSelect/MultiSelect.js +47 -25
- package/lib/components/Notification/Notification.js +27 -264
- package/lib/components/OverflowMenu/OverflowMenu.js +13 -139
- package/lib/components/OverflowMenuItem/OverflowMenuItem.d.ts +58 -0
- package/lib/components/OverflowMenuItem/OverflowMenuItem.js +12 -7
- package/lib/components/OverflowMenuV2/index.js +13 -49
- package/lib/components/Popover/index.d.ts +5 -1
- package/lib/components/Popover/index.js +37 -9
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +6 -3
- package/lib/components/RadioTile/RadioTile.js +6 -6
- package/lib/components/Select/Select.d.ts +89 -0
- package/lib/components/SelectItem/SelectItem.d.ts +62 -0
- package/lib/components/SelectItem/SelectItem.js +1 -3
- package/lib/components/SelectItemGroup/SelectItemGroup.d.ts +52 -0
- package/lib/components/SkeletonText/SkeletonText.js +1 -1
- package/lib/components/StructuredList/StructuredList.js +10 -38
- package/lib/components/Tabs/Tabs.js +3 -1
- package/lib/components/TextArea/TextArea.Skeleton.d.ts +33 -0
- package/lib/components/TextArea/TextArea.Skeleton.js +5 -5
- package/lib/components/TextArea/TextArea.d.ts +9 -2
- package/lib/components/TextArea/TextArea.js +30 -7
- package/lib/components/TextArea/index.js +2 -0
- package/lib/components/Toggle/Toggle.js +8 -19
- package/lib/components/Tooltip/DefinitionTooltip.d.ts +52 -0
- package/lib/components/Tooltip/DefinitionTooltip.js +2 -2
- package/lib/components/Tooltip/Tooltip.d.ts +117 -0
- package/lib/components/Tooltip/Tooltip.js +6 -4
- package/lib/components/Tooltip/index.d.ts +9 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +50 -46
- package/lib/internal/ClickListener.js +1 -2
- package/lib/internal/keyboard/match.js +1 -1
- package/lib/internal/useAttachedMenu.js +89 -0
- package/lib/internal/useDelayedState.d.ts +19 -0
- package/lib/internal/useDelayedState.js +7 -3
- package/lib/internal/useId.js +1 -1
- package/package.json +3 -3
|
@@ -18,7 +18,7 @@ import { Escape } from '../../internal/keyboard/keys.js';
|
|
|
18
18
|
|
|
19
19
|
var _excluded = ["align", "className", "children", "definition", "defaultOpen", "id", "openOnHover", "tooltipText", "triggerClassName"];
|
|
20
20
|
|
|
21
|
-
function DefinitionTooltip(_ref) {
|
|
21
|
+
var DefinitionTooltip = function DefinitionTooltip(_ref) {
|
|
22
22
|
var _ref$align = _ref.align,
|
|
23
23
|
align = _ref$align === void 0 ? 'bottom-left' : _ref$align,
|
|
24
24
|
className = _ref.className,
|
|
@@ -75,7 +75,7 @@ function DefinitionTooltip(_ref) {
|
|
|
75
75
|
className: "".concat(prefix, "--definition-tooltip"),
|
|
76
76
|
id: tooltipId
|
|
77
77
|
}, tooltipText !== null && tooltipText !== void 0 ? tooltipText : definition));
|
|
78
|
-
}
|
|
78
|
+
};
|
|
79
79
|
|
|
80
80
|
DefinitionTooltip.propTypes = {
|
|
81
81
|
/**
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
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
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { PopoverAlignment } from '../Popover';
|
|
10
|
+
import { PolymorphicProps } from '../../types/common';
|
|
11
|
+
interface TooltipBaseProps {
|
|
12
|
+
/**
|
|
13
|
+
* Specify how the trigger should align with the tooltip
|
|
14
|
+
*/
|
|
15
|
+
align?: PopoverAlignment;
|
|
16
|
+
/**
|
|
17
|
+
* Pass in the child to which the tooltip will be applied
|
|
18
|
+
*/
|
|
19
|
+
children?: React.ReactElement;
|
|
20
|
+
/**
|
|
21
|
+
* Specify an optional className to be applied to the container node
|
|
22
|
+
*/
|
|
23
|
+
className?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Determines wether the tooltip should close when inner content is activated (click, Enter or Space)
|
|
26
|
+
*/
|
|
27
|
+
closeOnActivation?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Specify whether the tooltip should be open when it first renders
|
|
30
|
+
*/
|
|
31
|
+
defaultOpen?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Provide the description to be rendered inside of the Tooltip. The
|
|
34
|
+
* description will use `aria-describedby` and will describe the child node
|
|
35
|
+
* in addition to the text rendered inside of the child. This means that if you
|
|
36
|
+
* have text in the child node, that it will be announced alongside the
|
|
37
|
+
* description to the screen reader.
|
|
38
|
+
*
|
|
39
|
+
* Note: if label and description are both provided, label will be used and
|
|
40
|
+
* description will not be used
|
|
41
|
+
*/
|
|
42
|
+
description?: React.ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* Specify the duration in milliseconds to delay before displaying the tooltip
|
|
45
|
+
*/
|
|
46
|
+
enterDelayMs?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Provide the label to be rendered inside of the Tooltip. The label will use
|
|
49
|
+
* `aria-labelledby` and will fully describe the child node that is provided.
|
|
50
|
+
* This means that if you have text in the child node, that it will not be
|
|
51
|
+
* announced to the screen reader.
|
|
52
|
+
*
|
|
53
|
+
* Note: if label and description are both provided, description will not be
|
|
54
|
+
* used
|
|
55
|
+
*/
|
|
56
|
+
label?: React.ReactNode;
|
|
57
|
+
/**
|
|
58
|
+
* Specify the duration in milliseconds to delay before hiding the tooltip
|
|
59
|
+
*/
|
|
60
|
+
leaveDelayMs?: number;
|
|
61
|
+
}
|
|
62
|
+
export type TooltipProps<T extends React.ElementType> = PolymorphicProps<T, TooltipBaseProps>;
|
|
63
|
+
declare function Tooltip<T extends React.ElementType>({ align, className: customClassName, children, label, description, enterDelayMs, leaveDelayMs, defaultOpen, closeOnActivation, ...rest }: TooltipProps<T>): JSX.Element;
|
|
64
|
+
declare namespace Tooltip {
|
|
65
|
+
var propTypes: {
|
|
66
|
+
/**
|
|
67
|
+
* Specify how the trigger should align with the tooltip
|
|
68
|
+
*/
|
|
69
|
+
align: PropTypes.Requireable<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Pass in the child to which the tooltip will be applied
|
|
72
|
+
*/
|
|
73
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
74
|
+
/**
|
|
75
|
+
* Specify an optional className to be applied to the container node
|
|
76
|
+
*/
|
|
77
|
+
className: PropTypes.Requireable<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Determines wether the tooltip should close when inner content is activated (click, Enter or Space)
|
|
80
|
+
*/
|
|
81
|
+
closeOnActivation: PropTypes.Requireable<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Specify whether the tooltip should be open when it first renders
|
|
84
|
+
*/
|
|
85
|
+
defaultOpen: PropTypes.Requireable<boolean>;
|
|
86
|
+
/**
|
|
87
|
+
* Provide the description to be rendered inside of the Tooltip. The
|
|
88
|
+
* description will use `aria-describedby` and will describe the child node
|
|
89
|
+
* in addition to the text rendered inside of the child. This means that if you
|
|
90
|
+
* have text in the child node, that it will be announced alongside the
|
|
91
|
+
* description to the screen reader.
|
|
92
|
+
*
|
|
93
|
+
* Note: if label and description are both provided, label will be used and
|
|
94
|
+
* description will not be used
|
|
95
|
+
*/
|
|
96
|
+
description: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
97
|
+
/**
|
|
98
|
+
* Specify the duration in milliseconds to delay before displaying the tooltip
|
|
99
|
+
*/
|
|
100
|
+
enterDelayMs: PropTypes.Requireable<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Provide the label to be rendered inside of the Tooltip. The label will use
|
|
103
|
+
* `aria-labelledby` and will fully describe the child node that is provided.
|
|
104
|
+
* This means that if you have text in the child node, that it will not be
|
|
105
|
+
* announced to the screen reader.
|
|
106
|
+
*
|
|
107
|
+
* Note: if label and description are both provided, description will not be
|
|
108
|
+
* used
|
|
109
|
+
*/
|
|
110
|
+
label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
111
|
+
/**
|
|
112
|
+
* Specify the duration in milliseconds to delay before hiding the tooltip
|
|
113
|
+
*/
|
|
114
|
+
leaveDelayMs: PropTypes.Requireable<number>;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export { Tooltip };
|
|
@@ -103,10 +103,12 @@ function Tooltip(_ref) {
|
|
|
103
103
|
|
|
104
104
|
useNoInteractiveChildren(tooltipRef, 'The Tooltip component must have no interactive content rendered by the' + '`label` or `description` prop');
|
|
105
105
|
useEffect(function () {
|
|
106
|
-
|
|
106
|
+
if (containerRef !== null && containerRef.current) {
|
|
107
|
+
var interactiveContent = getInteractiveContent(containerRef.current);
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
if (!interactiveContent) {
|
|
110
|
+
setOpen(false);
|
|
111
|
+
}
|
|
110
112
|
}
|
|
111
113
|
});
|
|
112
114
|
return /*#__PURE__*/React__default.createElement(Popover, _extends({}, rest, {
|
|
@@ -118,7 +120,7 @@ function Tooltip(_ref) {
|
|
|
118
120
|
onMouseLeave: onMouseLeave,
|
|
119
121
|
open: open,
|
|
120
122
|
ref: containerRef
|
|
121
|
-
}), /*#__PURE__*/React__default.cloneElement(child, _objectSpread2(_objectSpread2({}, triggerProps), getChildEventHandlers(child.props))), /*#__PURE__*/React__default.createElement(PopoverContent, {
|
|
123
|
+
}), child !== undefined ? /*#__PURE__*/React__default.cloneElement(child, _objectSpread2(_objectSpread2({}, triggerProps), getChildEventHandlers(child.props))) : null, /*#__PURE__*/React__default.createElement(PopoverContent, {
|
|
122
124
|
"aria-hidden": "true",
|
|
123
125
|
className: "".concat(prefix, "--tooltip-content"),
|
|
124
126
|
id: id,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
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
|
+
import { DefinitionTooltip } from './DefinitionTooltip';
|
|
8
|
+
import { Tooltip } from './Tooltip';
|
|
9
|
+
export { DefinitionTooltip, Tooltip };
|
package/es/index.d.ts
CHANGED
|
@@ -107,6 +107,8 @@ export * from './components/Layer';
|
|
|
107
107
|
export { LayoutDirection as unstable_LayoutDirection, useLayoutDirection as unstable_useLayoutDirection, } from './components/Layout';
|
|
108
108
|
export { Menu as unstable_Menu, MenuItem as unstable_MenuItem, MenuItemDivider as unstable_MenuItemDivider, MenuItemGroup as unstable_MenuItemGroup, MenuItemRadioGroup as unstable_MenuItemRadioGroup, MenuItemSelectable as unstable_MenuItemSelectable, } from './components/Menu';
|
|
109
109
|
export { OverflowMenuV2 as unstable_OverflowMenuV2 } from './components/OverflowMenuV2';
|
|
110
|
+
export { ComboButton as unstable_ComboButton } from './components/ComboButton';
|
|
111
|
+
export { MenuButton as unstable_MenuButton } from './components/MenuButton';
|
|
110
112
|
export { PageSelector as unstable_PageSelector, Pagination as unstable_Pagination, } from './components/Pagination/experimental';
|
|
111
113
|
export * from './components/Popover';
|
|
112
114
|
export * from './components/ProgressBar';
|
package/es/index.js
CHANGED
|
@@ -37,10 +37,13 @@ export { Heading, Section } from './components/Heading/index.js';
|
|
|
37
37
|
export { IconButton } from './components/IconButton/index.js';
|
|
38
38
|
export { Layer, useLayer } from './components/Layer/index.js';
|
|
39
39
|
export { OverflowMenuV2 as unstable_OverflowMenuV2 } from './components/OverflowMenuV2/index.js';
|
|
40
|
+
export { ComboButton as unstable_ComboButton } from './components/ComboButton/index.js';
|
|
41
|
+
export { MenuButton as unstable_MenuButton } from './components/MenuButton/index.js';
|
|
40
42
|
export { Popover, PopoverContent } from './components/Popover/index.js';
|
|
41
43
|
export { HStack, VStack } from './components/Stack/index.js';
|
|
42
|
-
import './components/Text/index.js';
|
|
43
44
|
export { DefinitionTooltip } from './components/Tooltip/DefinitionTooltip.js';
|
|
45
|
+
export { Tooltip } from './components/Tooltip/Tooltip.js';
|
|
46
|
+
import './components/Text/index.js';
|
|
44
47
|
export { GlobalTheme, Theme, ThemeContext, useTheme } from './components/Theme/index.js';
|
|
45
48
|
export { PrefixContext, usePrefix } from './internal/usePrefix.js';
|
|
46
49
|
export { useIdPrefix } from './internal/useIdPrefix.js';
|
|
@@ -76,7 +79,6 @@ export { default as NumberInputSkeleton } from './components/NumberInput/NumberI
|
|
|
76
79
|
export { default as ProgressIndicatorSkeleton } from './components/ProgressIndicator/ProgressIndicator.Skeleton.js';
|
|
77
80
|
export { default as ExpandableSearch } from './components/ExpandableSearch/ExpandableSearch.js';
|
|
78
81
|
export { default as TabsSkeleton } from './components/Tabs/Tabs.Skeleton.js';
|
|
79
|
-
export { default as RadioTile } from './components/RadioTile/RadioTile.js';
|
|
80
82
|
export { Toggle } from './components/Toggle/Toggle.js';
|
|
81
83
|
export { default as TreeNode } from './components/TreeView/TreeNode.js';
|
|
82
84
|
export { default as TreeView } from './components/TreeView/TreeView.js';
|
|
@@ -185,6 +187,7 @@ export { default as TextArea } from './components/TextArea/TextArea.js';
|
|
|
185
187
|
export { default as TextInputSkeleton } from './components/TextInput/TextInput.Skeleton.js';
|
|
186
188
|
export { default as TextInput } from './components/TextInput/TextInput.js';
|
|
187
189
|
export { ClickableTile, ExpandableTile, SelectableTile, Tile, TileAboveTheFoldContent, TileBelowTheFoldContent } from './components/Tile/Tile.js';
|
|
190
|
+
export { default as RadioTile } from './components/RadioTile/RadioTile.js';
|
|
188
191
|
export { default as TimePicker } from './components/TimePicker/TimePicker.js';
|
|
189
192
|
export { default as UnorderedList } from './components/UnorderedList/UnorderedList.js';
|
|
190
193
|
export { default as SkeletonText } from './components/SkeletonText/SkeletonText.js';
|
|
@@ -212,4 +215,3 @@ export { default as SideNavMenu } from './components/UIShell/SideNavMenu.js';
|
|
|
212
215
|
export { default as SideNavMenuItem } from './components/UIShell/SideNavMenuItem.js';
|
|
213
216
|
export { default as SideNavSwitcher } from './components/UIShell/SideNavSwitcher.js';
|
|
214
217
|
export { Stack } from './components/Stack/Stack.js';
|
|
215
|
-
export { Tooltip } from './components/Tooltip/Tooltip.js';
|
|
@@ -25,8 +25,7 @@ var ClickListener = /*#__PURE__*/function (_React$Component) {
|
|
|
25
25
|
_classCallCheck(this, ClickListener);
|
|
26
26
|
|
|
27
27
|
_this = _super.call(this, props); // We manually bind handlers in this Component, versus using class
|
|
28
|
-
// properties, so that we can properly test the `handleRef` handler
|
|
29
|
-
// enzyme.
|
|
28
|
+
// properties, so that we can properly test the `handleRef` handler.
|
|
30
29
|
|
|
31
30
|
_this.handleRef = _this.handleRef.bind(_assertThisInitialized(_this));
|
|
32
31
|
_this.handleDocumentClick = _this.handleDocumentClick.bind(_assertThisInitialized(_this));
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
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
|
+
import { useState } from 'react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {object} useAttachedMenuReturn
|
|
13
|
+
* @property {boolean} open Whether the menu is open or not
|
|
14
|
+
* @property {[number, number]} x The x position of the menu
|
|
15
|
+
* @property {[number, number]} y The y position of the menu
|
|
16
|
+
* @property {Function} handleClick A function to be called when the trigger element receives a click event
|
|
17
|
+
* @property {Function} handleMousedown A function to be called when the trigger element recives a mousedown event
|
|
18
|
+
* @property {Function} handleClose A function to be called when the menu emits onClose
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This hook contains common code to be used when a menu should be visually attached to an anchor based on a click event.
|
|
23
|
+
*
|
|
24
|
+
* @param {Element|object} anchor The element or ref the menu should visually be attached to.
|
|
25
|
+
* @returns {useAttachedMenuReturn}
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
function useAttachedMenu(anchor) {
|
|
29
|
+
var _useState = useState(false),
|
|
30
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
+
open = _useState2[0],
|
|
32
|
+
setOpen = _useState2[1];
|
|
33
|
+
|
|
34
|
+
var _useState3 = useState([[-1, -1], [-1, -1]]),
|
|
35
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
36
|
+
position = _useState4[0],
|
|
37
|
+
setPosition = _useState4[1];
|
|
38
|
+
|
|
39
|
+
function openMenu() {
|
|
40
|
+
var anchorEl = (anchor === null || anchor === void 0 ? void 0 : anchor.current) || anchor;
|
|
41
|
+
|
|
42
|
+
if (anchorEl) {
|
|
43
|
+
var _anchorEl$getBounding = anchorEl.getBoundingClientRect(),
|
|
44
|
+
left = _anchorEl$getBounding.left,
|
|
45
|
+
top = _anchorEl$getBounding.top,
|
|
46
|
+
right = _anchorEl$getBounding.right,
|
|
47
|
+
bottom = _anchorEl$getBounding.bottom;
|
|
48
|
+
|
|
49
|
+
setPosition([[left, right], [top, bottom]]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setOpen(true);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function closeMenu() {
|
|
56
|
+
setOpen(false);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleClick() {
|
|
60
|
+
if (open) {
|
|
61
|
+
closeMenu();
|
|
62
|
+
} else {
|
|
63
|
+
openMenu();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function handleMousedown(e) {
|
|
68
|
+
// prevent default for mousedown on trigger element to avoid
|
|
69
|
+
// the "blur" event from firing on the menu as this would close
|
|
70
|
+
// it and immediately re-open since "click" event is fired after
|
|
71
|
+
// "blur" event.
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
open: open,
|
|
77
|
+
x: position[0],
|
|
78
|
+
y: position[1],
|
|
79
|
+
handleClick: handleClick,
|
|
80
|
+
handleMousedown: handleMousedown,
|
|
81
|
+
handleClose: closeMenu
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { useAttachedMenu };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
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
|
+
import { SetStateAction } from 'react';
|
|
8
|
+
/**
|
|
9
|
+
* `useDelayedState` mirrors `useState` but also allows you to add a delay to
|
|
10
|
+
* when your state updates. You can provide a second argument to `setState`,
|
|
11
|
+
* `delayMs`, which will be the time in milliseconds after which the state is
|
|
12
|
+
* updated.
|
|
13
|
+
*
|
|
14
|
+
* This hook will clean up pending timers in `useEffect` and will cancel any
|
|
15
|
+
* pending timers when a `setState` is called before the state is updated from
|
|
16
|
+
* a previous call
|
|
17
|
+
*/
|
|
18
|
+
export type DispatchWithDelay<A> = (value: A, delayMS?: number) => void;
|
|
19
|
+
export declare function useDelayedState<S>(initialState: S): [S, DispatchWithDelay<SetStateAction<S>>];
|
|
@@ -29,8 +29,10 @@ function useDelayedState(initialState) {
|
|
|
29
29
|
// always return the same reference for the `setState` updater
|
|
30
30
|
|
|
31
31
|
var setStateWithDelay = useCallback(function (stateToSet) {
|
|
32
|
+
var _timeoutId$current;
|
|
33
|
+
|
|
32
34
|
var delayMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
33
|
-
clearTimeout(timeoutId.current);
|
|
35
|
+
window.clearTimeout((_timeoutId$current = timeoutId.current) !== null && _timeoutId$current !== void 0 ? _timeoutId$current : undefined);
|
|
34
36
|
timeoutId.current = null;
|
|
35
37
|
|
|
36
38
|
if (delayMs === 0) {
|
|
@@ -38,14 +40,16 @@ function useDelayedState(initialState) {
|
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
timeoutId.current = setTimeout(function () {
|
|
43
|
+
timeoutId.current = window.setTimeout(function () {
|
|
42
44
|
setState(stateToSet);
|
|
43
45
|
timeoutId.current = null;
|
|
44
46
|
}, delayMs);
|
|
45
47
|
}, []);
|
|
46
48
|
useEffect(function () {
|
|
47
49
|
return function () {
|
|
48
|
-
|
|
50
|
+
var _timeoutId$current2;
|
|
51
|
+
|
|
52
|
+
window.clearTimeout((_timeoutId$current2 = timeoutId.current) !== null && _timeoutId$current2 !== void 0 ? _timeoutId$current2 : undefined);
|
|
49
53
|
};
|
|
50
54
|
}, []);
|
|
51
55
|
return [state, setStateWithDelay];
|
package/es/internal/useId.js
CHANGED
|
@@ -31,7 +31,9 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
|
31
31
|
var useResizeObserver__default = /*#__PURE__*/_interopDefaultLegacy(useResizeObserver);
|
|
32
32
|
var copy__default = /*#__PURE__*/_interopDefaultLegacy(copy);
|
|
33
33
|
|
|
34
|
-
var
|
|
34
|
+
var _CodeSnippet$propType, _CodeSnippet$defaultP;
|
|
35
|
+
|
|
36
|
+
var _excluded = ["className", "type", "children", "disabled", "feedback", "feedbackTimeout", "onClick", "aria-label", "ariaLabel", "copyText", "copyButtonDescription", "light", "showMoreText", "showLessText", "hideCopyButton", "wrapText", "maxCollapsedNumberOfRows", "maxExpandedNumberOfRows", "minCollapsedNumberOfRows", "minExpandedNumberOfRows"];
|
|
35
37
|
var rowHeightInPixels = 16;
|
|
36
38
|
var defaultMaxCollapsedNumberOfRows = 15;
|
|
37
39
|
var defaultMaxExpandedNumberOfRows = 0;
|
|
@@ -48,7 +50,8 @@ function CodeSnippet(_ref) {
|
|
|
48
50
|
feedback = _ref.feedback,
|
|
49
51
|
feedbackTimeout = _ref.feedbackTimeout,
|
|
50
52
|
onClick = _ref.onClick,
|
|
51
|
-
ariaLabel = _ref
|
|
53
|
+
ariaLabel = _ref['aria-label'],
|
|
54
|
+
deprecatedAriaLabel = _ref.ariaLabel,
|
|
52
55
|
copyText = _ref.copyText,
|
|
53
56
|
copyButtonDescription = _ref.copyButtonDescription,
|
|
54
57
|
light = _ref.light,
|
|
@@ -183,7 +186,7 @@ function CodeSnippet(_ref) {
|
|
|
183
186
|
|
|
184
187
|
return /*#__PURE__*/React__default["default"].createElement(Copy["default"], _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
185
188
|
onClick: handleCopyClick,
|
|
186
|
-
"aria-label": ariaLabel,
|
|
189
|
+
"aria-label": deprecatedAriaLabel || ariaLabel,
|
|
187
190
|
"aria-describedby": uid,
|
|
188
191
|
className: codeSnippetClasses,
|
|
189
192
|
feedback: feedback,
|
|
@@ -226,10 +229,12 @@ function CodeSnippet(_ref) {
|
|
|
226
229
|
className: codeSnippetClasses
|
|
227
230
|
}), /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
|
|
228
231
|
ref: codeContainerRef,
|
|
229
|
-
role: type === 'single' ? 'textbox' : null,
|
|
230
|
-
tabIndex: type === 'single' && !disabled ? 0 : null,
|
|
232
|
+
role: type === 'single' || type === 'multi' ? 'textbox' : null,
|
|
233
|
+
tabIndex: (type === 'single' || type === 'multi') && !disabled ? 0 : null,
|
|
231
234
|
className: "".concat(prefix, "--snippet-container"),
|
|
232
|
-
"aria-label": ariaLabel || 'code-snippet',
|
|
235
|
+
"aria-label": deprecatedAriaLabel || ariaLabel || 'code-snippet',
|
|
236
|
+
"aria-readonly": type === 'single' || type === 'multi' ? true : null,
|
|
237
|
+
"aria-multiline": type === 'multi' ? true : null,
|
|
233
238
|
onScroll: type === 'single' && handleScroll || null
|
|
234
239
|
}, containerStyle), /*#__PURE__*/React__default["default"].createElement("pre", {
|
|
235
240
|
ref: codeContentRef,
|
|
@@ -263,114 +268,7 @@ function CodeSnippet(_ref) {
|
|
|
263
268
|
})));
|
|
264
269
|
}
|
|
265
270
|
|
|
266
|
-
CodeSnippet.propTypes = {
|
|
267
|
-
|
|
268
|
-
* Specify a label to be read by screen readers on the containing <textbox>
|
|
269
|
-
* node
|
|
270
|
-
*/
|
|
271
|
-
ariaLabel: PropTypes__default["default"].string,
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Provide the content of your CodeSnippet as a node or string
|
|
275
|
-
*/
|
|
276
|
-
children: PropTypes__default["default"].node,
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Specify an optional className to be applied to the container node
|
|
280
|
-
*/
|
|
281
|
-
className: PropTypes__default["default"].string,
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Specify the description for the Copy Button
|
|
285
|
-
*/
|
|
286
|
-
copyButtonDescription: PropTypes__default["default"].string,
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Optional text to copy. If not specified, the `children` node's `innerText`
|
|
290
|
-
* will be used as the copy value.
|
|
291
|
-
*/
|
|
292
|
-
copyText: PropTypes__default["default"].string,
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Specify whether or not the CodeSnippet should be disabled
|
|
296
|
-
*/
|
|
297
|
-
disabled: PropTypes__default["default"].bool,
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Specify the string displayed when the snippet is copied
|
|
301
|
-
*/
|
|
302
|
-
feedback: PropTypes__default["default"].string,
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Specify the time it takes for the feedback message to timeout
|
|
306
|
-
*/
|
|
307
|
-
feedbackTimeout: PropTypes__default["default"].number,
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Specify whether or not a copy button should be used/rendered.
|
|
311
|
-
*/
|
|
312
|
-
hideCopyButton: PropTypes__default["default"].bool,
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Specify whether you are using the light variant of the Code Snippet,
|
|
316
|
-
* typically used for inline snippet to display an alternate color
|
|
317
|
-
*/
|
|
318
|
-
light: deprecate["default"](PropTypes__default["default"].bool, 'The `light` prop for `CodeSnippet` has ' + 'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.'),
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Specify the maximum number of rows to be shown when in collapsed view
|
|
322
|
-
*/
|
|
323
|
-
maxCollapsedNumberOfRows: PropTypes__default["default"].number,
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Specify the maximum number of rows to be shown when in expanded view
|
|
327
|
-
*/
|
|
328
|
-
maxExpandedNumberOfRows: PropTypes__default["default"].number,
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Specify the minimum number of rows to be shown when in collapsed view
|
|
332
|
-
*/
|
|
333
|
-
minCollapsedNumberOfRows: PropTypes__default["default"].number,
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Specify the minimum number of rows to be shown when in expanded view
|
|
337
|
-
*/
|
|
338
|
-
minExpandedNumberOfRows: PropTypes__default["default"].number,
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* An optional handler to listen to the `onClick` even fired by the Copy
|
|
342
|
-
* Button
|
|
343
|
-
*/
|
|
344
|
-
onClick: PropTypes__default["default"].func,
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Specify a string that is displayed when the Code Snippet has been
|
|
348
|
-
* interacted with to show more lines
|
|
349
|
-
*/
|
|
350
|
-
showLessText: PropTypes__default["default"].string,
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Specify a string that is displayed when the Code Snippet text is more
|
|
354
|
-
* than 15 lines
|
|
355
|
-
*/
|
|
356
|
-
showMoreText: PropTypes__default["default"].string,
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Provide the type of Code Snippet
|
|
360
|
-
*/
|
|
361
|
-
type: PropTypes__default["default"].oneOf(['single', 'inline', 'multi']),
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Specify whether or not to wrap the text.
|
|
365
|
-
*/
|
|
366
|
-
wrapText: PropTypes__default["default"].bool
|
|
367
|
-
};
|
|
368
|
-
CodeSnippet.defaultProps = {
|
|
369
|
-
ariaLabel: 'Copy to clipboard',
|
|
370
|
-
type: 'single',
|
|
371
|
-
showMoreText: 'Show more',
|
|
372
|
-
showLessText: 'Show less',
|
|
373
|
-
wrapText: false
|
|
374
|
-
};
|
|
271
|
+
CodeSnippet.propTypes = (_CodeSnippet$propType = {}, _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, 'aria-label', PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "ariaLabel", deprecate["default"](PropTypes__default["default"].string, 'This prop syntax has been deprecated. Please use the new `aria-label`.')), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "children", PropTypes__default["default"].node), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "className", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "copyButtonDescription", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "copyText", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "disabled", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "feedback", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "feedbackTimeout", PropTypes__default["default"].number), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "hideCopyButton", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "light", deprecate["default"](PropTypes__default["default"].bool, 'The `light` prop for `CodeSnippet` has ' + 'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.')), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "maxCollapsedNumberOfRows", PropTypes__default["default"].number), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "maxExpandedNumberOfRows", PropTypes__default["default"].number), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "minCollapsedNumberOfRows", PropTypes__default["default"].number), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "minExpandedNumberOfRows", PropTypes__default["default"].number), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "onClick", PropTypes__default["default"].func), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "showLessText", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "showMoreText", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "type", PropTypes__default["default"].oneOf(['single', 'inline', 'multi'])), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$propType, "wrapText", PropTypes__default["default"].bool), _CodeSnippet$propType);
|
|
272
|
+
CodeSnippet.defaultProps = (_CodeSnippet$defaultP = {}, _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$defaultP, 'aria-label', 'Copy to clipboard'), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$defaultP, "type", 'single'), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$defaultP, "showMoreText", 'Show more'), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$defaultP, "showLessText", 'Show less'), _rollupPluginBabelHelpers.defineProperty(_CodeSnippet$defaultP, "wrapText", false), _CodeSnippet$defaultP);
|
|
375
273
|
|
|
376
274
|
exports["default"] = CodeSnippet;
|
|
@@ -11,6 +11,12 @@ import { ListBoxType, ListBoxSize } from '../ListBox';
|
|
|
11
11
|
type ExcludedAttributes = 'id' | 'onChange' | 'onClick' | 'type' | 'size';
|
|
12
12
|
export interface ComboBoxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
|
|
13
13
|
/**
|
|
14
|
+
* Specify a label to be read by screen readers on the container node
|
|
15
|
+
* 'aria-label' of the ListBox component.
|
|
16
|
+
*/
|
|
17
|
+
['aria-label']?: string;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated please use `aria-label` instead.
|
|
14
20
|
* 'aria-label' of the ListBox component.
|
|
15
21
|
*/
|
|
16
22
|
ariaLabel?: string;
|