我正在尝试使用block filter在块编辑器中将样式属性添加到块的包装器中:
const addStyle = createHigherOrderComponent( ( BlockListBlock ) => {
return ( props ) => {
return <BlockListBlock { ...props } className="my-class" style="color: red" />;
};
}, 'addStyle' );
wp.hooks.addFilter( 'editor.BlockListBlock', 'my-plugin/add-style', addStyle );
仅将my-class
类名称添加到类属性,但不添加样式属性。是否可以添加样式属性?该文档指出:
它接收原始的BlockListBlock组件并返回一个新的包装的组件。
但不是说您只能添加类名。
wp.hooks.addFilter('blocks.getSaveContent.extraProps','my-plugin/add-style', function(props, name, atts){
return Object.assign(props, { 'style': 'color: red' });
});
无法通过编辑功能知道。