UNPKG

@wordpress/components

Version:
33 lines (32 loc) • 1.11 kB
import { hasConnectNamespace, useContextSystem } from "../context/index.mjs"; import { FlexItem, useFlex } from "../flex/index.mjs"; import { getAlignmentProps } from "./utils.mjs"; import { getValidChildren } from "../utils/get-valid-children.mjs"; import { jsx } from "react/jsx-runtime"; // packages/components/src/h-stack/hook.tsx function useHStack(props) { const { alignment = "edge", children, direction, spacing = 2, ...otherProps } = useContextSystem(props, "HStack"); const align = getAlignmentProps(alignment, direction); const propsForFlex = { children: getValidChildren(children).map((child, index) => { if (hasConnectNamespace(child, ["Spacer"])) { const childElement = child; const _key = childElement.key || `hstack-${index}`; return /* @__PURE__ */ jsx(FlexItem, { isBlock: true, ...childElement.props }, _key); } return child; }), direction, justify: "center", ...align, ...otherProps, gap: spacing }; const { isColumn, ...flexProps } = useFlex(propsForFlex); return flexProps; } export { useHStack }; //# sourceMappingURL=hook.mjs.map