@via-profit/ui-kit 0.2.3 → 0.2.4
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/Popper/usePopper.js +11 -44
- package/package.json +1 -1
package/Popper/usePopper.js
CHANGED
|
@@ -173,63 +173,30 @@ const usePopper = (props) => {
|
|
|
173
173
|
return { left, top, width };
|
|
174
174
|
}, [offset, positionStrategy]);
|
|
175
175
|
const clampPopperToContainer = react_1.default.useCallback((style, popperRect) => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const containerRect = container.getBoundingClientRect();
|
|
179
|
-
// Базовые границы контейнера с учетом отступа
|
|
180
|
-
let minLeft = containerRect.left + viewportMargin;
|
|
181
|
-
let maxLeft = containerRect.right - popperRect.width - viewportMargin;
|
|
182
|
-
let minTop = containerRect.top + viewportMargin;
|
|
183
|
-
let maxTop = containerRect.bottom - popperRect.height - viewportMargin;
|
|
184
|
-
// Для fixed позиционирования добавляем ограничения viewport
|
|
185
|
-
if (positionStrategy === 'fixed') {
|
|
186
|
-
// Границы viewport с учетом отступа
|
|
187
|
-
const viewportMinLeft = viewportMargin;
|
|
188
|
-
const viewportMaxLeft = window.innerWidth - popperRect.width - viewportMargin;
|
|
189
|
-
const viewportMinTop = viewportMargin;
|
|
190
|
-
const viewportMaxTop = window.innerHeight - popperRect.height - viewportMargin;
|
|
191
|
-
// Берем пересечение границ контейнера и viewport
|
|
192
|
-
minLeft = Math.max(minLeft, viewportMinLeft);
|
|
193
|
-
maxLeft = Math.min(maxLeft, viewportMaxLeft);
|
|
194
|
-
minTop = Math.max(minTop, viewportMinTop);
|
|
195
|
-
maxTop = Math.min(maxTop, viewportMaxTop);
|
|
176
|
+
if (positionStrategy === 'absolute') {
|
|
177
|
+
return style;
|
|
196
178
|
}
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
const validMaxTop = Math.max(minTop, maxTop);
|
|
202
|
-
// Ограничиваем позицию
|
|
203
|
-
const clampedLeft = Math.max(validMinLeft, Math.min(style.left, validMaxLeft));
|
|
204
|
-
const clampedTop = Math.max(validMinTop, Math.min(style.top, validMaxTop));
|
|
179
|
+
const viewportMinLeft = viewportMargin;
|
|
180
|
+
const viewportMaxLeft = window.innerWidth - popperRect.width - viewportMargin;
|
|
181
|
+
const viewportMinTop = viewportMargin;
|
|
182
|
+
const viewportMaxTop = window.innerHeight - popperRect.height - viewportMargin;
|
|
205
183
|
return {
|
|
206
|
-
left:
|
|
207
|
-
top:
|
|
184
|
+
left: Math.max(viewportMinLeft, Math.min(style.left, viewportMaxLeft)),
|
|
185
|
+
top: Math.max(viewportMinTop, Math.min(style.top, viewportMaxTop)),
|
|
208
186
|
width: style.width,
|
|
209
187
|
};
|
|
210
|
-
}, [positionStrategy,
|
|
188
|
+
}, [positionStrategy, viewportMargin]);
|
|
211
189
|
const checkIfViewportFits = react_1.default.useCallback((style, popperRect) => {
|
|
212
190
|
const left = style.left;
|
|
213
191
|
const top = style.top;
|
|
214
192
|
const right = left + popperRect.width;
|
|
215
193
|
const bottom = top + popperRect.height;
|
|
216
|
-
if (positionStrategy === 'absolute' && scrollableAncestor instanceof HTMLElement) {
|
|
217
|
-
const containerRect = scrollableAncestor.getBoundingClientRect();
|
|
218
|
-
const relativeLeft = left - containerRect.left;
|
|
219
|
-
const relativeTop = top - containerRect.top;
|
|
220
|
-
const relativeRight = relativeLeft + popperRect.width;
|
|
221
|
-
const relativeBottom = relativeTop + popperRect.height;
|
|
222
|
-
const isWithinHorizontal = relativeLeft >= viewportMargin && relativeRight <= containerRect.width - viewportMargin;
|
|
223
|
-
const isWithinVertical = relativeTop >= viewportMargin && relativeBottom <= containerRect.height - viewportMargin;
|
|
224
|
-
return isWithinHorizontal && isWithinVertical;
|
|
225
|
-
}
|
|
226
194
|
const viewportWidth = window.innerWidth;
|
|
227
195
|
const viewportHeight = window.innerHeight;
|
|
228
196
|
const isWithinHorizontal = left >= viewportMargin && right <= viewportWidth - viewportMargin;
|
|
229
197
|
const isWithinVertical = top >= viewportMargin && bottom <= viewportHeight - viewportMargin;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}, [viewportMargin, scrollableAncestor, positionStrategy]);
|
|
198
|
+
return isWithinHorizontal && isWithinVertical;
|
|
199
|
+
}, [viewportMargin]);
|
|
233
200
|
const placementsOrder = react_1.default.useMemo(() => {
|
|
234
201
|
const basePlacements = {
|
|
235
202
|
top: ['top', 'top-left', 'top-right', 'top-start', 'top-end'],
|