Heading 是一个实验性的 WordPress 组件,用于渲染标题和标题文本,基于库的排版系统实现。它允许开发者通过指定 level 属性来控制标题的语义级别和样式大小。
import { __experimentalHeading as Heading } from '@wordpress/components';
function Example() {
return <Heading>Code is Poetry</Heading>;
}Heading renders headings and titles using the library’s typography system.
import { __experimentalHeading as Heading } from '@wordpress/components';
function Example() {
return <Heading>Code is Poetry</Heading>;
}
Heading uses Text underneath, so we have access to all of Text‘s props except for:
size which is replaced by level;isBlock‘s default value, which is true for the Heading component.For a complete list of those props, check out Text.
level: 1 | 2 | 3 | 4 | 5 | 6 | '1' | '2' | '3' | '4' | '5' | '6'Passing any of the heading levels to level will both render the correct typographic text size as well as the semantic element corresponding to the level (h1 for 1 for example).
2