Gutenberg使用块过滤器添加样式属性

问题描述 投票:0回答:1

我正在尝试使用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组件并返回一个新的包装的组件。

但不是说您只能添加类名。

wordpress wordpress-gutenberg
1个回答
0
投票
对于渲染部分,它是:

wp.hooks.addFilter('blocks.getSaveContent.extraProps','my-plugin/add-style', function(props, name, atts){ return Object.assign(props, { 'style': 'color: red' }); });

无法通过编辑功能知道。
© www.soinside.com 2019 - 2024. All rights reserved.