@prokodo/ui 0.1.10 → 0.1.12
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 +3 -0
- package/dist/_virtual/_commonjsHelpers.js +2 -0
- package/dist/_virtual/quill.js +34 -0
- package/dist/_virtual/quill2.js +4 -0
- package/dist/components/RTE/RTE.client.js +367 -0
- package/dist/components/RTE/RTE.css +473 -0
- package/dist/components/RTE/RTE.js +12 -0
- package/dist/components/RTE/RTE.lazy.js +12 -0
- package/dist/components/RTE/RTE.module.css +473 -0
- package/dist/components/RTE/RTE.module.scss.js +22 -0
- package/dist/components/RTE/RTE.server.js +19 -0
- package/dist/components/RTE/RTE.styles.js +21 -0
- package/dist/components/RTE/RTE.theme.js +4 -0
- package/dist/components/RTE/RTE.utils.js +73 -0
- package/dist/components/RTE/RTE.view.js +107 -0
- package/dist/components/RTE/index.js +4 -0
- package/dist/components/avatar/Avatar.css +1 -3
- package/dist/components/avatar/Avatar.module.css +1 -3
- package/dist/components/avatar/Avatar.view.js +30 -17
- package/dist/components/base-link/BaseLink.client.js +11 -1
- package/dist/components/button/Button.css +1 -0
- package/dist/components/button/Button.module.css +1 -0
- package/dist/components/button/Button.view.js +1 -0
- package/dist/components/card/Card.css +10 -1
- package/dist/components/card/Card.module.css +10 -1
- package/dist/components/card/Card.module.scss.js +1 -0
- package/dist/components/chip/Chip.css +2 -2
- package/dist/components/chip/Chip.module.css +2 -2
- package/dist/components/chip/Chip.view.js +1 -1
- package/dist/components/input/Input.css +21 -2
- package/dist/components/input/Input.module.css +21 -2
- package/dist/components/input/Input.view.js +21 -13
- package/dist/components/pagination/Pagination.client.js +14 -0
- package/dist/components/pagination/Pagination.css +191 -0
- package/dist/components/pagination/Pagination.js +12 -0
- package/dist/components/pagination/Pagination.lazy.js +12 -0
- package/dist/components/pagination/Pagination.module.css +191 -0
- package/dist/components/pagination/Pagination.module.scss.js +12 -0
- package/dist/components/pagination/Pagination.server.js +11 -0
- package/dist/components/pagination/Pagination.utils.js +55 -0
- package/dist/components/pagination/Pagination.view.js +98 -0
- package/dist/components/pagination/index.js +4 -0
- package/dist/components/rich-text/RichText.client.js +31 -0
- package/dist/components/rich-text/RichText.css +13 -1
- package/dist/components/rich-text/RichText.module.css +13 -1
- package/dist/components/rich-text/RichText.module.scss.js +2 -0
- package/dist/components/rich-text/RichText.server.js +1 -0
- package/dist/components/select/Select.client.js +230 -8
- package/dist/components/select/Select.css +47 -16
- package/dist/components/select/Select.module.css +47 -16
- package/dist/components/select/Select.module.scss.js +2 -0
- package/dist/components/select/Select.view.js +20 -57
- package/dist/components/switch/Switch.css +1 -1
- package/dist/components/switch/Switch.module.css +1 -1
- package/dist/components/switch/Switch.view.js +3 -1
- package/dist/components/tooltip/Tooltip.client.js +373 -0
- package/dist/components/tooltip/Tooltip.css +241 -0
- package/dist/components/tooltip/Tooltip.js +16 -0
- package/dist/components/tooltip/Tooltip.module.css +241 -0
- package/dist/components/tooltip/Tooltip.module.scss.js +15 -0
- package/dist/components/tooltip/Tooltip.server.js +12 -0
- package/dist/components/tooltip/Tooltip.view.js +127 -0
- package/dist/components/tooltip/index.js +4 -0
- package/dist/constants/project.js +1 -1
- package/dist/index.js +6 -0
- package/dist/node_modules/.pnpm/quill@2.0.3/node_modules/quill/dist/quill.js +6133 -0
- package/dist/node_modules/.pnpm/quill@2.0.3/node_modules/quill/dist/quill.snow.css.js +12 -0
- package/dist/theme.css +214 -26
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/components/RTE/RTE.client.d.ts +6 -0
- package/dist/types/components/RTE/RTE.d.ts +339 -0
- package/dist/types/components/RTE/RTE.lazy.d.ts +340 -0
- package/dist/types/components/RTE/RTE.model.d.ts +17 -0
- package/dist/types/components/RTE/RTE.server.d.ts +3 -0
- package/dist/types/components/RTE/RTE.styles.d.ts +1 -0
- package/dist/types/components/RTE/RTE.theme.d.ts +2 -0
- package/dist/types/components/RTE/RTE.utils.d.ts +5 -0
- package/dist/types/components/RTE/RTE.view.d.ts +11 -0
- package/dist/types/components/RTE/index.d.ts +2 -0
- package/dist/types/components/avatar/Avatar.model.d.ts +1 -1
- package/dist/types/components/card/Card.model.d.ts +1 -1
- package/dist/types/components/grid/Grid.model.d.ts +37 -7
- package/dist/types/components/input/Input.model.d.ts +13 -1
- package/dist/types/components/input/Input.view.d.ts +1 -1
- package/dist/types/components/pagination/Pagination.client.d.ts +5 -0
- package/dist/types/components/pagination/Pagination.d.ts +4 -0
- package/dist/types/components/pagination/Pagination.lazy.d.ts +5 -0
- package/dist/types/components/pagination/Pagination.model.d.ts +22 -0
- package/dist/types/components/pagination/Pagination.server.d.ts +3 -0
- package/dist/types/components/pagination/Pagination.utils.d.ts +13 -0
- package/dist/types/components/pagination/Pagination.view.d.ts +3 -0
- package/dist/types/components/pagination/index.d.ts +2 -0
- package/dist/types/components/rich-text/RichText.client.d.ts +1 -1
- package/dist/types/components/rich-text/RichText.d.ts +1 -0
- package/dist/types/components/rich-text/RichText.lazy.d.ts +1 -0
- package/dist/types/components/rich-text/RichText.model.d.ts +1 -0
- package/dist/types/components/select/Select.model.d.ts +16 -1
- package/dist/types/components/tooltip/Tooltip.client.d.ts +5 -0
- package/dist/types/components/tooltip/Tooltip.d.ts +4 -0
- package/dist/types/components/tooltip/Tooltip.lazy.d.ts +5 -0
- package/dist/types/components/tooltip/Tooltip.model.d.ts +47 -0
- package/dist/types/components/tooltip/Tooltip.server.d.ts +3 -0
- package/dist/types/components/tooltip/Tooltip.view.d.ts +3 -0
- package/dist/types/components/tooltip/index.d.ts +2 -0
- package/dist/types/helpers/validations.d.ts +2 -2
- package/dist/types/index.d.ts +3 -0
- package/package.json +19 -2
|
@@ -26,6 +26,7 @@ function SelectView({
|
|
|
26
26
|
items,
|
|
27
27
|
_clientState
|
|
28
28
|
}) {
|
|
29
|
+
var _a;
|
|
29
30
|
if (!(items == null ? void 0 : items.length)) return null;
|
|
30
31
|
const isError = Boolean(errorText);
|
|
31
32
|
const hasHelper = Boolean(helperText);
|
|
@@ -34,7 +35,6 @@ function SelectView({
|
|
|
34
35
|
const helperId = hasHelper ? `${id}-helper` : void 0;
|
|
35
36
|
const open = Boolean(_clientState == null ? void 0 : _clientState.open) ?? false;
|
|
36
37
|
const btnRef = _clientState == null ? void 0 : _clientState.buttonRef;
|
|
37
|
-
const listRef = _clientState == null ? void 0 : _clientState.listRef;
|
|
38
38
|
const selectedItems = Array.isArray(value) ? items.filter((i) => value.includes(i.value)) : items.filter((i) => i.value === value);
|
|
39
39
|
const display = selectedItems.length === 0 ? /* @__PURE__ */ jsx(
|
|
40
40
|
"span",
|
|
@@ -47,9 +47,9 @@ function SelectView({
|
|
|
47
47
|
children: placeholder
|
|
48
48
|
}
|
|
49
49
|
) : /* @__PURE__ */ jsx("span", { className: bem("button__inner", { expanded: open }), children: selectedItems.map((i, idx) => {
|
|
50
|
-
var
|
|
50
|
+
var _a2;
|
|
51
51
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
52
|
-
Boolean(iconVisible) && ((
|
|
52
|
+
Boolean(iconVisible) && ((_a2 = i.icon) == null ? void 0 : _a2.call(i)),
|
|
53
53
|
i.label,
|
|
54
54
|
idx < selectedItems.length - 1 && ", "
|
|
55
55
|
] }, i == null ? void 0 : i.label);
|
|
@@ -104,60 +104,23 @@ function SelectView({
|
|
|
104
104
|
value: Array.isArray(value) ? value.join(",") : value ?? ""
|
|
105
105
|
}
|
|
106
106
|
),
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
onKeyDown: /* @__PURE__ */ __name(() => _clientState == null ? void 0 : _clientState.onOptionClick(null), "onKeyDown"),
|
|
125
|
-
children: placeholder
|
|
126
|
-
},
|
|
127
|
-
"placeholder"
|
|
128
|
-
),
|
|
129
|
-
items.map((opt) => {
|
|
130
|
-
var _a;
|
|
131
|
-
const selected = Array.isArray(value) ? value.includes(opt.value) : opt.value === value;
|
|
132
|
-
return /* @__PURE__ */ jsxs(
|
|
133
|
-
"li",
|
|
134
|
-
{
|
|
135
|
-
"aria-selected": selected,
|
|
136
|
-
className: bem("item", { selected }),
|
|
137
|
-
role: "option",
|
|
138
|
-
onClick: /* @__PURE__ */ __name(() => _clientState == null ? void 0 : _clientState.onOptionClick(opt.value), "onClick"),
|
|
139
|
-
onKeyDown: /* @__PURE__ */ __name(() => _clientState == null ? void 0 : _clientState.onOptionClick(opt.value), "onKeyDown"),
|
|
140
|
-
children: [
|
|
141
|
-
Boolean(multiple) && /* @__PURE__ */ jsx(
|
|
142
|
-
"input",
|
|
143
|
-
{
|
|
144
|
-
readOnly: true,
|
|
145
|
-
"aria-hidden": "true",
|
|
146
|
-
className: bem("checkbox", { checked: selected }),
|
|
147
|
-
defaultChecked: selected,
|
|
148
|
-
type: "checkbox"
|
|
149
|
-
}
|
|
150
|
-
),
|
|
151
|
-
Boolean(iconVisible) && ((_a = opt.icon) == null ? void 0 : _a.call(opt)),
|
|
152
|
-
opt.label
|
|
153
|
-
]
|
|
154
|
-
},
|
|
155
|
-
`${id}-${opt.value}`
|
|
156
|
-
);
|
|
157
|
-
})
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
)
|
|
107
|
+
(_a = _clientState == null ? void 0 : _clientState.renderListbox) == null ? void 0 : _a.call(_clientState, {
|
|
108
|
+
id: listId,
|
|
109
|
+
className: bem("listbox", { "is-open": open, "is-closed": !open }),
|
|
110
|
+
open,
|
|
111
|
+
required,
|
|
112
|
+
multiple,
|
|
113
|
+
placeholder,
|
|
114
|
+
items,
|
|
115
|
+
value: value ?? (Boolean(multiple) ? [] : ""),
|
|
116
|
+
onOptionClick: /* @__PURE__ */ __name((opt) => {
|
|
117
|
+
var _a2;
|
|
118
|
+
return (_a2 = _clientState == null ? void 0 : _clientState.onOptionClick) == null ? void 0 : _a2.call(_clientState, opt);
|
|
119
|
+
}, "onOptionClick"),
|
|
120
|
+
iconVisible,
|
|
121
|
+
bemItem: /* @__PURE__ */ __name((mods) => bem("item", mods), "bemItem"),
|
|
122
|
+
bemCheckbox: /* @__PURE__ */ __name((mods) => bem("checkbox", mods), "bemCheckbox")
|
|
123
|
+
})
|
|
161
124
|
] }),
|
|
162
125
|
(isError || Boolean(helperText)) && /* @__PURE__ */ jsx(
|
|
163
126
|
"div",
|
|
@@ -20,7 +20,8 @@ const SwitchView = /* @__PURE__ */ __name(({
|
|
|
20
20
|
className,
|
|
21
21
|
onChangeInternal,
|
|
22
22
|
onFocusInternal,
|
|
23
|
-
onBlurInternal
|
|
23
|
+
onBlurInternal,
|
|
24
|
+
...props
|
|
24
25
|
}) => {
|
|
25
26
|
const hasLabel = typeof label === "string" && label.length > 0;
|
|
26
27
|
return /* @__PURE__ */ jsxs("div", { className: bem(void 0, { [variant]: true }, className), children: [
|
|
@@ -58,6 +59,7 @@ const SwitchView = /* @__PURE__ */ __name(({
|
|
|
58
59
|
/* @__PURE__ */ jsx(
|
|
59
60
|
"input",
|
|
60
61
|
{
|
|
62
|
+
...props,
|
|
61
63
|
"aria-checked": isChecked,
|
|
62
64
|
"aria-disabled": disabled || void 0,
|
|
63
65
|
"aria-required": required || void 0,
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
5
|
+
import { memo, useState, useRef, useCallback, useMemo, useLayoutEffect } from "react";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
|
+
import { create } from "../../helpers/bem.js";
|
|
8
|
+
import styles from "./Tooltip.module.scss.js";
|
|
9
|
+
import { TooltipView } from "./Tooltip.view.js";
|
|
10
|
+
const bem = create(styles, "Tooltip");
|
|
11
|
+
function clamp(n, min, max) {
|
|
12
|
+
return Math.max(min, Math.min(max, n));
|
|
13
|
+
}
|
|
14
|
+
__name(clamp, "clamp");
|
|
15
|
+
function getOverlayRoot(id, zIndex) {
|
|
16
|
+
let el = document.getElementById(id);
|
|
17
|
+
if (!el) {
|
|
18
|
+
el = document.createElement("div");
|
|
19
|
+
el.id = id;
|
|
20
|
+
document.body.appendChild(el);
|
|
21
|
+
}
|
|
22
|
+
el.style.position = "fixed";
|
|
23
|
+
el.style.left = "0";
|
|
24
|
+
el.style.top = "0";
|
|
25
|
+
el.style.width = "0";
|
|
26
|
+
el.style.height = "0";
|
|
27
|
+
el.style.pointerEvents = "none";
|
|
28
|
+
el.style.zIndex = String(zIndex);
|
|
29
|
+
return el;
|
|
30
|
+
}
|
|
31
|
+
__name(getOverlayRoot, "getOverlayRoot");
|
|
32
|
+
function opposite(p) {
|
|
33
|
+
if (p === "top") return "bottom";
|
|
34
|
+
if (p === "bottom") return "top";
|
|
35
|
+
if (p === "left") return "right";
|
|
36
|
+
return "left";
|
|
37
|
+
}
|
|
38
|
+
__name(opposite, "opposite");
|
|
39
|
+
function perpendicular(p) {
|
|
40
|
+
if (p === "top" || p === "bottom") return ["right", "left"];
|
|
41
|
+
return ["top", "bottom"];
|
|
42
|
+
}
|
|
43
|
+
__name(perpendicular, "perpendicular");
|
|
44
|
+
function fitsPlacement(args) {
|
|
45
|
+
const {
|
|
46
|
+
placement,
|
|
47
|
+
anchorX,
|
|
48
|
+
anchorY,
|
|
49
|
+
triggerRect,
|
|
50
|
+
bubbleSize,
|
|
51
|
+
gutter,
|
|
52
|
+
offset,
|
|
53
|
+
arrowSize
|
|
54
|
+
} = args;
|
|
55
|
+
const vw = window.innerWidth;
|
|
56
|
+
const vh = window.innerHeight;
|
|
57
|
+
const need = offset + arrowSize;
|
|
58
|
+
let left = 0;
|
|
59
|
+
let top = 0;
|
|
60
|
+
if (placement === "top") {
|
|
61
|
+
left = anchorX - bubbleSize.w / 2;
|
|
62
|
+
top = triggerRect.top - need - bubbleSize.h;
|
|
63
|
+
} else if (placement === "bottom") {
|
|
64
|
+
left = anchorX - bubbleSize.w / 2;
|
|
65
|
+
top = triggerRect.bottom + need;
|
|
66
|
+
} else if (placement === "left") {
|
|
67
|
+
left = triggerRect.left - need - bubbleSize.w;
|
|
68
|
+
top = anchorY - bubbleSize.h / 2;
|
|
69
|
+
} else {
|
|
70
|
+
left = triggerRect.right + need;
|
|
71
|
+
top = anchorY - bubbleSize.h / 2;
|
|
72
|
+
}
|
|
73
|
+
const right = left + bubbleSize.w;
|
|
74
|
+
const bottom = top + bubbleSize.h;
|
|
75
|
+
return left >= gutter && right <= vw - gutter && top >= gutter && bottom <= vh - gutter;
|
|
76
|
+
}
|
|
77
|
+
__name(fitsPlacement, "fitsPlacement");
|
|
78
|
+
function choosePlacement(args) {
|
|
79
|
+
const { preferred, preventOverflow } = args;
|
|
80
|
+
if (!preventOverflow) return preferred;
|
|
81
|
+
const tryOrder = [
|
|
82
|
+
preferred,
|
|
83
|
+
opposite(preferred),
|
|
84
|
+
...perpendicular(preferred)
|
|
85
|
+
];
|
|
86
|
+
for (const p of tryOrder) {
|
|
87
|
+
if (fitsPlacement({ ...args, placement: p })) return p;
|
|
88
|
+
}
|
|
89
|
+
return preferred;
|
|
90
|
+
}
|
|
91
|
+
__name(choosePlacement, "choosePlacement");
|
|
92
|
+
function computeFixedPosition(args) {
|
|
93
|
+
const { placement, anchorX, anchorY, bubbleSize, gutter, offset, arrowSize } = args;
|
|
94
|
+
const vw = window.innerWidth;
|
|
95
|
+
const vh = window.innerHeight;
|
|
96
|
+
const need = offset + arrowSize;
|
|
97
|
+
let x = 0;
|
|
98
|
+
let y = 0;
|
|
99
|
+
if (placement === "top") {
|
|
100
|
+
x = anchorX - bubbleSize.w / 2;
|
|
101
|
+
y = anchorY - need - bubbleSize.h;
|
|
102
|
+
} else if (placement === "bottom") {
|
|
103
|
+
x = anchorX - bubbleSize.w / 2;
|
|
104
|
+
y = anchorY + need;
|
|
105
|
+
} else if (placement === "left") {
|
|
106
|
+
x = anchorX - need - bubbleSize.w;
|
|
107
|
+
y = anchorY - bubbleSize.h / 2;
|
|
108
|
+
} else {
|
|
109
|
+
x = anchorX + need;
|
|
110
|
+
y = anchorY - bubbleSize.h / 2;
|
|
111
|
+
}
|
|
112
|
+
const clampedX = clamp(x, gutter, vw - gutter - bubbleSize.w);
|
|
113
|
+
const clampedY = clamp(y, gutter, vh - gutter - bubbleSize.h);
|
|
114
|
+
const pad = 12;
|
|
115
|
+
if (placement === "top" || placement === "bottom") {
|
|
116
|
+
const rawArrowX = anchorX - clampedX;
|
|
117
|
+
const arrowX = clamp(
|
|
118
|
+
rawArrowX,
|
|
119
|
+
arrowSize + pad,
|
|
120
|
+
bubbleSize.w - arrowSize - pad
|
|
121
|
+
);
|
|
122
|
+
return { x: clampedX, y: clampedY, arrowX };
|
|
123
|
+
}
|
|
124
|
+
const rawArrowY = anchorY - clampedY;
|
|
125
|
+
const arrowY = clamp(
|
|
126
|
+
rawArrowY,
|
|
127
|
+
arrowSize + pad,
|
|
128
|
+
bubbleSize.h - arrowSize - pad
|
|
129
|
+
);
|
|
130
|
+
return { x: clampedX, y: clampedY, arrowY };
|
|
131
|
+
}
|
|
132
|
+
__name(computeFixedPosition, "computeFixedPosition");
|
|
133
|
+
function TooltipClient(props) {
|
|
134
|
+
const {
|
|
135
|
+
anchor = "element",
|
|
136
|
+
content,
|
|
137
|
+
preventOverflow = true,
|
|
138
|
+
// Portal defaults.
|
|
139
|
+
portal = true,
|
|
140
|
+
overlayRootId = "pk-overlays",
|
|
141
|
+
zIndex = 2147483647,
|
|
142
|
+
offset = 6,
|
|
143
|
+
mobileBreakpoint = 960,
|
|
144
|
+
// Open logic.
|
|
145
|
+
open: controlledOpen,
|
|
146
|
+
defaultOpen,
|
|
147
|
+
onOpenChange,
|
|
148
|
+
delay = 120,
|
|
149
|
+
closeDelay = 80,
|
|
150
|
+
openOnHover = true,
|
|
151
|
+
openOnFocus = true,
|
|
152
|
+
disabled,
|
|
153
|
+
// View.
|
|
154
|
+
triggerProps,
|
|
155
|
+
placement = "top",
|
|
156
|
+
tooltipClassName,
|
|
157
|
+
...rest
|
|
158
|
+
} = props;
|
|
159
|
+
const isControlled = controlledOpen !== void 0;
|
|
160
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(
|
|
161
|
+
Boolean(defaultOpen)
|
|
162
|
+
);
|
|
163
|
+
const open = isControlled ? Boolean(controlledOpen) : uncontrolledOpen;
|
|
164
|
+
const lastPointer = useRef(null);
|
|
165
|
+
const triggerRef = useRef(null);
|
|
166
|
+
const bubbleRef = useRef(null);
|
|
167
|
+
const [bubbleStyle, setBubbleStyle] = useState(
|
|
168
|
+
void 0
|
|
169
|
+
);
|
|
170
|
+
const [effectivePlacement, setEffectivePlacement] = useState(placement);
|
|
171
|
+
const openTimer = useRef(null);
|
|
172
|
+
const closeTimer = useRef(null);
|
|
173
|
+
const clearTimers = useCallback(() => {
|
|
174
|
+
if (openTimer.current != null) window.clearTimeout(openTimer.current);
|
|
175
|
+
if (closeTimer.current != null) window.clearTimeout(closeTimer.current);
|
|
176
|
+
openTimer.current = null;
|
|
177
|
+
closeTimer.current = null;
|
|
178
|
+
}, []);
|
|
179
|
+
const setOpen = useCallback(
|
|
180
|
+
(next) => {
|
|
181
|
+
if (disabled) return;
|
|
182
|
+
if (!isControlled) setUncontrolledOpen(next);
|
|
183
|
+
onOpenChange == null ? void 0 : onOpenChange(next);
|
|
184
|
+
},
|
|
185
|
+
[disabled, isControlled, onOpenChange]
|
|
186
|
+
);
|
|
187
|
+
const scheduleOpen = useCallback(() => {
|
|
188
|
+
if (disabled) return;
|
|
189
|
+
clearTimers();
|
|
190
|
+
if (delay <= 0) return setOpen(true);
|
|
191
|
+
openTimer.current = window.setTimeout(() => setOpen(true), delay);
|
|
192
|
+
}, [clearTimers, delay, disabled, setOpen]);
|
|
193
|
+
const scheduleClose = useCallback(() => {
|
|
194
|
+
clearTimers();
|
|
195
|
+
if (closeDelay <= 0) return setOpen(false);
|
|
196
|
+
closeTimer.current = window.setTimeout(() => setOpen(false), closeDelay);
|
|
197
|
+
}, [clearTimers, closeDelay, setOpen]);
|
|
198
|
+
const mergedTriggerProps = useMemo(
|
|
199
|
+
() => ({
|
|
200
|
+
...triggerProps,
|
|
201
|
+
onMouseEnter: openOnHover ? (e) => {
|
|
202
|
+
var _a;
|
|
203
|
+
(_a = triggerProps == null ? void 0 : triggerProps.onMouseEnter) == null ? void 0 : _a.call(triggerProps, e);
|
|
204
|
+
if (anchor === "pointer")
|
|
205
|
+
lastPointer.current = { x: e.clientX, y: e.clientY };
|
|
206
|
+
scheduleOpen();
|
|
207
|
+
} : triggerProps == null ? void 0 : triggerProps.onMouseEnter,
|
|
208
|
+
onMouseLeave: openOnHover ? (e) => {
|
|
209
|
+
var _a;
|
|
210
|
+
(_a = triggerProps == null ? void 0 : triggerProps.onMouseLeave) == null ? void 0 : _a.call(triggerProps, e);
|
|
211
|
+
if (anchor === "pointer") lastPointer.current = null;
|
|
212
|
+
scheduleClose();
|
|
213
|
+
} : triggerProps == null ? void 0 : triggerProps.onMouseLeave,
|
|
214
|
+
onMouseMove: anchor === "pointer" ? (e) => {
|
|
215
|
+
var _a;
|
|
216
|
+
(_a = triggerProps == null ? void 0 : triggerProps.onMouseMove) == null ? void 0 : _a.call(triggerProps, e);
|
|
217
|
+
lastPointer.current = { x: e.clientX, y: e.clientY };
|
|
218
|
+
} : triggerProps == null ? void 0 : triggerProps.onMouseMove,
|
|
219
|
+
onFocus: openOnFocus ? (e) => {
|
|
220
|
+
var _a;
|
|
221
|
+
(_a = triggerProps == null ? void 0 : triggerProps.onFocus) == null ? void 0 : _a.call(triggerProps, e);
|
|
222
|
+
scheduleOpen();
|
|
223
|
+
} : triggerProps == null ? void 0 : triggerProps.onFocus,
|
|
224
|
+
onBlur: openOnFocus ? (e) => {
|
|
225
|
+
var _a;
|
|
226
|
+
(_a = triggerProps == null ? void 0 : triggerProps.onBlur) == null ? void 0 : _a.call(triggerProps, e);
|
|
227
|
+
scheduleClose();
|
|
228
|
+
} : triggerProps == null ? void 0 : triggerProps.onBlur,
|
|
229
|
+
onKeyDown: /* @__PURE__ */ __name((e) => {
|
|
230
|
+
var _a, _b, _c;
|
|
231
|
+
(_a = triggerProps == null ? void 0 : triggerProps.onKeyDown) == null ? void 0 : _a.call(triggerProps, e);
|
|
232
|
+
if (e.key === "Escape") {
|
|
233
|
+
clearTimers();
|
|
234
|
+
setOpen(false);
|
|
235
|
+
(_c = (_b = e.currentTarget) == null ? void 0 : _b.blur) == null ? void 0 : _c.call(_b);
|
|
236
|
+
}
|
|
237
|
+
}, "onKeyDown")
|
|
238
|
+
}),
|
|
239
|
+
[
|
|
240
|
+
triggerProps,
|
|
241
|
+
openOnHover,
|
|
242
|
+
openOnFocus,
|
|
243
|
+
scheduleOpen,
|
|
244
|
+
scheduleClose,
|
|
245
|
+
clearTimers,
|
|
246
|
+
setOpen,
|
|
247
|
+
anchor
|
|
248
|
+
]
|
|
249
|
+
);
|
|
250
|
+
const portalBubbleClassBase = useMemo(
|
|
251
|
+
() => bem("bubble", void 0, tooltipClassName),
|
|
252
|
+
[tooltipClassName]
|
|
253
|
+
);
|
|
254
|
+
const portalBubbleClassFinal = useMemo(
|
|
255
|
+
() => bem(
|
|
256
|
+
"bubble",
|
|
257
|
+
{ open: Boolean(open && bubbleStyle), [effectivePlacement]: true },
|
|
258
|
+
tooltipClassName
|
|
259
|
+
),
|
|
260
|
+
[open, bubbleStyle, effectivePlacement, tooltipClassName]
|
|
261
|
+
);
|
|
262
|
+
const compute = useCallback(() => {
|
|
263
|
+
if (!portal || !open || disabled) return;
|
|
264
|
+
const triggerEl = triggerRef.current;
|
|
265
|
+
const bubbleEl = bubbleRef.current;
|
|
266
|
+
if (!triggerEl || !bubbleEl) return;
|
|
267
|
+
const anchorEl = triggerEl.querySelector("[data-tooltip-anchor]") ?? triggerEl;
|
|
268
|
+
const gutter = 8;
|
|
269
|
+
const arrowSize = 8;
|
|
270
|
+
const triggerRect = anchorEl.getBoundingClientRect();
|
|
271
|
+
const bubbleSize = {
|
|
272
|
+
w: bubbleEl.offsetWidth,
|
|
273
|
+
h: bubbleEl.offsetHeight
|
|
274
|
+
};
|
|
275
|
+
if (!bubbleSize.w || !bubbleSize.h) return;
|
|
276
|
+
const isMobile = window.innerWidth < mobileBreakpoint;
|
|
277
|
+
const preferred = isMobile && (placement === "left" || placement === "right") ? "top" : placement;
|
|
278
|
+
const ar = anchorEl.getBoundingClientRect();
|
|
279
|
+
const anchorX = ar.left + ar.width / 2;
|
|
280
|
+
const anchorY = ar.top + ar.height / 2;
|
|
281
|
+
const chosen = choosePlacement({
|
|
282
|
+
preferred,
|
|
283
|
+
anchorX,
|
|
284
|
+
anchorY,
|
|
285
|
+
triggerRect,
|
|
286
|
+
bubbleSize,
|
|
287
|
+
gutter,
|
|
288
|
+
offset,
|
|
289
|
+
arrowSize,
|
|
290
|
+
preventOverflow
|
|
291
|
+
});
|
|
292
|
+
const { x, y, arrowX, arrowY } = computeFixedPosition({
|
|
293
|
+
placement: chosen,
|
|
294
|
+
anchorX,
|
|
295
|
+
anchorY,
|
|
296
|
+
bubbleSize,
|
|
297
|
+
gutter,
|
|
298
|
+
offset,
|
|
299
|
+
arrowSize
|
|
300
|
+
});
|
|
301
|
+
setEffectivePlacement(chosen);
|
|
302
|
+
setBubbleStyle({
|
|
303
|
+
["--pk-tt-x"]: `${x}px`,
|
|
304
|
+
["--pk-tt-y"]: `${y}px`,
|
|
305
|
+
["--pk-tt-arrow-x"]: arrowX != null ? `${arrowX}px` : void 0,
|
|
306
|
+
["--pk-tt-arrow-y"]: arrowY != null ? `${arrowY}px` : void 0,
|
|
307
|
+
["--pk-tt-z"]: String(zIndex)
|
|
308
|
+
});
|
|
309
|
+
}, [
|
|
310
|
+
portal,
|
|
311
|
+
open,
|
|
312
|
+
disabled,
|
|
313
|
+
placement,
|
|
314
|
+
preventOverflow,
|
|
315
|
+
offset,
|
|
316
|
+
zIndex,
|
|
317
|
+
mobileBreakpoint
|
|
318
|
+
]);
|
|
319
|
+
useLayoutEffect(() => {
|
|
320
|
+
if (!portal || !open) return;
|
|
321
|
+
setBubbleStyle(void 0);
|
|
322
|
+
const raf1 = requestAnimationFrame(() => {
|
|
323
|
+
requestAnimationFrame(() => compute());
|
|
324
|
+
});
|
|
325
|
+
const onResize = /* @__PURE__ */ __name(() => compute(), "onResize");
|
|
326
|
+
const onScroll = /* @__PURE__ */ __name(() => compute(), "onScroll");
|
|
327
|
+
window.addEventListener("resize", onResize);
|
|
328
|
+
window.addEventListener("scroll", onScroll, true);
|
|
329
|
+
return () => {
|
|
330
|
+
cancelAnimationFrame(raf1);
|
|
331
|
+
window.removeEventListener("resize", onResize);
|
|
332
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
333
|
+
};
|
|
334
|
+
}, [portal, open, compute]);
|
|
335
|
+
const overlayRoot = typeof document !== "undefined" && portal ? getOverlayRoot(overlayRootId, zIndex) : null;
|
|
336
|
+
const portalOpen = open && Boolean(bubbleStyle);
|
|
337
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
338
|
+
/* @__PURE__ */ jsx(
|
|
339
|
+
TooltipView,
|
|
340
|
+
{
|
|
341
|
+
...rest,
|
|
342
|
+
__open: portal ? portalOpen : open,
|
|
343
|
+
__placement: portal ? effectivePlacement : placement,
|
|
344
|
+
__renderVisualBubble: !portal,
|
|
345
|
+
__triggerRef: triggerRef,
|
|
346
|
+
content,
|
|
347
|
+
disabled,
|
|
348
|
+
placement,
|
|
349
|
+
tooltipClassName,
|
|
350
|
+
triggerProps: mergedTriggerProps
|
|
351
|
+
}
|
|
352
|
+
),
|
|
353
|
+
portal && !disabled && overlayRoot ? createPortal(
|
|
354
|
+
/* @__PURE__ */ jsx(
|
|
355
|
+
"span",
|
|
356
|
+
{
|
|
357
|
+
ref: bubbleRef,
|
|
358
|
+
"aria-hidden": open === void 0 ? void 0 : !open,
|
|
359
|
+
role: "tooltip",
|
|
360
|
+
style: bubbleStyle,
|
|
361
|
+
className: bubbleStyle ? portalBubbleClassFinal : portalBubbleClassBase,
|
|
362
|
+
children: content
|
|
363
|
+
}
|
|
364
|
+
),
|
|
365
|
+
overlayRoot
|
|
366
|
+
) : null
|
|
367
|
+
] });
|
|
368
|
+
}
|
|
369
|
+
__name(TooltipClient, "TooltipClient");
|
|
370
|
+
const Tooltip_client = memo(TooltipClient);
|
|
371
|
+
export {
|
|
372
|
+
Tooltip_client as default
|
|
373
|
+
};
|