Item 是一个实验性 WordPress 组件,用于与 ItemGroup 结合显示分组和样式化的项目列表。它通过 Context 从父组件 ItemGroup 接收属性,如 size。
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
} from '@wordpress/components';
function Example() {
return (
<ItemGroup>
<Item>Code</Item>
<Item>is</Item>
<Item>Poetry</Item>
</ItemGroup>
);
}由于是实验性功能,开发者应关注未来版本更新,避免在生产环境中依赖不稳定 API。
Item is used in combination with ItemGroup to display a list of items grouped and styled together.
Item should be used in combination with the ItemGroup 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>
);
}
onClick: React.MouseEventHandler<HTMLDivElement>Even handler for processing click events. When defined, the Item component will render as a button (unless differently specified via the as prop).
size: 'small' | 'medium' | 'large'Determines the amount of padding within the component.
mediumItem is connected to the <ItemGroup /> parent component 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>
</ItemGroup>
);