@@ -6,12 +6,12 @@ Universal Editable List React Component
66
77` react-edit-list ` allows for easy creation of editable lists in React that can be interfaced with a database
88
9- - Fully customizable
10- - Zero-dependency
11- - Supports async callbacks for calling externals APIs
12- - Supports input validation
13- - Supports optional ` null ` fields
14- - Supports custom field types
9+ * Fully customizable
10+ * Zero-dependency
11+ * Supports async callbacks for calling externals APIs
12+ * Supports input validation
13+ * Supports optional ` null ` fields
14+ * Supports custom field types
1515
1616# Installation
1717
@@ -31,51 +31,56 @@ Refer to the [examples](https://mmomtchev.github.io/react-edit-list/)
3131
3232### Table of Contents
3333
34- - [ Element] ( #element )
35- - [ Schema] ( #schema )
36- - [ Row] ( #row )
37- - [ Props] ( #props )
38- - [ schema] ( #schema-1 )
39- - [ onLoad] ( #onload )
40- - [ format] ( #format )
41- - [ edit] ( #edit )
42- - [ editProps] ( #editprops )
43- - [ headers] ( #headers )
44- - [ onChange] ( #onchange )
45- - [ onInsert] ( #oninsert )
46- - [ onUpdate] ( #onupdate )
47- - [ onDelete] ( #ondelete )
48- - [ defaultValues] ( #defaultvalues )
49- - [ className] ( #classname )
50- - [ btnValidateClassName] ( #btnvalidateclassname )
51- - [ btnDeleteClassName] ( #btndeleteclassname )
52- - [ btnCancelClassName] ( #btncancelclassname )
53- - [ headClassName] ( #headclassname )
54- - [ bodyClassName] ( #bodyclassname )
55- - [ trClassName] ( #trclassname )
56- - [ thClassName] ( #thclassname )
57- - [ tdClassName] ( #tdclassname )
58- - [ inputClassName] ( #inputclassname )
59- - [ btnValidateElement] ( #btnvalidateelement )
60- - [ btnDeleteElement] ( #btndeleteelement )
61- - [ btnCancelElement] ( #btncancelelement )
62- - [ disableUpdate] ( #disableupdate )
63- - [ disableDelete] ( #disabledelete )
64- - [ disableInsert] ( #disableinsert )
65- - [ tableElement] ( #tableelement )
66- - [ tbodyElement] ( #tbodyelement )
67- - [ theadElement] ( #theadelement )
68- - [ thElement] ( #thelement )
69- - [ trElement] ( #trelement )
70- - [ tdElement] ( #tdelement )
71- - [ ReactEditList] ( #reacteditlist )
72- - [ Parameters] ( #parameters )
34+ * [ Element] ( #element )
35+ * [ Schema] ( #schema )
36+ * [ Row] ( #row )
37+ * [ Props] ( #props )
38+ * [ schema] ( #schema-1 )
39+ * [ onLoad] ( #onload )
40+ * [ format] ( #format )
41+ * [ Examples] ( #examples )
42+ * [ edit] ( #edit )
43+ * [ Examples] ( #examples-1 )
44+ * [ editProps] ( #editprops )
45+ * [ headers] ( #headers )
46+ * [ onChange] ( #onchange )
47+ * [ onInsert] ( #oninsert )
48+ * [ onUpdate] ( #onupdate )
49+ * [ onDelete] ( #ondelete )
50+ * [ defaultValues] ( #defaultvalues )
51+ * [ className] ( #classname )
52+ * [ btnValidateClassName] ( #btnvalidateclassname )
53+ * [ btnDeleteClassName] ( #btndeleteclassname )
54+ * [ btnCancelClassName] ( #btncancelclassname )
55+ * [ headClassName] ( #headclassname )
56+ * [ bodyClassName] ( #bodyclassname )
57+ * [ trClassName] ( #trclassname )
58+ * [ thClassName] ( #thclassname )
59+ * [ tdClassName] ( #tdclassname )
60+ * [ inputClassName] ( #inputclassname )
61+ * [ btnValidateElement] ( #btnvalidateelement )
62+ * [ btnDeleteElement] ( #btndeleteelement )
63+ * [ btnCancelElement] ( #btncancelelement )
64+ * [ disableUpdate] ( #disableupdate )
65+ * [ disableDelete] ( #disabledelete )
66+ * [ disableInsert] ( #disableinsert )
67+ * [ tableElement] ( #tableelement )
68+ * [ tbodyElement] ( #tbodyelement )
69+ * [ theadElement] ( #theadelement )
70+ * [ thElement] ( #thelement )
71+ * [ trElement] ( #trelement )
72+ * [ tdElement] ( #tdelement )
73+ * [ filler] ( #filler )
74+ * [ rowClassName] ( #rowclassname )
75+ * [ insertClassName] ( #insertclassname )
76+ * [ ReactEditList] ( #reacteditlist )
77+ * [ Parameters] ( #parameters )
7378
7479## Element
7580
7681Field type
7782
78- ` id ` means a hidden element that will be carried on by react-edit-list without any processing
83+ ` id ` means a hidden field that will be carried on by react-edit-list without any processing
7984
8085` string ` and ` number ` have default rendering and input components
8186
@@ -117,14 +122,57 @@ Type: function (): ([Array](https://developer.mozilla.org/docs/Web/JavaScript/Re
117122
118123Custom field formatters
119124
125+ Each field formatter must be a React component
126+
127+ It will receive the value to be rendered in ` props.value `
128+
120129Type: Record<[ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) , Formatter>
121130
131+ #### Examples
132+
133+ ``` javascript
134+ function DefaultFormatString (props : {value: Value}): JSX.Element {
135+ return < React .Fragment > {props .value as string}< / React .Fragment > ;
136+ }
137+ ```
138+
122139### edit
123140
124141Custom field editors
125142
143+ Each field editor must be a React component
144+
145+ It will receive the previous value in ` props.value ` and
146+ should call ` props.onChange ` to update it
147+
126148Type: Record<[ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) , Editor>
127149
150+ #### Examples
151+
152+ ``` javascript
153+ function DefaultEditString (props : {
154+ value: Value;
155+ opts?: unknown;
156+ className?: string;
157+ editProps?: Record< string, unknown> ;
158+ onChange : (v : Value ) => void ;
159+ }) {
160+ const onChange = React .useCallback (
161+ (e ) => props .onChange (e .target .value != ' ' ? e .target .value : undefined ),
162+ [props]
163+ );
164+ return (
165+ < input
166+ className= {props .className }
167+ {... props .editProps }
168+ value= {props .value as string}
169+ type= ' text'
170+ onChange= {onChange}
171+ / >
172+ );
173+ }
174+ ```
175+
128176### editProps
129177
130178Custom props to be passed to the field editors
@@ -141,15 +189,19 @@ Type: (Record<[string](https://developer.mozilla.org/docs/Web/JavaScript/Referen
141189
142190Called on every change with all the elements
143191
144- Return ` boolean ` to deny the operation
192+ Return ` false ` to deny the operation
193+
194+ Return ` true ` to trigger a refresh through ` onLoad `
195+
196+ Return ` undefined ` for default behavior
145197
146198Type: function (data: [ Array] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array ) <[ Row] ( #row ) >): ([ boolean] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean ) | void | [ Promise] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise ) <([ boolean] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean ) | void)>)
147199
148200### onInsert
149201
150202Called after insertion of a new element
151203
152- Return ` boolean ` to deny the operation
204+ Return ` false ` to deny the operation
153205
154206Return a new item to modify its contents
155207
@@ -159,7 +211,7 @@ Type: function (item: [Row](#row)): ([boolean](https://developer.mozilla.org/doc
159211
160212Called after updating an existing element
161213
162- Return ` boolean ` to deny the operation
214+ Return ` false ` to deny the operation
163215
164216Return a new item to modify its contents
165217
@@ -169,7 +221,7 @@ Type: function (updated: [Row](#row), old: [Row](#row)): ([boolean](https://deve
169221
170222Called after deleting an element
171223
172- Return ` boolean ` to deny the operation
224+ Return ` false ` to deny the operation
173225
174226Type: function (item: [ Row] ( #row ) ): ([ boolean] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean ) | void | [ Promise] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise ) <([ boolean] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean ) | void)>)
175227
@@ -277,46 +329,66 @@ Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Glob
277329
278330### tableElement
279331
280- Element to use instead of table
332+ Element to use instead of < table >
281333
282- Type: ( [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.ComponentType<{className: [ string ] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?}> )
334+ Type: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String )
283335
284336### tbodyElement
285337
286- Element to use instead of tbody
338+ Element to use instead of < tbody >
287339
288- Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.ComponentType <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?}>)
340+ Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.FunctionComponent <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?}>)
289341
290342### theadElement
291343
292- Element to use instead of thead
344+ Element to use instead of < thead >
293345
294- Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.ComponentType <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?}>)
346+ Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.FunctionComponent <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?}>)
295347
296348### thElement
297349
298- Element to use instead of th
350+ Element to use instead of < th >
299351
300- Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.ComponentType <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?}>)
352+ Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.FunctionComponent <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?}>)
301353
302354### trElement
303355
304- Element to use instead of tr
356+ Element to use instead of < tr >
305357
306- Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.ComponentType <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?, onKeyDown: function (e: React.KeyboardEvent): void ?}>)
358+ Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.FunctionComponent <{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?, dataid: [ number ] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number ) ?}>)
307359
308360### tdElement
309361
310- Element to use instead of table
362+ Element to use instead of <td >
363+
364+ Element must accept mouse and keyboard input
311365
312- Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.ComponentType<{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?, onClick: function (e: React.MouseEvent): void?}>)
366+ Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | React.FunctionComponent<{className: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) ?, onClick: function (e: React.MouseEvent): void?, onKeyDown: function (e: React.KeyboardEvent): void?}>)
367+
368+ ### filler
369+
370+ Element to use for the empty row that allows adding a new item
371+
372+ Type: JSX.Element
373+
374+ ### rowClassName
375+
376+ Optional class to use for regular rows
377+
378+ Type: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String )
379+
380+ ### insertClassName
381+
382+ Optional class to use for the empty row allowing insertion
383+
384+ Type: [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String )
313385
314386## ReactEditList
315387
316388An universal editable list for React
317389
318390### Parameters
319391
320- - ` props ` ** [ Props ] ( #props ) ** {Props}
392+ * ` props ` {Props}
321393
322- Returns ** JSX.Element**
394+ Returns ** JSX.Element**
0 commit comments