@qoretechnologies/reqore 0.21.0 → 0.23.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/__tests__/dropdown.test.tsx +9 -0
- package/__tests__/popover.test.tsx +119 -28
- package/__tests__/table.test.tsx +20 -18
- package/dist/components/Breadcrumbs/index.d.ts.map +1 -1
- package/dist/components/Breadcrumbs/index.js +1 -1
- package/dist/components/Breadcrumbs/index.js.map +1 -1
- package/dist/components/Table/headerCell.js +2 -2
- package/dist/components/Table/headerCell.js.map +1 -1
- package/dist/components/Table/index.d.ts +7 -8
- package/dist/components/Table/index.d.ts.map +1 -1
- package/dist/components/Table/index.js +5 -4
- package/dist/components/Table/index.js.map +1 -1
- package/dist/hooks/usePopover.d.ts +2 -1
- package/dist/hooks/usePopover.d.ts.map +1 -1
- package/dist/hooks/usePopover.js +32 -13
- package/dist/hooks/usePopover.js.map +1 -1
- package/dist/types/global.d.ts +14 -0
- package/dist/types/global.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Breadcrumbs/index.tsx +1 -0
- package/src/components/Table/headerCell.tsx +2 -2
- package/src/components/Table/index.tsx +18 -10
- package/src/hooks/usePopover.tsx +43 -14
- package/src/mock/data.json +11000 -0
- package/src/mock/tableData.ts +5 -14
- package/src/stories/Popover/Popover.stories.tsx +16 -1
- package/src/stories/Table/Table.stories.tsx +12 -1
- package/src/types/global.ts +15 -0
- package/tests.json +1 -1
package/dist/hooks/usePopover.js
CHANGED
|
@@ -20,31 +20,40 @@ var endEvents = {
|
|
|
20
20
|
focus: null
|
|
21
21
|
};
|
|
22
22
|
var usePopover = function (_a) {
|
|
23
|
-
var targetElement = _a.targetElement, content = _a.content, _b = _a.handler, handler = _b === void 0 ? 'hover' : _b, placement = _a.placement, _c = _a.show, show = _c === void 0 ? true : _c, noArrow = _a.noArrow, useTargetWidth = _a.useTargetWidth, _d = _a.closeOnOutsideClick, closeOnOutsideClick = _d === void 0 ? true : _d, _e = _a.openOnMount, openOnMount = _e === void 0 ? false : _e;
|
|
23
|
+
var targetElement = _a.targetElement, content = _a.content, _b = _a.handler, handler = _b === void 0 ? 'hover' : _b, placement = _a.placement, _c = _a.show, show = _c === void 0 ? true : _c, noArrow = _a.noArrow, useTargetWidth = _a.useTargetWidth, _d = _a.closeOnOutsideClick, closeOnOutsideClick = _d === void 0 ? true : _d, _e = _a.openOnMount, openOnMount = _e === void 0 ? false : _e, delay = _a.delay;
|
|
24
24
|
var _f = (0, react_1.useContext)(PopoverContext_1["default"]), addPopover = _f.addPopover, removePopover = _f.removePopover, updatePopover = _f.updatePopover, popovers = _f.popovers;
|
|
25
25
|
var current = (0, react_1.useRef)(shortid_1["default"].generate()).current;
|
|
26
|
+
var timeout = (0, react_1.useRef)(0).current;
|
|
26
27
|
var startEvent = startEvents[handler];
|
|
27
28
|
var endEvent = endEvents[handler];
|
|
29
|
+
var currentPopover = (0, react_1.useMemo)(function () { return popovers === null || popovers === void 0 ? void 0 : popovers.find(function (p) { return p.id === current; }); }, [popovers, current]);
|
|
28
30
|
var _addPopover = function () {
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
+
if (currentPopover) {
|
|
32
|
+
_removePopover === null || _removePopover === void 0 ? void 0 : _removePopover();
|
|
31
33
|
}
|
|
32
34
|
else if (show) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
timeout = setTimeout(function () {
|
|
36
|
+
addPopover === null || addPopover === void 0 ? void 0 : addPopover({
|
|
37
|
+
id: current,
|
|
38
|
+
content: content,
|
|
39
|
+
targetElement: targetElement,
|
|
40
|
+
placement: placement,
|
|
41
|
+
noArrow: noArrow,
|
|
42
|
+
useTargetWidth: useTargetWidth,
|
|
43
|
+
closeOnOutsideClick: closeOnOutsideClick,
|
|
44
|
+
closeOnAnyClick: handler === 'hover' || handler === 'hoverStay'
|
|
45
|
+
});
|
|
46
|
+
}, delay || 0);
|
|
43
47
|
}
|
|
44
48
|
};
|
|
45
49
|
var _removePopover = function () {
|
|
50
|
+
cancelTimeout();
|
|
46
51
|
removePopover === null || removePopover === void 0 ? void 0 : removePopover(current);
|
|
47
52
|
};
|
|
53
|
+
var cancelTimeout = function () {
|
|
54
|
+
clearTimeout(timeout);
|
|
55
|
+
timeout = null;
|
|
56
|
+
};
|
|
48
57
|
(0, react_use_1.useUpdateEffect)(function () {
|
|
49
58
|
if (show) {
|
|
50
59
|
updatePopover === null || updatePopover === void 0 ? void 0 : updatePopover(current, {
|
|
@@ -70,15 +79,25 @@ var usePopover = function (_a) {
|
|
|
70
79
|
if (endEvent) {
|
|
71
80
|
targetElement.addEventListener(endEvent, _removePopover);
|
|
72
81
|
}
|
|
82
|
+
if (handler === 'hoverStay') {
|
|
83
|
+
targetElement.addEventListener('mouseleave', cancelTimeout);
|
|
84
|
+
}
|
|
73
85
|
}
|
|
74
86
|
return function () {
|
|
75
87
|
if (targetElement && content) {
|
|
88
|
+
cancelTimeout();
|
|
76
89
|
targetElement.removeEventListener(startEvent, _addPopover);
|
|
77
90
|
if (endEvent) {
|
|
78
91
|
targetElement.removeEventListener(endEvent, _removePopover);
|
|
79
92
|
}
|
|
93
|
+
if (handler === 'hoverStay') {
|
|
94
|
+
targetElement.removeEventListener('mouseleave', cancelTimeout);
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
97
|
};
|
|
98
|
+
}, [targetElement, content, current, currentPopover]);
|
|
99
|
+
(0, react_use_1.useUnmount)(function () {
|
|
100
|
+
cancelTimeout();
|
|
82
101
|
});
|
|
83
102
|
return current;
|
|
84
103
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopover.js","sourceRoot":"","sources":["../../src/hooks/usePopover.tsx"],"names":[],"mappings":";;;;;AACA,+
|
|
1
|
+
{"version":3,"file":"usePopover.js","sourceRoot":"","sources":["../../src/hooks/usePop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WAAW,IAAI,aAAa,EAAE;YAChC,WAAW,EAAE,CAAC;SACf;IACH,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,IAAA,iBAAS,EAAC;QACR,IAAI,aAAa,IAAI,OAAO,EAAE;YAC5B,aAAa,CAAC,gBAAgB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;YAExD,IAAI,QAAQ,EAAE;gBACZ,aAAa,CAAC,gBAAgB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;aAC1D;YAED,IAAI,OAAO,KAAK,WAAW,EAAE;gBAC3B,aAAa,CAAC,gBAAgB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;aAC7D;SACF;QAED,OAAO;YACL,IAAI,aAAa,IAAI,OAAO,EAAE;gBAC5B,aAAa,EAAE,CAAC;gBAChB,aAAa,CAAC,mBAAmB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;gBAE3D,IAAI,QAAQ,EAAE;oBACZ,aAAa,CAAC,mBAAmB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;iBAC7D;gBAED,IAAI,OAAO,KAAK,WAAW,EAAE;oBAC3B,aAAa,CAAC,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;iBAChE;aACF;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;IAEtD,IAAA,sBAAU,EAAC;QACT,aAAa,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,qBAAe,UAAU,CAAC"}
|
package/dist/types/global.d.ts
CHANGED
|
@@ -72,6 +72,20 @@ export interface IWithReqoreTooltip {
|
|
|
72
72
|
*/
|
|
73
73
|
tooltip?: string | IReqoreTooltip;
|
|
74
74
|
}
|
|
75
|
+
export interface IWithReqoreFlat {
|
|
76
|
+
/**
|
|
77
|
+
* If true, the component will be flat
|
|
78
|
+
* @default false
|
|
79
|
+
* @type boolean
|
|
80
|
+
* @memberof IWithReqoreFlat
|
|
81
|
+
* @example
|
|
82
|
+
* <ReqoreInput flat />
|
|
83
|
+
* <ReqoreInput flat={true} />
|
|
84
|
+
* <ReqoreInput flat={false} />
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
flat?: boolean;
|
|
88
|
+
}
|
|
75
89
|
export interface IReqoreTooltip extends IPopoverOptions {
|
|
76
90
|
}
|
|
77
91
|
export declare type TReqoreTooltipProp = string | IReqoreTooltip;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../src/types/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC;CACnC;AAED,MAAM,WAAW,cAAe,SAAQ,eAAe;CAAG;AAC1D,oBAAY,kBAAkB,GAAG,MAAM,GAAG,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../src/types/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;OAUG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,cAAe,SAAQ,eAAe;CAAG;AAC1D,oBAAY,kBAAkB,GAAG,MAAM,GAAG,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import styled, { css } from 'styled-components';
|
|
|
4
4
|
import { IReqoreTableColumn, IReqoreTableSort } from '.';
|
|
5
5
|
import { IReqoreTheme } from '../../constants/theme';
|
|
6
6
|
import { changeLightness, getReadableColor } from '../../helpers/colors';
|
|
7
|
-
import
|
|
7
|
+
import { useTooltip } from '../../hooks/useTooltip';
|
|
8
8
|
import ReqoreIcon from '../Icon';
|
|
9
9
|
import { alignToFlex } from './row';
|
|
10
10
|
|
|
@@ -72,7 +72,7 @@ const ReqoreTableHeaderCell = ({
|
|
|
72
72
|
}: IReqoreTableHeaderCellProps) => {
|
|
73
73
|
const [ref, setRef] = useState(null);
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
useTooltip(ref, { content: tooltip || header, delay: 300 });
|
|
76
76
|
|
|
77
77
|
return (
|
|
78
78
|
<StyledTableHeader
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
import { size as count } from 'lodash';
|
|
3
3
|
import React, { useState } from 'react';
|
|
4
|
-
import { useUpdateEffect } from 'react-use';
|
|
4
|
+
import { useMeasure, useUpdateEffect } from 'react-use';
|
|
5
5
|
import styled, { css } from 'styled-components';
|
|
6
6
|
import { TABLE_SIZE_TO_PX, TSizes } from '../../constants/sizes';
|
|
7
|
-
import {
|
|
7
|
+
import { IReqoreTheme, TReqoreIntent } from '../../constants/theme';
|
|
8
8
|
import ReqoreThemeProvider from '../../containers/ThemeProvider';
|
|
9
9
|
import { changeLightness, getReadableColor } from '../../helpers/colors';
|
|
10
10
|
import { useReqoreTheme } from '../../hooks/useTheme';
|
|
11
|
+
import { IReqoreIntent, IWithReqoreCustomTheme, IWithReqoreFlat } from '../../types/global';
|
|
11
12
|
import { IReqoreIconName } from '../../types/icons';
|
|
12
13
|
import ReqoreTableBody from './body';
|
|
13
14
|
import ReqoreTableHeader, { StyledColumnGroupHeader } from './header';
|
|
@@ -25,7 +26,7 @@ export type TReqoreTableColumnContent =
|
|
|
25
26
|
| 'text'
|
|
26
27
|
| `text:${TReqoreIntent}`;
|
|
27
28
|
|
|
28
|
-
export interface IReqoreTableColumn {
|
|
29
|
+
export interface IReqoreTableColumn extends IReqoreIntent {
|
|
29
30
|
dataId: string;
|
|
30
31
|
header?: string | JSX.Element;
|
|
31
32
|
grow?: 1 | 2 | 3 | 4;
|
|
@@ -38,7 +39,6 @@ export interface IReqoreTableColumn {
|
|
|
38
39
|
icon?: IReqoreIconName;
|
|
39
40
|
iconSize?: string;
|
|
40
41
|
tooltip?: string;
|
|
41
|
-
intent?: TReqoreIntent;
|
|
42
42
|
cellTooltip?: (data: { [key: string]: any; _selectId?: string }) => string | JSX.Element;
|
|
43
43
|
onCellClick?: (data: { [key: string]: any; _selectId?: string }) => void;
|
|
44
44
|
}
|
|
@@ -53,7 +53,11 @@ export interface IReqoreTableRowData {
|
|
|
53
53
|
export type IReqoreTableRowClick = (data: IReqoreTableRowData) => void;
|
|
54
54
|
export type IReqoreTableData = IReqoreTableRowData[];
|
|
55
55
|
|
|
56
|
-
export interface IReqoreTableProps
|
|
56
|
+
export interface IReqoreTableProps
|
|
57
|
+
extends React.HTMLAttributes<HTMLDivElement>,
|
|
58
|
+
IReqoreIntent,
|
|
59
|
+
IWithReqoreFlat,
|
|
60
|
+
IWithReqoreCustomTheme {
|
|
57
61
|
columns: IReqoreTableColumn[];
|
|
58
62
|
data?: IReqoreTableData;
|
|
59
63
|
className?: string;
|
|
@@ -68,16 +72,15 @@ export interface IReqoreTableProps extends React.HTMLAttributes<HTMLDivElement>
|
|
|
68
72
|
onSelectedChange?: (selected?: any[]) => void;
|
|
69
73
|
selectToggleTooltip?: string;
|
|
70
74
|
onRowClick?: IReqoreTableRowClick;
|
|
71
|
-
customTheme?: IReqoreCustomTheme;
|
|
72
|
-
intent?: TReqoreIntent;
|
|
73
75
|
rounded?: boolean;
|
|
74
|
-
flat?: boolean;
|
|
75
76
|
size?: TSizes;
|
|
77
|
+
fill?: boolean;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
export interface IReqoreTableStyle {
|
|
79
81
|
theme: IReqoreTheme;
|
|
80
82
|
width?: number;
|
|
83
|
+
fill?: number;
|
|
81
84
|
striped?: boolean;
|
|
82
85
|
selectable?: boolean;
|
|
83
86
|
rounded?: boolean;
|
|
@@ -90,8 +93,9 @@ export interface IReqoreTableSort {
|
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
const StyledTableWrapper = styled.div<IReqoreTableStyle>`
|
|
93
|
-
${({ theme, width, rounded, flat }: IReqoreTableStyle) => css`
|
|
96
|
+
${({ theme, width, rounded, flat, fill }: IReqoreTableStyle) => css`
|
|
94
97
|
width: ${width ? `${width}px` : '100%'};
|
|
98
|
+
height: ${fill ? '100%' : 'auto'};
|
|
95
99
|
|
|
96
100
|
position: relative;
|
|
97
101
|
clear: both;
|
|
@@ -136,6 +140,7 @@ const ReqoreTable = ({
|
|
|
136
140
|
selectedRowIntent,
|
|
137
141
|
size,
|
|
138
142
|
intent,
|
|
143
|
+
fill,
|
|
139
144
|
...rest
|
|
140
145
|
}: IReqoreTableProps) => {
|
|
141
146
|
const [leftScroll, setLeftScroll] = useState<number>(0);
|
|
@@ -143,6 +148,7 @@ const ReqoreTable = ({
|
|
|
143
148
|
const [_sort, setSort] = useState<IReqoreTableSort>(fixSort(sort));
|
|
144
149
|
const [_selected, setSelected] = useState<string[]>([]);
|
|
145
150
|
const [_selectedQuant, setSelectedQuant] = useState<'all' | 'none' | 'some'>('none');
|
|
151
|
+
const [wrapperRef, sizes] = useMeasure();
|
|
146
152
|
const theme = useReqoreTheme('main', customTheme, intent);
|
|
147
153
|
|
|
148
154
|
useUpdateEffect(() => {
|
|
@@ -228,9 +234,11 @@ const ReqoreTable = ({
|
|
|
228
234
|
<ReqoreThemeProvider theme={theme}>
|
|
229
235
|
<StyledTableWrapper
|
|
230
236
|
{...rest}
|
|
237
|
+
fill={fill}
|
|
231
238
|
className={`${className || ''} reqore-table`}
|
|
232
239
|
rounded={rounded}
|
|
233
240
|
width={width}
|
|
241
|
+
ref={wrapperRef}
|
|
234
242
|
>
|
|
235
243
|
<ReqoreTableHeader
|
|
236
244
|
columns={columns}
|
|
@@ -247,7 +255,7 @@ const ReqoreTable = ({
|
|
|
247
255
|
data={_sort ? sortTableData(_data, _sort) : _data}
|
|
248
256
|
columns={columns}
|
|
249
257
|
setLeftScroll={setLeftScroll}
|
|
250
|
-
height={height}
|
|
258
|
+
height={fill ? sizes.height : height}
|
|
251
259
|
selectable={selectable}
|
|
252
260
|
onSelectClick={handleSelectClick}
|
|
253
261
|
onRowClick={onRowClick}
|
package/src/hooks/usePopover.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Placement } from '@popperjs/core';
|
|
2
|
-
import { MutableRefObject, useContext, useEffect, useRef } from 'react';
|
|
3
|
-
import { useUpdateEffect } from 'react-use';
|
|
2
|
+
import { MutableRefObject, useContext, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { useUnmount, useUpdateEffect } from 'react-use';
|
|
4
4
|
import shortid from 'shortid';
|
|
5
5
|
import PopoverContext from '../context/PopoverContext';
|
|
6
6
|
|
|
@@ -28,6 +28,7 @@ export interface IPopover {
|
|
|
28
28
|
useTargetWidth?: boolean;
|
|
29
29
|
closeOnOutsideClick?: boolean;
|
|
30
30
|
closeOnAnyClick?: boolean;
|
|
31
|
+
delay?: number;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export interface IPopoverOptions extends IPopover {
|
|
@@ -44,34 +45,48 @@ const usePopover = ({
|
|
|
44
45
|
useTargetWidth,
|
|
45
46
|
closeOnOutsideClick = true,
|
|
46
47
|
openOnMount = false,
|
|
48
|
+
delay,
|
|
47
49
|
}: IPopoverOptions) => {
|
|
48
50
|
const { addPopover, removePopover, updatePopover, popovers } = useContext(PopoverContext);
|
|
49
51
|
const { current }: MutableRefObject<string> = useRef(shortid.generate());
|
|
52
|
+
let { current: timeout }: MutableRefObject<any> = useRef(0);
|
|
50
53
|
|
|
51
54
|
const startEvent = startEvents[handler];
|
|
52
55
|
const endEvent = endEvents[handler];
|
|
56
|
+
const currentPopover = useMemo(
|
|
57
|
+
() => popovers?.find((p) => p.id === current),
|
|
58
|
+
[popovers, current]
|
|
59
|
+
);
|
|
53
60
|
|
|
54
61
|
const _addPopover = () => {
|
|
55
|
-
if (
|
|
56
|
-
|
|
62
|
+
if (currentPopover) {
|
|
63
|
+
_removePopover?.();
|
|
57
64
|
} else if (show) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
timeout = setTimeout(() => {
|
|
66
|
+
addPopover?.({
|
|
67
|
+
id: current,
|
|
68
|
+
content,
|
|
69
|
+
targetElement,
|
|
70
|
+
placement,
|
|
71
|
+
noArrow,
|
|
72
|
+
useTargetWidth,
|
|
73
|
+
closeOnOutsideClick,
|
|
74
|
+
closeOnAnyClick: handler === 'hover' || handler === 'hoverStay',
|
|
75
|
+
});
|
|
76
|
+
}, delay || 0);
|
|
68
77
|
}
|
|
69
78
|
};
|
|
70
79
|
|
|
71
80
|
const _removePopover = () => {
|
|
81
|
+
cancelTimeout();
|
|
72
82
|
removePopover?.(current);
|
|
73
83
|
};
|
|
74
84
|
|
|
85
|
+
const cancelTimeout = () => {
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
timeout = null;
|
|
88
|
+
};
|
|
89
|
+
|
|
75
90
|
useUpdateEffect(() => {
|
|
76
91
|
if (show) {
|
|
77
92
|
updatePopover?.(current, {
|
|
@@ -100,16 +115,30 @@ const usePopover = ({
|
|
|
100
115
|
if (endEvent) {
|
|
101
116
|
targetElement.addEventListener(endEvent, _removePopover);
|
|
102
117
|
}
|
|
118
|
+
|
|
119
|
+
if (handler === 'hoverStay') {
|
|
120
|
+
targetElement.addEventListener('mouseleave', cancelTimeout);
|
|
121
|
+
}
|
|
103
122
|
}
|
|
104
123
|
|
|
105
124
|
return () => {
|
|
106
125
|
if (targetElement && content) {
|
|
126
|
+
cancelTimeout();
|
|
107
127
|
targetElement.removeEventListener(startEvent, _addPopover);
|
|
128
|
+
|
|
108
129
|
if (endEvent) {
|
|
109
130
|
targetElement.removeEventListener(endEvent, _removePopover);
|
|
110
131
|
}
|
|
132
|
+
|
|
133
|
+
if (handler === 'hoverStay') {
|
|
134
|
+
targetElement.removeEventListener('mouseleave', cancelTimeout);
|
|
135
|
+
}
|
|
111
136
|
}
|
|
112
137
|
};
|
|
138
|
+
}, [targetElement, content, current, currentPopover]);
|
|
139
|
+
|
|
140
|
+
useUnmount(() => {
|
|
141
|
+
cancelTimeout();
|
|
113
142
|
});
|
|
114
143
|
|
|
115
144
|
return current;
|