@elliemae/ds-tooltip 2.3.0-alpha.8 → 2.3.0-next.10
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/cjs/index.js +25 -0
- package/cjs/v1/DSTooltip.js +115 -0
- package/cjs/v1/TooltipType.js +10 -0
- package/cjs/v2/DSTooltip.js +147 -0
- package/cjs/v2/DSTooltipArrow.js +39 -0
- package/cjs/v2/TooltipType.js +10 -0
- package/cjs/v2/index.d.js +2 -0
- package/cjs/v2/propTypes.js +27 -0
- package/cjs/v2/styles.js +62 -0
- package/cjs/v2/utils/setMultipleRefs.js +30 -0
- package/cjs/v2/utils/tooltipPositions.js +20 -0
- package/cjs/v3/DSTooltipV3.js +122 -0
- package/cjs/v3/TooltipV3DatatestId.js +10 -0
- package/cjs/v3/constants.js +9 -0
- package/cjs/v3/defaultProps.js +15 -0
- package/cjs/v3/index.js +12 -0
- package/cjs/v3/propTypes.js +29 -0
- package/cjs/v3/styles.js +52 -0
- package/cjs/v3/utils.js +14 -0
- package/esm/index.js +6 -0
- package/esm/v1/DSTooltip.js +100 -0
- package/esm/v1/TooltipType.js +6 -0
- package/esm/v2/DSTooltip.js +136 -0
- package/esm/v2/DSTooltipArrow.js +31 -0
- package/esm/v2/TooltipType.js +6 -0
- package/esm/v2/index.d.js +1 -0
- package/esm/v2/propTypes.js +23 -0
- package/esm/v2/styles.js +49 -0
- package/esm/v2/utils/setMultipleRefs.js +26 -0
- package/esm/v2/utils/tooltipPositions.js +16 -0
- package/esm/v3/DSTooltipV3.js +110 -0
- package/esm/v3/TooltipV3DatatestId.js +6 -0
- package/esm/v3/constants.js +4 -0
- package/esm/v3/defaultProps.js +11 -0
- package/esm/v3/index.js +2 -0
- package/esm/v3/propTypes.js +25 -0
- package/esm/v3/styles.js +41 -0
- package/esm/v3/utils.js +10 -0
- package/package.json +72 -62
- package/types/index.d.ts +6 -0
- package/types/v1/DSTooltip.d.ts +89 -0
- package/types/v1/TooltipType.d.ts +4 -0
- package/types/v2/DSTooltip.d.ts +70 -0
- package/types/v2/DSTooltipArrow.d.ts +4 -0
- package/types/v2/TooltipType.d.ts +5 -0
- package/types/v2/propTypes.d.ts +60 -0
- package/types/v2/styles.d.ts +7 -0
- package/types/v2/tests/DSTooltipV2.test.d.ts +1 -0
- package/types/v2/utils/setMultipleRefs.d.ts +1 -0
- package/types/v2/utils/tooltipPositions.d.ts +15 -0
- package/types/v3/DSTooltipV3.d.ts +61 -0
- package/types/v3/TooltipV3DatatestId.d.ts +4 -0
- package/types/v3/constants.d.ts +2 -0
- package/types/v3/defaultProps.d.ts +2 -0
- package/types/v3/index.d.ts +2 -0
- package/types/v3/propTypes.d.ts +87 -0
- package/types/v3/styles.d.ts +10 -0
- package/types/v3/utils.d.ts +3 -0
- package/dist/cjs/index.js +0 -41
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/v1/DSTooltip.js +0 -118
- package/dist/cjs/v1/DSTooltip.js.map +0 -7
- package/dist/cjs/v1/TooltipType.js +0 -38
- package/dist/cjs/v1/TooltipType.js.map +0 -7
- package/dist/cjs/v2/DSTooltip.js +0 -143
- package/dist/cjs/v2/DSTooltip.js.map +0 -7
- package/dist/cjs/v2/DSTooltipArrow.js +0 -51
- package/dist/cjs/v2/DSTooltipArrow.js.map +0 -7
- package/dist/cjs/v2/TooltipType.js +0 -38
- package/dist/cjs/v2/TooltipType.js.map +0 -7
- package/dist/cjs/v2/index.d.js +0 -27
- package/dist/cjs/v2/index.d.js.map +0 -7
- package/dist/cjs/v2/propTypes.js +0 -56
- package/dist/cjs/v2/propTypes.js.map +0 -7
- package/dist/cjs/v2/styles.js +0 -131
- package/dist/cjs/v2/styles.js.map +0 -7
- package/dist/cjs/v2/utils/setMultipleRefs.js +0 -50
- package/dist/cjs/v2/utils/setMultipleRefs.js.map +0 -7
- package/dist/cjs/v2/utils/tooltipPositions.js +0 -48
- package/dist/cjs/v2/utils/tooltipPositions.js.map +0 -7
- package/dist/cjs/v3/TooltipV3DatatestId.js +0 -38
- package/dist/cjs/v3/TooltipV3DatatestId.js.map +0 -7
- package/dist/cjs/v3/config/useWithDefaultProps.js +0 -44
- package/dist/cjs/v3/config/useWithDefaultProps.js.map +0 -7
- package/dist/cjs/v3/index.d.js +0 -27
- package/dist/cjs/v3/index.d.js.map +0 -7
- package/dist/cjs/v3/index.js +0 -115
- package/dist/cjs/v3/index.js.map +0 -7
- package/dist/cjs/v3/propsTypes.js +0 -80
- package/dist/cjs/v3/propsTypes.js.map +0 -7
- package/dist/cjs/v3/styleds.js +0 -70
- package/dist/cjs/v3/styleds.js.map +0 -7
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/v1/DSTooltip.js +0 -101
- package/dist/esm/v1/DSTooltip.js.map +0 -7
- package/dist/esm/v1/TooltipType.js +0 -9
- package/dist/esm/v1/TooltipType.js.map +0 -7
- package/dist/esm/v2/DSTooltip.js +0 -119
- package/dist/esm/v2/DSTooltip.js.map +0 -7
- package/dist/esm/v2/DSTooltipArrow.js +0 -22
- package/dist/esm/v2/DSTooltipArrow.js.map +0 -7
- package/dist/esm/v2/TooltipType.js +0 -9
- package/dist/esm/v2/TooltipType.js.map +0 -7
- package/dist/esm/v2/index.d.js +0 -2
- package/dist/esm/v2/index.d.js.map +0 -7
- package/dist/esm/v2/propTypes.js +0 -27
- package/dist/esm/v2/propTypes.js.map +0 -7
- package/dist/esm/v2/styles.js +0 -102
- package/dist/esm/v2/styles.js.map +0 -7
- package/dist/esm/v2/utils/setMultipleRefs.js +0 -21
- package/dist/esm/v2/utils/setMultipleRefs.js.map +0 -7
- package/dist/esm/v2/utils/tooltipPositions.js +0 -19
- package/dist/esm/v2/utils/tooltipPositions.js.map +0 -7
- package/dist/esm/v3/TooltipV3DatatestId.js +0 -9
- package/dist/esm/v3/TooltipV3DatatestId.js.map +0 -7
- package/dist/esm/v3/config/useWithDefaultProps.js +0 -15
- package/dist/esm/v3/config/useWithDefaultProps.js.map +0 -7
- package/dist/esm/v3/index.d.js +0 -2
- package/dist/esm/v3/index.d.js.map +0 -7
- package/dist/esm/v3/index.js +0 -91
- package/dist/esm/v3/index.js.map +0 -7
- package/dist/esm/v3/propsTypes.js +0 -51
- package/dist/esm/v3/propsTypes.js.map +0 -7
- package/dist/esm/v3/styleds.js +0 -41
- package/dist/esm/v3/styleds.js.map +0 -7
package/cjs/v3/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var DSTooltipV3 = require('./DSTooltipV3.js');
|
|
6
|
+
var TooltipV3DatatestId = require('./TooltipV3DatatestId.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.DSTooltipV3 = DSTooltipV3.DSTooltipV3;
|
|
11
|
+
exports.DSTooltipV3WithSchema = DSTooltipV3.DSTooltipV3WithSchema;
|
|
12
|
+
exports.TooltipV3DatatestId = TooltipV3DatatestId.TooltipV3DatatestId;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var reactDesc = require('react-desc');
|
|
6
|
+
var constants = require('./constants.js');
|
|
7
|
+
|
|
8
|
+
const propTypes = {
|
|
9
|
+
text: reactDesc.PropTypes.string.description('Tooltip text to be displayed on hover/focus').isRequired,
|
|
10
|
+
textAlign: reactDesc.PropTypes.oneOf(constants.TEXT_ALIGNMENT).description('Tooltip text alignment').defaultValue('left'),
|
|
11
|
+
wrapWords: reactDesc.PropTypes.bool.description('Break words into a new line. Useful when words exceed tooltip max-lenght.').defaultValue(false),
|
|
12
|
+
children: reactDesc.PropTypes.node.description('Element to tie the tooltip to, must be a single node').isRequired,
|
|
13
|
+
withoutPortal: reactDesc.PropTypes.bool.description('Whether or not the tooltip content should appear in a DOM portal or not').defaultValue(true),
|
|
14
|
+
withoutArrow: reactDesc.PropTypes.bool.description('Whether or not the tooltip should use the arrow').defaultValue(false),
|
|
15
|
+
boundaryElement: reactDesc.PropTypes.element.description('Bounding element to calculate upon, defaults to "clippingParents",' + 'which are the scrolling containers that may cause element to be partially or fully cut off').defaultValue(undefined),
|
|
16
|
+
withoutAnimation: reactDesc.PropTypes.bool.description('Whether or not the popper context menu should be animated').defaultValue(false),
|
|
17
|
+
animationDuration: reactDesc.PropTypes.number.description('Popper context menus Animation duration in ms').defaultValue(100),
|
|
18
|
+
portalDOMContainer: reactDesc.PropTypes.element.description('When using portal, the container in which to append the DOM content, defaults to document body').defaultValue(undefined),
|
|
19
|
+
startPlacementPreference: reactDesc.PropTypes.oneOf(constants.PLACEMENT).description('start placement preferences, as per popperjs placement option').defaultValue("'top'"),
|
|
20
|
+
placementOrderPreference: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.oneOf(constants.PLACEMENT)).description('Array of placement preferences, as per popperjs "flip" placement option').defaultValue("['top', 'bottom', 'left', 'right']"),
|
|
21
|
+
zIndex: reactDesc.PropTypes.number.description('popperjs content z-index').defaultValue(1),
|
|
22
|
+
customOffset: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.number).description('placement offset array').defaultValue([0, 14]),
|
|
23
|
+
modifiers: reactDesc.PropTypes.array.description('modifiers array for full-custom tooltip-js override, https://tooltip.js.org/docs/v2/modifiers/').defaultValue(1),
|
|
24
|
+
id: reactDesc.PropTypes.string.description('Optional id appended to data-testid').defaultValue(''),
|
|
25
|
+
onOpen: reactDesc.PropTypes.func.description('Optional callback to be invoked when the tooltip opens').defaultValue('() => {}'),
|
|
26
|
+
onClose: reactDesc.PropTypes.func.description('Optional callback to be invoked when the tooltip closes').defaultValue('() => {}')
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.propTypes = propTypes;
|
package/cjs/v3/styles.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var styled = require('styled-components');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
10
|
+
|
|
11
|
+
const StyledTooltipContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
12
|
+
componentId: "sc-1jxtr2y-0"
|
|
13
|
+
})(["text-align:center;min-width:", ";max-width:250px;min-height:30px;display:grid;align-items:center;padding:", ";position:relative;background-color:white;border-radius:2px;font-size:13px;color:", ";"], _ref => {
|
|
14
|
+
let {
|
|
15
|
+
theme
|
|
16
|
+
} = _ref;
|
|
17
|
+
return theme.space.l;
|
|
18
|
+
}, _ref2 => {
|
|
19
|
+
let {
|
|
20
|
+
theme
|
|
21
|
+
} = _ref2;
|
|
22
|
+
return "".concat(theme.space.xxxs, " ").concat(theme.space.xs);
|
|
23
|
+
}, _ref3 => {
|
|
24
|
+
let {
|
|
25
|
+
theme
|
|
26
|
+
} = _ref3;
|
|
27
|
+
return theme.colors.neutral[600];
|
|
28
|
+
});
|
|
29
|
+
const StyledTooltipText = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
30
|
+
componentId: "sc-1jxtr2y-1"
|
|
31
|
+
})(["display:inline-block;text-align:", ";word-wrap:break-word;", ""], _ref4 => {
|
|
32
|
+
let {
|
|
33
|
+
textAlign
|
|
34
|
+
} = _ref4;
|
|
35
|
+
return textAlign;
|
|
36
|
+
}, _ref5 => {
|
|
37
|
+
let {
|
|
38
|
+
wrapWords
|
|
39
|
+
} = _ref5;
|
|
40
|
+
return wrapWords ? "word-break: break-all;" : "white-space: normal;";
|
|
41
|
+
});
|
|
42
|
+
const StyledMouseOverDetectionBox = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
43
|
+
componentId: "sc-1jxtr2y-2"
|
|
44
|
+
})(["position:absolute;top:-15px;right:-15px;width:calc(100% + 30px);height:calc(100% + 30px);z-index:-1;"]);
|
|
45
|
+
const StyledTriggerWrapper = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
46
|
+
componentId: "sc-1jxtr2y-3"
|
|
47
|
+
})(["display:inline-flex;width:100%;"]);
|
|
48
|
+
|
|
49
|
+
exports.StyledMouseOverDetectionBox = StyledMouseOverDetectionBox;
|
|
50
|
+
exports.StyledTooltipContainer = StyledTooltipContainer;
|
|
51
|
+
exports.StyledTooltipText = StyledTooltipText;
|
|
52
|
+
exports.StyledTriggerWrapper = StyledTriggerWrapper;
|
package/cjs/v3/utils.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
const useGlobalKeyboardListener = func => {
|
|
8
|
+
react.useEffect(() => {
|
|
9
|
+
document.addEventListener('keydown', func);
|
|
10
|
+
return () => document.removeEventListener('keydown', func);
|
|
11
|
+
}, [func]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.useGlobalKeyboardListener = useGlobalKeyboardListener;
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DSTooltip, TooltipContainer, TooltipText, TooltipWithSchema, DSTooltip as default } from './v1/DSTooltip.js';
|
|
2
|
+
export { DSTooltipV2, TooltipV2WithSchema } from './v2/DSTooltip.js';
|
|
3
|
+
export { tooltipPositions } from './v2/utils/tooltipPositions.js';
|
|
4
|
+
export { TooltipType } from './v2/TooltipType.js';
|
|
5
|
+
export { DSTooltipV3, DSTooltipV3WithSchema } from './v3/DSTooltipV3.js';
|
|
6
|
+
export { TooltipV3DatatestId } from './v3/TooltipV3DatatestId.js';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
8
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
9
|
+
import 'react';
|
|
10
|
+
import { PropTypes, describe } from 'react-desc';
|
|
11
|
+
import { aggregatedClasses, convertPropToCssClassName } from '@elliemae/ds-classnames';
|
|
12
|
+
import { getComponentFromProps } from '@elliemae/ds-utilities';
|
|
13
|
+
import { DEFAULT_DELAY_CLOSE, DEFAULT_DELAY_OPEN } from '@elliemae/ds-shared/constants';
|
|
14
|
+
import DSPopper, { positions, PopperPositions, interactions, PopperInteractions } from '@elliemae/ds-popper';
|
|
15
|
+
import { TooltipType } from './TooltipType.js';
|
|
16
|
+
import { jsx } from 'react/jsx-runtime';
|
|
17
|
+
|
|
18
|
+
const _excluded = ["containerProps", "innerRef", "placement", "title", "delayClose", "delayOpen", "interactionType", "triggerComponent", "className", "isOpen", "onOpen", "springAnimationComponent", "tooltipType", "showArrow", "zIndex"];
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
const blockName = 'tooltip';
|
|
24
|
+
const TooltipContainer = aggregatedClasses('div')(blockName, false, false, {
|
|
25
|
+
propsToRemoveFromFinalElement: ['isHovered', 'isDragged']
|
|
26
|
+
});
|
|
27
|
+
const TooltipText = aggregatedClasses('span')(blockName, 'text', false, {
|
|
28
|
+
propsToRemoveFromFinalElement: ['isHovered', 'isDragged']
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const DSTooltip = _ref => {
|
|
32
|
+
let {
|
|
33
|
+
containerProps = {},
|
|
34
|
+
innerRef,
|
|
35
|
+
placement = PopperPositions.TOP,
|
|
36
|
+
title = '',
|
|
37
|
+
delayClose = DEFAULT_DELAY_CLOSE,
|
|
38
|
+
delayOpen = DEFAULT_DELAY_OPEN,
|
|
39
|
+
interactionType = PopperInteractions.HOVER,
|
|
40
|
+
triggerComponent = null,
|
|
41
|
+
className = '',
|
|
42
|
+
isOpen = undefined,
|
|
43
|
+
onOpen = () => null,
|
|
44
|
+
springAnimationComponent = undefined,
|
|
45
|
+
tooltipType = TooltipType.TOOLTIP,
|
|
46
|
+
showArrow = true,
|
|
47
|
+
zIndex
|
|
48
|
+
} = _ref,
|
|
49
|
+
otherTooltipProps = _objectWithoutProperties(_ref, _excluded);
|
|
50
|
+
|
|
51
|
+
const {
|
|
52
|
+
cssClassName: tooltipBlockName
|
|
53
|
+
} = convertPropToCssClassName(blockName);
|
|
54
|
+
let Content = title;
|
|
55
|
+
|
|
56
|
+
if (typeof title === 'string') {
|
|
57
|
+
Content = /*#__PURE__*/_jsx(TooltipText, {}, void 0, title);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return /*#__PURE__*/_jsx(DSPopper, {
|
|
61
|
+
blockName: tooltipBlockName,
|
|
62
|
+
contentComponent: /*#__PURE__*/jsx(TooltipContainer, _objectSpread(_objectSpread(_objectSpread({}, containerProps), otherTooltipProps), {}, {
|
|
63
|
+
className: "tooltip-container--".concat(tooltipType, " ").concat(className),
|
|
64
|
+
innerRef: innerRef,
|
|
65
|
+
children: Content
|
|
66
|
+
})),
|
|
67
|
+
delayClose: delayClose,
|
|
68
|
+
delayOpen: delayOpen,
|
|
69
|
+
interactionType: interactionType,
|
|
70
|
+
isOpen: isOpen,
|
|
71
|
+
onOpen: onOpen,
|
|
72
|
+
placement: placement,
|
|
73
|
+
showArrow: tooltipType === TooltipType.TOOLTIP ? showArrow : false,
|
|
74
|
+
springAnimationComponent: springAnimationComponent,
|
|
75
|
+
triggerComponent: getComponentFromProps(triggerComponent),
|
|
76
|
+
zIndex: zIndex
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const tooltipProps = {
|
|
81
|
+
containerProps: PropTypes.object.description('Set of Properties attached to the main container'),
|
|
82
|
+
placement: PropTypes.oneOf(positions).description('Tooltip position').defaultValue(PopperPositions.TOP),
|
|
83
|
+
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).description('Tooltip content').isRequired,
|
|
84
|
+
delayClose: PropTypes.string.description('Delay to close the tooltip').defaultValue(DEFAULT_DELAY_CLOSE),
|
|
85
|
+
delayOpen: PropTypes.string.description('Delay to open the tooltip ').defaultValue(DEFAULT_DELAY_OPEN),
|
|
86
|
+
interactionType: PropTypes.oneOf(interactions).description('A type indicating how to open/close the tooltip').defaultValue(PopperInteractions.HOVER),
|
|
87
|
+
triggerComponent: PropTypes.element.description("The component that will open/close the tooltip. \n Cannot be used with disabled elements. \n https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled").isRequired,
|
|
88
|
+
isOpen: PropTypes.bool.description('Whether the tooltip is visible or not').defaultValue(undefined),
|
|
89
|
+
onOpen: PropTypes.func.description('Handler when the tooltip opens'),
|
|
90
|
+
springAnimationComponent: PropTypes.element.description('Spring animation component'),
|
|
91
|
+
showArrow: PropTypes.bool.description('Whether to show an arrow or not').defaultValue(true),
|
|
92
|
+
className: PropTypes.string.description('css class'),
|
|
93
|
+
tooltipType: PropTypes.oneOf(['tooltip', 'toolbar']).description('Type of tooltip').defaultValue(TooltipType.TOOLTIP),
|
|
94
|
+
zIndex: PropTypes.number.description('z-index value assigned to the tooltip').defaultValue(undefined),
|
|
95
|
+
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).description('Ref to the tooltip container element')
|
|
96
|
+
};
|
|
97
|
+
const TooltipWithSchema = describe(DSTooltip);
|
|
98
|
+
TooltipWithSchema.propTypes = tooltipProps;
|
|
99
|
+
|
|
100
|
+
export { DSTooltip, TooltipContainer, TooltipText, TooltipWithSchema, DSTooltip as default };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
8
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
9
|
+
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
10
|
+
import { describe } from 'react-desc';
|
|
11
|
+
import DSPortal from '@elliemae/ds-portal';
|
|
12
|
+
import { DEFAULT_DELAY_CLOSE, DEFAULT_DELAY_OPEN } from '@elliemae/ds-shared/constants';
|
|
13
|
+
import { usePopper } from 'react-popper';
|
|
14
|
+
import { tooltipPositions } from './utils/tooltipPositions.js';
|
|
15
|
+
import { TooltipType } from './TooltipType.js';
|
|
16
|
+
import { StyledTriggerComponentContainer, StyledTooltipContainer, StyledAnimatedTooltip, StyledTooltipText } from './styles.js';
|
|
17
|
+
import { DSTooltipArrow } from './DSTooltipArrow.js';
|
|
18
|
+
import { tooltipV2Props } from './propTypes.js';
|
|
19
|
+
import { setMultipleRefs } from './utils/setMultipleRefs.js';
|
|
20
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
21
|
+
|
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
+
|
|
26
|
+
const DSTooltipV2 = _ref => {
|
|
27
|
+
let {
|
|
28
|
+
containerProps = {},
|
|
29
|
+
innerRef,
|
|
30
|
+
placement = tooltipPositions.BOTTOM,
|
|
31
|
+
title = '',
|
|
32
|
+
delayClose = DEFAULT_DELAY_CLOSE,
|
|
33
|
+
delayOpen = DEFAULT_DELAY_OPEN,
|
|
34
|
+
triggerComponent = null,
|
|
35
|
+
className = '',
|
|
36
|
+
getIsOpen = () => null,
|
|
37
|
+
onOpen = () => null,
|
|
38
|
+
tooltipType = TooltipType.TOOLTIP,
|
|
39
|
+
showArrow = true,
|
|
40
|
+
offset = [0, 14],
|
|
41
|
+
zIndex = 10,
|
|
42
|
+
extraModifiers = {}
|
|
43
|
+
} = _ref;
|
|
44
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
45
|
+
const [isAnimating, setIsAnimating] = useState(false);
|
|
46
|
+
const [referenceElement, setReferenceElement] = useState(triggerComponent);
|
|
47
|
+
const [popperElement, setPopperElement] = useState(null);
|
|
48
|
+
const [arrowElement, setArrowElement] = useState(null);
|
|
49
|
+
const timerOpen = useRef(null);
|
|
50
|
+
const timerClosed = useRef(null);
|
|
51
|
+
const {
|
|
52
|
+
styles,
|
|
53
|
+
attributes
|
|
54
|
+
} = usePopper(referenceElement, popperElement, {
|
|
55
|
+
placement,
|
|
56
|
+
modifiers: [{
|
|
57
|
+
name: 'hide',
|
|
58
|
+
enabled: true
|
|
59
|
+
}, {
|
|
60
|
+
name: 'offset',
|
|
61
|
+
enabled: true,
|
|
62
|
+
options: {
|
|
63
|
+
offset: tooltipType === TooltipType.TOOLBAR ? [0, 0] : offset
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
name: 'arrow',
|
|
67
|
+
options: {
|
|
68
|
+
element: arrowElement
|
|
69
|
+
}
|
|
70
|
+
}, _objectSpread({}, extraModifiers)]
|
|
71
|
+
});
|
|
72
|
+
const handleShowTooltipOn = useCallback(() => {
|
|
73
|
+
timerOpen.current = setTimeout(() => {
|
|
74
|
+
setShowTooltip(true);
|
|
75
|
+
setIsAnimating(true);
|
|
76
|
+
getIsOpen(true);
|
|
77
|
+
onOpen();
|
|
78
|
+
}, delayOpen);
|
|
79
|
+
}, [delayOpen, getIsOpen, onOpen]);
|
|
80
|
+
const handleShowTooltipOff = useCallback(() => {
|
|
81
|
+
timerClosed.current = setTimeout(() => {
|
|
82
|
+
setShowTooltip(false);
|
|
83
|
+
setIsAnimating(true);
|
|
84
|
+
getIsOpen(false);
|
|
85
|
+
}, delayClose);
|
|
86
|
+
}, [delayClose, getIsOpen]);
|
|
87
|
+
const handleKeyDown = useCallback(e => {
|
|
88
|
+
if (e.key === 'Escape') {
|
|
89
|
+
e.target.blur();
|
|
90
|
+
}
|
|
91
|
+
}, []);
|
|
92
|
+
const checkAnimationStatus = useCallback(() => {
|
|
93
|
+
if (!showTooltip) {
|
|
94
|
+
setIsAnimating(false);
|
|
95
|
+
}
|
|
96
|
+
}, [showTooltip]);
|
|
97
|
+
useEffect(() => () => {
|
|
98
|
+
clearTimeout(timerClosed.current);
|
|
99
|
+
clearTimeout(timerOpen.current);
|
|
100
|
+
}, []);
|
|
101
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
102
|
+
children: [/*#__PURE__*/jsx(StyledTriggerComponentContainer, {
|
|
103
|
+
ref: setReferenceElement,
|
|
104
|
+
onMouseEnter: handleShowTooltipOn,
|
|
105
|
+
onMouseLeave: handleShowTooltipOff,
|
|
106
|
+
onFocus: handleShowTooltipOn,
|
|
107
|
+
onBlur: handleShowTooltipOff,
|
|
108
|
+
onKeyDown: handleKeyDown,
|
|
109
|
+
children: triggerComponent
|
|
110
|
+
}), isAnimating || showTooltip ? /*#__PURE__*/_jsx(DSPortal, {}, void 0, /*#__PURE__*/jsx(StyledTooltipContainer, _objectSpread(_objectSpread(_objectSpread({
|
|
111
|
+
className: className,
|
|
112
|
+
showTooltip: showTooltip,
|
|
113
|
+
tooltipType: tooltipType,
|
|
114
|
+
"data-testid": "ds-tooltip-container",
|
|
115
|
+
ref: ref => setMultipleRefs(setPopperElement, innerRef)(ref),
|
|
116
|
+
style: _objectSpread(_objectSpread({}, styles.popper), {}, {
|
|
117
|
+
zIndex
|
|
118
|
+
})
|
|
119
|
+
}, containerProps), attributes.popper), {}, {
|
|
120
|
+
children: /*#__PURE__*/_jsx(StyledAnimatedTooltip, {
|
|
121
|
+
showTooltip: showTooltip,
|
|
122
|
+
"data-testid": "ds-tooltip",
|
|
123
|
+
onAnimationEnd: checkAnimationStatus
|
|
124
|
+
}, void 0, /*#__PURE__*/_jsx(StyledTooltipText, {}, void 0, title), tooltipType === TooltipType.TOOLTIP && showArrow ? /*#__PURE__*/_jsx(DSTooltipArrow, {
|
|
125
|
+
arrowElementRef: setArrowElement,
|
|
126
|
+
style: styles.arrow,
|
|
127
|
+
placement: attributes.popper ? attributes.popper['data-popper-placement'] : 'bottom'
|
|
128
|
+
}) : null)
|
|
129
|
+
}))) : null]
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const TooltipV2WithSchema = describe(DSTooltipV2);
|
|
134
|
+
TooltipV2WithSchema.propTypes = tooltipV2Props;
|
|
135
|
+
|
|
136
|
+
export { DSTooltipV2, TooltipV2WithSchema };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'react';
|
|
3
|
+
import { StyledTooltipArrow } from './styles.js';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var _svg;
|
|
7
|
+
|
|
8
|
+
const DSTooltipArrow = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
placement,
|
|
11
|
+
style,
|
|
12
|
+
arrowElementRef
|
|
13
|
+
} = _ref;
|
|
14
|
+
return /*#__PURE__*/jsx(StyledTooltipArrow, {
|
|
15
|
+
"data-placement": placement,
|
|
16
|
+
style: style,
|
|
17
|
+
ref: arrowElementRef,
|
|
18
|
+
"data-testid": "ds-tooltip-arrow",
|
|
19
|
+
children: _svg || (_svg = /*#__PURE__*/_jsx("svg", {
|
|
20
|
+
viewBox: "0 0 30 30"
|
|
21
|
+
}, void 0, /*#__PURE__*/_jsx("path", {
|
|
22
|
+
className: "stroke",
|
|
23
|
+
d: "M23.7,27.1L17,19.9C16.5,19.3,15.8,19,15,19s-1.6,0.3-2.1,0.9l-6.6,7.2C5.3,28.1,3.4,29,2,29h26 C26.7,29,24.6,28.1,23.7,27.1z"
|
|
24
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
25
|
+
className: "fill",
|
|
26
|
+
d: "M23,27.8c1.1,1.2,3.4,2.2,5,2.2h2H0h2c1.7,0,3.9-1,5-2.2l6.6-7.2c0.7-0.8,2-0.8,2.7,0L23,27.8L23,27.8z"
|
|
27
|
+
})))
|
|
28
|
+
}, "popper-arrow");
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { DSTooltipArrow };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PropTypes } from 'react-desc';
|
|
2
|
+
import { DEFAULT_DELAY_CLOSE, DEFAULT_DELAY_OPEN } from '@elliemae/ds-shared/constants';
|
|
3
|
+
import { TooltipType } from './TooltipType.js';
|
|
4
|
+
import { tooltipPositions } from './utils/tooltipPositions.js';
|
|
5
|
+
|
|
6
|
+
const tooltipV2Props = {
|
|
7
|
+
containerProps: PropTypes.object.description('Set of Properties attached to the main container'),
|
|
8
|
+
placement: PropTypes.oneOf(Object.values(tooltipPositions)).description('Tooltip position').defaultValue(tooltipPositions.TOP),
|
|
9
|
+
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).description('Tooltip content').isRequired,
|
|
10
|
+
delayClose: PropTypes.number.description('Delay to close the tooltip').defaultValue(DEFAULT_DELAY_CLOSE),
|
|
11
|
+
delayOpen: PropTypes.number.description('Delay to open the tooltip ').defaultValue(DEFAULT_DELAY_OPEN),
|
|
12
|
+
triggerComponent: PropTypes.element.description("The component that will open/close the tooltip. \n Cannot be used with disabled elements. \n https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled").isRequired,
|
|
13
|
+
getIsOpen: PropTypes.func.description('Whether the tooltip is visible or not'),
|
|
14
|
+
onOpen: PropTypes.func.description('Callback when the tooltip opens'),
|
|
15
|
+
showArrow: PropTypes.bool.description('Whether to show an arrow or not').defaultValue(true),
|
|
16
|
+
className: PropTypes.string.description('css class'),
|
|
17
|
+
tooltipType: PropTypes.oneOf(['tooltip', 'toolbar']).description('Type of tooltip').defaultValue(TooltipType.TOOLTIP),
|
|
18
|
+
zIndex: PropTypes.number.description('z-index value assigned to the tooltip').defaultValue(undefined),
|
|
19
|
+
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).description('Ref to the tooltip container element'),
|
|
20
|
+
offset: PropTypes.arrayOf(PropTypes.number).description('Custom Offset for the tooltip [x, y]')
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { tooltipV2Props };
|
package/esm/v2/styles.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from '@babel/runtime/helpers/esm/taggedTemplateLiteral';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { kfrm, css } from '@elliemae/ds-system';
|
|
4
|
+
|
|
5
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
6
|
+
const showAnimation = kfrm(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n from {\n opacity: 0;\n transform: scale(0.8);\n }\n\n to {\n opacity: 1;\n transform: scale(1);\n visibility: visible;\n }\n"])));
|
|
7
|
+
const hideAnimation = kfrm(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n 0% {\n opacity: 1;\n transform: scale(1);\n }\n\n 100% {\n opacity: 0;\n transform: scale(0.8);\n }\n"])));
|
|
8
|
+
const StyledTooltipContainer = /*#__PURE__*/styled.div.withConfig({
|
|
9
|
+
componentId: "sc-1dtjf9j-0"
|
|
10
|
+
})(["&[data-popper-reference-hidden='true']{display:none;pointer-events:none;}"]);
|
|
11
|
+
const StyledAnimatedTooltip = /*#__PURE__*/styled.div.withConfig({
|
|
12
|
+
componentId: "sc-1dtjf9j-1"
|
|
13
|
+
})(["text-align:center;min-width:", ";max-width:250px;min-height:24px;padding:", ";position:relative;background-color:white;border-radius:2px;font-size:13px;color:", ";box-shadow:0 1px 5px 0 rgb(0 0 0 / 13%),0 2px 4px 0 rgb(0 0 0 / 20%);filter:drop-shadow(0 4px 8px rgba(0,0,0,0.2));visibility:", ";", " transition:visibility 0.1s ease-in;"], _ref => {
|
|
14
|
+
let {
|
|
15
|
+
theme
|
|
16
|
+
} = _ref;
|
|
17
|
+
return theme.space.l;
|
|
18
|
+
}, _ref2 => {
|
|
19
|
+
let {
|
|
20
|
+
theme
|
|
21
|
+
} = _ref2;
|
|
22
|
+
return "".concat(theme.space.xxxs, " ").concat(theme.space.xs);
|
|
23
|
+
}, _ref3 => {
|
|
24
|
+
let {
|
|
25
|
+
theme
|
|
26
|
+
} = _ref3;
|
|
27
|
+
return theme.colors.neutral[600];
|
|
28
|
+
}, _ref4 => {
|
|
29
|
+
let {
|
|
30
|
+
showTooltip
|
|
31
|
+
} = _ref4;
|
|
32
|
+
return showTooltip ? 'visible' : 'hidden';
|
|
33
|
+
}, _ref5 => {
|
|
34
|
+
let {
|
|
35
|
+
showTooltip
|
|
36
|
+
} = _ref5;
|
|
37
|
+
return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n animation: ", " 0.1s ease-in;\n "])), showTooltip ? showAnimation : hideAnimation);
|
|
38
|
+
});
|
|
39
|
+
const StyledTriggerComponentContainer = /*#__PURE__*/styled.div.withConfig({
|
|
40
|
+
componentId: "sc-1dtjf9j-2"
|
|
41
|
+
})(["display:inline-block;"]);
|
|
42
|
+
const StyledTooltipText = /*#__PURE__*/styled.div.withConfig({
|
|
43
|
+
componentId: "sc-1dtjf9j-3"
|
|
44
|
+
})(["white-space:normal;word-wrap:break-word;display:inline-block;"]);
|
|
45
|
+
const StyledTooltipArrow = /*#__PURE__*/styled.div.withConfig({
|
|
46
|
+
componentId: "sc-1dtjf9j-4"
|
|
47
|
+
})(["position:absolute;width:18px;height:18px;pointer-events:none;background-color:transparent;& .stroke{fill:white;}& .fill{fill:white;}&[data-placement^='top']{svg{transform:rotateZ(180deg);}top:98%;}&[data-placement^='right']{svg{transform:rotateZ(-90deg);}right:99.5%;}&[data-placement^='bottom']{bottom:97%;}&[data-placement^='left']{svg{transform:rotateZ(90deg);}left:99.5%;}"]);
|
|
48
|
+
|
|
49
|
+
export { StyledAnimatedTooltip, StyledTooltipArrow, StyledTooltipContainer, StyledTooltipText, StyledTriggerComponentContainer };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
|
|
7
|
+
const setMultipleRefs = function () {
|
|
8
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
|
+
refs[_key] = arguments[_key];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const filteredRefs = refs.filter(Boolean);
|
|
13
|
+
if (!filteredRefs.length) return null;
|
|
14
|
+
if (filteredRefs.length === 0) return filteredRefs[0];
|
|
15
|
+
return newRef => {
|
|
16
|
+
filteredRefs.forEach(refToBeUpdated => {
|
|
17
|
+
if (typeof refToBeUpdated === 'function') {
|
|
18
|
+
refToBeUpdated(newRef);
|
|
19
|
+
} else if (refToBeUpdated) {
|
|
20
|
+
refToBeUpdated.current = newRef;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { setMultipleRefs };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const tooltipPositions = {
|
|
2
|
+
TOP: 'top',
|
|
3
|
+
BOTTOM: 'bottom',
|
|
4
|
+
RIGHT: 'right',
|
|
5
|
+
LEFT: 'left',
|
|
6
|
+
TOP_START: 'top-start',
|
|
7
|
+
TOP_END: 'top-end',
|
|
8
|
+
BOTTOM_START: 'bottom-start',
|
|
9
|
+
BOTTOM_END: 'bottom-end',
|
|
10
|
+
RIGHT_START: 'right-start',
|
|
11
|
+
RIGHT_END: 'right-end',
|
|
12
|
+
LEFT_START: 'left-start',
|
|
13
|
+
LEFT_END: 'left-end'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { tooltipPositions };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
3
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
8
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
9
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
10
|
+
import { useState, useCallback } from 'react';
|
|
11
|
+
import { DSPopperJS } from '@elliemae/ds-popperjs';
|
|
12
|
+
import { describe, useMemoMergePropsWithDefault } from '@elliemae/ds-props-helpers';
|
|
13
|
+
import { propTypes } from './propTypes.js';
|
|
14
|
+
import { TooltipV3DatatestId } from './TooltipV3DatatestId.js';
|
|
15
|
+
import { defaultProps } from './defaultProps.js';
|
|
16
|
+
import { StyledTriggerWrapper, StyledTooltipContainer, StyledTooltipText, StyledMouseOverDetectionBox } from './styles.js';
|
|
17
|
+
import { useGlobalKeyboardListener } from './utils.js';
|
|
18
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
19
|
+
|
|
20
|
+
var _StyledMouseOverDetec;
|
|
21
|
+
|
|
22
|
+
const _excluded = ["text", "children", "onOpen", "onClose", "id", "textAlign", "wrapWords"];
|
|
23
|
+
|
|
24
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
+
|
|
26
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
27
|
+
|
|
28
|
+
const DSTooltipV3 = props => {
|
|
29
|
+
const _useMemoMergePropsWit = useMemoMergePropsWithDefault(props, defaultProps),
|
|
30
|
+
{
|
|
31
|
+
text,
|
|
32
|
+
children,
|
|
33
|
+
onOpen,
|
|
34
|
+
onClose,
|
|
35
|
+
id,
|
|
36
|
+
textAlign,
|
|
37
|
+
wrapWords
|
|
38
|
+
} = _useMemoMergePropsWit,
|
|
39
|
+
extraPopperJsProps = _objectWithoutProperties(_useMemoMergePropsWit, _excluded);
|
|
40
|
+
|
|
41
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
42
|
+
const [isHover, setIsHover] = useState(false);
|
|
43
|
+
const [latestOpenInteraction, setLatestOpenInteraction] = useState('');
|
|
44
|
+
const [referenceElement, setReferenceElement] = useState();
|
|
45
|
+
const [showPopover, setShowPopover] = useState(false);
|
|
46
|
+
const showTooltip = useCallback(() => {
|
|
47
|
+
setShowPopover(true);
|
|
48
|
+
onOpen();
|
|
49
|
+
}, [onOpen]);
|
|
50
|
+
const hideTooltip = useCallback(() => {
|
|
51
|
+
setShowPopover(false);
|
|
52
|
+
onClose();
|
|
53
|
+
}, [onClose]);
|
|
54
|
+
const onFocus = useCallback(() => {
|
|
55
|
+
setIsFocused(true);
|
|
56
|
+
|
|
57
|
+
if (!showPopover) {
|
|
58
|
+
showTooltip();
|
|
59
|
+
setLatestOpenInteraction('onFocus');
|
|
60
|
+
}
|
|
61
|
+
}, [showPopover, showTooltip]);
|
|
62
|
+
const onBlur = useCallback(() => {
|
|
63
|
+
setIsFocused(false);
|
|
64
|
+
if (!isHover || latestOpenInteraction === 'onFocus') hideTooltip();
|
|
65
|
+
}, [hideTooltip, isHover, latestOpenInteraction]);
|
|
66
|
+
const onMouseEnter = useCallback(() => {
|
|
67
|
+
setIsHover(true);
|
|
68
|
+
|
|
69
|
+
if (!showPopover) {
|
|
70
|
+
showTooltip();
|
|
71
|
+
setLatestOpenInteraction('onMouseEnter');
|
|
72
|
+
}
|
|
73
|
+
}, [showPopover, showTooltip]);
|
|
74
|
+
const onMouseLeave = useCallback(() => {
|
|
75
|
+
setIsHover(false);
|
|
76
|
+
if (!isFocused || latestOpenInteraction === 'onMouseEnter') hideTooltip();
|
|
77
|
+
}, [hideTooltip, isFocused, latestOpenInteraction]);
|
|
78
|
+
const handleEscKey = useCallback(_ref => {
|
|
79
|
+
let {
|
|
80
|
+
key
|
|
81
|
+
} = _ref;
|
|
82
|
+
if (key === 'Escape') hideTooltip();
|
|
83
|
+
}, [hideTooltip]);
|
|
84
|
+
useGlobalKeyboardListener(handleEscKey);
|
|
85
|
+
return /*#__PURE__*/jsxs(StyledTriggerWrapper, {
|
|
86
|
+
onMouseEnter: onMouseEnter,
|
|
87
|
+
onMouseLeave: onMouseLeave,
|
|
88
|
+
onFocus: onFocus,
|
|
89
|
+
onBlur: onBlur,
|
|
90
|
+
ref: setReferenceElement,
|
|
91
|
+
"data-testid": "".concat(TooltipV3DatatestId.TRIGGER_WRAPPER).concat(id !== '' ? "_".concat(id) : ''),
|
|
92
|
+
children: [/*#__PURE__*/jsx(DSPopperJS, _objectSpread(_objectSpread({
|
|
93
|
+
referenceElement: referenceElement,
|
|
94
|
+
showPopover: showPopover,
|
|
95
|
+
withoutPortal: true
|
|
96
|
+
}, extraPopperJsProps), {}, {
|
|
97
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
98
|
+
"data-testid": "".concat(TooltipV3DatatestId.TOOLTIP_TEXT_WRAPPER).concat(id !== '' ? "_".concat(id) : '')
|
|
99
|
+
}, void 0, /*#__PURE__*/_jsx(StyledTooltipContainer, {}, void 0, /*#__PURE__*/_jsx(StyledTooltipText, {
|
|
100
|
+
textAlign: textAlign,
|
|
101
|
+
wrapWords: wrapWords
|
|
102
|
+
}, void 0, text), _StyledMouseOverDetec || (_StyledMouseOverDetec = /*#__PURE__*/_jsx(StyledMouseOverDetectionBox, {}))))
|
|
103
|
+
})), children]
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const DSTooltipV3WithSchema = describe(DSTooltipV3);
|
|
108
|
+
DSTooltipV3WithSchema.propTypes = propTypes;
|
|
109
|
+
|
|
110
|
+
export { DSTooltipV3, DSTooltipV3WithSchema, DSTooltipV3 as default };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const PLACEMENT = ['top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start'];
|
|
2
|
+
const TEXT_ALIGNMENT = ['left', 'right', 'center', 'justify', 'initial', 'inherit'];
|
|
3
|
+
|
|
4
|
+
export { PLACEMENT, TEXT_ALIGNMENT };
|