Skip to content

Instantly share code, notes, and snippets.

@dmitrizzle
Forked from jeffthemaximum/Slate Placeholder
Created June 21, 2017 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitrizzle/928ed016109bc74a03be18efcb8b05cf to your computer and use it in GitHub Desktop.
Save dmitrizzle/928ed016109bc74a03be18efcb8b05cf to your computer and use it in GitHub Desktop.
const wrapperStyle = {
position: 'relative'
}
const PlaceHolder = React.createClass({
renderPlaceholder(){
const { node, state, parent } = this.props;
const placeholderText = node.data.get('placeholderText');
return (
<Placeholder
firstOnly={false}
parent={parent}
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