@sydsoft/base 1.49.0 → 1.50.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/package.json +2 -2
- package/_lib/baseFunctions.ts +0 -94
- package/_lib/inputMask.ts +0 -257
- package/_lib/listFunctions.ts +0 -106
- package/_lib/storage/cookies.ts +0 -39
- package/_lib/storage/encData.ts +0 -41
- package/_lib/storage/localStorage.ts +0 -67
- package/_lib/storage/sessionStorage.ts +0 -67
- package/_lib/useInterval.ts +0 -30
- package/alert/index.module.css +0 -119
- package/alert/index.tsx +0 -131
- package/box/Box.module.css +0 -153
- package/box/Box.tsx +0 -33
- package/box/BoxContent.tsx +0 -18
- package/box/BoxFooter.tsx +0 -25
- package/box/BoxHeader.tsx +0 -46
- package/box/index.ts +0 -10
- package/countDown/index.tsx +0 -116
- package/dateTime/index.ts +0 -79
- package/form/Button.tsx +0 -143
- package/form/Checkbox.tsx +0 -48
- package/form/Dialog.tsx +0 -109
- package/form/Form.tsx +0 -19
- package/form/FormOlustur.tsx +0 -105
- package/form/Input.tsx +0 -364
- package/form/Label.tsx +0 -20
- package/form/SearchableInput.tsx +0 -406
- package/form/UploadBase.tsx +0 -133
- package/form/index.ts +0 -10
- package/form/styles/Button.module.css +0 -145
- package/form/styles/Input.module.css +0 -221
- package/form/styles/Label.module.css +0 -31
- package/form/styles/SearchableInput.module.css +0 -80
- package/global.d.ts +0 -9
- package/grid/index.module.css +0 -805
- package/grid/index.tsx +0 -171
- package/icon/icons.tsx +0 -33
- package/icon/index.tsx +0 -95
- package/icon/mui.tsx +0 -5932
- package/index.ts +0 -21
- package/menu/index.module.css +0 -92
- package/menu/index.tsx +0 -143
- package/modal/index.module.css +0 -77
- package/modal/index.tsx +0 -106
- package/npm_recovery_codes.txt +0 -5
- package/popover/index.module.css +0 -89
- package/popover/index.tsx +0 -392
- package/tooltip/index.tsx +0 -216
- package/tsconfig.json +0 -24
package/popover/index.tsx
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
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
|
-
};
|
package/tooltip/index.tsx
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
}
|