A react library for inline editing components
npm install react-easy-edit


 




input (most types, even inputs with datalist), textarea,radio, checkbox, tel, url and select HTML types
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!


:cool: Props
For the full list of props, please visit our documentation site.
:page_facing_up: Examples
More examples can be found here
#### A simple example - Textbox
`jsx
import React, { Component } from 'react';
import EasyEdit from 'react-easy-edit';
function App() {
const save = (value) => {alert(value)}
const cancel = () => {alert("Cancelled")}
return (
type="text"
onSave={save}
onCancel={cancel}
saveButtonLabel="Save Me"
cancelButtonLabel="Cancel Me"
inputAttributes={{ name: "awesome-input", id: 1}}
instructions="Star this repo!"
/>
);
}
`
#### Radio buttons
`jsx
type="radio"
value="one"
onSave={save}
options={[
{label: 'First option', value: 'one'},
{label: 'Second option', value: 'two'}]}
instructions="Custom instructions"
/>
`
#### Date
`jsx
type="date"
onSave={save}
instructions="Select your date of birth"
/>
`
#### Dropdown
`jsx
type="select"
options={[
{label: 'First option', value: 'one'},
{label: 'Second option', value: 'two'}]}
onSave={save}
placeholder="My Placeholder"
instructions="Custom instructions"
/>
`
#### Datalist
`jsx
type="datalist"
options={[
{label: 'First option', value: 'one'},
{label: 'Second option', value: 'two'}]}
onSave={save}
instructions="Custom instructions"
/>
`
#### Checkboxes
`jsx
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:
`jsx
type="text"
onSave={() => {}}
editComponent={ }
displayComponent={ }
/>
`
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.
`jsx
// 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.
`jsx
class CustomComponent extends React.Component{
constructor(props){
super(props);
}
render(){
return
Custom editor
;
}
}
`
:handshake: Contributing
Contributions, issues and feature requests are welcome.
Feel free to check issues page if you want to contribute.
Special thanks to all the contributors below for spending their time improving this library
:1234: Versioning
For transparency and insight into our release cycle, releases will be numbered with the following format:
`.. ``