{"version":3,"file":"createOdysseyStyledComponent.cjs","names":["_styled","_interopRequireDefault","require","_react","_OdysseyDesignTokensContext","_jsxRuntime","e","__esModule","default","createOdysseyStyledComponent","tag","shouldForwardProp","styleArg","InternalStyled","styled","prop","InternalComponent","memo","forwardRef","OdysseyStyledComponent","props","componentReference","odysseyDesignTokens","useOdysseyDesignTokens","jsx","ref","exports"],"sources":["../../src/createOdysseyStyledComponent.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport type {\n  ComponentPropsWithoutRef,\n  ComponentRef,\n  ComponentType,\n  ElementType,\n} from \"react\";\n\nimport styled, { type CSSObject } from \"@emotion/styled\";\nimport { forwardRef, memo } from \"react\";\n\nimport {\n  type DesignTokens,\n  useOdysseyDesignTokens,\n} from \"./OdysseyDesignTokensContext.js\";\n\nexport type CreateOdysseyStyledComponentArgs<Tag extends ElementType> = {\n  shouldForwardProp?: (prop: string) => boolean;\n  tag: Tag;\n};\n\ntype OdysseyStyleFunction<\n  Tag extends ElementType,\n  StyleProps extends object,\n> = (\n  props: ComponentPropsWithoutRef<Tag> &\n    StyleProps & { odysseyDesignTokens: DesignTokens },\n) => CSSObject;\n\n/**\n * Creates a styled component that automatically receives Odyssey design tokens from context, eliminating the need to pass `odysseyDesignTokens` as a prop at every call site.\n *\n * @example Basic usage\n * ```tsx\n * const StyledCard = createOdysseyStyledComponent({ tag: \"div\" })(\n *   ({ odysseyDesignTokens }) => ({\n *     padding: odysseyDesignTokens.Spacing4,\n *     borderRadius: odysseyDesignTokens.BorderRadiusTight,\n *   })\n * );\n * // No need to call useOdysseyDesignTokens or pass tokens as a prop:\n * <StyledCard>content</StyledCard>\n * ```\n *\n * @example With custom styling props\n * ```tsx\n * const StyledButton = createOdysseyStyledComponent({\n *   tag: \"button\",\n *   shouldForwardProp: (prop) => prop !== \"isActive\",\n * })<{ isActive: boolean }>(({ odysseyDesignTokens, isActive }) => ({\n *   backgroundColor: isActive\n *     ? odysseyDesignTokens.PalettePrimaryMain\n *     : \"transparent\",\n * }));\n * <StyledButton isActive={true}>click me</StyledButton>\n * ```\n *\n * @example As a ref target\n * ```tsx\n * // The returned component forwards its ref to the underlying DOM node, so it\n * // can anchor a MUI Tooltip or Popper, or be focused and measured directly.\n * const buttonRef = useRef<HTMLButtonElement>(null);\n * <StyledButton isActive={false} ref={buttonRef} />\n * ```\n */\nexport const createOdysseyStyledComponent =\n  <Tag extends ElementType>({\n    tag,\n    shouldForwardProp,\n  }: CreateOdysseyStyledComponentArgs<Tag>) =>\n  <StyleProps extends object = Record<never, never>>(\n    styleArg: OdysseyStyleFunction<Tag, StyleProps> | CSSObject,\n  ) => {\n    type InternalProps = ComponentPropsWithoutRef<Tag> &\n      StyleProps & { odysseyDesignTokens: DesignTokens };\n\n    // Cast to ComponentType<InternalProps> so emotion's overload resolver sees a concrete component type — ElementType is too broad for styled() to pick the correct overload signature.\n    const InternalStyled = styled(tag as ComponentType<InternalProps>, {\n      shouldForwardProp: (prop) =>\n        prop !== \"odysseyDesignTokens\" && (shouldForwardProp?.(prop) ?? true),\n    })(typeof styleArg === \"function\" ? styleArg : () => styleArg);\n\n    // LibraryManagedAttributes wraps StyledComponent and cannot be satisfied with a generic Tag. Cast to ComponentType<any> for the render site;\n    // the public API is typed by the outer curried function.\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    const InternalComponent = InternalStyled as unknown as ComponentType<any>;\n\n    type PublicProps = ComponentPropsWithoutRef<Tag> & StyleProps;\n\n    // forwardRef, not a plain function component: emotion's styled(tag) already forwards a ref to the underlying DOM node, so without this wrapper passing one through, the ref is dropped and the DOM node is unreachable. MUI clones a Tooltip/Popper child with an injected ref to anchor the popper (childNode/anchorEl in @mui/material/Tooltip/Tooltip.js), so a component\n    // that cannot carry a ref silently fails to open on hover.\n    return memo(\n      forwardRef<ComponentRef<Tag>, PublicProps>(\n        function OdysseyStyledComponent(props, componentReference) {\n          const odysseyDesignTokens = useOdysseyDesignTokens();\n          return (\n            <InternalComponent\n              {...props}\n              odysseyDesignTokens={odysseyDesignTokens}\n              ref={componentReference}\n            />\n          );\n        },\n      ),\n    );\n  };\n"],"mappings":";;;;;;AAmBA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,2BAAA,GAAAF,OAAA;AAGyC,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAzBzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAkEO,MAAMG,4BAA4B,GACvCA,CAA0B;EACxBC,GAAG;EACHC;AACqC,CAAC,KAEtCC,QAA2D,IACxD;EAKH,MAAMC,cAAc,GAAG,IAAAC,eAAM,EAACJ,GAAG,EAAkC;IACjEC,iBAAiB,EAAGI,IAAI,IACtBA,IAAI,KAAK,qBAAqB,KAAKJ,iBAAiB,GAAGI,IAAI,CAAC,IAAI,IAAI;EACxE,CAAC,CAAC,CAAC,OAAOH,QAAQ,KAAK,UAAU,GAAGA,QAAQ,GAAG,MAAMA,QAAQ,CAAC;EAK9D,MAAMI,iBAAiB,GAAGH,cAA+C;EAMzE,OAAO,IAAAI,WAAI,EACT,IAAAC,iBAAU,EACR,SAASC,sBAAsBA,CAACC,KAAK,EAAEC,kBAAkB,EAAE;IACzD,MAAMC,mBAAmB,GAAG,IAAAC,kDAAsB,EAAC,CAAC;IACpD,OACE,IAAAlB,WAAA,CAAAmB,GAAA,EAACR,iBAAiB;MAAA,GACZI,KAAK;MACTE,mBAAmB,EAAEA,mBAAoB;MACzCG,GAAG,EAAEJ;IAAmB,CACzB,CAAC;EAEN,CACF,CACF,CAAC;AACH,CAAC;AAACK,OAAA,CAAAjB,4BAAA,GAAAA,4BAAA","ignoreList":[]}