UNPKG

@wordpress/components

Version:
66 lines (52 loc) 1.59 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.useHStack = useHStack; var _element = require("@wordpress/element"); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _context = require("../ui/context"); var _flex = require("../flex"); var _utils = require("./utils"); var _getValidChildren = require("../ui/utils/get-valid-children"); /** * External dependencies */ /** * Internal dependencies */ function useHStack(props) { const { alignment = 'edge', children, direction, spacing = 2, ...otherProps } = (0, _context.useContextSystem)(props, 'HStack'); const align = (0, _utils.getAlignmentProps)(alignment, direction); const validChildren = (0, _getValidChildren.getValidChildren)(children); const clonedChildren = validChildren.map((child, index) => { const _isSpacer = (0, _context.hasConnectNamespace)(child, ['Spacer']); if (_isSpacer) { const childElement = child; const _key = childElement.key || `hstack-${index}`; return (0, _element.createElement)(_flex.FlexItem, (0, _extends2.default)({ isBlock: true, key: _key }, childElement.props)); } return child; }); const propsForFlex = { children: clonedChildren, direction, justify: 'center', ...align, ...otherProps, gap: spacing }; const flexProps = (0, _flex.useFlex)(propsForFlex); return flexProps; } //# sourceMappingURL=hook.js.map