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-simple-list

v2.2.0

Published

Component that renders dynamic html list

Downloads

38

Readme

React-List

SemVer License Build Status

A react component that renders an array as an html list. The array can consist of primitives or objects. In the case of objects, the formatItem function property can be used to format the item and return either a primitive or object. By default a string is expected. In case of an object, a custom itemComponent is required.

Demo

Install

Install as node dependency:

npm install react-simple-list --save

Usage 1 - Basic Example

var React = require('react');
var list = require('react-simple-list');

React.render(React.createElement(list, {
  items: ['Java', 'Java Flash', 'JavaScript']
}), document.querySelector('#list-1'));

Usage 2 - With object

Note that the value property is used as the label by default. This allows the usage of objects without the help of the item formatter and component.

React.render(React.createElement(list, {
  items: [{
    value: 'Apple'
  }, {
    value: 'Banana'
  }, {
    value: 'Cherry'
  }]
}), document.querySelector('#list-2'));

Usage 3 - With object, item component and formatter

var items = [
  {id: 1, firstname: 'Mike', lastname: 'November'},
  {id: 2, firstname: 'India', lastname: 'Juliet'},
  {id: 3, firstname: 'Alpha', lastname: 'Bravo'}
];

var itemComponent = React.createClass({
  propTypes: {
    href: React.PropTypes.string.isRequired,
    text: React.PropTypes.string.isRequired
  },
  render: function () {
    return (
      React.DOM.a({ href: this.props.href }, this.props.text)
    );
  }
});

function formatItem(item) {
  return {
    href: '#' + item.id,
    text: item.firstname + ' ' + item.lastname
  };
}

React.render(React.createElement(list, {
  items: items,
  formatItem: formatItem,
  itemComponent: itemComponent,
  cssClass: 'list'
}), document.querySelector('#list-2'));

Properties

  • items: an array of items, where items can be an arbitrary object
  • formatItem: an optional function that is called with each item and used to map the item to the properties of itemComponent
  • itemComponent: an optional react class that is used to display an item
  • cssClass: optional css class for the list
  • onItemClick(event, item, index): optional click handler. The argument contains the value of the clicked item and its index.

List item properties

  • cssClass: If an item object contains the property cssClass it will be applied to the rendered <li> element.
  • value: If an item object contains the property value, it is used as the item label if no custom itemComponent is given.

Run local demo

npm start & npm run watch
  • npm run build - build production css and js
  • npm run watch - compile css and js
  • npm start - start static dev server

License

MIT