UNPKG

@chakra-ui/layout

Version:

Chakra UI layout components that give you massive speed

90 lines (88 loc) 2.34 kB
'use client' import { StackItem } from "./chunk-ZFQCCYWD.mjs"; import { getDividerStyles } from "./chunk-5VJV6UNA.mjs"; // src/stack/stack.tsx import { getValidChildren } from "@chakra-ui/react-children-utils"; import { cx } from "@chakra-ui/shared-utils"; import { chakra, forwardRef } from "@chakra-ui/system"; import { cloneElement, Fragment, useMemo } from "react"; import { jsx, jsxs } from "react/jsx-runtime"; var Stack = forwardRef((props, ref) => { const { isInline, direction: directionProp, align, justify, spacing = "0.5rem", wrap, children, divider, className, shouldWrapChildren, ...rest } = props; const direction = isInline ? "row" : directionProp != null ? directionProp : "column"; const dividerStyle = useMemo( () => getDividerStyles({ spacing, direction }), [spacing, direction] ); const hasDivider = !!divider; const shouldUseChildren = !shouldWrapChildren && !hasDivider; const clones = useMemo(() => { const validChildren = getValidChildren(children); return shouldUseChildren ? validChildren : validChildren.map((child, index) => { const key = typeof child.key !== "undefined" ? child.key : index; const isLast = index + 1 === validChildren.length; const wrappedChild = /* @__PURE__ */ jsx(StackItem, { children: child }, key); const _child = shouldWrapChildren ? wrappedChild : child; if (!hasDivider) return _child; const clonedDivider = cloneElement( divider, { __css: dividerStyle } ); const _divider = isLast ? null : clonedDivider; return /* @__PURE__ */ jsxs(Fragment, { children: [ _child, _divider ] }, key); }); }, [ divider, dividerStyle, hasDivider, shouldUseChildren, shouldWrapChildren, children ]); const _className = cx("chakra-stack", className); return /* @__PURE__ */ jsx( chakra.div, { ref, display: "flex", alignItems: align, justifyContent: justify, flexDirection: direction, flexWrap: wrap, gap: hasDivider ? void 0 : spacing, className: _className, ...rest, children: clones } ); }); Stack.displayName = "Stack"; export { Stack }; //# sourceMappingURL=chunk-ZHMYA64R.mjs.map