/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/components/src/heading/hook.ts
42 строки
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { WordPressComponentProps } from '../context'; import { useContextSystem } from '../context'; import { useText } from '../text'; import { getHeadingFontSize } from '../utils/font-size'; import { CONFIG, COLORS } from '../utils'; import type { HeadingProps } from './types'; export function useHeading( props: WordPressComponentProps< HeadingProps, 'h1' > ) { const { as: asProp, level = 2, color = COLORS.theme.foreground, isBlock = true, weight = CONFIG.fontWeightEmphasis as React.CSSProperties[ 'fontWeight' ], ...otherProps } = useContextSystem( props, 'Heading' ); const as = ( asProp || `h${ level }` ) as keyof React.JSX.IntrinsicElements; const a11yProps: { role?: string; 'aria-level'?: number; } = {}; if ( typeof as === 'string' && as[ 0 ] !== 'h' ) { // If not a semantic `h` element, add a11y props: a11yProps.role = 'heading'; a11yProps[ 'aria-level' ] = typeof level === 'string' ? parseInt( level ) : level; } const textProps = useText( { color, isBlock, weight, size: getHeadingFontSize( level ), ...otherProps, } ); return { ...textProps, ...a11yProps, as }; }