Flex 是 WordPress 组件库中的一个基础布局组件,用于自适应地水平或垂直对齐子内容。它支持 FlexItem 和 FlexBlock 子组件,并提供了灵活的 CSS Flexbox 属性配置。
import { Flex, FlexBlock, FlexItem } from '@wordpress/components';
function Example() {
return (
<Flex>
<FlexItem>
<p>Code</p>
</FlexItem>
<FlexBlock>
<p>Poetry</p>
</FlexBlock>
</Flex>
);
}Flex is a primitive layout component that adaptively aligns child content horizontally or vertically. Flex powers components like HStack and VStack.
Flex is used with any of it’s two sub-components, FlexItem and FlexBlock.
import { Flex, FlexBlock, FlexItem } from '@wordpress/components';
function Example() {
return (
<Flex>
<FlexItem>
<p>Code</p>
</FlexItem>
<FlexBlock>
<p>Poetry</p>
</FlexBlock>
</Flex>
);
}
align: CSSProperties['alignItems']Aligns children using CSS Flexbox align-items. Vertically aligns content if the direction is row, or horizontally aligns content if the direction is column.
centerdirection: ResponsiveCSSValue<CSSProperties['flexDirection']>The direction flow of the children content can be adjusted with direction. column will align children vertically and row will align children horizontally.
rowexpanded: booleanExpands to the maximum available width (if horizontal) or height (if vertical).
truegap: numberSpacing in between each child can be adjusted by using gap. The value of gap works as a multiplier to the library’s grid system (base of 4px).
2justify: CSSProperties['justifyContent']Horizontally aligns content if the direction is row, or vertically aligns content if the direction is column.
space-betweenwrap: booleanDetermines if children should wrap.
false