{"version":3,"file":"Stack.mjs","sources":["../../../../src/components/Stack/Stack.tsx"],"sourcesContent":["'use client'\n\nimport { createElement, forwardRef } from 'react'\n\nimport classNames from 'classnames'\n\nimport {\n  getLayoutStyles,\n  getMarginStyles,\n  splitByLayoutProps,\n  splitByMarginProps,\n} from '~/src/types/props-helpers'\nimport { cssDimension } from '~/src/utils/style'\n\nimport type { HStackProps, StackProps, VStackProps } from './Stack.types'\n\nimport styles from './Stack.module.scss'\n\n/**\n * `Stack` is a layout component used to group elements together and apply a space between them.\n * @example\n *\n * ```tsx\n * <Stack\n *   direction=\"horizontal\"\n *   spacing={6}\n * >\n *   <div>{ ... }</div>\n *   <div>{ ... }</div>\n * </Stack>\n * ```\n */\nexport const Stack = forwardRef<HTMLElement, StackProps>(\n  function Stack(props, forwardedRef) {\n    const [marginProps, marginRest] = splitByMarginProps(props)\n    const [layoutProps, layoutRest] = splitByLayoutProps(marginRest)\n    const marginStyles = getMarginStyles(marginProps)\n    const layoutStyles = getLayoutStyles(layoutProps)\n\n    const {\n      children,\n      style,\n      className,\n      as = 'div',\n      display = 'flex',\n      direction,\n      justify,\n      align,\n      spacing,\n      reverse,\n      wrap,\n      ...rest\n    } = layoutRest\n\n    return createElement(\n      as,\n      {\n        ref: forwardedRef,\n        style: {\n          '--b-stack-spacing': cssDimension(spacing),\n          ...marginStyles.style,\n          ...layoutStyles.style,\n          ...style,\n        },\n        className: classNames(\n          styles.Stack,\n          display && styles[`display-${display}`],\n          direction && styles[`direction-${direction}`],\n          justify && styles[`justify-${justify}`],\n          align && styles[`align-${align}`],\n          reverse && styles.reverse,\n          wrap && styles.wrap,\n          marginStyles.className,\n          layoutStyles.className,\n          className\n        ),\n        'data-testid': 'bezier-stack',\n        ...rest,\n      },\n      children\n    )\n  }\n)\n\n/**\n * `HStack` is a shorthand component equivalent to `Stack` with a horizontal direction property.\n * @see Stack\n */\nexport const HStack = forwardRef<HTMLElement, HStackProps>(\n  function HStack(props, forwardedRef) {\n    return createElement(Stack, {\n      ...props,\n      direction: 'horizontal',\n      ref: forwardedRef,\n    })\n  }\n)\n\n/**\n * `VStack` is a shorthand component equivalent to `Stack` with a vertical direction property.\n * @see Stack\n */\nexport const VStack = forwardRef<HTMLElement, VStackProps>(\n  function VStack(props, forwardedRef) {\n    return createElement(Stack, {\n      ...props,\n      direction: 'vertical',\n      ref: forwardedRef,\n    })\n  }\n)\n"],"names":["Stack","forwardRef","props","forwardedRef","marginProps","marginRest","splitByMarginProps","layoutProps","layoutRest","splitByLayoutProps","marginStyles","getMarginStyles","layoutStyles","getLayoutStyles","children","style","className","as","display","direction","justify","align","spacing","reverse","wrap","rest","createElement","ref","cssDimension","classNames","styles","HStack","VStack"],"mappings":";;;;;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,KAAK,gBAAGC,UAAU,CAC7B,SAASD,KAAKA,CAACE,KAAK,EAAEC,YAAY,EAAE;EAClC,MAAM,CAACC,WAAW,EAAEC,UAAU,CAAC,GAAGC,kBAAkB,CAACJ,KAAK,CAAC;EAC3D,MAAM,CAACK,WAAW,EAAEC,UAAU,CAAC,GAAGC,kBAAkB,CAACJ,UAAU,CAAC;AAChE,EAAA,MAAMK,YAAY,GAAGC,eAAe,CAACP,WAAW,CAAC;AACjD,EAAA,MAAMQ,YAAY,GAAGC,eAAe,CAACN,WAAW,CAAC;EAEjD,MAAM;IACJO,QAAQ;IACRC,KAAK;IACLC,SAAS;AACTC,IAAAA,EAAE,GAAG,KAAK;AACVC,IAAAA,OAAO,GAAG,MAAM;IAChBC,SAAS;IACTC,OAAO;IACPC,KAAK;IACLC,OAAO;IACPC,OAAO;IACPC,IAAI;IACJ,GAAGC;AACL,GAAC,GAAGjB,UAAU;EAEd,oBAAOkB,aAAa,CAClBT,EAAE,EACF;AACEU,IAAAA,GAAG,EAAExB,YAAY;AACjBY,IAAAA,KAAK,EAAE;AACL,MAAA,mBAAmB,EAAEa,YAAY,C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