1.1.2 • Published 2 years ago

tiny-use-detect-horizontal-overflow v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

tiny-use-detect-horizontal-overflow

Small (~1 Kb) react hook for detecting items are overflown. Something like this:

https://user-images.githubusercontent.com/513452/187036364-28e55b05-2f6b-41d7-ab71-37df6b1d02a7.mp4

Usage

npm i tiny-use-detect-horizontal-overflow --save

And in your react code

import { useDetectHorizontalOverflow } from "tiny-use-detect-horizontal-overflow";

// ...

useDetectHorizontalOverflow(containerRef, (hiddenElements) => {
  console.log(hiddenElements)
  /*
    It'll print out hidden elements which are overflown by container
    (4) [li#Membeship, li#Register, li#Login, li#Learn]
  */
});

API

Usage: Let's say you have this JSX component

<div className="container" ref={containerRef}>
  <ul className="links_list" ref={listRef}>
    <li>
      <a href="/about">About</a>
    </li>
    {/*...*/}
  </ul>
</div>

And in order to use this hook:

useDetectHorizontalOverflow(
  containerRef, // react ref of container
  (entries) => {}, // callback which will be called when number of hidden element is changed
  listRef, // optional react ref for items parent - if items are not direct children of the container
  throttleTimeout // optional timeout throttle timeout for resize callback, default is 16ms
);

License

MIT

1.1.1

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago