@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.
@@ -1,37 +1,58 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useAlign_exports = {};
20
+ __export(useAlign_exports, {
21
+ useAlign: () => useAlign
5
22
  });
6
- exports.useAlign = useAlign;
7
- var _shared = require("@clayui/shared");
8
- var _domAlign = require("dom-align");
9
- var _react = require("react");
10
- /**
11
- * SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
12
- * SPDX-License-Identifier: BSD-3-Clause
13
- */
14
-
15
- const ALIGNMENTS = ['top', 'top-right', 'right', 'bottom-right', 'bottom', 'bottom-left', 'left', 'top-left'];
23
+ module.exports = __toCommonJS(useAlign_exports);
24
+ var import_shared = require("@clayui/shared");
25
+ var import_dom_align = require("dom-align");
26
+ var import_react = require("react");
27
+ const ALIGNMENTS = [
28
+ "top",
29
+ "top-right",
30
+ "right",
31
+ "bottom-right",
32
+ "bottom",
33
+ "bottom-left",
34
+ "left",
35
+ "top-left"
36
+ ];
16
37
  const ALIGNMENTS_MAP = {
17
- bottom: ['tc', 'bc'],
18
- 'bottom-left': ['tl', 'bl'],
19
- 'bottom-right': ['tr', 'br'],
20
- left: ['cr', 'cl'],
21
- right: ['cl', 'cr'],
22
- top: ['bc', 'tc'],
23
- 'top-left': ['bl', 'tl'],
24
- 'top-right': ['br', 'tr']
38
+ "bottom": ["tc", "bc"],
39
+ "bottom-left": ["tl", "bl"],
40
+ "bottom-right": ["tr", "br"],
41
+ "left": ["cr", "cl"],
42
+ "right": ["cl", "cr"],
43
+ "top": ["bc", "tc"],
44
+ "top-left": ["bl", "tl"],
45
+ "top-right": ["br", "tr"]
25
46
  };
26
47
  const ALIGNMENTS_INVERSE_MAP = {
27
- bctc: 'top',
28
- bltl: 'top-left',
29
- brtr: 'top-right',
30
- clcr: 'right',
31
- crcl: 'left',
32
- tcbc: 'bottom',
33
- tlbl: 'bottom-left',
34
- trbr: 'bottom-right'
48
+ bctc: "top",
49
+ bltl: "top-left",
50
+ brtr: "top-right",
51
+ clcr: "right",
52
+ crcl: "left",
53
+ tcbc: "bottom",
54
+ tlbl: "bottom-left",
55
+ trbr: "bottom-right"
35
56
  };
36
57
  const BOTTOM_OFFSET = [0, 7];
37
58
  const LEFT_OFFSET = [-7, 0];
@@ -49,38 +70,41 @@ const OFFSET_MAP = {
49
70
  };
50
71
  const ALIGNMENTS_FORCE_MAP = {
51
72
  ...ALIGNMENTS_INVERSE_MAP,
52
- bctc: 'top-left',
53
- tcbc: 'bottom-left'
73
+ bctc: "top-left",
74
+ tcbc: "bottom-left"
54
75
  };
