npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-dynamic-overflow

v1.1.0

Published

A React Component that lets you know what elements are overflowing

Downloads

2,488

Readme

Travis build status Codecov branch npm downloads MIT License

gzip size size

Maintainability PRs Welcome

react-dynamic-overflow

A React component that lets you know what elements are overflowing.

Getting started

npm install --save react-dynamic-overflow

Why?

react-dynamic-overflow is used for a specific UI pattern.

Imagine you are displaying 1 row of tabs with the same width.

+-------+-------+--------+--------+--------+
| Tab 1 | Tab 2 |  Tab 3 |  Tab 4 |  Tab 5 |
+-------+-------+--------+--------+--------+

When the page gets smaller, the 1 row of tabs may overflow into a second row.

+-------+-------+--------+
| Tab 1 | Tab 2 |  Tab 3 |
+-------+-------+--------+
| Tab 4 | Tab 5 |
+-------+-------+

What if we don't want a second row, and instead display a button that toggles those overflowing elements?

+-------+-------+--------+
| Tab 1 | Tab 2 |  More  |
+-------+-------+--------+

// Clicking on the More button...
+-------+-------+--------+
| Tab 1 | Tab 2 |  More  |
+-------+-------+--------+
                |  Tab 3 |
                +--------+
                |  Tab 4 |
                +--------+
                |  Tab 5 |
                +--------+

react-dynamic-overflow gives you an API that tells you what elements are visible and which have overflowed.

import React from "react";
import DynamicOverflow from "react-dynamic-overflow";

const Example = () => (
  <DynamicOverflow
    list={({ tabRef }) => ([
      <span ref={tabRef} key={0}>Tab 1</span>,
      <span key={1}>Tab 2</span>,
      <span key={2}>Tab 3</span>,
      <span key={3}>Tab 4</span>,
      <span key={4}>Tab 5</span>,
    ])}
  >
  {
    ({ visibleElements, overflowElements, containerRef }) => {
      return (
        <div ref={containerRef}>
          {visibleElements}

          <div>
            {overflowElements}
          </div>
        </div>
      );
    }
  }
  </DynamicOverflow>
);

API

| Props | Description | Default | | ----- | ----------- | ------- | | children | (Function) A render prop function | None. This is required | | list | (Function) A function that returns an array of elements that will be rendered | None. This is required | | throttle | (Number) A number (in milliseconds) in which the resize window event will be throttled | 200 |

children function

The children prop is a function that is called with the following arguments.

| Name | Description | | ---- | ----------- | | visibleElements | An array of elements from the list props which are visible. The first element will always be visible. | | overflowElements | An array of elements from the list props which are overflowed. | | containerRef | A ref function that should be added to the parent element. This element, combined with the tabRef, will be used in determining which elements are overflowed. |

list function

The list prop is a function that is called with the following argument.

| Name | Description | | ---- | ----------- | | tabRef | A ref function that should be added to an element. This element, combined with the containerRef, will be used in determining which elements are overflowed. |

Demo

See this CodeSandbox demo.