Skip to content
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

Merged
merged 4 commits into from
Sep 27, 2017

Conversation

skogsmaskin
Copy link
Member

@skogsmaskin skogsmaskin commented Sep 27, 2017

A working example on how to wrap and customise inputs would be nice to have in the example studio right?

onChange: PropTypes.func.isRequired
};

constructor(props) {
Copy link
Member

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'
Copy link
Member

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

Copy link
Member

@bjoerge bjoerge Sep 27, 2017

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'

Copy link
Member Author

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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed in #210

Copy link
Member Author

@skogsmaskin skogsmaskin Sep 27, 2017

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 :(

Copy link
Member

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

Copy link
Member

@bjoerge bjoerge Sep 27, 2017

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)
Copy link
Member

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}
     />
    //...
  )
}

Copy link
Member Author

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).

Copy link
Member

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 handleChangedescribing that we could do something with the value if we wanted to)

@bjoerge
Copy link
Member

bjoerge commented Sep 27, 2017

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.

@skogsmaskin skogsmaskin merged commit 852b8f0 into next Sep 27, 2017
@skogsmaskin skogsmaskin deleted the example/funky-editor branch September 27, 2017 12:13
@bjoerge
Copy link
Member

bjoerge commented Sep 27, 2017

💖

bjoerge pushed a commit that referenced this pull request Sep 27, 2017
…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
@bjoerge bjoerge mentioned this pull request Sep 27, 2017
bjoerge pushed a commit that referenced this pull request Sep 27, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants