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-hyper-responsive-table

v1.0.0-rc.0

Published

react-hyper-responsive-table React component

Downloads

100

Readme

react-hyper-responsive-table on npm Build Status Coverage

react-hyper-responsive-table

A responsive container for displaying tables traditionally on wide screens and with headers prepended to each data cell on narrow screens.

Installation

npm install react-hyper-responsive-table

This module uses useSyncExternalStore, which was introduced in React 18. If you are still using React 17 or older, also install use-sync-external-store:

npm install use-sync-external-store

Example

const headers = {
  image: '',
  name: 'Name',
  role: 'Role',
};

const rows = [
  {
    name: 'Marlon Brando',
    role: <a href="https://en.wikipedia.org/wiki/Vito_Corleone">Vito Corleone</a>,
    image: <img src="https://upload.wikimedia.org/wikipedia/en/2/21/Godfather15_flip.jpg" alt="Vito Corleone" />
  },
  {
    image: <img src="https://upload.wikimedia.org/wikipedia/en/d/df/Michaelcoreleone.jpg" alt="Al Pacino" />,
    name: 'Al Pacino',
    role: <a href="https://en.wikipedia.org/wiki/Michael_Corleone">Michael Corleone</a>,
  },
];

const keyGetter = row => row.name;

<ReactHyperResponsiveTable
  headers={headers}
  rows={rows}
  keyGetter={keyGetter}
  breakpoint={578}
  tableStyling={({ narrow }) => (narrow ? 'narrowtable' : 'widetable')}
/>

Output in wide mode:

<table class="widetable">
  <thead>
    <tr>
      <th scope="col"></th>
      <th scope="col">Name</th>
      <th scope="col">Role</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><img src="https://upload.wikimedia.org/wikipedia/en/2/21/Godfather15_flip.jpg" alt="Vito Corleone"></td>
      <td>Marlon Brando</td>
      <td><a href="https://en.wikipedia.org/wiki/Vito_Corleone">Vito Corleone</a></td>
    </tr>
    <tr>
      <td><img src="https://upload.wikimedia.org/wikipedia/en/d/df/Michaelcoreleone.jpg" alt="Al Pacino"></td>
      <td>Al Pacino</td>
      <td><a href="https://en.wikipedia.org/wiki/Michael_Corleone">Michael Corleone</a></td>
    </tr>
  </tbody>
</table>

Output in narrow mode:

Note that each data row is now a <tbody> with multiple rows.

<table class="narrowtable">
  <tbody>
    <tr>
      <th scope="row"></th>
      <td><img src="https://upload.wikimedia.org/wikipedia/en/2/21/Godfather15_flip.jpg" alt="Vito Corleone"></td>
    </tr>
    <tr>
      <th scope="row">Name</th>
      <td>Marlon Brando</td>
    </tr>
    <tr>
      <th scope="row">Role</th>
      <td><a href="https://en.wikipedia.org/wiki/Vito_Corleone">Vito Corleone</a></td>
    </tr>
  </tbody>
  <tbody>
    <tr>
      <th scope="row"></th>
      <td><img src="https://upload.wikimedia.org/wikipedia/en/d/df/Michaelcoreleone.jpg" alt="Al Pacino"></td>
    </tr>
    <tr>
      <th scope="row">Name</th>
      <td>Al Pacino</td>
    </tr>
    <tr>
      <th scope="row">Role</th>
      <td><a href="https://en.wikipedia.org/wiki/Michael_Corleone">Michael Corleone</a></td>
    </tr>
  </tbody>
</table>

See online

Properties

Some properties have multiple types. Properties marked with an asterisk (*) are required.

| Name | Type | Description | |--------|---------|-------------| | headers * | object | Object of strings or React elements to use as headers. Strings and elements can be used interchangeably. The keys of the object must correspond to the keys in the data objects. The order of the entries in the headers object determines display order. | | rows * | array | Array of data objects. These data objects can also be strings or React elements. Keys of data objects that are not in headers are ignored. | | keyGetter * | function | Function that should return a unique key when given a data object. | | breakpoint * | number | Minimum viewport width in which the wide table is displayed. | | | string | Media query that triggers the full width table. | | tableStyling | string | Class name to apply to the parent table tag. | | | object | CSS styles to apply to the parent table tag. | | | function | Function returning one of the above. The function receives a state object with boolean property narrow indicating if the current presentation is narrow or wide. | | initialNarrow | bool | Initially render the table in narrow mode when rendering serverside. Set to true when you expect the browser to be narrow to prevent rerendering client side. | | withClasses | bool | Add unique class names to each row and header cell, respectively row-KEY and header-KEY |

name

The purpose of this package is identical to the package react-super-responsive-table. The main difference is that the responsiveness of react-hyper-responsive-table is based on javascript and not on CSS.