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'; // define our target tooltip sizeconst tooltipSize = height: 100 width: 200; // grab our target element and its containerconst container = document;const target = container; const ringside = target // target bounds container // container bounds tooltipSizeheight tooltipSizewidth; // select all positions that will fitconst possiblePositions = ringside ; // select a position from those that fitconst position = possiblePositions; // and use it!const tooltipPosition = top: positiontop left: positionleft height: tooltipSizeheight width: tooltipSizewidth;
Development
# install packages npm install # run the storybook server npm run storybook # run tests npm test