ToggleGroupControlOptionIcon 是一个实验性的表单组件,用于作为 ToggleGroupControl 的子组件,通过图标展示选项。它适用于 WordPress 区块编辑器开发,提供图标化的交互界面。
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';
import { formatLowercase, formatUppercase } from '@wordpress/icons';
function Example() {
return (
<ToggleGroupControl __next40pxDefaultSize>
<ToggleGroupControlOptionIcon
value="uppercase"
icon={ formatUppercase }
label="Uppercase"
/>
<ToggleGroupControlOptionIcon
value="lowercase"
icon={ formatLowercase }
label="Lowercase"
/>
</ToggleGroupControl>
);
}由于是实验性组件,建议在非生产环境中测试,并关注 WordPress 更新以应对可能的 API 变化。
ToggleGroupControlOptionIcon is a form component which is meant to be used as a child of ToggleGroupControl and displays an icon.
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';
import { formatLowercase, formatUppercase } from '@wordpress/icons';
function Example() {
return (
<ToggleGroupControl __next40pxDefaultSize>
<ToggleGroupControlOptionIcon
value="uppercase"
icon={ formatUppercase }
label="Uppercase"
/>
<ToggleGroupControlOptionIcon
value="lowercase"
icon={ formatLowercase }
label="Lowercase"
/>
</ToggleGroupControl>
);
}
value: string | numberThe value of the ToggleGroupControlOption.
icon: ComponentIcon displayed as the content of the option. Usually one of the icons from the @wordpress/icons package, or a custom React <svg> icon.
label: stringThe text to accessibly label the icon option. Will also be shown in a tooltip.