UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

45 lines 1.66 kB
// Imported from yandex-ui. Source: https://github.com/bem/yandex-ui/ var __assign = this && this.__assign || function () { __assign = Object.assign || function (t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { detectOverflow } from '@popperjs/core'; import getBasePlacement from '../utils'; // TODO: #bug this mod can decrease height when we have free space // probably we should apply different strategies to calc this depends of placement (x or y direction) 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 _c = (state.modifiersData.preventOverflow || {}).y, y = _c === void 0 ? 0 : _c; var height = state.rects.popper.height; var basePlacement = getBasePlacement(state.placement); 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: "".concat(popupMaxHeight, "px") }); } /** * Modifier to set optimal height of popup within viewport */ export var applyMaxHeight = { name: 'applyMaxHeight', enabled: true, fn: applyMaxHeightFn, phase: 'main', requires: ['computeStyles'] };