-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example on how to wrap and customize the block editor #209
Conversation
00c0d0a
to
b19f4f9
Compare
onChange: PropTypes.func.isRequired | ||
}; | ||
|
||
constructor(props) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the constructor?
@@ -0,0 +1,32 @@ | |||
import PropTypes from 'prop-types' | |||
import React from 'react' | |||
import SlateEditor from '@sanity/form-builder/lib/inputs/BlockEditor-slate' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit sceptical to documenting this as the way to get the default block editor, as it makes refactoring the internals of the form-builder package a breaking change. IMO our official stance should be to never recommend importing anything from ./lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized that the BlockEditor is exported by default as SlateInput
export {default as SlateInput} from './inputs/BlockEditor-slate' |
If we change the exported name to BlockEditor, the import would be:
import {BlockEditor} from '@sanity/form-builder'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be nice yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed in #210
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that @sanity/form-builder
is not a direct dependency in the studio :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #210 by exporting it from the sanity form builder part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the import would now be:
import {BlockEditor} from 'part:@sanity/form-builder'
}; | ||
|
||
handleChange = event => { | ||
this.props.onChange(event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all handleChange
do is just call the given onChange
-prop, maybe just pass it from render()?
render() {
const {type, value, level, onChange} = this.props
return (
//...
<SlateEditor
//...
onChange={onChange}
/>
//...
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has some value to show that you can make your own handler and do stuff. As you say in the below comment (readable.io).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but then maybe we should add an example where we are actually doing something with the value (or at least a comment in handleChange
describing that we could do something with the value if we wanted to)
This is nice! Possible future work could be to turn it into an example of how to use it with an external service like readable.io. |
197449b
to
6ed66b4
Compare
b97a9b8
to
46b7e99
Compare
46b7e99
to
0aa1970
Compare
💖 |
…ditor (#209) * [example-studio] Add example on how to wrap and customize the block editor * [example-studio] Fix errors in FunkyEditor * [example-studio] Fix localizedSlug schema bug * [example-studio] Make a cleaner example of FunkyEditor
…ditor (#209) * [example-studio] Add example on how to wrap and customize the block editor * [example-studio] Fix errors in FunkyEditor * [example-studio] Fix localizedSlug schema bug * [example-studio] Make a cleaner example of FunkyEditor
A working example on how to wrap and customise inputs would be nice to have in the example studio right?