{"version":3,"file":"Flex.cjs","sources":["../../../../src/components/flex/Flex.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { forwardRef } from \"react\";\nimport { SlotComponent } from \"../../utilities/index.js\";\nimport type { PolymorphicRef } from \"../../utilities/polymorphism/polymorphism.js\";\nimport {\n    type Breakpoint,\n    type FlexComponent,\n    type FlexProps,\n    type Responsive,\n    isResponsive,\n} from \"./types.js\";\n\nexport const Flex = forwardRef(function Flex<\n    ElementType extends React.ElementType = \"div\",\n>(props: FlexProps<ElementType>, ref?: PolymorphicRef<ElementType>) {\n    const {\n        asChild,\n        alignItems,\n        alignContent,\n        as = \"div\",\n        center = false,\n        className,\n        direction = \"row\",\n        fill,\n        gap = \"m\",\n        inline,\n        justifyContent,\n        layout = {},\n        textAlign,\n        wrap = \"nowrap\",\n        ...rest\n    } = props;\n\n    const Tag = asChild ? SlotComponent : as;\n    const gaps = toObjectEntries(gap).flatMap(([breakpoint, gap]) => {\n        const [row, col = row] = gap.trim().split(\" \");\n        return [\n            `screen-${breakpoint}-row-gap-${row}`,\n            `screen-${breakpoint}-col-gap-${col}`,\n        ];\n    });\n    const layouts = toObjectEntries(layout).map(\n        ([breakpoint, layout]) => `screen-${breakpoint}-${layout}`, // Convert to number to convert 2.10 to 2.1 and false to 0\n    );\n\n    return (\n        <Tag\n            {...rest}\n            className={clsx(\n                \"jkl-flex\",\n                !alignItems || `align-items-${alignItems}`,\n                !alignContent || `align-content-${alignContent}`,\n                !center || `center-${center === true ? \"2xl\" : center}`,\n                !fill || \"fill\",\n                !inline || \"inline-flex\",\n                !justifyContent || `justify-content-${justifyContent}`,\n                !textAlign || `text-align-${textAlign}`,\n                !wrap || `flex-wrap-${wrap}`,\n                !direction || `flex-direction-${direction}`,\n                ...gaps,\n                ...layouts,\n                className,\n            )}\n            ref={ref}\n        />\n    );\n}) as FlexComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\n/**\n * Gjør en enkeltstående eller responsiv verdi om til et nøstet array,\n * der hvert indre array inneholder et breakpoint med tilhørende verdi.\n * @example `{ small: \"12\", large: \"64\" }` -> `[[\"small\", \"12\"], [\"large\", \"64\"]]`\n * @example `\"24\"` -> `[[\"small\", \"24\"]]`\n * @param value enkeltstående eller responsiv verdi\n * @returns nøstet array med breakpoints og verdier\n */\nfunction toObjectEntries<T>(value: T | Responsive<T>): [Breakpoint, T][] {\n    if (isResponsive(value)) {\n        return Object.entries(value) as [Breakpoint, T][];\n    }\n\n    return [[\"small\", value]];\n}\n"],"names":["Flex","forwardRef","props","ref","asChild","alignItems","alignContent","as","center","className","direction","fill","gap","inline","justifyContent","layout","textAlign","wrap","rest","Tag","SlotComponent","gaps","toObjectEntries","flatMap","breakpoint","row","col","trim","split","layouts","map","jsx","clsx","value","isResponsive","Object","entries"],"mappings":"qQAYaA,EAAOC,EAAAA,WAAW,SAE7BC,EAA+BC,GAC7B,MACIC,QAAAA,EACAC,WAAAA,EACAC,aAAAA,EACAC,GAAAA,EAAK,MACLC,OAAAA,GAAS,EACTC,UAAAA,EACAC,UAAAA,EAAY,MACZC,KAAAA,EACAC,IAAAA,EAAM,IACNC,OAAAA,EACAC,eAAAA,EACAC,OAAAA,EAAS,CAAA,EACTC,UAAAA,EACAC,KAAAA,EAAO,YACJC,GACHhB,EAEEiB,EAAMf,EAAUgB,EAAAA,cAAgBb,EAChCc,EAAOC,EAAgBV,GAAKW,QAAQ,EAAEC,EAAYZ,MACpD,MAAOa,EAAKC,EAAMD,GAAOb,EAAIe,OAAOC,MAAM,KAC1C,MAAO,CACH,UAAUJ,aAAsBC,IAChC,UAAUD,aAAsBE,OAGlCG,EAAUP,EAAgBP,GAAQe,IACpC,EAAEN,EAAYT,KAAY,UAAUS,KAAcT,KAGtD,OACIgB,EAAAA,IAACZ,EAAA,IACOD,EACJT,UAAWuB,EAAAA,KACP,YACC3B,GAAc,eAAeA,KAC7BC,GAAgB,iBAAiBA,KACjCE,GAAU,WAAqB,IAAXA,EAAkB,MAAQA,KAC9CG,GAAQ,QACRE,GAAU,eACVC,GAAkB,mBAAmBA,KACrCE,GAAa,cAAcA,KAC3BC,GAAQ,aAAaA,KACrBP,GAAa,kBAAkBA,OAC7BW,KACAQ,EACHpB,GAEJN,IAAAA,GAGZ,GAUA,SAASmB,EAAmBW,GACxB,OAAIC,EAAAA,aAAaD,GACNE,OAAOC,QAAQH,GAGnB,CAAC,CAAC,QAASA,GACtB"}