Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@humanmade/react-tasklist

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@humanmade/react-tasklist

react-tasklist React component

  • 0.0.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

react-tasklist

Simple task lists in React.

Demo GIF

Installation

npm install --save @humanmade/react-tasklist

Usage

import Tasklist from '@humanmade/react-tasklist';

import '@humanmade/react-tasklist/css/index.css';

class MyComponent extends React.Component {
	constructor( props ) {
		super( props );

		this.state = {
			items: [
				{
					label: 'Item one',
					checked: false,
				},
				{
					label: 'Item two',
					checked: false,
					disabled: true,
				},
				{
					label: 'Item three',
					checked: true,
				},
			],
		};
	}

	onChange = ( index, checked ) => {
		const { items } = this.state;
		this.setState( {
			items: [
				...items.slice( 0, index ),
				{ ...items[ index ], checked },
				...items.slice( index + 1 )
			],
		} );
	}

	render() {
		const { items } = this.state;

		return <Tasklist
			items={ items }
			onChange={ this.onChange }
			onReorder={ items => this.setState( { items } ) }
		/>
	}

Props API

items

A sorted list of items to display on the list. Each item is an object with the following properties:

  • label (required, string|ReactElement): Label for the item. May be a React element.
  • task (boolean, default true): Is this a task item? Set to false for regular list items.
  • checked (required, boolean): Checkbox state.
  • disabled (boolean, default false): Is the checkbox disabled?
  • id (string, default label): Unique ID for the item. Value of label by default.

disableSort

Boolean

Whether sorting is disabled (e.g. for users without permission to edit the list).

onChange

( index: Number, checked: Boolean ) => void

Callback function for when the checked state of an item changes. Passed following parameters:

  • index (Number): Index of the item which changed.
  • checked (Boolean): True if the new state is checked, false if the new state is unchecked.

onReorder

( items: Array, oldIndex: Number, newIndex: Number ) => void

Callback function for when items are reordered. This receives the reordered items for convenience, but you can use the oldIndex and newIndex parameters to manually reorder your items if you'd prefer.

Passed following parameters:

  • items (Array): Reordered list of items.
  • oldIndex (Number): Index of the item in the original array.
  • newIndex (Number): Index of the item in the new array.

Keywords

FAQs

Package last updated on 24 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc