UNPKG

@yandex/ui

Version:

Yandex UI components

25 lines (24 loc) 1.15 kB
import { __assign, __read } from "tslib"; import { detectOverflow } from '@popperjs/core'; /** * Модификатор, устанавливающий оптимальную высоту попапа в пределах экрана. */ export var applyMaxHeight = { name: 'applyMaxHeight', enabled: true, fn: applyMaxHeightFn, phase: 'main', requires: ['computeStyles'], }; function applyMaxHeightFn(_a) { var state = _a.state, options = _a.options; var userMaxHeight = options.maxHeight, _b = options.padding, padding = _b === void 0 ? 16 : _b; var overflow = detectOverflow(state, { padding: padding }); var y = (state.modifiersData.preventOverflow || { y: 0 }).y; var height = state.rects.popper.height; var _c = __read(state.placement.split('-'), 1), basePlacement = _c[0]; var heightProp = basePlacement === 'top' ? 'top' : 'bottom'; var maxHeight = height - overflow[heightProp] - y; var popupMaxHeight = userMaxHeight ? Math.min(maxHeight - y, userMaxHeight) : maxHeight; state.styles.popper = __assign(__assign({}, state.styles.popper), { maxHeight: popupMaxHeight + "px" }); }