首先需要导入组件
const { InspectorControls } = wp.editor;
const { PanelBody } = wp.components;
然后在编辑功能中,您需要像这样放置InspectorControl-
<InspectorControls>
<PanelBody title={ __( \'Settings One\' ) }>
</PanelBody>
<PanelBody title={ __( \'Settings Two\' ) }>
</PanelBody>
<PanelBody title={ __( \'Settings Three\' ) >
</PanelBody>
</InspectorControls>
您有三个设置面板。下面是另一个例子-
isSelected && (
<InspectorControls key= { \'inspector\' } >
<PanelBody>
<RangeControl
label= { __(\'Title Size\', \'tar\') }
value= { textSize }
min= \'25\'
max= \'50\'
onChange={ (set) => setAttributes({ textSize : set }) }
/>
<PanelColorSettings
title={ __(\'Title Color\', \'tar\') }
colorSettings= { [
{
value: textColor,
onChange: (colorValue) => setAttributes ( { textColor: colorValue } ),
label: __(\'Color\', \'tar\'),
},
] }
/>
<PanelColorSettings
title={ __(\'Background Color\', \'tar\') }
colorSettings= { [
{
value: bgColor,
onChange: (colorValue) => setAttributes ( { bgColor: colorValue } ),
label: __(\'Color\', \'tar\'),
},
] }
/>
</PanelBody>
</InspectorControls>
),
注意到isSelected道具了吗?这意味着只有在单击块时,才会显示块侧栏设置。我希望这有帮助。