@kne/react-filter 1.0.0 → 1.0.1
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/dist/index.js +22 -9
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +22 -9
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.modern.js
CHANGED
|
@@ -544,16 +544,24 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
544
544
|
height: 0
|
|
545
545
|
});
|
|
546
546
|
const triggerRef = useRef(null);
|
|
547
|
+
const setMobilePopupVariables = useCallback(metrics => {
|
|
548
|
+
if (typeof document === 'undefined') return;
|
|
549
|
+
document.body.style.setProperty('--react-filter-field-mobile-height', `${metrics.height}px`);
|
|
550
|
+
document.body.style.setProperty('--react-filter-popover-mobile-height', `${metrics.height}px`);
|
|
551
|
+
document.body.style.setProperty('--react-filter-field-mobile-top', `${metrics.pageTop}px`);
|
|
552
|
+
}, []);
|
|
547
553
|
const updatePopupMetrics = useCallback(() => {
|
|
548
554
|
if (typeof window === 'undefined' || !triggerRef.current) return;
|
|
549
555
|
const rect = triggerRef.current.getBoundingClientRect();
|
|
550
556
|
const top = Math.max(rect.bottom + MOBILE_POPUP_OFFSET$1, 0);
|
|
551
|
-
|
|
557
|
+
const metrics = {
|
|
552
558
|
top,
|
|
553
559
|
pageTop: top + window.scrollY,
|
|
554
560
|
height: Math.max(window.innerHeight - top, 0)
|
|
555
|
-
}
|
|
556
|
-
|
|
561
|
+
};
|
|
562
|
+
setPopupMetrics(metrics);
|
|
563
|
+
setMobilePopupVariables(metrics);
|
|
564
|
+
}, [setMobilePopupVariables]);
|
|
557
565
|
useEffect(() => {
|
|
558
566
|
if (typeof window === 'undefined') return;
|
|
559
567
|
const mediaQuery = window.matchMedia('(max-width: 768px)');
|
|
@@ -577,16 +585,14 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
577
585
|
};
|
|
578
586
|
}, [isMobile, open, updatePopupMetrics]);
|
|
579
587
|
useEffect(() => {
|
|
580
|
-
if (typeof document === 'undefined' || !isMobile) return;
|
|
581
|
-
|
|
582
|
-
document.body.style.setProperty('--react-filter-popover-mobile-height', `${popupMetrics.height}px`);
|
|
583
|
-
document.body.style.setProperty('--react-filter-field-mobile-top', `${popupMetrics.pageTop}px`);
|
|
588
|
+
if (typeof document === 'undefined' || !isMobile || popupMetrics.height <= 0) return;
|
|
589
|
+
setMobilePopupVariables(popupMetrics);
|
|
584
590
|
return () => {
|
|
585
591
|
document.body.style.removeProperty('--react-filter-field-mobile-height');
|
|
586
592
|
document.body.style.removeProperty('--react-filter-popover-mobile-height');
|
|
587
593
|
document.body.style.removeProperty('--react-filter-field-mobile-top');
|
|
588
594
|
};
|
|
589
|
-
}, [isMobile, popupMetrics
|
|
595
|
+
}, [isMobile, popupMetrics, setMobilePopupVariables]);
|
|
590
596
|
useEffect(() => {
|
|
591
597
|
if (open && isMobile) {
|
|
592
598
|
setRenderMask(true);
|
|
@@ -619,7 +625,9 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
619
625
|
const mobilePopupStyle = isMobile ? {
|
|
620
626
|
'--react-filter-field-mobile-height': `${popupMetrics.height}px`,
|
|
621
627
|
'--react-filter-popover-mobile-height': `${popupMetrics.height}px`,
|
|
622
|
-
'--react-filter-field-mobile-top': `${popupMetrics.pageTop}px
|
|
628
|
+
'--react-filter-field-mobile-top': `${popupMetrics.pageTop}px`,
|
|
629
|
+
top: popupMetrics.pageTop,
|
|
630
|
+
left: 0
|
|
623
631
|
} : undefined;
|
|
624
632
|
const mergePopupClassNames = classNames => {
|
|
625
633
|
var _classNames$popup;
|
|
@@ -651,11 +659,16 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
651
659
|
popupClassName: classnames(props.popupClassName, isMobile && style$1['field-item-mobile-popup'], isMobile && FIELD_MOBILE_POPUP_CLASS),
|
|
652
660
|
dropdownClassName: classnames(props.dropdownClassName, isMobile && style$1['field-item-mobile-popup'], isMobile && FIELD_MOBILE_POPUP_CLASS),
|
|
653
661
|
overlayClassName: classnames(props.overlayClassName, isMobile && style$1['field-item-mobile-popup'], isMobile && FIELD_MOBILE_POPUP_CLASS),
|
|
662
|
+
overlayStyle: Object.assign({}, props.overlayStyle, mobilePopupStyle),
|
|
654
663
|
popupStyle: Object.assign({}, props.popupStyle, mobilePopupStyle),
|
|
655
664
|
dropdownStyle: Object.assign({}, props.dropdownStyle, mobilePopupStyle),
|
|
656
665
|
classNames: mergePopupClassNames(props.classNames),
|
|
657
666
|
styles: mergePopupStyles(props.styles),
|
|
658
667
|
transitionName: isMobile ? '' : props.transitionName,
|
|
668
|
+
autoAdjustOverflow: isMobile ? false : props.autoAdjustOverflow,
|
|
669
|
+
align: isMobile ? {
|
|
670
|
+
offset: [0, 0]
|
|
671
|
+
} : props.align,
|
|
659
672
|
isPopup: options.forcePopup ? true : props.isPopup,
|
|
660
673
|
overlayWidth: isMobile && options.forcePopup ? typeof window === 'undefined' ? props.overlayWidth : window.innerWidth : props.overlayWidth
|
|
661
674
|
}));
|