/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/components/src/h-stack/hook.tsx
47 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { ReactElement } from 'react'; import type { WordPressComponentProps } from '../context'; import { hasConnectNamespace, useContextSystem } from '../context'; import { FlexItem, useFlex } from '../flex'; import { getAlignmentProps } from './utils'; import { getValidChildren } from '../utils/get-valid-children'; import type { Props } from './types'; export function useHStack( props: WordPressComponentProps< Props, 'div' > ) { const { alignment = 'edge', children, direction, spacing = 2, ...otherProps } = useContextSystem( props, 'HStack' ); const align = getAlignmentProps( alignment, direction ); const validChildren = getValidChildren( children ); const clonedChildren = validChildren.map( ( child, index ) => { const _isSpacer = hasConnectNamespace( child, [ 'Spacer' ] ); if ( _isSpacer ) { const childElement = child as ReactElement; const _key = childElement.key || `hstack-${ index }`; return <FlexItem isBlock key={ _key } { ...childElement.props } />; } return child; } ); const propsForFlex = { children: clonedChildren, direction, justify: 'center', ...align, ...otherProps, gap: spacing, }; // Omit `isColumn` because it's not used in HStack. const { isColumn, ...flexProps } = useFlex( propsForFlex ); return flexProps; }