Skip to content

Commit

Permalink
[example-studio] Add example on how to wrap and customize the block e…
Browse files Browse the repository at this point in the history
…ditor
  • Loading branch information
skogsmaskin authored and bjoerge committed Sep 27, 2017
1 parent 2917354 commit 6ed66b4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/example-studio/components/FunkyEditor/FunkyEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import PropTypes from 'prop-types'
import React from 'react'
import SlateEditor from '@sanity/form-builder/lib/inputs/BlockEditor-slate'
export default class FunkyEditor extends React.Component {
static propTypes = {
type: PropTypes.shape({
title: PropTypes.string
}).isRequired,
level: PropTypes.number,
value: PropTypes.array,
onChange: PropTypes.func.isRequired
};

handleChange = event => {
this.props.onChange(event)
}

render() {
const {type, value, level} = this.props
return (
<div>
<h3>Take me to Funky Town</h3>
<SlateEditor
type={type}
level={level}
value={value === undefined ? '' : value}
onChange={this.handleChange}
/>
</div>
)
}
}
1 change: 1 addition & 0 deletions packages/example-studio/components/FunkyEditor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from './FunkyEditor'
5 changes: 5 additions & 0 deletions packages/example-studio/parts/inputResolver.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import FunkyEditor from '../components/FunkyEditor/FunkyEditor'
import Slider from '../components/Slider/Slider'
import {get} from 'lodash'

Expand All @@ -6,5 +7,9 @@ export default function resolveInput(type) {
return Slider
}

if (type.name === 'array' && type.of.find(ofType => ofType.name === 'block')) {
return FunkyEditor
}

return false
}
4 changes: 4 additions & 0 deletions packages/example-studio/sanity.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
{
"implements": "part:@sanity/base/brand-logo",
"path": "components/BrandLogo.js"
},
{
"implements": "part:@sanity/form-builder/input-resolver",
"path": "./parts/inputResolver.js"
}
],
"env": {
Expand Down

0 comments on commit 6ed66b4

Please sign in to comment.