DimensionControl 是一个用于控制间距或尺寸的 UI 组件,目前处于实验性阶段,已弃用,可能发生重大变更。
import { useState } from 'react';
import { __experimentalDimensionControl as DimensionControl } from '@wordpress/components';
export default function MyCustomDimensionControl() {
const [ paddingSize, setPaddingSize ] = useState( '' );
return (
<DimensionControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ 'Padding' }
icon={ 'desktop' }
onChange={ ( value ) => setPaddingSize( value ) }
value={ paddingSize }
/>
);
}DimensionControl is a component designed to provide a UI to control spacing and/or dimensions.
import { useState } from 'react';
import { __experimentalDimensionControl as DimensionControl } from '@wordpress/components';
export default function MyCustomDimensionControl() {
const [ paddingSize, setPaddingSize ] = useState( '' );
return (
<DimensionControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ 'Padding' }
icon={ 'desktop' }
onChange={ ( value ) => setPaddingSize( value ) }
value={ paddingSize }
/>
);
}
Note: by default, if you do not provide an initial value prop for the current dimension value, then no value will be selected (ie: there is no default dimension set).
labelstringThe human readable label for the control.
valuestringThe current value of the dimension UI control. If provided the UI with automatically select the value.
sizes{ name: string; slug: string }[]packages/block-editor/src/components/dimension-control/sizes.tsAn optional array of size objects in the following shape:
[
{
name: __( 'Small' ),
slug: 'small',
},
{
name: __( 'Medium' ),
slug: 'small',
},
// ...etc
]
By default a set of relative sizes (small, medium…etc) are provided. See packages/block-editor/src/components/dimension-control/sizes.js.
iconstringAn optional dashicon to display before to the control label.
onChange( value?: string ) => void;size – a string representing the selected size (eg: medium)A callback which is triggered when a spacing size value changes (is selected/clicked).
classNamestring''A string of classes to be added to the control component.
__next40pxDefaultSizeBooleanfalseStart opting into the larger default height that will become the default size in a future version.
__nextHasNoMarginBottomBooleanfalseStart opting into the new margin-free styles that will become the default in a future version.