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

v1.1.0

Published

Universal Editable List React Component

Downloads

193

Readme

react-edit-list

License: ISC npm version Node.js CI codecov

Universal Editable List React Component

react-edit-list allows for easy creation of editable lists in React that can be interfaced with a database

  • Fully customizable
  • Zero-dependency
  • Supports async callbacks for calling externals APIs
  • Supports input validation
  • Supports optional null fields
  • Supports custom field types

Installation

npm i --save react-edit-layers

Usage

Refer to the examples

screenshot

API

Table of Contents

Element

Field type

id means a hidden field that will be carried on by react-edit-list without any processing

string and number have default rendering and input components

custom allows you to define your own rendering and input components

Passing an array of name/value pairs allows defining of an enum field

Type: ("id" | "string" | "number" | Array<{name: string, value: (string | undefined)}> | "custom")

Schema

Schema for the data

Type: Array<{name: string, type: Element}>

Row

A row of data

Type: Record<string, Value>

Props

ReactEditList properties

schema

The schema for the data

Type: Schema

onLoad

Will be called to load the data, can be asynchronous

Type: function (): (Array<Row> | Promise<Array<Row>>)

format

Custom field formatters

Each field formatter must be a React component

It will receive the value to be rendered in props.value

Type: Record<string, Formatter>

Examples

function DefaultFormatString(props: {value: Value}): JSX.Element {
  return <React.Fragment>{props.value as string}</React.Fragment>;
}

edit

Custom field editors

Each field editor must be a React component

It will receive the previous value in props.value and should call props.onChange to update it

Type: Record<string, Editor>

Examples

function DefaultEditString(props: {
  value: Value;
  opts?: unknown;
  className?: string;
  editProps?: Record<string, unknown>;
  onChange: (v: Value) => void;
}) {
  const onChange = React.useCallback(
    (e) => props.onChange(e.target.value != '' ? e.target.value : undefined),
    [props]
  );
  return (
    <input
      className={props.className}
      {...props.editProps}
      value={props.value as string}
      type='text'
      onChange={onChange}
    />
  );
}

editProps

Custom props to be passed to the field editors

Type: Record<string, Record<string, any>>

headers

Custom headers, set to null to completely disable headers

Type: (Record<string, JSX.Element> | null)

onChange

Called on every change with all the elements

Return false to deny the operation

Return true to trigger a refresh through onLoad

Return undefined for default behavior

Type: function (data: Array<Row>): (boolean | void | Promise<(boolean | void)>)

onInsert

Called after insertion of a new element

Return false to deny the operation

Return a new item to modify its contents

Type: function (item: Row): (boolean | void | Row | Promise<(boolean | void | Row)>)

onUpdate

Called after updating an existing element

Return false to deny the operation

Return a new item to modify its contents

Type: function (updated: Row, old: Row): (boolean | void | Row | Promise<(boolean | void | Row)>)

onDelete

Called after deleting an element

Return false to deny the operation

Type: function (item: Row): (boolean | void | Promise<(boolean | void)>)

defaultValues

Optional default values for new elements

Type: Row

className

Optional CSS class name

Type: string

btnValidateClassName

Optional validate button class name

Type: string

btnDeleteClassName

Optional delete button class name

Type: string

btnCancelClassName

Optional cancel button class name

Type: string

headClassName

Optional table head class name

Type: string

bodyClassName

Optional table body class name

Type: string

trClassName

Optional table TR class name

Type: string

thClassName

Optional table TH class name

Type: (string | Record<string, string>)

tdClassName

Optional table TD class name

Type: (string | Record<string, string>)

inputClassName

Optional table INPUT class name

Type: string

btnValidateElement

Optional custom button element

Type: JSX.Element

btnDeleteElement

Optional custom button element

Type: JSX.Element

btnCancelElement

Optional custom button element

Type: JSX.Element

disableUpdate

Disable updating

Type: boolean

disableDelete

Disable deleting

Type: boolean

disableInsert

Disable inserting

Type: boolean

tableElement

Element to use instead of

Type: string

tbodyElement

Element to use instead of

Type: (string | React.FunctionComponent<{className: string?}>)

theadElement

Element to use instead of

Type: (string | React.FunctionComponent<{className: string?}>)

thElement

Element to use instead of

Type: (string | React.FunctionComponent<{className: string?}>)

trElement

Element to use instead of

Type: (string | React.FunctionComponent<{className: string?, dataid: number?}>)

tdElement

Element to use instead of

Element must accept mouse and keyboard input

Type: (string | React.FunctionComponent<{className: string?, onClick: function (e: React.MouseEvent): void?, onKeyDown: function (e: React.KeyboardEvent): void?}>)

filler

Element to use for the empty row that allows adding a new item

Type: JSX.Element

rowClassName

Optional class to use for regular rows

Type: string

insertClassName

Optional class to use for the empty row allowing insertion

Type: string

ReactEditList

An universal editable list for React

Parameters

  • props {Props}

Returns JSX.Element