@sydsoft/base 1.44.0 → 1.48.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 +8 -1
- package/dist/esm/_lib/baseFunctions.js +25 -38
- package/dist/esm/_lib/inputMask.js +66 -68
- package/dist/esm/_lib/listFunctions.js +12 -13
- package/dist/esm/_lib/storage/cookies.js +20 -21
- package/dist/esm/_lib/storage/encData.js +19 -21
- package/dist/esm/_lib/storage/localStorage.js +10 -10
- package/dist/esm/_lib/storage/sessionStorage.js +10 -10
- package/dist/esm/_lib/useInterval.js +5 -5
- package/dist/esm/alert/index.js +28 -30
- package/dist/esm/box/Box.js +6 -7
- package/dist/esm/box/BoxContent.js +2 -4
- package/dist/esm/box/BoxFooter.js +6 -4
- package/dist/esm/box/BoxHeader.js +6 -5
- package/dist/esm/countDown/index.js +28 -33
- package/dist/esm/dateTime/index.js +25 -31
- package/dist/esm/form/Button.js +28 -22
- package/dist/esm/form/Checkbox.js +7 -8
- package/dist/esm/form/Dialog.d.ts +7 -6
- package/dist/esm/form/Dialog.js +51 -38
- package/dist/esm/form/Form.js +3 -5
- package/dist/esm/form/FormOlustur.js +15 -17
- package/dist/esm/form/Input.d.ts +12 -7
- package/dist/esm/form/Input.js +68 -77
- package/dist/esm/form/Label.d.ts +1 -1
- package/dist/esm/form/Label.js +5 -10
- package/dist/esm/form/SearchableInput.js +77 -89
- package/dist/esm/form/UploadBase.js +30 -32
- package/dist/esm/grid/index.js +40 -41
- package/dist/esm/icon/icons.js +1 -1
- package/dist/esm/icon/index.js +21 -10
- package/dist/esm/index.module.css +89 -0
- package/dist/esm/menu/index.d.ts +30 -4
- package/dist/esm/menu/index.js +32 -14
- package/dist/esm/modal/index.js +14 -16
- package/dist/esm/popover/index.d.ts +21 -7
- package/dist/esm/popover/index.js +320 -119
- package/dist/esm/tooltip/index.js +117 -34
- package/package.json +12 -6
- package/dist/esm/alert/index.module.css +0 -119
- package/dist/esm/grid/index.module.css +0 -805
- package/dist/esm/menu/index.module.css +0 -67
- package/dist/esm/modal/index.module.css +0 -76
- /package/dist/esm/{box/Box.module.css → Box.module.css} +0 -0
- /package/dist/esm/{form/styles → styles}/Button.module.css +0 -0
- /package/dist/esm/{form/styles → styles}/Input.module.css +0 -0
- /package/dist/esm/{form/styles → styles}/Label.module.css +0 -0
- /package/dist/esm/{form/styles → styles}/SearchableInput.module.css +0 -0
|
@@ -1,142 +1,343 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
popoverSil();
|
|
1
|
+
/**
|
|
2
|
+
* @author : izzetseydaoglu
|
|
3
|
+
* @copyright : sydSOFT Bilişim Hizmetleri (c) 2026
|
|
4
|
+
* @version : 2026-02-10 16:12:35
|
|
5
|
+
*/
|
|
6
|
+
import { cloneElement, memo, useEffect, useRef } from 'react';
|
|
7
|
+
import { createRoot } from 'react-dom/client';
|
|
8
|
+
import styles from './index.module.css';
|
|
9
|
+
export const Popover = memo(function MemoFunction({ children, component, position = 'top', arrow = false, distance = 5, removeWhenClickInside = false, hideBackdrop = true, fade = true, arrowColor = 'auto', hover = false, hoverCloseDelay = 120, keepMounted = false, ...other }) {
|
|
10
|
+
const refComponent = useRef(null);
|
|
11
|
+
const closeTimer = useRef(null);
|
|
12
|
+
const hoverCloseTimer = useRef(null);
|
|
13
|
+
const popoverRef = useRef(null);
|
|
14
|
+
const rootRef = useRef(null);
|
|
15
|
+
const zIndexRef = useRef(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (typeof window === 'undefined')
|
|
18
|
+
return;
|
|
19
|
+
return () => {
|
|
20
|
+
popoverSil(false);
|
|
21
21
|
};
|
|
22
22
|
}, []);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
23
|
+
const checkHideBackDrop = (e) => {
|
|
24
|
+
const spopover = popoverRef.current;
|
|
25
|
+
if (!spopover)
|
|
26
|
+
return;
|
|
27
|
+
if (!((e === null || e === void 0 ? void 0 : e.target) instanceof Node)) {
|
|
28
|
+
popoverSil();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!spopover.contains(e.target))
|
|
26
32
|
popoverSil();
|
|
27
33
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
const popoverEkle = (e) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
if (popoverRef.current && keepMounted) {
|
|
37
|
+
const popover = popoverRef.current;
|
|
38
|
+
const target = e.currentTarget;
|
|
39
|
+
const wasVisible = popover.classList.contains(styles.visible);
|
|
40
|
+
(_b = (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.render) === null || _b === void 0 ? void 0 : _b.call(_a, children);
|
|
41
|
+
applyArrowColor(popover);
|
|
42
|
+
popoverPosition({ target, position: position });
|
|
43
|
+
popover.style.zIndex = String(nextPopoverZIndex());
|
|
44
|
+
popover.classList.remove(styles.closing);
|
|
45
|
+
popover.classList.add(styles.visible);
|
|
46
|
+
if (!wasVisible) {
|
|
47
|
+
if (hideBackdrop) {
|
|
48
|
+
window.addEventListener('mousedown', checkHideBackDrop);
|
|
49
|
+
window.addEventListener('blur', checkHideBackDrop);
|
|
50
|
+
}
|
|
51
|
+
if (removeWhenClickInside)
|
|
52
|
+
popover.addEventListener('mouseup', popoverGecikmeliSil);
|
|
53
|
+
if (hover) {
|
|
54
|
+
popover.addEventListener('mouseenter', clearHoverClose);
|
|
55
|
+
popover.addEventListener('mouseleave', scheduleHoverClose);
|
|
56
|
+
}
|
|
57
|
+
incrementBodyPopover();
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
popoverSil(false);
|
|
62
|
+
const popover = document.createElement('div');
|
|
63
|
+
popover.classList.add('spopover', styles.popover);
|
|
64
|
+
const zIndex = nextPopoverZIndex();
|
|
65
|
+
zIndexRef.current = zIndex;
|
|
32
66
|
document.body.appendChild(popover);
|
|
33
67
|
// ReactDOM.render(children, popover)
|
|
34
|
-
|
|
68
|
+
const root = createRoot(popover);
|
|
35
69
|
root.render(children);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
70
|
+
popoverRef.current = popover;
|
|
71
|
+
rootRef.current = root;
|
|
72
|
+
const target = e.currentTarget;
|
|
73
|
+
refComponent.current && refComponent.current.classList.add('spopover_active');
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
var _a;
|
|
76
|
+
applyArrowColor(popover);
|
|
77
|
+
popoverPosition({ target, position: position });
|
|
78
|
+
popover.style.zIndex = String((_a = zIndexRef.current) !== null && _a !== void 0 ? _a : zIndex);
|
|
79
|
+
popover.classList.add(styles.visible);
|
|
39
80
|
}, 100);
|
|
40
|
-
|
|
81
|
+
if (hideBackdrop) {
|
|
82
|
+
window.addEventListener('mousedown', checkHideBackDrop);
|
|
83
|
+
window.addEventListener('blur', checkHideBackDrop);
|
|
84
|
+
}
|
|
41
85
|
if (removeWhenClickInside)
|
|
42
|
-
popover.addEventListener(
|
|
43
|
-
|
|
86
|
+
popover.addEventListener('mouseup', popoverGecikmeliSil);
|
|
87
|
+
if (hover) {
|
|
88
|
+
popover.addEventListener('mouseenter', clearHoverClose);
|
|
89
|
+
popover.addEventListener('mouseleave', scheduleHoverClose);
|
|
90
|
+
}
|
|
91
|
+
incrementBodyPopover();
|
|
44
92
|
};
|
|
45
|
-
|
|
46
|
-
|
|
93
|
+
const popoverSil = (animate = true) => {
|
|
94
|
+
refComponent.current && refComponent.current.classList.remove('spopover_active');
|
|
95
|
+
const check = popoverRef.current;
|
|
96
|
+
const wasVisible = !!(check === null || check === void 0 ? void 0 : check.classList.contains(styles.visible));
|
|
47
97
|
if (check) {
|
|
48
98
|
if (removeWhenClickInside)
|
|
49
|
-
check.removeEventListener(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (position === "top") {
|
|
69
|
-
if (targetPosition.top - popoverPosition_1.height - margin < 0) {
|
|
70
|
-
style.push("top:" + (targetPosition.bottom + margin) + "px");
|
|
71
|
-
popover.classList.add("bottom");
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
style.push("top:" + (targetPosition.top - popoverPosition_1.height - margin) + "px");
|
|
75
|
-
popover.classList.add("top");
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (position === "bottom") {
|
|
79
|
-
if (targetPosition.bottom + popoverPosition_1.height + margin > window.innerHeight) {
|
|
80
|
-
style.push("top:" + (targetPosition.top - popoverPosition_1.height - margin) + "px");
|
|
81
|
-
popover.classList.add("top");
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
style.push("top:" + (targetPosition.bottom + margin) + "px");
|
|
85
|
-
popover.classList.add("bottom");
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (targetPosition.left + targetPosition.width / 2 - popoverPosition_1.width / 2 < 0) {
|
|
89
|
-
style.push("left:2px");
|
|
90
|
-
popover.classList.add("start");
|
|
91
|
-
}
|
|
92
|
-
else if (targetPosition.left + targetPosition.width / 2 + popoverPosition_1.width > window.innerWidth) {
|
|
93
|
-
style.push("right:2px");
|
|
94
|
-
popover.classList.add("end");
|
|
99
|
+
check.removeEventListener('mouseup', popoverGecikmeliSil);
|
|
100
|
+
if (hover) {
|
|
101
|
+
check.removeEventListener('mouseenter', clearHoverClose);
|
|
102
|
+
check.removeEventListener('mouseleave', scheduleHoverClose);
|
|
103
|
+
}
|
|
104
|
+
if (closeTimer.current)
|
|
105
|
+
window.clearTimeout(closeTimer.current);
|
|
106
|
+
if (hoverCloseTimer.current)
|
|
107
|
+
window.clearTimeout(hoverCloseTimer.current);
|
|
108
|
+
if (!fade || !animate) {
|
|
109
|
+
if (!keepMounted) {
|
|
110
|
+
const root = rootRef.current;
|
|
111
|
+
window.setTimeout(() => {
|
|
112
|
+
var _a;
|
|
113
|
+
(_a = root === null || root === void 0 ? void 0 : root.unmount) === null || _a === void 0 ? void 0 : _a.call(root);
|
|
114
|
+
}, 0);
|
|
115
|
+
check.remove();
|
|
116
|
+
popoverRef.current = null;
|
|
117
|
+
rootRef.current = null;
|
|
95
118
|
}
|
|
96
119
|
else {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
popover.classList.add("center");
|
|
120
|
+
check.classList.remove(styles.visible);
|
|
121
|
+
check.classList.remove(styles.closing);
|
|
100
122
|
}
|
|
101
123
|
}
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
if (position === "right") {
|
|
114
|
-
if (targetPosition.left + targetPosition.width / 2 + popoverPosition_1.width + margin > window.innerWidth) {
|
|
115
|
-
style.push("left:" + (targetPosition.left - popoverPosition_1.width - margin) + "px");
|
|
116
|
-
popover.classList.add("left");
|
|
124
|
+
else if (!check.classList.contains(styles.closing)) {
|
|
125
|
+
check.classList.add(styles.closing);
|
|
126
|
+
closeTimer.current = window.setTimeout(() => {
|
|
127
|
+
var _a;
|
|
128
|
+
if (!keepMounted) {
|
|
129
|
+
const root = rootRef.current;
|
|
130
|
+
(_a = root === null || root === void 0 ? void 0 : root.unmount) === null || _a === void 0 ? void 0 : _a.call(root);
|
|
131
|
+
check.remove();
|
|
132
|
+
popoverRef.current = null;
|
|
133
|
+
rootRef.current = null;
|
|
117
134
|
}
|
|
118
135
|
else {
|
|
119
|
-
|
|
120
|
-
|
|
136
|
+
check.classList.remove(styles.visible);
|
|
137
|
+
check.classList.remove(styles.closing);
|
|
121
138
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
}, FADE_DURATION);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (hideBackdrop) {
|
|
143
|
+
window.removeEventListener('mousedown', checkHideBackDrop);
|
|
144
|
+
window.removeEventListener('blur', checkHideBackDrop);
|
|
145
|
+
}
|
|
146
|
+
if (wasVisible)
|
|
147
|
+
decrementBodyPopover();
|
|
148
|
+
};
|
|
149
|
+
const popoverGecikmeliSil = () => setTimeout(() => popoverSil(), 100);
|
|
150
|
+
const clearHoverClose = () => {
|
|
151
|
+
if (hoverCloseTimer.current)
|
|
152
|
+
window.clearTimeout(hoverCloseTimer.current);
|
|
153
|
+
hoverCloseTimer.current = null;
|
|
154
|
+
};
|
|
155
|
+
const scheduleHoverClose = () => {
|
|
156
|
+
clearHoverClose();
|
|
157
|
+
hoverCloseTimer.current = window.setTimeout(() => popoverSil(), hoverCloseDelay);
|
|
158
|
+
};
|
|
159
|
+
const popoverPosition = ({ target, position }) => {
|
|
160
|
+
const popover = popoverRef.current;
|
|
161
|
+
if (popover) {
|
|
162
|
+
const arrowMargin = arrow ? 5 : 0;
|
|
163
|
+
const margin = distance + arrowMargin;
|
|
164
|
+
const { side: preferredSide, align: preferredAlign } = normalizePosition(position);
|
|
165
|
+
const targetPosition = target.getBoundingClientRect();
|
|
166
|
+
const popoverPosition = popover.getBoundingClientRect();
|
|
167
|
+
const style = [];
|
|
168
|
+
let side = preferredSide;
|
|
169
|
+
if (side === 'top' && targetPosition.top - popoverPosition.height - margin < 0)
|
|
170
|
+
side = 'bottom';
|
|
171
|
+
if (side === 'bottom' && targetPosition.bottom + popoverPosition.height + margin > window.innerHeight)
|
|
172
|
+
side = 'top';
|
|
173
|
+
if (side === 'left' && targetPosition.left - popoverPosition.width - margin < 0)
|
|
174
|
+
side = 'right';
|
|
175
|
+
if (side === 'right' && targetPosition.right + popoverPosition.width + margin > window.innerWidth)
|
|
176
|
+
side = 'left';
|
|
177
|
+
if (side === 'top')
|
|
178
|
+
style.push('top:' + (targetPosition.top - popoverPosition.height - margin) + 'px');
|
|
179
|
+
if (side === 'bottom')
|
|
180
|
+
style.push('top:' + (targetPosition.bottom + margin) + 'px');
|
|
181
|
+
if (side === 'left')
|
|
182
|
+
style.push('left:' + (targetPosition.left - popoverPosition.width - margin) + 'px');
|
|
183
|
+
if (side === 'right')
|
|
184
|
+
style.push('left:' + (targetPosition.right + margin) + 'px');
|
|
185
|
+
let alignClass = 'center';
|
|
186
|
+
if (side === 'top' || side === 'bottom') {
|
|
187
|
+
const { left, alignClass: resolvedAlign } = resolveHorizontalAlign(preferredAlign, targetPosition, popoverPosition);
|
|
188
|
+
alignClass = resolvedAlign;
|
|
189
|
+
style.push('left:' + left + 'px');
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const { top, alignClass: resolvedAlign } = resolveVerticalAlign(preferredAlign, targetPosition, popoverPosition);
|
|
193
|
+
alignClass = resolvedAlign;
|
|
194
|
+
style.push('top:' + top + 'px');
|
|
195
|
+
}
|
|
196
|
+
const classNames = ['spopover', styles.popover, arrow ? styles.arrow : '', fade ? '' : styles.noFade, sideClass[side], alignClassMap[alignClass]].filter(Boolean);
|
|
197
|
+
popover.className = classNames.join(' ');
|
|
198
|
+
popover.setAttribute('style', style.join(';'));
|
|
199
|
+
applyArrowColor(popover);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
function applyArrowColor(popoverEl) {
|
|
203
|
+
var _a;
|
|
204
|
+
if (!arrowColor) {
|
|
205
|
+
popoverEl.style.removeProperty('--popover-arrow-color');
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (arrowColor === 'auto') {
|
|
209
|
+
const targetEl = (_a = popoverEl.firstElementChild) !== null && _a !== void 0 ? _a : popoverEl;
|
|
210
|
+
let bg = window.getComputedStyle(targetEl).backgroundColor;
|
|
211
|
+
if (bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent') {
|
|
212
|
+
const parent = targetEl.parentElement;
|
|
213
|
+
if (parent)
|
|
214
|
+
bg = window.getComputedStyle(parent).backgroundColor;
|
|
136
215
|
}
|
|
137
|
-
|
|
216
|
+
if (bg)
|
|
217
|
+
popoverEl.style.setProperty('--popover-arrow-color', bg);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
popoverEl.style.setProperty('--popover-arrow-color', arrowColor);
|
|
221
|
+
}
|
|
222
|
+
function incrementBodyPopover() {
|
|
223
|
+
const body = document.body;
|
|
224
|
+
const count = Number(body.dataset.spopoverCount || '0') + 1;
|
|
225
|
+
body.dataset.spopoverCount = String(count);
|
|
226
|
+
if (count > 0)
|
|
227
|
+
body.classList.add('spopover_open');
|
|
228
|
+
}
|
|
229
|
+
function decrementBodyPopover() {
|
|
230
|
+
const body = document.body;
|
|
231
|
+
const count = Math.max(0, Number(body.dataset.spopoverCount || '0') - 1);
|
|
232
|
+
if (count === 0) {
|
|
233
|
+
delete body.dataset.spopoverCount;
|
|
234
|
+
body.classList.remove('spopover_open');
|
|
138
235
|
}
|
|
236
|
+
else {
|
|
237
|
+
body.dataset.spopoverCount = String(count);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function nextPopoverZIndex() {
|
|
241
|
+
const body = document.body;
|
|
242
|
+
const current = Number(body.dataset.spopoverZIndex || '10000');
|
|
243
|
+
const next = current + 1;
|
|
244
|
+
body.dataset.spopoverZIndex = String(next);
|
|
245
|
+
return next;
|
|
246
|
+
}
|
|
247
|
+
const componentProps = {
|
|
248
|
+
ref: refComponent,
|
|
249
|
+
onClick: (e) => {
|
|
250
|
+
var _a, _b;
|
|
251
|
+
(_b = (_a = component.props) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
252
|
+
popoverEkle(e);
|
|
253
|
+
},
|
|
254
|
+
...other
|
|
139
255
|
};
|
|
140
|
-
|
|
256
|
+
if (hover) {
|
|
257
|
+
componentProps.onMouseEnter = (e) => {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
(_b = (_a = component.props) === null || _a === void 0 ? void 0 : _a.onMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
260
|
+
clearHoverClose();
|
|
261
|
+
popoverEkle(e);
|
|
262
|
+
};
|
|
263
|
+
componentProps.onMouseLeave = (e) => {
|
|
264
|
+
var _a, _b;
|
|
265
|
+
(_b = (_a = component.props) === null || _a === void 0 ? void 0 : _a.onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
266
|
+
scheduleHoverClose();
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
return cloneElement(component, componentProps);
|
|
141
270
|
});
|
|
142
|
-
|
|
271
|
+
const sideClass = {
|
|
272
|
+
top: styles.top,
|
|
273
|
+
bottom: styles.bottom,
|
|
274
|
+
left: styles.left,
|
|
275
|
+
right: styles.right
|
|
276
|
+
};
|
|
277
|
+
const alignClassMap = {
|
|
278
|
+
start: styles.alignStart,
|
|
279
|
+
center: styles.alignCenter,
|
|
280
|
+
end: styles.alignEnd
|
|
281
|
+
};
|
|
282
|
+
const FADE_DURATION = 160;
|
|
283
|
+
const normalizePosition = (position) => {
|
|
284
|
+
const [side, rawAlign] = position.split('-');
|
|
285
|
+
if (side === 'top' || side === 'bottom') {
|
|
286
|
+
const align = rawAlign === 'left' || rawAlign === 'right' ? rawAlign : 'center';
|
|
287
|
+
return { side, align };
|
|
288
|
+
}
|
|
289
|
+
const align = rawAlign === 'top' || rawAlign === 'bottom' ? rawAlign : 'center';
|
|
290
|
+
return { side, align };
|
|
291
|
+
};
|
|
292
|
+
const resolveHorizontalAlign = (align, target, popover) => {
|
|
293
|
+
const clamp = 2;
|
|
294
|
+
let left = 0;
|
|
295
|
+
let alignClass = 'center';
|
|
296
|
+
if (align === 'left') {
|
|
297
|
+
left = target.left;
|
|
298
|
+
alignClass = 'start';
|
|
299
|
+
}
|
|
300
|
+
else if (align === 'right') {
|
|
301
|
+
left = target.right - popover.width;
|
|
302
|
+
alignClass = 'end';
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
left = target.left + target.width / 2 - popover.width / 2;
|
|
306
|
+
alignClass = 'center';
|
|
307
|
+
}
|
|
308
|
+
if (left < clamp) {
|
|
309
|
+
left = clamp;
|
|
310
|
+
alignClass = 'start';
|
|
311
|
+
}
|
|
312
|
+
else if (left + popover.width > window.innerWidth - clamp) {
|
|
313
|
+
left = window.innerWidth - popover.width - clamp;
|
|
314
|
+
alignClass = 'end';
|
|
315
|
+
}
|
|
316
|
+
return { left, alignClass };
|
|
317
|
+
};
|
|
318
|
+
const resolveVerticalAlign = (align, target, popover) => {
|
|
319
|
+
const clamp = 2;
|
|
320
|
+
let top = 0;
|
|
321
|
+
let alignClass = 'center';
|
|
322
|
+
if (align === 'top') {
|
|
323
|
+
top = target.top;
|
|
324
|
+
alignClass = 'start';
|
|
325
|
+
}
|
|
326
|
+
else if (align === 'bottom') {
|
|
327
|
+
top = target.bottom - popover.height;
|
|
328
|
+
alignClass = 'end';
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
top = target.top + target.height / 2 - popover.height / 2;
|
|
332
|
+
alignClass = 'center';
|
|
333
|
+
}
|
|
334
|
+
if (top < clamp) {
|
|
335
|
+
top = clamp;
|
|
336
|
+
alignClass = 'start';
|
|
337
|
+
}
|
|
338
|
+
else if (top + popover.height > window.innerHeight - clamp) {
|
|
339
|
+
top = window.innerHeight - popover.height - clamp;
|
|
340
|
+
alignClass = 'end';
|
|
341
|
+
}
|
|
342
|
+
return { top, alignClass };
|
|
343
|
+
};
|