我想分配一个仅在列数为2时设置左右列比率的类。
我试图根据官方文档获取ColumnCount的值,但未找到获取方法。
const withColumnsControls = createHigherOrderComponent((BlockEdit) => {
let selectOption = '';
return (props) => {
const {
name,
attributes,
setAttributes,
isSelected,
} = props;
const {
columnsRatio
} = attributes;
return (
<Fragment>
<BlockEdit {...props} />
{isSelected && allowedBlocks.includes(name) &&
<InspectorControls>
<PanelBody title="Columns Option" initialOpen={true} className="columns-control">
<RadioControl
label={__('Columns Ratio')}
selected={selectOption}
options={[
{label:'1:1', value: ''},
{label:'1:2', value: 'col1-2'},
{label:'1:3', value: 'col1-3'},
{label:'1:4', value: 'col1-4'},
{label:'1:5', value: 'col1-5'},
{label:'2:3', value: 'col2-3'}
]}
onChange={(value) => setAttributes({columnsRatio:value})}
help={!!selectOption?__(''):__('')}
/>
</PanelBody>
</InspectorControls>
}
</Fragment>
);
};
}, 'withColumnsControls');
addFilter('editor.BlockEdit', 'my-block/my-block-control', withColumnsControls);