@@ -427,6 +427,72 @@ class Test extends React.Component {
427
427
</ pre >
428
428
</ div >
429
429
430
+ < div className = "section" >
431
+ < h4 className = 'title' > Override position</ h4 >
432
+ < p className = "sub-title" >
433
+ Try to resize/zoom in window - tooltip in this sample will try to
434
+ magnet to window borders, top left border is priority here. Idea is following:
435
+ sometimes you have custom border cases, like custom scrolls, small windows,
436
+ iframes, react-tooltip itself can not cover everything, so up to you if you want to customize
437
+ default behavior, or may be just limit it like in this example.
438
+ </ p >
439
+ < div className = "example-jsx" >
440
+ < div className = "side" style = { { display : 'flex' , width : '100%' } } >
441
+ < a data-tip data-for = 'overridePosition' > ( •̀д•́) override</ a >
442
+ < ReactTooltip id = 'overridePosition' overridePosition = { ( { left, top } ,
443
+ currentEvent , currentTarget , node ) => {
444
+ const d = document . documentElement ;
445
+
446
+ left = Math . min ( d . clientWidth - node . clientWidth , left ) ;
447
+ top = Math . min ( d . clientHeight - node . clientHeight , top ) ;
448
+
449
+ left = Math . max ( 0 , left ) ;
450
+ top = Math . max ( 0 , top ) ;
451
+
452
+ return { top, left }
453
+ } } >
454
+ < div > header</ div >
455
+ < img src = "http://lorempixel.com/100/1500" alt = "lorem image 100x1500" />
456
+ < div > footer</ div >
457
+ </ ReactTooltip >
458
+ < a data-tip data-for = 'noOverridePosition' > ( •̀д•́) noOverride</ a >
459
+ < ReactTooltip id = 'noOverridePosition' >
460
+ < div > header</ div >
461
+ < img src = "http://lorempixel.com/100/1500" alt = "lorem image 100x1500" />
462
+ < div > footer</ div >
463
+ </ ReactTooltip >
464
+ </ div >
465
+ </ div >
466
+ < br />
467
+ < pre className = 'example-pre' >
468
+ < div >
469
+ < p > { `
470
+ <a data-tip data-for='overridePosition'>( •̀д•́) override</a>
471
+ <ReactTooltip id='overridePosition' overridePosition={ ({ left, top },
472
+ currentEvent, currentTarget, node) => {
473
+ const d = document.documentElement;
474
+
475
+ left = Math.min(d.clientWidth - node.clientWidth, left);
476
+ top = Math.min(d.clientHeight - node.clientHeight, top);
477
+
478
+ left = Math.max(0, left);
479
+ top = Math.max(0, top);
480
+
481
+ return { top, left }
482
+ } }>
483
+ <div>header</div>
484
+ <img src="http://lorempixel.com/100/1500" alt="lorem image 100x1500" />
485
+ <div>footer</div>
486
+ </ReactTooltip>
487
+ <a data-tip data-for='noOverridePosition'>( •̀д•́) noOverride</a>
488
+ <ReactTooltip id='noOverridePosition'>
489
+ <div>header</div>
490
+ <img src="http://lorempixel.com/100/1500" alt="lorem image 100x1500" />
491
+ <div>footer</div>
492
+ </ReactTooltip>` } </ p >
493
+ </ div >
494
+ </ pre >
495
+ </ div >
430
496
</ section >
431
497
</ div >
432
498
)
0 commit comments