const {__} = wp.i18n; // Import __() from wp.i18n | |
const {registerBlockType} = wp.blocks; // Import registerBlockType() from wp.blocks | |
const { | |
RichText | |
} = wp.blockEditor; | |
/** | |
* Register block | |
*/ | |
export default registerBlockType( | |
"tct/article-card-block", | |
{ | |
attributes: { | |
title: { | |
type: "string", | |
source: 'text', | |
selector: 'h2', | |
default: "untitled" | |
}, | |
content: { | |
type: 'array', | |
source: 'children', | |
selector:'.content', | |
default: "..." | |
}, | |
}, | |
edit({attributes, setAttributes}) { | |
return ( | |
<Fragment> | |
<RichText | |
tagName="h2" | |
multiline={false} | |
allowedFormats={[]} | |
value={attributes.title} | |
onChange={(title) => setAttributes({title})} | |
/> | |
<RichText | |
tagName="div" | |
multiline="p" | |
value={attributes.content} | |
onChange={(content) => setAttributes({content})} | |
/> | |
</Fragment> | |
); | |
}, | |
save({attributes, className}) { | |
return ( | |
<div className={className}> | |
<RichText.Content tagName="h2" value={attributes.title}/> | |
<RichText.Content className="content" tagName="div" value={attributes.content}/> | |
</div> | |
); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Amazing, thank you🙏 , works like a charm now