Spacer 是一个实验性的布局组件,用于在组件之间提供内边距(padding)或外边距(margin)空间,并可在 HStack 或 VStack 中自适应调整间距。它基于 WordPress 组件库的网格系统(以 4px 为基准),通过简写属性控制间距。
import {
__experimentalSpacer as Spacer,
__experimentalHeading as Heading,
__experimentalView as View,
} from '@wordpress/components';
function Example() {
return (
<View>
<Spacer>
<Heading>WordPress.org</Heading>
</Spacer>
<Text>Code is Poetry</Text>
</View>
);
}由于 Spacer 是实验性功能,其 API 和行为可能不稳定,建议在开发中谨慎使用并关注更新。
Spacer is a primitive layout component that providers inner (padding) or outer (margin) space in-between components. It can also be used to adaptively provide space within an HStack or VStack.
Spacer comes with a bunch of shorthand props to adjust margin and padding. The values of these props work as a multiplier to the library’s grid system (base of 4px).
import {
__experimentalSpacer as Spacer,
__experimentalHeading as Heading,
__experimentalView as View,
} from '@wordpress/components';
function Example() {
return (
<View>
<Spacer>
<Heading>WordPress.org</Heading>
</Spacer>
<Text>Code is Poetry</Text>
</View>
);
}
children: ReactNodeThe children elements.
margin: numberAdjusts all margins.
marginBottom: numberAdjusts bottom margin, potentially overriding the value from the more generic margin and marginY props.
2marginLeft: numberAdjusts left margin, potentially overriding the value from the more generic margin and marginX props.
marginRight: numberAdjusts right margin, potentially overriding the value from the more generic margin and marginX props.
marginTop: numberAdjusts top margin, potentially overriding the value from the more generic margin and marginY props.
marginX: numberAdjusts left and right margins, potentially overriding the value from the more generic margin prop.
marginY: numberAdjusts top and bottom margins, potentially overriding the value from the more generic margin prop.
padding: numberAdjusts all padding.
paddingBottom: numberAdjusts bottom padding, potentially overriding the value from the more generic padding and paddingY props.
paddingLeft: numberAdjusts left padding, potentially overriding the value from the more generic padding and paddingX props.
paddingRight: numberAdjusts right padding, potentially overriding the value from the more generic padding and paddingX props.
paddingTop: numberAdjusts top padding, potentially overriding the value from the more generic padding and paddingY props.
paddingX: numberAdjusts left and right padding, potentially overriding the value from the more generic padding prop.
paddingY: numberAdjusts top and bottom padding, potentially overriding the value from the more generic padding prop.