@ainias42/react-bootstrap-mobile 0.2.14 → 0.2.15
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
CHANGED
|
@@ -60,7 +60,6 @@ export const Switch = withMemo(function Switch<OnChangeCheckedData>({
|
|
|
60
60
|
|
|
61
61
|
const checkStopPropagation = useCallback((ev: MouseEvent) => {
|
|
62
62
|
if (stopPropagation) {
|
|
63
|
-
console.log("LOG-d stopPropagation inside checkStopPropagation", ev);
|
|
64
63
|
ev.stopPropagation();
|
|
65
64
|
ev.nativeEvent.stopPropagation();
|
|
66
65
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {withMemo} from '../../helper/withMemo';
|
|
3
|
-
import {RbmComponentProps} from '../RbmComponentProps';
|
|
4
|
-
import {IconSource} from '../Icon/Icon';
|
|
5
|
-
import {Block} from '../Layout/Block';
|
|
2
|
+
import { withMemo } from '../../helper/withMemo';
|
|
3
|
+
import { RbmComponentProps } from '../RbmComponentProps';
|
|
4
|
+
import { IconSource } from '../Icon/Icon';
|
|
5
|
+
import { Block } from '../Layout/Block';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
import styles from './menu.scss';
|
|
8
|
-
import {useEffect, useRef, useState} from 'react';
|
|
9
|
-
import {withRenderBrowserOnly} from '../../helper/withRenderBrowserOnly';
|
|
10
|
-
import {useWindow} from '../../WindowContext/WindowContext';
|
|
11
|
-
import {MenuItem} from "./MenuItem";
|
|
12
|
-
import {MenuCloseContextProvider} from "./MenuCloseContext";
|
|
13
|
-
import {createPortal} from "react-dom";
|
|
8
|
+
import { useEffect, useRef, useState } from 'react';
|
|
9
|
+
import { withRenderBrowserOnly } from '../../helper/withRenderBrowserOnly';
|
|
10
|
+
import { useWindow } from '../../WindowContext/WindowContext';
|
|
11
|
+
import { MenuItem } from "./MenuItem";
|
|
12
|
+
import { MenuCloseContextProvider } from "./MenuCloseContext";
|
|
13
|
+
import { createPortal } from "react-dom";
|
|
14
14
|
import { useClientLayoutEffect } from "../Hooks/useClientLayoutEffect";
|
|
15
15
|
|
|
16
16
|
export type MenuItemType = {
|
|
@@ -71,7 +71,7 @@ export const Menu = withMemo(
|
|
|
71
71
|
// Effects
|
|
72
72
|
useEffect(() => {
|
|
73
73
|
if (isOpen) {
|
|
74
|
-
const listener = (e: MouseEvent|TouchEvent) => {
|
|
74
|
+
const listener = (e: MouseEvent | TouchEvent) => {
|
|
75
75
|
if (!menuRef.current?.contains(e.target as Node)) {
|
|
76
76
|
onClose();
|
|
77
77
|
}
|
|
@@ -90,7 +90,7 @@ export const Menu = withMemo(
|
|
|
90
90
|
if (!isOpen) {
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
let elem = window?.document.body.querySelector(`.${
|
|
93
|
+
let elem = window?.document.body.querySelector(`.${MENU_CONTAINER_CLASS}`);
|
|
94
94
|
if (!elem) {
|
|
95
95
|
elem = window?.document.body;
|
|
96
96
|
}
|
|
@@ -99,37 +99,38 @@ export const Menu = withMemo(
|
|
|
99
99
|
|
|
100
100
|
useClientLayoutEffect(() => {
|
|
101
101
|
if (!menuRef.current) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const width = parseFloat(getComputedStyle(menuRef.current).width);
|
|
105
|
-
let newX = x;
|
|
106
|
-
if (newX > (window?.innerWidth ?? 0) - width) {
|
|
107
|
-
newX -= width + offsetX;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (newX < 0) {
|
|
111
|
-
newX = 0;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
setInnerX(newX);
|
|
115
|
-
}, [offsetX, window?.innerWidth, x]);
|
|
116
|
-
|
|
117
|
-
useClientLayoutEffect(() => {
|
|
118
|
-
if (!menuRef.current) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const height = parseFloat(getComputedStyle(menuRef.current).height);
|
|
122
|
-
let newY = y;
|
|
123
|
-
if (newY > (window?.innerHeight ?? 0) - height) {
|
|
124
|
-
newY -= height + offsetY;
|
|
102
|
+
return undefined;
|
|
125
103
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
const menuElement = menuRef.current;
|
|
105
|
+
|
|
106
|
+
const updateInnerPositions = () => {
|
|
107
|
+
const computedStyle = getComputedStyle(menuElement);
|
|
108
|
+
const height = parseFloat(computedStyle.height);
|
|
109
|
+
let newY = y;
|
|
110
|
+
if (newY > (window?.innerHeight ?? 0) - height) {
|
|
111
|
+
newY -= height + offsetY;
|
|
112
|
+
}
|
|
113
|
+
setInnerY(Math.max(0, newY));
|
|
114
|
+
|
|
115
|
+
const width = parseFloat(computedStyle.width);
|
|
116
|
+
let newX = x;
|
|
117
|
+
if (newX > (window?.innerWidth ?? 0) - width) {
|
|
118
|
+
newX -= width + offsetX;
|
|
119
|
+
}
|
|
120
|
+
setInnerX(Math.max(0, newX));
|
|
121
|
+
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const observer = new ResizeObserver(() => {
|
|
125
|
+
updateInnerPositions();
|
|
126
|
+
});
|
|
127
|
+
observer.observe(menuElement);
|
|
128
|
+
updateInnerPositions();
|
|
129
|
+
|
|
130
|
+
return () => {
|
|
131
|
+
observer.disconnect();
|
|
132
|
+
};
|
|
133
|
+
}, [window, x, y, offsetX, offsetY]);
|
|
133
134
|
|
|
134
135
|
// Other
|
|
135
136
|
|