Socket
Socket
Sign inDemoInstall

@visx/bounds

Package Overview
Dependencies
12
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @visx/bounds

Utilities to make your life with bounding boxes better


Version published
Weekly downloads
392K
increased by8.75%
Maintainers
4
Install size
1.79 MB
Created
Weekly downloads
 

Changelog

Source

v3.3.0 (2023-07-11)

:rocket: Enhancements
  • Create new @visx/delaunay package #1678
:bug: Bug Fix
  • Fix glyph positioning in the xychart demo. #1730
:trophy: Contributors

Readme

Source

@visx/bounds

npm install --save @visx/bounds

withBoundingRects HOC

It's often useful to determine whether elements (e.g., tooltips) overflow the bounds of their parent container and adjust positioning accordingly. The withBoundingRects higher-order component is meant to simplify this computation by passing in a component's bounding rect as well as its parent's bounding rect.

Example usage

Example usage with a <Tooltip /> component

import React from 'react';
import PropTypes from 'prop-types';
import { withBoundingRects, withBoundingRectsProps } from '@visx/bounds';

const propTypes = {
  ...withBoundingRectsProps,
  left: PropTypes.number.isRequired,
  top: PropTypes.number.isRequired,
  children: PropTypes.node,
};

const defaultProps = {
  children: null,
};

function Tooltip({ left: initialLeft, top: initialTop, rect, parentRect, children }) {
  let left = initialLeft;
  let top = initialTop;

  if (rect && parentRect) {
    left = rect.right > parentRect.right ? left - rect.width : left;
    top = rect.bottom > parentRect.bottom ? top - rect.height : top;
  }

  return <div style={{ top, left, ...myTheme }}>{children}</div>;
}

Tooltip.propTypes = propTypes;
Tooltip.defaultProps = defaultProps;

export default withBoundingRects(Tooltip);

Keywords

FAQs

Last updated on 11 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc