UNPKG

@wordpress/components

Version:
58 lines (54 loc) 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useHStack = useHStack; var _context = require("../context"); var _flex = require("../flex"); var _utils = require("./utils"); var _getValidChildren = require("../utils/get-valid-children"); var _jsxRuntime = require("react/jsx-runtime"); /** * 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 /*#__PURE__*/(0, _jsxRuntime.jsx)(_flex.FlexItem, { isBlock: true, ...childElement.props }, _key); } 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 } = (0, _flex.useFlex)(propsForFlex); return flexProps; } //# sourceMappingURL=hook.js.map