Created
June 18, 2017 19:11
-
-
Save jeffthemaximum/5f5c28e4a1f7bc62fe744124b2445914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
) | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works beautifully, thank you! Only thing is that
firstOnly
option when set to true causes placeholder not to render.