ringside 
A library that determines the fit and positioning of a rectangle relative to inner and outer bounds.
Installation
npm install ringside
Usage
Here's how you might generate the positioning for a tooltip:
import Ringside from 'ringside';
const tooltipSize = {
height: 100,
width: 200
};
const container = document.querySelector('.container');
const target = container.querySelector('.target');
const ringside = new Ringside(
target.getBoundingClientRect(),
container.getBoundingClientRect(),
tooltipSize.height,
tooltipSize.width
);
const possiblePositions = ringside
.positions()
.filter(position => position.fits);
const [position] = possiblePositions;
const tooltipPosition = {
top: position.top,
left: position.left,
height: tooltipSize.height,
width: tooltipSize.width
};
Development
npm install
npm run storybook
npm test