New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-easy-edit

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-easy-edit

A react library for inline editing components

  • 1.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
decreased by-74.11%
Maintainers
1
Weekly downloads
 
Created
Source

Test License: MIT CircleCI Greenkeeper badge install size

react-easy-edit

A React library that allows inline editing on HTML5 input components.

:pencil: Features

  • Supports input (most types, even inputs with datalist), textarea,radio, checkbox and select HTML types
  • Validates user input
  • Allows customisation on all elements including the save and cancel buttons
  • Supports custom editComponent and custom displayComponent for each type

:rocket: Installation

npm i react-easy-edit or yarn add react-easy-edit

:pray: Show your support

Give a :star: if this project helped you in any way!

ko-fi

:cool: Props

PropTypeRequiredDefaultDescription
typestringYesThe type of the input element to display. Supported types are text, number, color, textarea, date, datetime-local,time, month, week, radio, email, checkbox, select, range and datalist
valuestring or number or arrayNonullThe value of the input element depended on its type
optionsarrayNoA key value pair object that is used as available options for select, radio and checkbox.options = [{label:'Test One', value: '1'},{label:'Test Two', value: '2'}];
saveButtonLabelstring or elementNoSaveThe label to be used for the "Save" button
saveButtonStylestringNoeasy-edit-buttonOne or more CSS classes to be used to style the "Save" button
cancelButtonLabelstring or elementNoCancelThe label to be used for the "Cancel" button
cancelButtonStylestringNoeasy-edit-buttonOne or more CSS classes to be used to style the "Cancel" button
placeholderstringNoClick to editThe text to be shown as a hint that describes the expected value of the input element
onCancelfunctionNo() => {}A function that will be called when editing is cancelled. Also called when the Esc button is pressed
onSavefunctionYesA function that will be called when editing is saved. Also called when the Enter button is pressed (Textarea component is excluded)
onValidatefunctionNo() => {}A function that will be called before the onSave() event. It must return true or false and has one parameter which is the value of the component being edited
validationMessagestringNoThe text to be displayed if validation fails
allowEditbooleanNotrueDetermines whether the component itself should be editable or not
attributesobjectNo{}A key value pair of HTML attributes to be applied on the element
instructionsstringNoInstructions to be shown below the component
editComponentelementNonullThe custom component to be displayed when editing the value. This will override the standard input shown for the type provided
displayComponentelementNonullThe custom component to be displayed the value when not editing

Usage

A simple example

import React, { Component } from 'react';
import EasyEdit from 'react-easy-edit';

function App() {
  
  const save = (value) => {alert(value)}
  const cancel = () => {alert("Cancelled")}

  return (
    <EasyEdit
      type="text"
      onSave={save}
      onCancel={cancel}
      saveButtonLabel="Save Me"
      cancelButtonLabel="Cancel Me"
      attributes={{ name: "awesome-input", id: 1}}
      instructions="Star this repo!"
    />
  );
}
Custom components

When using custom input components, they must be passed in as props, like so:

<EasyEdit
    type="text"
    onSave={() => {}}
    editComponent={<CustomInput />}
    displayComponent={<CustomDisplay />}
/>

When defining a custom input component, the function setParentValue is injected into your custom component, which must be called in order to pass the desired value up to the parent EasyEdit component.

For example, if your component was a text field that needed to set the EasyEdit value as a user id based on a username entered, you would need to pass the id to this.props.setParentValue in order to get that value to the EasyEdit component.

e.g.

// Inside your custom input

onChange(searchTerm) {
  getUserIdByUsername(searchTerm).then((userId) => {
    this.props.setParentValue(userId);
  })
}

:handshake: Contributing

Contributions, issues and feature requests are welcome.

Feel free to check issues page if you want to contribute.

Contributors

giorgosartmnnalxndrliamwithers
@giorgosart@mnnalxndr@liamwithers
:construction::computer::bug::computer::bug::bug:

:1234: Versioning

For transparency and insight into our release cycle, releases will be numbered with the following format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch
  • For more information on semantic versioning, please visit http://semver.org/.

:scroll: Licence

Copyright © 2019 George Artemiou.

This project is MIT licensed.

Keywords

FAQs

Package last updated on 02 Nov 2019

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