{"version":3,"file":"Flex.mjs","names":[],"sources":["../../../src/flex/Flex.tsx"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { tokens } from '@neo4j-ndl/base';\nimport type React from 'react';\n\nimport {\n  type PolymorphicCommonProps,\n  type Radius,\n  type ReactComponent,\n  type Spacing,\n} from '../_common/types';\nimport { getRadius, getSpacing } from '../_common/utils';\n\ntype AllowedFlexElements = 'div' | 'span' | 'ul' | 'ol' | 'li';\n\ntype BaseFlexProps = {\n  /**\n   * @default tokens.space['4']\n   */\n  gap?: Spacing;\n  /**\n   * @default undefined\n   */\n  rowGap?: Spacing;\n  /**\n   * @default undefined\n   */\n  columnGap?: Spacing;\n  /**\n   * @default undefined\n   */\n  borderRadius?: Radius;\n  /**\n   * Flex direction is set to column by default.\n   * The `row-reverse` and `column-reverse` values\n   * are skipped due to accessibility concerns.\n   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction#accessibility_concerns\n   *\n   * @default row\n   */\n  flexDirection?: Exclude<\n    React.CSSProperties['flexDirection'],\n    'row-reverse' | 'column-reverse'\n  >;\n  /**\n   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap\n   * @default nowrap\n   */\n  flexWrap?: React.CSSProperties['flexWrap'];\n  /**\n   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content\n   * @default undefined\n   */\n  justifyContent?: React.CSSProperties['justifyContent'];\n  /**\n   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/align-items\n   * @default undefined\n   */\n  alignItems?: React.CSSProperties['alignItems'];\n  children?: React.ReactNode;\n  style?: React.CSSProperties;\n};\n\n/**\n * Flex is a general-purpose container that helps\n * lay out components with consistent spacing in a row or column.\n */\nexport const Flex = <T extends AllowedFlexElements = 'div'>({\n  as,\n  gap = '8',\n  rowGap,\n  columnGap,\n  children,\n  borderRadius,\n  flexDirection = 'column',\n  flexWrap = 'nowrap',\n  alignItems,\n  justifyContent,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: PolymorphicCommonProps<T, BaseFlexProps>) => {\n  const Component = (as || 'div') as unknown as ReactComponent;\n\n  // If gap is not provided,\n  // and rowGap and columnGap are not provided,\n  // then use the default value.\n  const gapPx = getSpacing(gap, 'gap');\n  const rowGapPx = rowGap ? tokens.space[rowGap] : undefined;\n  const columnGapPx = columnGap ? tokens.space[columnGap] : undefined;\n  const gapFormatted = `${rowGapPx ?? gapPx} ${columnGapPx ?? gapPx}`;\n\n  const additionalStyle: React.CSSProperties = {\n    alignItems,\n    borderRadius: getRadius(borderRadius, 'borderRadius'),\n    display: 'flex',\n    flexDirection,\n    flexWrap,\n    gap: gapFormatted,\n    justifyContent,\n  };\n\n  return (\n    <Component\n      ref={ref}\n      className={className}\n      style={{ ...additionalStyle, ...style }}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      {children}\n    </Component>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;AAdF,MAAa,QAA+C,SAgBZ;CAhBY,IAAA,EAC1D,IACA,MAAM,KACN,QACA,WACA,UACA,cACA,gBAAgB,UAChB,WAAW,UACX,YACA,gBACA,WACA,OACA,gBACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,YAAa,MAAM;CAKzB,MAAM,QAAQ,WAAW,KAAK,KAAK;CACnC,MAAM,WAAW,SAAS,OAAO,MAAM,UAAU,KAAA;CACjD,MAAM,cAAc,YAAY,OAAO,MAAM,aAAa,KAAA;CAC1D,MAAM,eAAe,GAAG,aAAA,QAAA,aAAA,KAAA,IAAA,WAAY,MAAM,GAAG,gBAAA,QAAA,gBAAA,KAAA,IAAA,cAAe;CAE5D,MAAM,kBAAuC;EAC3C;EACA,cAAc,UAAU,cAAc,cAAc;EACpD,SAAS;EACT;EACA;EACA,KAAK;EACL;CACF;CAEA,OACE,oBAAC,WAAA,eAAA,eAAA,eAAA;EACM;EACM;EACX,OAAA,eAAA,eAAA,CAAA,GAAY,eAAA,GAAoB,KAAM;CAClC,GAAA,SAAA,GACA,cAAA,GAAA,CAAA,GAAA,EAEH,SAAA,CACQ,CAAA;AAEf"}