1 | [![Test](https://img.shields.io/npm/v/react-easy-edit.svg?style=flat)](https://www.npmjs.com/package/react-easy-edit)
|
2 | [![NPM](https://img.shields.io/npm/dm/react-easy-edit.svg)](https://www.npmjs.com/package/react-easy-edit)
|
3 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
4 | [![CircleCI](https://dl.circleci.com/status-badge/img/gh/giorgosart/react-easy-edit/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/giorgosart/react-easy-edit/tree/master) [![Known Vulnerabilities](https://snyk.io/test/github/giorgosart/react-easy-edit/badge.svg?targetFile=package.json)](https://snyk.io/test/github/giorgosart/react-easy-edit?targetFile=package.json)
|
5 | [![install size](https://packagephobia.now.sh/badge?p=react-easy-edit@latest)](https://packagephobia.now.sh/result?p=react-easy-edit@latest)
|
6 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=giorgosart_react-easy-edit&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=giorgosart_react-easy-edit)
|
7 | [![DeepScan grade](https://deepscan.io/api/teams/6030/projects/7886/branches/87202/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=6030&pid=7886&bid=87202)
|
8 |
|
9 | ![](https://i.imgur.com/vwqcqeD.gif)
|
10 |
|
11 | # react-easy-edit
|
12 | A React library that allows inline editing on HTML5 input components, try the sandbox **[here](https://codesandbox.io/s/react-easy-edit-sandbox-2y97j)**!
|
13 |
|
14 | For full library documentation, **[visit this site](https://giorgosart.gitbook.io/react-easy-edit/)**!
|
15 |
|
16 | ### :pencil: Features
|
17 | - Supports `input` (most types, even inputs with `datalist`), `textarea`,`radio`, `checkbox`, `tel`, `url` and `select` HTML types
|
18 | - Validates user input
|
19 | - Allows customisation on all elements including the save and cancel buttons
|
20 | - Supports custom editComponent and custom displayComponent for each type
|
21 |
|
22 | ## :rocket: Installation
|
23 | ```npm i react-easy-edit``` or ```yarn add react-easy-edit```
|
24 |
|
25 | ## :pray: Show your support
|
26 | Give a :star: if this project helped you in any way!
|
27 |
|
28 | [![paypal](https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=TUJKB5DPLHA3N¤cy_code=GBP&source=url)
|
29 | [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y611NE2)
|
30 |
|
31 | ## :cool: Props
|
32 | For the full list of props, please visit **[our documentation site](https://giorgosart.gitbook.io/react-easy-edit/props)**.
|
33 |
|
34 | ## :page_facing_up: Examples
|
35 | More examples can be found **[here](https://giorgosart.gitbook.io/react-easy-edit/examples)**
|
36 | #### A simple example - Textbox
|
37 | ```jsx
|
38 | import React, { Component } from 'react';
|
39 | import EasyEdit from 'react-easy-edit';
|
40 |
|
41 | function App() {
|
42 |
|
43 | const save = (value) => {alert(value)}
|
44 | const cancel = () => {alert("Cancelled")}
|
45 |
|
46 | return (
|
47 | <EasyEdit
|
48 | type="text"
|
49 | onSave={save}
|
50 | onCancel={cancel}
|
51 | saveButtonLabel="Save Me"
|
52 | cancelButtonLabel="Cancel Me"
|
53 | attributes={{ name: "awesome-input", id: 1}}
|
54 | instructions="Star this repo!"
|
55 | />
|
56 | );
|
57 | }
|
58 | ```
|
59 |
|
60 | #### Radio buttons
|
61 | ```jsx
|
62 | <EasyEdit
|
63 | type="radio"
|
64 | value="one"
|
65 | onSave={save}
|
66 | options={[
|
67 | {label: 'First option', value: 'one'},
|
68 | {label: 'Second option', value: 'two'}]}
|
69 | instructions="Custom instructions"
|
70 | />
|
71 | ```
|
72 |
|
73 | #### Date
|
74 | ```jsx
|
75 | <EasyEdit
|
76 | type="date"
|
77 | onSave={save}
|
78 | instructions="Select your date of birth"
|
79 | />
|
80 | ```
|
81 |
|
82 | #### Dropdown
|
83 | ```jsx
|
84 | <EasyEdit
|
85 | type="select"
|
86 | options={[
|
87 | {label: 'First option', value: 'one'},
|
88 | {label: 'Second option', value: 'two'}]}
|
89 | onSave={save}
|
90 | placeholder="My Placeholder"
|
91 | instructions="Custom instructions"
|
92 | />
|
93 | ```
|
94 |
|
95 | #### Datalist
|
96 | ```jsx
|
97 | <EasyEdit
|
98 | type="datalist"
|
99 | options={[
|
100 | {label: 'First option', value: 'one'},
|
101 | {label: 'Second option', value: 'two'}]}
|
102 | onSave={save}
|
103 | instructions="Custom instructions"
|
104 | />
|
105 | ```
|
106 |
|
107 | #### Checkboxes
|
108 | ```jsx
|
109 | <EasyEdit
|
110 | type="checkbox"
|
111 | options={[
|
112 | {label: 'First option', value: 'one'},
|
113 | {label: 'Second option', value: 'two'}]}
|
114 | onSave={save}
|
115 | value={['one', 'two']} // this will preselect both options
|
116 | />
|
117 | ```
|
118 |
|
119 | #### Custom components
|
120 |
|
121 | When using custom input components, they must be passed in as props, like so:
|
122 | ```jsx
|
123 | <EasyEdit
|
124 | type="text"
|
125 | onSave={() => {}}
|
126 | editComponent={<CustomInput />}
|
127 | displayComponent={<CustomDisplay />}
|
128 | />
|
129 | ```
|
130 |
|
131 | 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.
|
132 |
|
133 | 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.
|
134 |
|
135 | e.g.
|
136 | ```jsx
|
137 | // Inside your custom input
|
138 |
|
139 | onChange(searchTerm) {
|
140 | getUserIdByUsername(searchTerm).then((userId) => {
|
141 | this.props.setParentValue(userId);
|
142 | })
|
143 | }
|
144 | ```
|
145 |
|
146 | 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.
|
147 |
|
148 | ```jsx
|
149 | class CustomComponent extends React.Component{
|
150 | constructor(props){
|
151 | super(props);
|
152 | }
|
153 |
|
154 | render(){
|
155 | return <div>
|
156 | <p>Custom editor</p>
|
157 | <input onBlur={this.props.onBlur} />
|
158 | </div>;
|
159 | }
|
160 | }
|
161 | ```
|
162 |
|
163 | ## :handshake: Contributing
|
164 | Contributions, issues and feature requests are welcome.
|
165 |
|
166 | Feel free to check [issues page](https://github.com/giorgosart/react-easy-edit/issues) if you want to contribute.
|
167 |
|
168 | ## :1234: Versioning
|
169 | For transparency and insight into our release cycle, releases will be numbered with the following format:
|
170 |
|
171 | ```<major>.<minor>.<patch>```
|
172 |
|
173 | And constructed with the following guidelines:
|
174 |
|
175 | - Breaking backwards compatibility bumps the major
|
176 | - New additions without breaking backwards compatibility bumps the minor
|
177 | - Bug fixes and misc changes bump the patch
|
178 | - For more information on semantic versioning, please visit http://semver.org/.
|
179 |
|
180 | ## :scroll: Licence
|
181 | Copyright © 2023 [George Artemiou](https://github.com/giorgosart).
|
182 |
|
183 | This project is under [MIT license](https://github.com/giorgosart/react-easy-edit/blob/master/LICENSE).
|
184 |
|
\ | No newline at end of file |