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

relisted

v0.2.1

Published

React Primitives to build a sortable, filterable, data-list.

Downloads

2

Readme

Relisted

React Primitives to build a sortable, filterable, data-list.

What this is

Relisted is a component that manages user interaction for sorting and filtering a list of data, while allowing you to retain complete control over the rendering of the list.

What this is NOT

This is a super early version that is just barely generalized enough for me to open-source. It does not currently have any accessibility considerations. It does not support paging or virtualization. It has built-in sort and filter functionality that might not meet your needs. My next plan on the roadmap for this is to add the ability to override the filter/sort functionality with your own custom functions.

Installation

npm install --save relisted

or

yarn add relisted

This package also depends on react and prop-types. Make sure those are both installed!

Simple Example

import Relisted from 'relisted'

function BasicList({columns, data}) {
  return (
    <Relisted>
      {({getColumnProps}) => (
        <div style={{display: 'flex', flexDirection: 'column', width: '500px', height: '500px', border: '1px solid blue'}}>
          <div style={{display: 'flex', width: '100%', borderBottom: '1px solid #cdcdcd'}}>
            {columns.map(c => (
              <div key={c.name} {...getColumnProps((style: {flex: 1}))}>
                {c.text}
              </div>
            ))}
          </div>
          {data.length > 0 ?(
            <div style={{display: 'flex', width: '100%', flex: 1, flexDirection: 'column'}}>
              {data.map(row => (
                <div style={{width: '100%', display: 'flex' flexShrink: '0'}}>
                  {columns.map(c => (
                    <div key={c.name} style={{flex: 1}}>
                      {row[c.name]}
                    </div>
                  ))}
                </div>
              ))}
              </div>
          ) : (
            <div>Empty Data</div>
          )}
        </div>
      )}
    </Relisted>
  )
}

const columns = [
  { name: 'cost', text: 'Cost' },
  { name: 'name', text: 'Name' },
  { name: 'hero', text: 'Hero' },
  { name: 'rarity', text: 'Rarity' },
]

const data = [
  { cost: 1, name: 'Mistress of Mixtures', hero: 'Neutral', rarity: 'Common' },
  { cost: 2, name: 'Frostbolt', hero: 'Mage', rarity: 'Basic' },
  { cost: 3, name: 'Jade Blossom', hero: 'Druid', rarity: 'Common' },
  { cost: 6, name: 'Dragonfire Potion', hero: 'Priest', rarity: 'Epic' },
  { cost: 4, name: 'Mortal Strike', hero: 'Warrior', rarity: 'Rare' },
  {
    cost: 8,
    name: 'Ragnaros, Lightlord',
    hero: 'Paladin',
    rarity: 'Legendary',
  },
]

function App() {
  return (
    <BasicList
      columns={columns}
      data={data}
    />
  )
}

Props

sortBy

string | defaults to empty string

Pass a the name of the column you want to sort by. Used by the default filter function.

sortAscending

bool | defaults to true

Determines the sort direction on load.

children

function({}) | required

This function is called by the render of relisted and is passed an object. Read more below.

Child Callback Function

The child callback function is passed an object that has 3 different categories of properties:

prop getters

These are functions that will return an object representing props to apply to a component. Any props that you would like to apply to that component along with the ones returned by the getter should be passed to the getter function.

getColumnProps

This function is responsible for wiring up the click handling of each column header for sorting.

Required properties:

  • name: the name of the column. This name gets set as the sortBy once a column header is clicked.

getFilterProps

This function applies props for controlling the state of the search filter.

There are no required properties for this function.

getClearProps

This function applies props for wiring up a button for clearing the search filter.

There are no requrired properties for this function.

helpers

These are functions that provide built-in sorting and filtering of a list.

| property | type | description | | ------------ | --------------------------------- | --------------------------------------------- | | filterData | function(data: [], columns: []) | filters the given data using the filter state | | sortData | function(data: []) | sorts the given data using the sort state |

state

These are values that represent the current internal state of the Relisted component.

| property | type | description | | --------------- | --------- | ----------------------------------------- | | sortBy | string | the column name to sort by | | sortAscending | boolean | whether to sort in ascending order or not | | filterValue | string | the value of the filter input |

Examples

Examples can be found in the stories folder.

Inspiration

This library was inspired by the awesome Downshift created by Kent C. Dodds. I highly recommend checking out the documentation for that library to get a better understanding of the patterns utilized here.

LICENSE

MIT