UNPKG

@yandex/ui

Version:

Yandex UI components

28 lines (27 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.applyMaxHeight = void 0; var tslib_1 = require("tslib"); var core_1 = require("@popperjs/core"); /** * Модификатор, устанавливающий оптимальную высоту попапа в пределах экрана. */ exports.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 = core_1.detectOverflow(state, { padding: padding }); var y = (state.modifiersData.preventOverflow || { y: 0 }).y; var height = state.rects.popper.height; var _c = tslib_1.__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 = tslib_1.__assign(tslib_1.__assign({}, state.styles.popper), { maxHeight: popupMaxHeight + "px" }); }