@clayui/tooltip 3.156.0 → 3.158.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/README.md +4 -4
- package/lib/Tooltip.d.ts +3 -3
- package/lib/TooltipProvider.d.ts +4 -4
- package/lib/cjs/Tooltip.js +67 -30
- package/lib/cjs/TooltipProvider.js +173 -151
- package/lib/cjs/index.js +25 -22
- package/lib/cjs/useAlign.js +84 -58
- package/lib/cjs/useClosestTitle.js +79 -61
- package/lib/cjs/useTooltipState.js +34 -22
- package/lib/esm/Tooltip.js +39 -27
- package/lib/esm/TooltipProvider.js +142 -135
- package/lib/esm/index.js +8 -8
- package/lib/esm/useAlign.js +62 -50
- package/lib/esm/useClosestTitle.js +59 -55
- package/lib/esm/useTooltipState.js +12 -14
- package/lib/index.d.ts +2 -2
- package/lib/useAlign.d.ts +3 -3
- package/lib/useClosestTitle.d.ts +3 -3
- package/lib/useTooltipState.d.ts +2 -2
- package/package.json +33 -34
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
|
|
3
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useCallback, useRef } from 'react';
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
7
2
|
function matches(element, selectorString) {
|
|
8
3
|
if (element.matches) {
|
|
9
4
|
return element.matches(selectorString);
|
|
@@ -29,50 +24,51 @@ function closestAncestor(node, s) {
|
|
|
29
24
|
} while (ancestor !== null);
|
|
30
25
|
return null;
|
|
31
26
|
}
|
|
32
|
-
|
|
27
|
+
function useClosestTitle(props) {
|
|
33
28
|
const targetRef = useRef(null);
|
|
34
29
|
const titleNodeRef = useRef(null);
|
|
35
|
-
const saveTitle = useCallback(element => {
|
|
36
|
-
const title = element.getAttribute(
|
|
30
|
+
const saveTitle = useCallback((element) => {
|
|
31
|
+
const title = element.getAttribute("title");
|
|
37
32
|
if (title) {
|
|
38
|
-
element.setAttribute(
|
|
39
|
-
element.removeAttribute(
|
|
40
|
-
} else if (element.tagName ===
|
|
41
|
-
const titleTag = element.querySelector(
|
|
33
|
+
element.setAttribute("data-restore-title", title);
|
|
34
|
+
element.removeAttribute("title");
|
|
35
|
+
} else if (element.tagName === "svg") {
|
|
36
|
+
const titleTag = element.querySelector("title");
|
|
42
37
|
if (titleTag) {
|
|
43
|
-
element.setAttribute(
|
|
38
|
+
element.setAttribute("data-restore-title", titleTag.innerHTML);
|
|
44
39
|
titleTag.remove();
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
|
-
const hasParentTitle = element.closest(
|
|
42
|
+
const hasParentTitle = element.closest("[title]");
|
|
48
43
|
if (hasParentTitle) {
|
|
49
44
|
saveTitle(hasParentTitle);
|
|
50
45
|
}
|
|
51
46
|
}, []);
|
|
52
|
-
const restoreTitle = useCallback(element => {
|
|
53
|
-
const title = element.getAttribute(
|
|
47
|
+
const restoreTitle = useCallback((element) => {
|
|
48
|
+
const title = element.getAttribute("data-restore-title");
|
|
54
49
|
if (title) {
|
|
55
|
-
if (element.tagName ===
|
|
56
|
-
const titleTag = document.createElement(
|
|
50
|
+
if (element.tagName === "svg") {
|
|
51
|
+
const titleTag = document.createElement("title");
|
|
57
52
|
titleTag.innerHTML = title;
|
|
58
53
|
element.appendChild(titleTag);
|
|
59
54
|
} else {
|
|
60
|
-
element.setAttribute(
|
|
55
|
+
element.setAttribute("title", title);
|
|
61
56
|
}
|
|
62
|
-
element.removeAttribute(
|
|
57
|
+
element.removeAttribute("data-restore-title");
|
|
63
58
|
}
|
|
64
|
-
const hasParentTitle = element.closest(
|
|
59
|
+
const hasParentTitle = element.closest(
|
|
60
|
+
"[data-restore-title]"
|
|
61
|
+
);
|
|
65
62
|
if (hasParentTitle) {
|
|
66
63
|
restoreTitle(hasParentTitle);
|
|
67
64
|
}
|
|
68
65
|
}, []);
|
|
69
|
-
const onClick = useCallback(event => {
|
|
66
|
+
const onClick = useCallback((event) => {
|
|
70
67
|
props.onClick();
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
72
68
|
onHide(event);
|
|
73
69
|
}, []);
|
|
74
|
-
const onHide = useCallback(event => {
|
|
75
|
-
if (event && !event.relatedTarget?.getAttribute(
|
|
70
|
+
const onHide = useCallback((event) => {
|
|
71
|
+
if (event && !event.relatedTarget?.getAttribute("title") && (props.tooltipRef.current?.contains(event.relatedTarget) || targetRef.current?.contains(event.relatedTarget))) {
|
|
76
72
|
return null;
|
|
77
73
|
}
|
|
78
74
|
props.onHide();
|
|
@@ -81,7 +77,7 @@ export function useClosestTitle(props) {
|
|
|
81
77
|
titleNodeRef.current = null;
|
|
82
78
|
}
|
|
83
79
|
if (targetRef.current) {
|
|
84
|
-
targetRef.current.removeEventListener(
|
|
80
|
+
targetRef.current.removeEventListener("click", onClick);
|
|
85
81
|
targetRef.current = null;
|
|
86
82
|
}
|
|
87
83
|
}, []);
|
|
@@ -92,38 +88,43 @@ export function useClosestTitle(props) {
|
|
|
92
88
|
titleNodeRef.current = null;
|
|
93
89
|
}
|
|
94
90
|
if (targetRef.current) {
|
|
95
|
-
targetRef.current.removeEventListener(
|
|
91
|
+
targetRef.current.removeEventListener("click", onClick);
|
|
96
92
|
targetRef.current = null;
|
|
97
93
|
}
|
|
98
94
|
}, []);
|
|
99
|
-
const getProps = useCallback(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
const getProps = useCallback(
|
|
96
|
+
(event, hideBrowserTitle) => {
|
|
97
|
+
if (targetRef.current) {
|
|
98
|
+
props.onClick();
|
|
99
|
+
if (onHide(event) === null) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
104
102
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
103
|
+
const target = event.target;
|
|
104
|
+
const hasTitle = target && (target.hasAttribute("[title]") || target.hasAttribute("[data-title]"));
|
|
105
|
+
const node = hasTitle ? target : closestAncestor(target, "[title], [data-title]");
|
|
106
|
+
const hasNonEmptyTitle = node?.getAttribute("title") !== "";
|
|
107
|
+
if (node && hasNonEmptyTitle) {
|
|
108
|
+
targetRef.current = target;
|
|
109
|
+
target.addEventListener("click", onClick);
|
|
110
|
+
const title = node.getAttribute("title") || node.getAttribute("data-title") || "";
|
|
111
|
+
titleNodeRef.current = node;
|
|
112
|
+
if (hideBrowserTitle) {
|
|
113
|
+
saveTitle(node);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
align: node.getAttribute("data-tooltip-align"),
|
|
117
|
+
delay: node.getAttribute("data-tooltip-delay"),
|
|
118
|
+
floating: Boolean(
|
|
119
|
+
node.getAttribute("data-tooltip-floating")
|
|
120
|
+
),
|
|
121
|
+
setAsHTML: !!node.getAttribute("data-title-set-as-html"),
|
|
122
|
+
title
|
|
123
|
+
};
|
|
117
124
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
floating: Boolean(node.getAttribute('data-tooltip-floating')),
|
|
122
|
-
setAsHTML: !!node.getAttribute('data-title-set-as-html'),
|
|
123
|
-
title
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}, []);
|
|
125
|
+
},
|
|
126
|
+
[]
|
|
127
|
+
);
|
|
127
128
|
return {
|
|
128
129
|
forceHide,
|
|
129
130
|
getProps,
|
|
@@ -131,4 +132,7 @@ export function useClosestTitle(props) {
|
|
|
131
132
|
target: targetRef,
|
|
132
133
|
titleNode: titleNodeRef
|
|
133
134
|
};
|
|
134
|
-
}
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
useClosestTitle
|
|
138
|
+
};
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useCallback, useRef, useState } from 'react';
|
|
7
|
-
export function useTooltipState(_ref) {
|
|
8
|
-
let {
|
|
9
|
-
delay = 600
|
|
10
|
-
} = _ref;
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
|
+
function useTooltipState({ delay = 600 }) {
|
|
11
3
|
const [isOpen, setOpen] = useState(false);
|
|
12
4
|
const timeoutIdRef = useRef();
|
|
13
5
|
const open = useCallback((immediate, customDelay) => {
|
|
14
6
|
if (!immediate) {
|
|
15
7
|
clearTimeout(timeoutIdRef.current);
|
|
16
|
-
timeoutIdRef.current = setTimeout(
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
timeoutIdRef.current = setTimeout(
|
|
9
|
+
() => {
|
|
10
|
+
setOpen(true);
|
|
11
|
+
},
|
|
12
|
+
customDelay !== void 0 ? customDelay : delay
|
|
13
|
+
);
|
|
19
14
|
} else {
|
|
20
15
|
setOpen(true);
|
|
21
16
|
}
|
|
@@ -29,4 +24,7 @@ export function useTooltipState(_ref) {
|
|
|
29
24
|
isOpen,
|
|
30
25
|
open
|
|
31
26
|
};
|
|
32
|
-
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
useTooltipState
|
|
30
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SPDX-FileCopyrightText:
|
|
3
|
-
* SPDX-License-Identifier:
|
|
2
|
+
* SPDX-FileCopyrightText: (c) 2026 Liferay, Inc. https://liferay.com
|
|
3
|
+
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
|
|
4
4
|
*/
|
|
5
5
|
import { Tooltip } from './Tooltip';
|
|
6
6
|
import { ClayTooltipProvider } from './TooltipProvider';
|
package/lib/useAlign.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SPDX-FileCopyrightText:
|
|
3
|
-
* SPDX-License-Identifier:
|
|
2
|
+
* SPDX-FileCopyrightText: (c) 2026 Liferay, Inc. https://liferay.com
|
|
3
|
+
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
6
|
declare const ALIGNMENTS: readonly ["top", "top-right", "right", "bottom-right", "bottom", "bottom-left", "left", "top-left"];
|
|
7
|
-
export declare type Align = typeof ALIGNMENTS[number];
|
|
7
|
+
export declare type Align = (typeof ALIGNMENTS)[number];
|
|
8
8
|
declare type Props = {
|
|
9
9
|
align: Align;
|
|
10
10
|
autoAlign: boolean;
|
package/lib/useClosestTitle.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SPDX-FileCopyrightText:
|
|
3
|
-
* SPDX-License-Identifier:
|
|
2
|
+
* SPDX-FileCopyrightText: (c) 2026 Liferay, Inc. https://liferay.com
|
|
3
|
+
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
6
|
declare type Props = {
|
|
7
7
|
forceHide: () => void;
|
|
8
|
-
onHide: () => void;
|
|
9
8
|
onClick: () => void;
|
|
9
|
+
onHide: () => void;
|
|
10
10
|
tooltipRef: React.MutableRefObject<HTMLElement | null>;
|
|
11
11
|
};
|
|
12
12
|
export declare function useClosestTitle(props: Props): {
|
package/lib/useTooltipState.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SPDX-FileCopyrightText:
|
|
3
|
-
* SPDX-License-Identifier:
|
|
2
|
+
* SPDX-FileCopyrightText: (c) 2026 Liferay, Inc. https://liferay.com
|
|
3
|
+
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
|
|
4
4
|
*/
|
|
5
5
|
declare type Props = {
|
|
6
6
|
delay?: number;
|
package/package.json
CHANGED
|
@@ -1,48 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./lib/index.d.ts",
|
|
12
|
-
"import": "./lib/esm/index.js",
|
|
13
|
-
"require": "./lib/cjs/index.js"
|
|
14
|
-
}
|
|
2
|
+
"browserslist": [
|
|
3
|
+
"extends browserslist-config-clay"
|
|
4
|
+
],
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@clayui/shared": "^3.158.0",
|
|
7
|
+
"classnames": "2.3.1",
|
|
8
|
+
"dom-align": "^1.12.2",
|
|
9
|
+
"warning": "^4.0.3"
|
|
15
10
|
},
|
|
16
|
-
"
|
|
17
|
-
"ts:main": "src/index.tsx",
|
|
11
|
+
"description": "ClayTooltip component",
|
|
18
12
|
"files": [
|
|
19
13
|
"lib"
|
|
20
14
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "yarn build:cjs && yarn build:esm",
|
|
23
|
-
"build:cjs": "cross-env NODE_ENV=production babel src --root-mode upward --out-dir lib/cjs --extensions .ts,.tsx",
|
|
24
|
-
"build:esm": "cross-env NODE_ENV=production babel src --root-mode upward --out-dir lib/esm --extensions .ts,.tsx --env-name esm",
|
|
25
|
-
"buildTypes": "cross-env NODE_ENV=production tsc --project ./tsconfig.declarations.json",
|
|
26
|
-
"format": "prettier --write \"**/*.{js,ts,tsx,md,mdx,json,scss}\"",
|
|
27
|
-
"test": "jest --config ../../jest.config.js"
|
|
28
|
-
},
|
|
29
15
|
"keywords": [
|
|
30
16
|
"clay",
|
|
31
17
|
"react"
|
|
32
18
|
],
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"dom-align": "^1.12.2",
|
|
37
|
-
"warning": "^4.0.3"
|
|
38
|
-
},
|
|
19
|
+
"license": "BSD-3-Clause",
|
|
20
|
+
"main": "lib/cjs/index.js",
|
|
21
|
+
"name": "@clayui/tooltip",
|
|
39
22
|
"peerDependencies": {
|
|
40
|
-
"@clayui/css": "3.
|
|
23
|
+
"@clayui/css": "^3.158.0",
|
|
41
24
|
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
42
25
|
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
43
26
|
},
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
"repository": "https://github.com/liferay/clay",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "yarn build:cjs && yarn build:esm",
|
|
30
|
+
"build:cjs": "cross-env NODE_ENV=production node ../build-package-esbuild.js --format=cjs --outdir=lib/cjs",
|
|
31
|
+
"build:esm": "cross-env NODE_ENV=production node ../build-package-esbuild.js --format=esm --outdir=lib/esm",
|
|
32
|
+
"buildTypes": "cross-env NODE_ENV=production tsc --project ./tsconfig.declarations.json",
|
|
33
|
+
"format": "prettier --write \"**/*.{js,ts,tsx,md,mdx,json,scss}\"",
|
|
34
|
+
"test": "jest --config ../../jest.config.js"
|
|
35
|
+
},
|
|
36
|
+
"version": "3.158.0",
|
|
37
|
+
"module": "lib/esm/index.js",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./lib/index.d.ts",
|
|
41
|
+
"import": "./lib/esm/index.js",
|
|
42
|
+
"require": "./lib/cjs/index.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"types": "lib/index.d.ts",
|
|
46
|
+
"ts:main": "src/index.tsx"
|
|
48
47
|
}
|