Skip to content

Instantly share code, notes, and snippets.

@jeffthemaximum
Created June 18, 2017 19:11
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jeffthemaximum/5f5c28e4a1f7bc62fe744124b2445914 to your computer and use it in GitHub Desktop.
const wrapperStyle = {
position: 'relative'
}
const PlaceHolder = React.createClass({
renderPlaceholder(){
const { node, state } = this.props;
const placeholderText = node.data.get('placeholderText');
return (
<Placeholder
firstOnly={false}
parent={node}
node={node}
state={state}
>
{ placeholderText }
</Placeholder>
)
},
render(){
const { node, attributes, children } = this.props;
const wrapperNodeType = node.data.get('wrapperNodeType');
switch (wrapperNodeType) {
case 'p':
return (
<p {...attributes} style={wrapperStyle} >
{ this.renderPlaceholder() }
{children}
</p>
)
case 'h1':
return (
<h1 {...attributes} style={wrapperStyle} >
{ this.renderPlaceholder() }
{children}
</h1>
)
case 'h2':
return (
<h2 {...attributes} style={wrapperStyle} >
{ this.renderPlaceholder() }
{children}
</h2>
)
default:
return (
<p {...attributes} style={wrapperStyle} >
{ this.renderPlaceholder() }
{children}
</p>
)
}
}
});
@dmitrizzle
Copy link

Works beautifully, thank you! Only thing is that firstOnly option when set to true causes placeholder not to render.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment