如何根据设置的列数显示自定义面板?

时间:2019-07-16 10:01:10

标签: javascript php wordpress wordpress-gutenberg

我想分配一个仅在列数为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);

0 个答案:

没有答案
相关问题