@sydsoft/base 1.47.0 → 1.49.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 → _dist}/_lib/baseFunctions.d.ts +0 -1
- package/{dist/esm → _dist}/_lib/baseFunctions.js +25 -38
- package/{dist/esm → _dist}/_lib/inputMask.js +66 -69
- package/{dist/esm → _dist}/_lib/listFunctions.js +12 -13
- package/_dist/_lib/storage/cookies.d.ts +4 -0
- package/_dist/_lib/storage/cookies.js +33 -0
- package/_dist/_lib/storage/encData.js +41 -0
- package/{dist/esm → _dist}/_lib/storage/localStorage.js +10 -10
- package/{dist/esm → _dist}/_lib/storage/sessionStorage.js +10 -10
- package/{dist/esm → _dist}/_lib/useInterval.js +5 -5
- package/{dist/esm → _dist}/alert/index.js +28 -30
- package/_dist/box/Box.js +14 -0
- package/_dist/box/BoxContent.js +5 -0
- package/_dist/box/BoxFooter.js +10 -0
- package/_dist/box/BoxHeader.js +10 -0
- package/_dist/countDown/index.js +92 -0
- package/{dist/esm → _dist}/dateTime/index.js +25 -31
- package/_dist/form/Button.js +82 -0
- package/_dist/form/Checkbox.js +22 -0
- package/_dist/form/Dialog.js +53 -0
- package/_dist/form/Form.js +10 -0
- package/_dist/form/FormOlustur.js +50 -0
- package/{dist/esm → _dist}/form/Input.js +57 -56
- package/_dist/form/Label.js +7 -0
- package/{dist/esm → _dist}/form/SearchableInput.d.ts +0 -1
- package/_dist/form/SearchableInput.js +260 -0
- package/_dist/form/UploadBase.js +84 -0
- package/_dist/grid/index.js +96 -0
- package/{dist/esm → _dist}/icon/icons.js +1 -1
- package/{dist/esm → _dist}/icon/index.d.ts +1 -1
- package/_dist/icon/index.js +34 -0
- package/_dist/menu/index.js +50 -0
- package/_dist/modal/index.js +64 -0
- package/{dist/esm → _dist}/popover/index.js +100 -100
- package/_dist/tooltip/index.js +202 -0
- package/_lib/baseFunctions.ts +94 -0
- package/_lib/inputMask.ts +257 -0
- package/_lib/listFunctions.ts +106 -0
- package/_lib/storage/cookies.ts +39 -0
- package/_lib/storage/encData.ts +41 -0
- package/_lib/storage/localStorage.ts +67 -0
- package/_lib/storage/sessionStorage.ts +67 -0
- package/_lib/useInterval.ts +30 -0
- package/alert/index.module.css +119 -0
- package/alert/index.tsx +131 -0
- package/box/Box.module.css +153 -0
- package/box/Box.tsx +33 -0
- package/box/BoxContent.tsx +18 -0
- package/box/BoxFooter.tsx +25 -0
- package/box/BoxHeader.tsx +46 -0
- package/box/index.ts +10 -0
- package/countDown/index.tsx +116 -0
- package/dateTime/index.ts +79 -0
- package/form/Button.tsx +143 -0
- package/form/Checkbox.tsx +48 -0
- package/form/Dialog.tsx +109 -0
- package/form/Form.tsx +19 -0
- package/form/FormOlustur.tsx +105 -0
- package/form/Input.tsx +364 -0
- package/form/Label.tsx +20 -0
- package/form/SearchableInput.tsx +406 -0
- package/form/UploadBase.tsx +133 -0
- package/form/index.ts +10 -0
- package/form/styles/Button.module.css +145 -0
- package/form/styles/Input.module.css +221 -0
- package/form/styles/Label.module.css +31 -0
- package/form/styles/SearchableInput.module.css +80 -0
- package/global.d.ts +9 -0
- package/grid/index.module.css +805 -0
- package/grid/index.tsx +171 -0
- package/icon/icons.tsx +33 -0
- package/icon/index.tsx +95 -0
- package/icon/mui.tsx +5932 -0
- package/index.ts +21 -0
- package/menu/index.module.css +92 -0
- package/menu/index.tsx +143 -0
- package/modal/index.module.css +77 -0
- package/modal/index.tsx +106 -0
- package/npm_recovery_codes.txt +5 -0
- package/package.json +18 -11
- package/popover/index.module.css +89 -0
- package/popover/index.tsx +392 -0
- package/tooltip/index.tsx +216 -0
- package/tsconfig.json +24 -0
- package/dist/esm/_lib/storage/cookies.d.ts +0 -4
- package/dist/esm/_lib/storage/cookies.js +0 -34
- package/dist/esm/_lib/storage/encData.js +0 -43
- package/dist/esm/box/Box.js +0 -15
- package/dist/esm/box/BoxContent.js +0 -7
- package/dist/esm/box/BoxFooter.js +0 -8
- package/dist/esm/box/BoxHeader.js +0 -9
- package/dist/esm/countDown/index.js +0 -97
- package/dist/esm/form/Button.js +0 -76
- package/dist/esm/form/Checkbox.js +0 -23
- package/dist/esm/form/Dialog.js +0 -40
- package/dist/esm/form/Form.js +0 -12
- package/dist/esm/form/FormOlustur.js +0 -52
- package/dist/esm/form/Label.js +0 -9
- package/dist/esm/form/SearchableInput.js +0 -272
- package/dist/esm/form/UploadBase.js +0 -86
- package/dist/esm/grid/index.js +0 -97
- package/dist/esm/icon/index.js +0 -26
- package/dist/esm/menu/index.js +0 -52
- package/dist/esm/modal/index.js +0 -66
- package/dist/esm/tooltip/index.js +0 -119
- /package/{dist/esm → _dist}/_lib/inputMask.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/listFunctions.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/storage/encData.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/storage/localStorage.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/storage/sessionStorage.d.ts +0 -0
- /package/{dist/esm → _dist}/_lib/useInterval.d.ts +0 -0
- /package/{dist/esm → _dist}/alert/index.d.ts +0 -0
- /package/{dist/esm → _dist}/alert/index.module.css +0 -0
- /package/{dist/esm → _dist}/box/Box.d.ts +0 -0
- /package/{dist/esm → _dist}/box/Box.module.css +0 -0
- /package/{dist/esm → _dist}/box/BoxContent.d.ts +0 -0
- /package/{dist/esm → _dist}/box/BoxFooter.d.ts +0 -0
- /package/{dist/esm → _dist}/box/BoxHeader.d.ts +0 -0
- /package/{dist/esm → _dist}/box/index.d.ts +0 -0
- /package/{dist/esm → _dist}/box/index.js +0 -0
- /package/{dist/esm → _dist}/countDown/index.d.ts +0 -0
- /package/{dist/esm → _dist}/dateTime/index.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Button.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Checkbox.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Dialog.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Form.d.ts +0 -0
- /package/{dist/esm → _dist}/form/FormOlustur.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Input.d.ts +0 -0
- /package/{dist/esm → _dist}/form/Label.d.ts +0 -0
- /package/{dist/esm → _dist}/form/UploadBase.d.ts +0 -0
- /package/{dist/esm → _dist}/form/index.d.ts +0 -0
- /package/{dist/esm → _dist}/form/index.js +0 -0
- /package/{dist/esm → _dist}/form/styles/Button.module.css +0 -0
- /package/{dist/esm → _dist}/form/styles/Input.module.css +0 -0
- /package/{dist/esm → _dist}/form/styles/Label.module.css +0 -0
- /package/{dist/esm → _dist}/form/styles/SearchableInput.module.css +0 -0
- /package/{dist/esm → _dist}/grid/index.d.ts +0 -0
- /package/{dist/esm → _dist}/grid/index.module.css +0 -0
- /package/{dist/esm → _dist}/icon/icons.d.ts +0 -0
- /package/{dist/esm → _dist}/icon/mui.d.ts +0 -0
- /package/{dist/esm → _dist}/icon/mui.js +0 -0
- /package/{dist/esm → _dist}/index.d.ts +0 -0
- /package/{dist/esm → _dist}/index.js +0 -0
- /package/{dist/esm → _dist}/menu/index.d.ts +0 -0
- /package/{dist/esm → _dist}/menu/index.module.css +0 -0
- /package/{dist/esm → _dist}/modal/index.d.ts +0 -0
- /package/{dist/esm → _dist}/modal/index.module.css +0 -0
- /package/{dist/esm → _dist}/popover/index.d.ts +0 -0
- /package/{dist/esm → _dist}/popover/index.module.css +0 -0
- /package/{dist/esm → _dist}/tooltip/index.d.ts +0 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author : izzetseydaoglu
|
|
3
|
+
* @copyright : sydSOFT Bilişim Hizmetleri (c) 2026
|
|
4
|
+
* @version : 2026-02-10 16:12:35
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { cloneElement, memo, useEffect, useRef } from 'react';
|
|
8
|
+
|
|
9
|
+
import { createRoot } from 'react-dom/client';
|
|
10
|
+
import styles from './index.module.css';
|
|
11
|
+
|
|
12
|
+
type PopoverSide = 'top' | 'bottom' | 'left' | 'right';
|
|
13
|
+
type PopoverPosition =
|
|
14
|
+
| 'top'
|
|
15
|
+
| 'top-left'
|
|
16
|
+
| 'top-right'
|
|
17
|
+
| 'bottom'
|
|
18
|
+
| 'bottom-left'
|
|
19
|
+
| 'bottom-right'
|
|
20
|
+
| 'left'
|
|
21
|
+
| 'left-top'
|
|
22
|
+
| 'left-center'
|
|
23
|
+
| 'left-bottom'
|
|
24
|
+
| 'right'
|
|
25
|
+
| 'right-top'
|
|
26
|
+
| 'right-center'
|
|
27
|
+
| 'right-bottom';
|
|
28
|
+
type HorizontalAlign = 'left' | 'center' | 'right';
|
|
29
|
+
type VerticalAlign = 'top' | 'center' | 'bottom';
|
|
30
|
+
type AlignClass = 'start' | 'center' | 'end';
|
|
31
|
+
type ArrowColor = 'auto' | string;
|
|
32
|
+
|
|
33
|
+
export interface PopoverConfigBaseProps {
|
|
34
|
+
position?: PopoverPosition;
|
|
35
|
+
removeWhenClickInside?: boolean;
|
|
36
|
+
hideBackdrop?: boolean;
|
|
37
|
+
arrow?: boolean;
|
|
38
|
+
distance?: number;
|
|
39
|
+
fade?: boolean;
|
|
40
|
+
arrowColor?: ArrowColor;
|
|
41
|
+
hover?: boolean;
|
|
42
|
+
hoverCloseDelay?: number;
|
|
43
|
+
keepMounted?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PopoverProps extends PopoverConfigBaseProps {
|
|
47
|
+
component: any;
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const Popover = memo(function MemoFunction({
|
|
52
|
+
children,
|
|
53
|
+
component,
|
|
54
|
+
position = 'top',
|
|
55
|
+
arrow = false,
|
|
56
|
+
distance = 5,
|
|
57
|
+
removeWhenClickInside = false,
|
|
58
|
+
hideBackdrop = true,
|
|
59
|
+
fade = true,
|
|
60
|
+
arrowColor = 'auto',
|
|
61
|
+
hover = false,
|
|
62
|
+
hoverCloseDelay = 120,
|
|
63
|
+
keepMounted = false,
|
|
64
|
+
...other
|
|
65
|
+
}: PopoverProps) {
|
|
66
|
+
const refComponent = useRef<any>(null);
|
|
67
|
+
const closeTimer = useRef<number | null>(null);
|
|
68
|
+
const hoverCloseTimer = useRef<number | null>(null);
|
|
69
|
+
const popoverRef = useRef<HTMLDivElement | null>(null);
|
|
70
|
+
const rootRef = useRef<any>(null);
|
|
71
|
+
const zIndexRef = useRef<number | null>(null);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (typeof window === 'undefined') return;
|
|
75
|
+
return () => {
|
|
76
|
+
popoverSil(false);
|
|
77
|
+
};
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
const checkHideBackDrop = (e: any) => {
|
|
81
|
+
const spopover = popoverRef.current;
|
|
82
|
+
if (!spopover) return;
|
|
83
|
+
|
|
84
|
+
if (!(e?.target instanceof Node)) {
|
|
85
|
+
popoverSil();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!spopover.contains(e.target)) popoverSil();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const popoverEkle = (e: any) => {
|
|
93
|
+
if (popoverRef.current && keepMounted) {
|
|
94
|
+
const popover = popoverRef.current;
|
|
95
|
+
const target = e.currentTarget;
|
|
96
|
+
const wasVisible = popover.classList.contains(styles.visible);
|
|
97
|
+
rootRef.current?.render?.(children);
|
|
98
|
+
applyArrowColor(popover);
|
|
99
|
+
popoverPosition({ target, position: position });
|
|
100
|
+
popover.style.zIndex = String(nextPopoverZIndex());
|
|
101
|
+
popover.classList.remove(styles.closing);
|
|
102
|
+
popover.classList.add(styles.visible);
|
|
103
|
+
if (!wasVisible) {
|
|
104
|
+
if (hideBackdrop) {
|
|
105
|
+
window.addEventListener('mousedown', checkHideBackDrop);
|
|
106
|
+
window.addEventListener('blur', checkHideBackDrop);
|
|
107
|
+
}
|
|
108
|
+
if (removeWhenClickInside) popover.addEventListener('mouseup', popoverGecikmeliSil);
|
|
109
|
+
if (hover) {
|
|
110
|
+
popover.addEventListener('mouseenter', clearHoverClose);
|
|
111
|
+
popover.addEventListener('mouseleave', scheduleHoverClose);
|
|
112
|
+
}
|
|
113
|
+
incrementBodyPopover();
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
popoverSil(false);
|
|
118
|
+
const popover = document.createElement('div');
|
|
119
|
+
popover.classList.add('spopover', styles.popover);
|
|
120
|
+
const zIndex = nextPopoverZIndex();
|
|
121
|
+
zIndexRef.current = zIndex;
|
|
122
|
+
document.body.appendChild(popover);
|
|
123
|
+
// ReactDOM.render(children, popover)
|
|
124
|
+
const root = createRoot(popover!);
|
|
125
|
+
root.render(children);
|
|
126
|
+
popoverRef.current = popover;
|
|
127
|
+
rootRef.current = root;
|
|
128
|
+
const target = e.currentTarget;
|
|
129
|
+
refComponent.current && refComponent.current.classList.add('spopover_active');
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
applyArrowColor(popover);
|
|
132
|
+
popoverPosition({ target, position: position });
|
|
133
|
+
popover.style.zIndex = String(zIndexRef.current ?? zIndex);
|
|
134
|
+
popover.classList.add(styles.visible);
|
|
135
|
+
}, 100);
|
|
136
|
+
if (hideBackdrop) {
|
|
137
|
+
window.addEventListener('mousedown', checkHideBackDrop);
|
|
138
|
+
window.addEventListener('blur', checkHideBackDrop);
|
|
139
|
+
}
|
|
140
|
+
if (removeWhenClickInside) popover.addEventListener('mouseup', popoverGecikmeliSil);
|
|
141
|
+
if (hover) {
|
|
142
|
+
popover.addEventListener('mouseenter', clearHoverClose);
|
|
143
|
+
popover.addEventListener('mouseleave', scheduleHoverClose);
|
|
144
|
+
}
|
|
145
|
+
incrementBodyPopover();
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const popoverSil = (animate = true) => {
|
|
149
|
+
refComponent.current && refComponent.current.classList.remove('spopover_active');
|
|
150
|
+
const check = popoverRef.current;
|
|
151
|
+
const wasVisible = !!check?.classList.contains(styles.visible);
|
|
152
|
+
if (check) {
|
|
153
|
+
if (removeWhenClickInside) check.removeEventListener('mouseup', popoverGecikmeliSil);
|
|
154
|
+
if (hover) {
|
|
155
|
+
check.removeEventListener('mouseenter', clearHoverClose);
|
|
156
|
+
check.removeEventListener('mouseleave', scheduleHoverClose);
|
|
157
|
+
}
|
|
158
|
+
if (closeTimer.current) window.clearTimeout(closeTimer.current);
|
|
159
|
+
if (hoverCloseTimer.current) window.clearTimeout(hoverCloseTimer.current);
|
|
160
|
+
if (!fade || !animate) {
|
|
161
|
+
if (!keepMounted) {
|
|
162
|
+
const root = rootRef.current;
|
|
163
|
+
window.setTimeout(() => {
|
|
164
|
+
root?.unmount?.();
|
|
165
|
+
}, 0);
|
|
166
|
+
check.remove();
|
|
167
|
+
popoverRef.current = null;
|
|
168
|
+
rootRef.current = null;
|
|
169
|
+
} else {
|
|
170
|
+
check.classList.remove(styles.visible);
|
|
171
|
+
check.classList.remove(styles.closing);
|
|
172
|
+
}
|
|
173
|
+
} else if (!check.classList.contains(styles.closing)) {
|
|
174
|
+
check.classList.add(styles.closing);
|
|
175
|
+
closeTimer.current = window.setTimeout(() => {
|
|
176
|
+
if (!keepMounted) {
|
|
177
|
+
const root = rootRef.current;
|
|
178
|
+
root?.unmount?.();
|
|
179
|
+
check.remove();
|
|
180
|
+
popoverRef.current = null;
|
|
181
|
+
rootRef.current = null;
|
|
182
|
+
} else {
|
|
183
|
+
check.classList.remove(styles.visible);
|
|
184
|
+
check.classList.remove(styles.closing);
|
|
185
|
+
}
|
|
186
|
+
}, FADE_DURATION);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (hideBackdrop) {
|
|
190
|
+
window.removeEventListener('mousedown', checkHideBackDrop);
|
|
191
|
+
window.removeEventListener('blur', checkHideBackDrop);
|
|
192
|
+
}
|
|
193
|
+
if (wasVisible) decrementBodyPopover();
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const popoverGecikmeliSil = () => setTimeout(() => popoverSil(), 100);
|
|
197
|
+
const clearHoverClose = () => {
|
|
198
|
+
if (hoverCloseTimer.current) window.clearTimeout(hoverCloseTimer.current);
|
|
199
|
+
hoverCloseTimer.current = null;
|
|
200
|
+
};
|
|
201
|
+
const scheduleHoverClose = () => {
|
|
202
|
+
clearHoverClose();
|
|
203
|
+
hoverCloseTimer.current = window.setTimeout(() => popoverSil(), hoverCloseDelay);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const popoverPosition = ({ target, position }: { target: HTMLElement; position: PopoverPosition }) => {
|
|
207
|
+
const popover: any = popoverRef.current;
|
|
208
|
+
if (popover) {
|
|
209
|
+
const arrowMargin = arrow ? 5 : 0;
|
|
210
|
+
const margin = distance + arrowMargin;
|
|
211
|
+
const { side: preferredSide, align: preferredAlign } = normalizePosition(position);
|
|
212
|
+
const targetPosition = target.getBoundingClientRect();
|
|
213
|
+
const popoverPosition = popover.getBoundingClientRect();
|
|
214
|
+
|
|
215
|
+
const style = [];
|
|
216
|
+
|
|
217
|
+
let side = preferredSide;
|
|
218
|
+
if (side === 'top' && targetPosition.top - popoverPosition.height - margin < 0) side = 'bottom';
|
|
219
|
+
if (side === 'bottom' && targetPosition.bottom + popoverPosition.height + margin > window.innerHeight) side = 'top';
|
|
220
|
+
if (side === 'left' && targetPosition.left - popoverPosition.width - margin < 0) side = 'right';
|
|
221
|
+
if (side === 'right' && targetPosition.right + popoverPosition.width + margin > window.innerWidth) side = 'left';
|
|
222
|
+
|
|
223
|
+
if (side === 'top') style.push('top:' + (targetPosition.top - popoverPosition.height - margin) + 'px');
|
|
224
|
+
if (side === 'bottom') style.push('top:' + (targetPosition.bottom + margin) + 'px');
|
|
225
|
+
if (side === 'left') style.push('left:' + (targetPosition.left - popoverPosition.width - margin) + 'px');
|
|
226
|
+
if (side === 'right') style.push('left:' + (targetPosition.right + margin) + 'px');
|
|
227
|
+
|
|
228
|
+
let alignClass: AlignClass = 'center';
|
|
229
|
+
if (side === 'top' || side === 'bottom') {
|
|
230
|
+
const { left, alignClass: resolvedAlign } = resolveHorizontalAlign(preferredAlign as HorizontalAlign, targetPosition, popoverPosition);
|
|
231
|
+
alignClass = resolvedAlign;
|
|
232
|
+
style.push('left:' + left + 'px');
|
|
233
|
+
} else {
|
|
234
|
+
const { top, alignClass: resolvedAlign } = resolveVerticalAlign(preferredAlign as VerticalAlign, targetPosition, popoverPosition);
|
|
235
|
+
alignClass = resolvedAlign;
|
|
236
|
+
style.push('top:' + top + 'px');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const classNames = ['spopover', styles.popover, arrow ? styles.arrow : '', fade ? '' : styles.noFade, sideClass[side], alignClassMap[alignClass]].filter(Boolean);
|
|
240
|
+
|
|
241
|
+
popover.className = classNames.join(' ');
|
|
242
|
+
popover.setAttribute('style', style.join(';'));
|
|
243
|
+
applyArrowColor(popover);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
function applyArrowColor(popoverEl: HTMLElement) {
|
|
248
|
+
if (!arrowColor) {
|
|
249
|
+
popoverEl.style.removeProperty('--popover-arrow-color');
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (arrowColor === 'auto') {
|
|
253
|
+
const targetEl = (popoverEl.firstElementChild as HTMLElement | null) ?? popoverEl;
|
|
254
|
+
let bg = window.getComputedStyle(targetEl).backgroundColor;
|
|
255
|
+
if (bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent') {
|
|
256
|
+
const parent = targetEl.parentElement;
|
|
257
|
+
if (parent) bg = window.getComputedStyle(parent).backgroundColor;
|
|
258
|
+
}
|
|
259
|
+
if (bg) popoverEl.style.setProperty('--popover-arrow-color', bg);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
popoverEl.style.setProperty('--popover-arrow-color', arrowColor);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function incrementBodyPopover() {
|
|
266
|
+
const body = document.body;
|
|
267
|
+
const count = Number(body.dataset.spopoverCount || '0') + 1;
|
|
268
|
+
body.dataset.spopoverCount = String(count);
|
|
269
|
+
if (count > 0) body.classList.add('spopover_open');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function decrementBodyPopover() {
|
|
273
|
+
const body = document.body;
|
|
274
|
+
const count = Math.max(0, Number(body.dataset.spopoverCount || '0') - 1);
|
|
275
|
+
if (count === 0) {
|
|
276
|
+
delete body.dataset.spopoverCount;
|
|
277
|
+
body.classList.remove('spopover_open');
|
|
278
|
+
} else {
|
|
279
|
+
body.dataset.spopoverCount = String(count);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function nextPopoverZIndex() {
|
|
284
|
+
const body = document.body;
|
|
285
|
+
const current = Number(body.dataset.spopoverZIndex || '10000');
|
|
286
|
+
const next = current + 1;
|
|
287
|
+
body.dataset.spopoverZIndex = String(next);
|
|
288
|
+
return next;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const componentProps: Record<string, any> = {
|
|
292
|
+
ref: refComponent,
|
|
293
|
+
onClick: (e: any) => {
|
|
294
|
+
component.props?.onClick?.(e);
|
|
295
|
+
popoverEkle(e);
|
|
296
|
+
},
|
|
297
|
+
...other
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
if (hover) {
|
|
301
|
+
componentProps.onMouseEnter = (e: any) => {
|
|
302
|
+
component.props?.onMouseEnter?.(e);
|
|
303
|
+
clearHoverClose();
|
|
304
|
+
popoverEkle(e);
|
|
305
|
+
};
|
|
306
|
+
componentProps.onMouseLeave = (e: any) => {
|
|
307
|
+
component.props?.onMouseLeave?.(e);
|
|
308
|
+
scheduleHoverClose();
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return cloneElement(component, componentProps);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const sideClass: Record<PopoverSide, string> = {
|
|
316
|
+
top: styles.top,
|
|
317
|
+
bottom: styles.bottom,
|
|
318
|
+
left: styles.left,
|
|
319
|
+
right: styles.right
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const alignClassMap: Record<AlignClass, string> = {
|
|
323
|
+
start: styles.alignStart,
|
|
324
|
+
center: styles.alignCenter,
|
|
325
|
+
end: styles.alignEnd
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const FADE_DURATION = 160;
|
|
329
|
+
|
|
330
|
+
const normalizePosition = (position: PopoverPosition): { side: PopoverSide; align: HorizontalAlign | VerticalAlign } => {
|
|
331
|
+
const [side, rawAlign] = position.split('-') as [PopoverSide, string | undefined];
|
|
332
|
+
if (side === 'top' || side === 'bottom') {
|
|
333
|
+
const align: HorizontalAlign = rawAlign === 'left' || rawAlign === 'right' ? rawAlign : 'center';
|
|
334
|
+
return { side, align };
|
|
335
|
+
}
|
|
336
|
+
const align: VerticalAlign = rawAlign === 'top' || rawAlign === 'bottom' ? rawAlign : 'center';
|
|
337
|
+
return { side, align };
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const resolveHorizontalAlign = (align: HorizontalAlign, target: DOMRect, popover: DOMRect): { left: number; alignClass: AlignClass } => {
|
|
341
|
+
const clamp = 2;
|
|
342
|
+
let left = 0;
|
|
343
|
+
let alignClass: AlignClass = 'center';
|
|
344
|
+
|
|
345
|
+
if (align === 'left') {
|
|
346
|
+
left = target.left;
|
|
347
|
+
alignClass = 'start';
|
|
348
|
+
} else if (align === 'right') {
|
|
349
|
+
left = target.right - popover.width;
|
|
350
|
+
alignClass = 'end';
|
|
351
|
+
} else {
|
|
352
|
+
left = target.left + target.width / 2 - popover.width / 2;
|
|
353
|
+
alignClass = 'center';
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (left < clamp) {
|
|
357
|
+
left = clamp;
|
|
358
|
+
alignClass = 'start';
|
|
359
|
+
} else if (left + popover.width > window.innerWidth - clamp) {
|
|
360
|
+
left = window.innerWidth - popover.width - clamp;
|
|
361
|
+
alignClass = 'end';
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return { left, alignClass };
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const resolveVerticalAlign = (align: VerticalAlign, target: DOMRect, popover: DOMRect): { top: number; alignClass: AlignClass } => {
|
|
368
|
+
const clamp = 2;
|
|
369
|
+
let top = 0;
|
|
370
|
+
let alignClass: AlignClass = 'center';
|
|
371
|
+
|
|
372
|
+
if (align === 'top') {
|
|
373
|
+
top = target.top;
|
|
374
|
+
alignClass = 'start';
|
|
375
|
+
} else if (align === 'bottom') {
|
|
376
|
+
top = target.bottom - popover.height;
|
|
377
|
+
alignClass = 'end';
|
|
378
|
+
} else {
|
|
379
|
+
top = target.top + target.height / 2 - popover.height / 2;
|
|
380
|
+
alignClass = 'center';
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (top < clamp) {
|
|
384
|
+
top = clamp;
|
|
385
|
+
alignClass = 'start';
|
|
386
|
+
} else if (top + popover.height > window.innerHeight - clamp) {
|
|
387
|
+
top = window.innerHeight - popover.height - clamp;
|
|
388
|
+
alignClass = 'end';
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return { top, alignClass };
|
|
392
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import React, { ReactElement, memo, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
export type typeTooltipPosition = "top" | "bottom" | "left" | "right";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
children: ReactElement;
|
|
7
|
+
title: string;
|
|
8
|
+
position?: typeTooltipPosition;
|
|
9
|
+
arrow?: boolean;
|
|
10
|
+
distance?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Tooltip = memo(function MemoFunction({children, title, position = "top", arrow = false, distance = 5, ...other}: Props) {
|
|
14
|
+
useEffect((): any => {
|
|
15
|
+
if (typeof window === "undefined") return null;
|
|
16
|
+
const cssCheck = document.getElementsByClassName("stooltip_css")[0];
|
|
17
|
+
if (!cssCheck) {
|
|
18
|
+
const head = document.getElementsByTagName('head')[0];
|
|
19
|
+
const s = document.createElement('style');
|
|
20
|
+
s.setAttribute('type', 'text/css');
|
|
21
|
+
s.classList.add("stooltip_css");
|
|
22
|
+
s.appendChild(document.createTextNode(tooltipCss));
|
|
23
|
+
head.appendChild(s);
|
|
24
|
+
}
|
|
25
|
+
return () => tooltipSil();
|
|
26
|
+
}, [])
|
|
27
|
+
|
|
28
|
+
const tooltipEkle = (e: any) => {
|
|
29
|
+
tooltipSil();
|
|
30
|
+
const tooltip = document.createElement("div");
|
|
31
|
+
tooltip.innerHTML = title;
|
|
32
|
+
tooltip.classList.add("stooltip");
|
|
33
|
+
document.body.appendChild(tooltip);
|
|
34
|
+
tooltipPosition({target: e.currentTarget, position: position});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const tooltipSil = () => {
|
|
38
|
+
const check = document.body.getElementsByClassName("stooltip")[0];
|
|
39
|
+
if (check) check.remove();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const tooltipPosition = ({target, position}: { target: HTMLElement, position: typeTooltipPosition }) => {
|
|
43
|
+
const tooltip = document.body.getElementsByClassName("stooltip")[0];
|
|
44
|
+
if (tooltip) {
|
|
45
|
+
|
|
46
|
+
const arrowMargin = (arrow) ? 5 : 0;
|
|
47
|
+
const margin = distance + arrowMargin;
|
|
48
|
+
|
|
49
|
+
if (arrow) tooltip.classList.add("arrow");
|
|
50
|
+
|
|
51
|
+
const targetPosition = target.getBoundingClientRect();
|
|
52
|
+
const tooltipPosition = tooltip.getBoundingClientRect();
|
|
53
|
+
|
|
54
|
+
const style = [];
|
|
55
|
+
|
|
56
|
+
if (position === "top" || position === "bottom") {
|
|
57
|
+
if (position === "top") {
|
|
58
|
+
if ((targetPosition.top - tooltipPosition.height - margin) < 0) {
|
|
59
|
+
style.push("top:" + (targetPosition.bottom + margin) + "px");
|
|
60
|
+
tooltip.classList.add("bottom");
|
|
61
|
+
} else {
|
|
62
|
+
style.push("top:" + (targetPosition.top - tooltipPosition.height - margin) + "px");
|
|
63
|
+
tooltip.classList.add("top");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (position === "bottom") {
|
|
67
|
+
if ((targetPosition.bottom + tooltipPosition.height + margin) > window.innerHeight) {
|
|
68
|
+
style.push("top:" + (targetPosition.top - tooltipPosition.height - margin) + "px");
|
|
69
|
+
tooltip.classList.add("top");
|
|
70
|
+
} else {
|
|
71
|
+
style.push("top:" + (targetPosition.bottom + margin) + "px");
|
|
72
|
+
tooltip.classList.add("bottom");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// if ((targetPosition.left - tooltipPosition.width) < 0) {
|
|
76
|
+
if ((targetPosition.left + (targetPosition.width / 2) - (tooltipPosition.width / 2)) < 0) {
|
|
77
|
+
style.push("left:2px");
|
|
78
|
+
tooltip.classList.add("start");
|
|
79
|
+
} else if ((targetPosition.left + (targetPosition.width / 2) + tooltipPosition.width) > window.innerWidth) {
|
|
80
|
+
style.push("right:2px");
|
|
81
|
+
tooltip.classList.add("end");
|
|
82
|
+
} else {
|
|
83
|
+
style.push("left:" + (targetPosition.left + (targetPosition.width / 2)) + "px");
|
|
84
|
+
style.push("transform:translate(-50%,0)");
|
|
85
|
+
tooltip.classList.add("center");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (position === "left" || position === "right") {
|
|
90
|
+
if (position === "left") {
|
|
91
|
+
if ((targetPosition.left - tooltipPosition.width - margin) < 0) {
|
|
92
|
+
style.push("left:" + (targetPosition.right + margin) + "px");
|
|
93
|
+
tooltip.classList.add("right");
|
|
94
|
+
} else {
|
|
95
|
+
style.push("left:" + (targetPosition.left - tooltipPosition.width - margin) + "px");
|
|
96
|
+
tooltip.classList.add("left");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (position === "right") {
|
|
100
|
+
if ((targetPosition.left + (targetPosition.width / 2) + tooltipPosition.width + margin) > window.innerWidth) {
|
|
101
|
+
style.push("left:" + (targetPosition.left - tooltipPosition.width - margin) + "px");
|
|
102
|
+
tooltip.classList.add("left");
|
|
103
|
+
} else {
|
|
104
|
+
style.push("left:" + (targetPosition.right + margin) + "px");
|
|
105
|
+
tooltip.classList.add("right");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if ((targetPosition.top + (targetPosition.height / 2) - (tooltipPosition.height / 2)) < 0) {
|
|
110
|
+
style.push("top:2px");
|
|
111
|
+
tooltip.classList.add("start");
|
|
112
|
+
} else if ((targetPosition.top + (targetPosition.height / 2) + (tooltipPosition.height / 2)) > window.innerHeight) {
|
|
113
|
+
style.push("bottom:2px");
|
|
114
|
+
tooltip.classList.add("end");
|
|
115
|
+
} else {
|
|
116
|
+
style.push("top:" + (targetPosition.top + (targetPosition.height / 2)) + "px");
|
|
117
|
+
style.push("transform:translate(0,-50%)");
|
|
118
|
+
tooltip.classList.add("center");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
tooltip.setAttribute("style", style.join(";"));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return React.cloneElement(children, {
|
|
127
|
+
onMouseEnter: tooltipEkle,
|
|
128
|
+
onMouseLeave: tooltipSil,
|
|
129
|
+
onMouseDown: tooltipSil,
|
|
130
|
+
...other
|
|
131
|
+
});
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const tooltipCss = `
|
|
136
|
+
.stooltip {
|
|
137
|
+
position: fixed;
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
justify-content: center;
|
|
141
|
+
background-color: #1a1a1a;
|
|
142
|
+
color: rgba(255,255,255,0.9);
|
|
143
|
+
text-align: center;
|
|
144
|
+
font-size: 0.9rem;
|
|
145
|
+
font-weight:400;
|
|
146
|
+
padding: 5px 10px;
|
|
147
|
+
border-radius: 8px;
|
|
148
|
+
z-index: 1000000;
|
|
149
|
+
opacity: 0.9;
|
|
150
|
+
pointer-events: none;
|
|
151
|
+
/*transition: all 0.1s;*/
|
|
152
|
+
white-space:pre-line;
|
|
153
|
+
max-width: 300px;
|
|
154
|
+
animation: stooltip_fadein 0.7s;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.stooltip.arrow:after {
|
|
158
|
+
content: "";
|
|
159
|
+
position: absolute;
|
|
160
|
+
margin-left: -5px;
|
|
161
|
+
border-width: 5px;
|
|
162
|
+
border-style: solid;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.stooltip.arrow.top:after {
|
|
166
|
+
top: 100%;
|
|
167
|
+
border-color: #1a1a1a transparent transparent transparent;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.stooltip.arrow.top.start:after { left: 15px;}
|
|
171
|
+
|
|
172
|
+
.stooltip.arrow.top.center:after { left: 50%;}
|
|
173
|
+
|
|
174
|
+
.stooltip.arrow.top.end:after { right: 15px;}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
.stooltip.arrow.bottom:after {
|
|
178
|
+
bottom: 100%;
|
|
179
|
+
border-color: transparent transparent #1a1a1a transparent;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.stooltip.arrow.bottom.start:after { left: 15px;}
|
|
183
|
+
|
|
184
|
+
.stooltip.arrow.bottom.center:after { left: 50%;}
|
|
185
|
+
|
|
186
|
+
.stooltip.bottom.end:after { right: 15px;}
|
|
187
|
+
|
|
188
|
+
.stooltip.arrow.left:after {
|
|
189
|
+
margin-left: -1px;
|
|
190
|
+
left: 100%;
|
|
191
|
+
border-color: transparent transparent transparent #1a1a1a;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.stooltip.arrow.left.start:after { top: 5px;}
|
|
195
|
+
|
|
196
|
+
.stooltip.arrow.left.center:after { top: 50%; margin-top: -5px;}
|
|
197
|
+
|
|
198
|
+
.stooltip.arrow.left.end:after { bottom: 15px;}
|
|
199
|
+
|
|
200
|
+
.stooltip.arrow.right:after {
|
|
201
|
+
margin-right: -1px;
|
|
202
|
+
right: 100%;
|
|
203
|
+
border-color: transparent #1a1a1a transparent transparent;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.stooltip.arrow.right.start:after { top: 5px;}
|
|
207
|
+
|
|
208
|
+
.stooltip.arrow.right.center:after { top: 50%; margin-top: -5px;}
|
|
209
|
+
|
|
210
|
+
.stooltip.arrow.right.end:after { bottom: 15px;}
|
|
211
|
+
|
|
212
|
+
@keyframes stooltip_fadein {
|
|
213
|
+
from { opacity: 0; }
|
|
214
|
+
to { opacity: 0.85; }
|
|
215
|
+
}
|
|
216
|
+
`;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2018",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"lib": ["dom", "esnext"],
|
|
6
|
+
"importHelpers": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"sourceMap": false,
|
|
9
|
+
"rootDir": ".",
|
|
10
|
+
"outDir": "_dist",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noFallthroughCasesInSwitch": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"moduleResolution": "Node",
|
|
16
|
+
"jsx": "react-jsx",
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
|
19
|
+
"resolveJsonModule": true,
|
|
20
|
+
"esModuleInterop": true
|
|
21
|
+
},
|
|
22
|
+
"include": ["**/*.ts", "**/*.tsx", "global.d.ts"],
|
|
23
|
+
"exclude": ["_dist", "node_modules"]
|
|
24
|
+
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const cerezOku: (context: any | null, key: string) => string | false;
|
|
2
|
-
export declare const cerezKaydet: (context: any | null, key: string, value: string, time?: number) => void;
|
|
3
|
-
export declare const cerezSil: (context: any | null, key: string) => void;
|
|
4
|
-
export declare const cerezTumuSil: (context?: any | null) => void;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import nookies, { destroyCookie, parseCookies, setCookie } from 'nookies';
|
|
3
|
-
import { getDomain } from '../baseFunctions';
|
|
4
|
-
export var cerezOku = function (context, key) {
|
|
5
|
-
if (context === void 0) { context = null; }
|
|
6
|
-
var cookies = context ? nookies.get(context) : parseCookies();
|
|
7
|
-
return cookies[key] || false;
|
|
8
|
-
};
|
|
9
|
-
export var cerezKaydet = function (context, key, value, time) {
|
|
10
|
-
if (context === void 0) { context = null; }
|
|
11
|
-
if (time === void 0) { time = 0; }
|
|
12
|
-
var newConfig = checkDomain(context);
|
|
13
|
-
setCookie(context, key, value, __assign({ maxAge: time > 0 ? time : null }, newConfig));
|
|
14
|
-
};
|
|
15
|
-
export var cerezSil = function (context, key) {
|
|
16
|
-
if (context === void 0) { context = null; }
|
|
17
|
-
var newConfig = checkDomain(context);
|
|
18
|
-
destroyCookie(context, key, newConfig);
|
|
19
|
-
};
|
|
20
|
-
export var cerezTumuSil = function (context) {
|
|
21
|
-
if (context === void 0) { context = null; }
|
|
22
|
-
var cookies = parseCookies(context);
|
|
23
|
-
if (cookies) {
|
|
24
|
-
Object.keys(cookies).forEach(function (key) {
|
|
25
|
-
destroyCookie(context, key);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var checkDomain = function (context, config) {
|
|
30
|
-
if (context === void 0) { context = null; }
|
|
31
|
-
if (config === void 0) { config = {}; }
|
|
32
|
-
var cookieDomain = getDomain(context);
|
|
33
|
-
return __assign(__assign({}, config), { domain: '.' + cookieDomain, path: '/' });
|
|
34
|
-
};
|