positioning-strategy
v4.1.9
Published
The [`positioning-strategy`](https://www.npmjs.com/package/positioning-strategy) module implements a function to calculate where to position an element relative to another element.
Readme
The positioning-strategy module implements a function to calculate where to position an element relative to another element.
Usage
This module exports a single function,
function calculateChildPosition(
strategy,
parentRect,
childDimension,
viewportDimension,
options
): { left: number, top: number }Parameters
strategyThe wanted position of the child relative to the parent represented by the combination of two axes: (top, bottom) and (left, center, right)Possible values are:
"top left","top center","top right","bottom left","bottom center","bottom right","left top","left center","left bottom","right top","right center","right bottom",
including the shorthands:"top","bottom","left"and"right"parentRectAn object representing the rectangle of the parent. It has these properties:leftThe distance from the left edge of the viewport to the element.topThe distance from the top edge of the viewport to the element.widthThe width of the element.heightThe height of the element.
childDimensionAn object representing the size of the child you want to position.widthThe width of the element.heightThe height of the element.
viewportDimensionAn object representing the size of the viewport.widthThe width of the element.heightThe height of the element.
optionsOptional.gapThe distance between the child and the parent.
Return value
It returns an object representing where to position the child relative to the parent element. It contains these properties:
leftThe distance from the left edge of the viewport to the child.topThe distance from the top edge of the viewport to the child.
