ItemGroup 是一个实验性的 WordPress 组件,用于将多个 Item 子组件分组并统一样式。它通过 Context 传递属性,支持边框、圆角、间距和大小等配置。
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
} from '@wordpress/components';
function Example() {
return (
<ItemGroup>
<Item>Code</Item>
<Item>is</Item>
<Item>Poetry</Item>
</ItemGroup>
);
}ItemGroup displays a list of Items grouped and styled together.
ItemGroup should be used in combination with the Item sub-component.
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
} from '@wordpress/components';
function Example() {
return (
<ItemGroup>
<Item>Code</Item>
<Item>is</Item>
<Item>Poetry</Item>
</ItemGroup>
);
}
isBordered: booleanRenders borders around each items.
falseisRounded: booleanRenders with rounded corners.
trueisSeparated: booleanRenders items individually. Even if isBordered is false, a border in between each item will be still be displayed.
falsesize: 'small' | 'medium' | 'large'Determines the amount of padding within the component.
When not defined, it defaults to the value from the context (which is medium by default).
mediumThe Item sub-component is connected to <ItemGroup /> using Context. Therefore, Item receives the size prop from the ItemGroup parent component.
In the following example, the <Item /> will render with a size of small:
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
} from '@wordpress/components';
const Example = () => (
<ItemGroup size="small">
<Item>Item text</Item>
</ItemGroup>
);