UNPKG

zent

Version:

一套前端设计语言和基于React的实现

34 lines (33 loc) 1.07 kB
import getViewportSize from '../../utils/dom/getViewportSize'; import { BottomLeft } from './bottom-left'; import { BottomRight } from './bottom-right'; import { TopLeft } from './top-left'; import { TopRight } from './top-right'; var positionMap = { BottomLeft: BottomLeft, BottomRight: BottomRight, TopLeft: TopLeft, TopRight: TopRight, }; export var AutoTopRight = function (props) { var contentRect = props.contentRect, cushion = props.cushion, anchorRect = props.anchorRect; var viewport = getViewportSize(); var horizontal; var vertical; if (anchorRect.right - contentRect.width < 0 && anchorRect.left + contentRect.width < viewport.width) { horizontal = 'Left'; } else { horizontal = 'Right'; } if (anchorRect.top - cushion - contentRect.height < 0 && anchorRect.bottom + cushion + contentRect.height < viewport.height) { vertical = 'Bottom'; } else { vertical = 'Top'; } var key = "" + vertical + horizontal; return positionMap[key](props); };