From 8eed6c4d1a19a1b4066f9fd5f45cbcaadae04450 Mon Sep 17 00:00:00 2001 From: b-gran Date: Sat, 26 Oct 2019 21:30:40 +0100 Subject: [PATCH 1/2] Add support for render functions in cells --- src/Editor.js | 33 ++++++++++++++++++++------------- src/examples/example.js | 8 +++++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Editor.js b/src/Editor.js index 148172e..1875bb3 100644 --- a/src/Editor.js +++ b/src/Editor.js @@ -385,14 +385,17 @@ class StringCell extends React.Component { BaseClassnames.EditorInput('--value') ); + const cellContent = typeof this.props.type.render === 'function' + ? this.props.type.render(this.props.type, this.props.value, this.props.onChange) + : this.props.onChange(evt.target.value)}/> + return ( - this.props.onChange(evt.target.value)}/> + {cellContent} ); } @@ -421,15 +424,19 @@ class BooleanCell extends React.Component { }; render () { + const cellContent = typeof this.props.type.render === 'function' + ? this.props.type.render(this.props.type, this.props.value, this.props.onChange) + : + return ( - + { cellContent } ); } diff --git a/src/examples/example.js b/src/examples/example.js index 8c94e61..b8b91fb 100644 --- a/src/examples/example.js +++ b/src/examples/example.js @@ -17,7 +17,13 @@ const APP_ROOT = document.getElementById('root') // A deeply nested test schema const schema = { - foo: Schema.SchemaTypes.string({ required: true }), + foo: Schema.SchemaTypes.string({ + required: true, + render: (type, value, onChange) =>