Skip to content

Instantly share code, notes, and snippets.

@mkaz

mkaz/block-test.js

Last active Nov 7, 2019
Embed
What would you like to do?
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>
);
}
}
);
@Mahjouba91

This comment has been minimized.

Copy link

@Mahjouba91 Mahjouba91 commented Nov 7, 2019

Amazing, thank you 🙏 , works like a charm now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.