Skip to content

Commit

Permalink
Merge pull request #2 from rylnd/api_improvements
Browse files Browse the repository at this point in the history
API Improvements
  • Loading branch information
rylnd committed Dec 14, 2018
2 parents 1af0b95 + 281e072 commit ffd1171
Show file tree
Hide file tree
Showing 16 changed files with 4,892 additions and 3,901 deletions.
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
# ringside

Determines fit and positioning of a rectangle within inner and outer bounds.
A library that determines the fit and positioning of a rectangle relative to inner and outer bounds.

## Installation

```bash
npm install ringside
```

## Usage

Here's how you might generate the positioning for a tooltip:

```jsx
import Ringside from 'ringside';

// define our target tooltip size
const tooltipSize = {
height: 100,
width: 200
};

// grab our target element and its container
const container = document.querySelector('.container');
const target = container.querySelector('.target');

const ringside = new Ringside(
target.getBoundingClientRect(), // target bounds
container.getBoundingClientRect(), // container bounds
tooltipSize.height,
tooltipSize.width
);

// select all positions that will fit
const possiblePositions = ringside
.positions()
.filter(position => position.fits);

// select a position from those that fit
const [position] = possiblePositions;

// and use it!
const tooltipPosition = {
top: position.top,
left: position.left,
height: tooltipSize.height,
width: tooltipSize.width
};
```

## Development

```bash
# install packages
npm install

# run the storybook server
npm run storybook

# run tests
npm test
```

0 comments on commit ffd1171

Please sign in to comment.