AlignmentMatrixControl 是 WordPress 组件库中的一个控件,用于调整 UI 元素的水平和垂直对齐方式。它提供矩阵式交互界面,支持多种对齐选项,并可通过 Props 进行配置。
import { AlignmentMatrixControl } from '@wordpress/components';
import { useState } from '@wordpress/element';
const Example = () => {
const [ alignment, setAlignment ] = useState( 'center center' );
return (
<AlignmentMatrixControl
value={ alignment }
onChange={ setAlignment }
/>
);
};使用前需导入 @wordpress/components 和 @wordpress/element。对齐值必须符合指定类型,如 'center' 或 'top left' 等组合。Props 如 defaultValue 和 label 是可选的,但 value 和 onChange 通常用于状态管理。
See the WordPress Storybook for more detailed, interactive documentation.
AlignmentMatrixControl components enable adjustments to horizontal and vertical alignments for UI.
import { AlignmentMatrixControl } from '@wordpress/components';
import { useState } from '@wordpress/element';
const Example = () => {
const [ alignment, setAlignment ] = useState( 'center center' );
return (
<AlignmentMatrixControl
value={ alignment }
onChange={ setAlignment }
/>
);
};
defaultValue"center" | "top left" | "top center" | "top right" | "center left" | "center center" | "center right" | "bottom left" | "bottom center" | "bottom right"'center center'If provided, sets the default alignment value.
labelstring'Alignment Matrix Control'Accessible label. If provided, sets the aria-label attribute of the
underlying grid widget.
onChange((newValue: AlignmentMatrixControlValue) => void)A function that receives the updated alignment value.
value"center" | "top left" | "top center" | "top right" | "center left" | "center center" | "center right" | "bottom left" | "bottom center" | "bottom right"The current alignment value.
widthnumber92If provided, sets the width of the control.
disablePointerEventsbooleantrueIf true, disables pointer events on the icon.
value"center" | "top left" | "top center" | "top right" | "center left" | "center center" | "center right" | "bottom left" | "bottom center" | "bottom right"centerThe current alignment value.