Coder Social home page Coder Social logo

mrrenaud / react-easy-edit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from giorgosart/react-easy-edit

0.0 1.0 0.0 1.22 MB

Inline editing library for React

Home Page: https://giorgosart.gitbook.io/react-easy-edit/

License: MIT License

HTML 2.01% CSS 0.77% JavaScript 97.23%

react-easy-edit's Introduction

Test NPM License: MIT CircleCI Known Vulnerabilities install size DeepScan grade

react-easy-edit

A React library that allows inline editing on HTML5 input components, try the sandbox here!

For full library documentation, visit this site!

๐Ÿ“ 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

๐Ÿš€ Installation

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

๐Ÿ™ Show your support

Give a โญ if this project helped you in any way!

paypal ko-fi

๐Ÿ†’ Props

For the full list of props, please visit our documentation.

๐Ÿ“„ Examples

More examples can be found here

A simple example - Textbox

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!"
    />
  );
}

Radio buttons

<EasyEdit
  type="radio"
  value="one"
  onSave={save}
  options={[
      {label: 'First option', value: 'one'},
      {label: 'Second option', value: 'two'}]}
  instructions="Custom instructions"
/>

Date

<EasyEdit
  type="date"
  onSave={save}
  instructions="Select your date of birth"
/>

Dropdown

<EasyEdit
  type="select"
  options={[
      {label: 'First option', value: 'one'},
      {label: 'Second option', value: 'two'}]}
  onSave={save}
  placeholder="My Placeholder"
  instructions="Custom instructions"
/>

Datalist

<EasyEdit
  type="datalist"
  options={[
      {label: 'First option', value: 'one'},
      {label: 'Second option', value: 'two'}]}
  onSave={save}
  instructions="Custom instructions"
/>

Checkboxes

<EasyEdit
  type="checkbox"
  options={[
      {label: 'First option', value: 'one'},
      {label: 'Second option', value: 'two'}]}
  onSave={save}
  value={['one', 'two']} // this will preselect both options
/>

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);
  })
}

You can use a custom EditComponent and still use the saveOnBlur behavior. An onBlur function will be passed to your custom component, for you to trigger the behavior.

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

  render(){
    return <div>
      <p>Custom editor</p>
      <input onBlur={this.props.onBlur} />
    </diV>;
  }
}

๐Ÿค Contributing

Contributions, issues and feature requests are welcome.

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

๐Ÿ”ข 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/.

๐Ÿ“œ Licence

Copyright ยฉ 2020 George Artemiou.

This project is MIT licensed.

react-easy-edit's People

Contributors

giorgosart avatar greenkeeper[bot] avatar liamwithers avatar mnnalxndr avatar mrrenaud avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.