55
- function useAlign(_ref) {
56
- let {
57
- align,
58
- autoAlign,
59
- floating,
60
- isOpen,
61
- onAlign,
62
- sourceElement,
63
- targetElement,
64
- title
65
- } = _ref;
66
- const mousePosition = (0, _shared.useMousePosition)(20);
67
- (0, _react.useEffect)(() => {
76
+ function useAlign({
77
+ align,
78
+ autoAlign,
79
+ floating,
80
+ isOpen,
81
+ onAlign,
82
+ sourceElement,
83
+ targetElement,
84
+ title
85
+ }) {
86
+ const mousePosition = (0, import_shared.useMousePosition)(20);
87
+ (0, import_react.useEffect)(() => {
68
88
  if (sourceElement.current && isOpen && floating) {
69
- const points = ALIGNMENTS_MAP[align || 'top'];
89
+ const points = ALIGNMENTS_MAP[align || "top"];
70
90
  const [clientX, clientY] = mousePosition;
71
- (0, _domAlign.alignPoint)(sourceElement.current, {
72
- clientX,
73
- clientY
74
- }, {
75
- offset: OFFSET_MAP[points.join('')],
76
- points
77
- });
91
+ (0, import_dom_align.alignPoint)(
92
+ sourceElement.current,
93
+ {
94
+ clientX,
95
+ clientY
96
+ },
97
+ {
98
+ offset: OFFSET_MAP[points.join("")],
99
+ points
100
+ }
101
+ );
78
102
  }
79
103
  }, [isOpen, floating]);
80
- (0, _react.useEffect)(() => {
104
+ (0, import_react.useEffect)(() => {
81
105
  if (targetElement.current && sourceElement.current && isOpen && !floating) {
82
- const points = ALIGNMENTS_MAP[align || 'top'];
83
- const alignment = (0, _shared.doAlign)({
106
+ const points = ALIGNMENTS_MAP[align || "top"];
107
+ const alignment = (0, import_shared.doAlign)({
84
108
  overflow: {
85
109
  adjustX: autoAlign,
86
110
  adjustY: autoAlign
@@ -89,8 +113,10 @@ function useAlign(_ref) {
89
113
  sourceElement: sourceElement.current,
90
114
  targetElement: targetElement.current
91
115
  });
92
- const alignmentString = alignment.points.join('');
93
- const pointsString = points.join('');
116
+ const alignmentString = alignment.points.join(
117
+ ""
118
+ );
119
+ const pointsString = points.join("");
94
120
  if (alignment.overflow.adjustX) {
95
121
  onAlign(ALIGNMENTS_FORCE_MAP[alignmentString]);
96
122
  } else if (pointsString !== alignmentString) {
@@ -98,4 +124,4 @@ function useAlign(_ref) {
98
124
  }
99
125
  }
100
126
  }, [align, title, isOpen]);
101
- }
127
+ }
@@ -1,15 +1,27 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useClosestTitle_exports = {};
20
+ __export(useClosestTitle_exports, {
21
+ useClosestTitle: () => useClosestTitle
5
22
  });
6
- exports.useClosestTitle = useClosestTitle;
7
- var _react = require("react");
8
- /**
9
- * SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
10
- * SPDX-License-Identifier: BSD-3-Clause
11
- */
12
-
23
+ module.exports = __toCommonJS(useClosestTitle_exports);
24
+ var import_react = require("react");
13
25
  function matches(element, selectorString) {
14
26
  if (element.matches) {
15
27
  return element.matches(selectorString);
@@ -36,49 +48,50 @@ function closestAncestor(node, s) {
36
48
  return null;
37
49
  }
38
50
  function useClosestTitle(props) {
39
- const targetRef = (0, _react.useRef)(null);
40
- const titleNodeRef = (0, _react.useRef)(null);
41
- const saveTitle = (0, _react.useCallback)(element => {
42
- const title = element.getAttribute('title');
51
+ const targetRef = (0, import_react.useRef)(null);
52
+ const titleNodeRef = (0, import_react.useRef)(null);
53
+ const saveTitle = (0, import_react.useCallback)((element) => {
54
+ const title = element.getAttribute("title");
43
55
  if (title) {
44
- element.setAttribute('data-restore-title', title);
45
- element.removeAttribute('title');
46
- } else if (element.tagName === 'svg') {
47
- const titleTag = element.querySelector('title');
56
+ element.setAttribute("data-restore-title", title);
57
+ element.removeAttribute("title");
58
+ } else if (element.tagName === "svg") {
59
+ const titleTag = element.querySelector("title");
48
60
  if (titleTag) {
49
- element.setAttribute('data-restore-title', titleTag.innerHTML);
61
+ element.setAttribute("data-restore-title", titleTag.innerHTML);
50
62
  titleTag.remove();
51
63
  }
52
64
  }
53
- const hasParentTitle = element.closest('[title]');
65
+ const hasParentTitle = element.closest("[title]");
54
66
  if (hasParentTitle) {
55
67
  saveTitle(hasParentTitle);
56
68
  }
57
69
  }, []);
58
- const restoreTitle = (0, _react.useCallback)(element => {
59
- const title = element.getAttribute('data-restore-title');
70
+ const restoreTitle = (0, import_react.useCallback)((element) => {
71
+ const title = element.getAttribute("data-restore-title");
60
72
  if (title) {
61
- if (element.tagName === 'svg') {
62
- const titleTag = document.createElement('title');
73
+ if (element.tagName === "svg") {
74
+ const titleTag = document.createElement("title");
63
75
  titleTag.innerHTML = title;
64
76
  element.appendChild(titleTag);
65
77
  } else {
66
- element.setAttribute('title', title);
78
+ element.setAttribute("title", title);
67
79
  }
68
- element.removeAttribute('data-restore-title');
80
+ element.removeAttribute("data-restore-title");
69
81
  }
70
- const hasParentTitle = element.closest('[data-restore-title]');
82
+ const hasParentTitle = element.closest(
83
+ "[data-restore-title]"
84
+ );
71
85
  if (hasParentTitle) {
72
86
  restoreTitle(hasParentTitle);
73
87
  }
74
88
  }, []);
75
- const onClick = (0, _react.useCallback)(event => {
89
+ const onClick = (0, import_react.useCallback)((event) => {
76
90
  props.onClick();
77
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
78
91
  onHide(event);
79
92
  }, []);
80
- const onHide = (0, _react.useCallback)(event => {
81
- if (event && !event.relatedTarget?.getAttribute('title') && (props.tooltipRef.current?.contains(event.relatedTarget) || targetRef.current?.contains(event.relatedTarget))) {
93
+ const onHide = (0, import_react.useCallback)((event) => {
94
+ if (event && !event.relatedTarget?.getAttribute("title") && (props.tooltipRef.current?.contains(event.relatedTarget) || targetRef.current?.contains(event.relatedTarget))) {
82
95
  return null;
83
96
  }
84
97
  props.onHide();
@@ -87,49 +100,54 @@ function useClosestTitle(props) {
87
100
  titleNodeRef.current = null;
88
101
  }
89
102
  if (targetRef.current) {
90
- targetRef.current.removeEventListener('click', onClick);
103
+ targetRef.current.removeEventListener("click", onClick);
91
104
  targetRef.current = null;
92
105
  }
93
106
  }, []);
94
- const forceHide = (0, _react.useCallback)(() => {
107
+ const forceHide = (0, import_react.useCallback)(() => {
95
108
  props.forceHide();
96
109
  if (titleNodeRef.current) {
97
110
  restoreTitle(titleNodeRef.current);
98
111
  titleNodeRef.current = null;
99
112
  }
100
113
  if (targetRef.current) {
101
- targetRef.current.removeEventListener('click', onClick);
114
+ targetRef.current.removeEventListener("click", onClick);
102
115
  targetRef.current = null;
103
116
  }
104
117
  }, []);
105
- const getProps = (0, _react.useCallback)((event, hideBrowserTitle) => {
106
- if (targetRef.current) {
107
- props.onClick();
108
- if (onHide(event) === null) {
109
- return;
118
+ const getProps = (0, import_react.useCallback)(
119
+ (event, hideBrowserTitle) => {
120
+ if (targetRef.current) {
121
+ props.onClick();
122
+ if (onHide(event) === null) {
123
+ return;
124
+ }
110
125
  }
111
- }
112
- const target = event.target;
113
- const hasTitle = target && (target.hasAttribute('[title]') || target.hasAttribute('[data-title]'));
114
- const node = hasTitle ? target : closestAncestor(target, '[title], [data-title]');
115
- const hasNonEmptyTitle = node?.getAttribute('title') !== '';
116
- if (node && hasNonEmptyTitle) {
117
- targetRef.current = target;
118
- target.addEventListener('click', onClick);
119
- const title = node.getAttribute('title') || node.getAttribute('data-title') || '';
120
- titleNodeRef.current = node;
121
- if (hideBrowserTitle) {
122
- saveTitle(node);
126
+ const target = event.target;
127
+ const hasTitle = target && (target.hasAttribute("[title]") || target.hasAttribute("[data-title]"));
128
+ const node = hasTitle ? target : closestAncestor(target, "[title], [data-title]");
129
+ const hasNonEmptyTitle = node?.getAttribute("title") !== "";
130
+ if (node && hasNonEmptyTitle) {
131
+ targetRef.current = target;
132
+ target.addEventListener("click", onClick);
133
+ const title = node.getAttribute("title") || node.getAttribute("data-title") || "";
134
+ titleNodeRef.current = node;
135
+ if (hideBrowserTitle) {
136
+ saveTitle(node);
137
+ }
138
+ return {
139
+ align: node.getAttribute("data-tooltip-align"),
140
+ delay: node.getAttribute("data-tooltip-delay"),
141
+ floating: Boolean(
142
+ node.getAttribute("data-tooltip-floating")
143
+ ),
144
+ setAsHTML: !!node.getAttribute("data-title-set-as-html"),
145
+ title
146
+ };
123
147
  }
124
- return {
125
- align: node.getAttribute('data-tooltip-align'),
126
- delay: node.getAttribute('data-tooltip-delay'),
127
- floating: Boolean(node.getAttribute('data-tooltip-floating')),
128
- setAsHTML: !!node.getAttribute('data-title-set-as-html'),
129
- title
130
- };
131
- }
132
- }, []);
148
+ },
149
+ []
150
+ );
133
151
  return {
134
152
  forceHide,
135
153
  getProps,
@@ -137,4 +155,4 @@ function useClosestTitle(props) {
137
155
  target: targetRef,
138
156
  titleNode: titleNodeRef
139
157
  };
140
- }
158
+ }
@@ -1,32 +1,44 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useTooltipState_exports = {};
20
+ __export(useTooltipState_exports, {
21
+ useTooltipState: () => useTooltipState
5
22
  });
6
- exports.useTooltipState = useTooltipState;
7
- var _react = require("react");
8
- /**
9
- * SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
10
- * SPDX-License-Identifier: BSD-3-Clause
11
- */
12
-
13
- function useTooltipState(_ref) {
14
- let {
15
- delay = 600
16
- } = _ref;
17
- const [isOpen, setOpen] = (0, _react.useState)(false);
18
- const timeoutIdRef = (0, _react.useRef)();
19
- const open = (0, _react.useCallback)((immediate, customDelay) => {
23
+ module.exports = __toCommonJS(useTooltipState_exports);
24
+ var import_react = require("react");
25
+ function useTooltipState({ delay = 600 }) {
26
+ const [isOpen, setOpen] = (0, import_react.useState)(false);
27
+ const timeoutIdRef = (0, import_react.useRef)();
28
+ const open = (0, import_react.useCallback)((immediate, customDelay) => {
20
29
  if (!immediate) {
21
30
  clearTimeout(timeoutIdRef.current);
22
- timeoutIdRef.current = setTimeout(() => {
23
- setOpen(true);
24
- }, customDelay !== undefined ? customDelay : delay);
31
+ timeoutIdRef.current = setTimeout(
32
+ () => {
33
+ setOpen(true);
34
+ },
35
+ customDelay !== void 0 ? customDelay : delay
36
+ );
25
37
  } else {
26
38
  setOpen(true);
27
39
  }
28
40
  }, []);
29
- const close = (0, _react.useCallback)(() => {
41
+ const close = (0, import_react.useCallback)(() => {
30
42
  clearTimeout(timeoutIdRef.current);
31
43
  setOpen(false);
32
44
  }, []);
@@ -35,4 +47,4 @@ function useTooltipState(_ref) {
35
47
  isOpen,
36
48
  open
37
49
  };
38
- }
50
+ }
@@ -1,31 +1,43 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- /**
3
- * SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- */
6
-
7
- import classNames from 'classnames';
8
- import React from 'react';
9
- export const ALIGN_POSITIONS = ['top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'left', 'right'];
10
- export const Tooltip = /*#__PURE__*/React.forwardRef((_ref, ref) => {
11
- let {
12
- alignPosition = 'bottom',
1
+ import classNames from "classnames";
2
+ import React from "react";
3
+ const ALIGN_POSITIONS = [
4
+ "top",
5
+ "top-left",
6
+ "top-right",
7
+ "bottom",
8
+ "bottom-left",
9
+ "bottom-right",
10
+ "left",
11
+ "right"
12
+ ];
13
+ const Tooltip = React.forwardRef(
14
+ ({
15
+ alignPosition = "bottom",
13
16
  children,
14
17
  className,
15
18
  show,
16
19
  ...otherProps
17
- } = _ref;
18
- return /*#__PURE__*/React.createElement("div", _extends({
19
- className: classNames(className, 'tooltip', `clay-tooltip-${alignPosition}`, {
20
- show
21
- }),
22
- role: "tooltip"
23
- }, otherProps, {
24
- ref: ref
25
- }), /*#__PURE__*/React.createElement("div", {
26
- className: "arrow"
27
- }), /*#__PURE__*/React.createElement("div", {
28
- className: "tooltip-inner"
29
- }, children));
30
- });
31
- Tooltip.displayName = 'ClayTooltip';
20
+ }, ref) => {
21
+ return /* @__PURE__ */ React.createElement(
22
+ "div",
23
+ {
24
+ className: classNames(
25
+ className,
26
+ "tooltip",
27
+ `clay-tooltip-${alignPosition}`,
28
+ { show }
29
+ ),
30
+ role: "tooltip",
31
+ ...otherProps,
32
+ ref
33
+ },
34
+ /* @__PURE__ */ React.createElement("div", { className: "arrow" }),
35
+ /* @__PURE__ */ React.createElement("div", { className: "tooltip-inner" }, children)
36
+ );
37
+ }
38
+ );
39
+ Tooltip.displayName = "ClayTooltip";
40
+ export {
41
+ ALIGN_POSITIONS,
42
+ Tooltip
43
+ };