UNPKG

@fluentui/react-northstar

Version:
70 lines (68 loc) 2.73 kB
var PlacementParts = /*#__PURE__*/function (PlacementParts) { PlacementParts["top"] = "top"; PlacementParts["bottom"] = "bottom"; PlacementParts["start"] = "start"; PlacementParts["end"] = "end"; PlacementParts["left"] = "left"; PlacementParts["right"] = "right"; PlacementParts["center"] = ""; return PlacementParts; }(PlacementParts || {}); var getPositionMap = function getPositionMap(rtl) { return { above: PlacementParts.top, below: PlacementParts.bottom, before: rtl ? PlacementParts.right : PlacementParts.left, after: rtl ? PlacementParts.left : PlacementParts.right }; }; var getAlignmentMap = function getAlignmentMap(rtl) { return { start: rtl ? PlacementParts.end : PlacementParts.start, end: rtl ? PlacementParts.start : PlacementParts.end, top: PlacementParts.start, bottom: PlacementParts.end, center: PlacementParts.center }; }; var shouldAlignToCenter = function shouldAlignToCenter(p, a) { var positionedVertically = p === 'above' || p === 'below'; var alignedVertically = a === 'top' || a === 'bottom'; return positionedVertically && alignedVertically || !positionedVertically && !alignedVertically; }; /** * | position | alignment | placement | placement RTL * ----------------------------------------------------------------- * | above | start | top-start | top-end * | above | center | top | top * | above | end | top-end | top-start * | below | start | bottom-start | bottom-end * | below | center | bottom | bottom * | below | end | bottom-end | bottom-start * | before | top | left-start | right-start * | before | center | left | right * | before | bottom | left-end | right-end * | after | top | right-start | left-start * | after | center | right | left * | after | bottom | right-end | left-end */ export var getPlacement = function getPlacement(align, position, rtl) { var alignment = shouldAlignToCenter(position, align) ? 'center' : align; var computedPosition = getPositionMap(rtl)[position]; var computedAlignment = getAlignmentMap(rtl)[alignment]; var stringifiedAlignment = computedAlignment && "-" + computedAlignment; return "" + computedPosition + stringifiedAlignment; }; export var applyRtlToOffset = function applyRtlToOffset(offset) { if (typeof offset === 'undefined') { return undefined; } if (Array.isArray(offset)) { offset[0] = offset[0] * -1; return offset; } return function (param) { return applyRtlToOffset(offset(param)); }; }; //# sourceMappingURL=positioningHelper.js.map