{"version":3,"file":"AppProxyLink.mjs","sources":["../../../../../../src/react/components/AppProxyLink/AppProxyLink.tsx"],"sourcesContent":["import {useContext} from 'react';\n\nimport {AppProxyProviderContext} from '../AppProxyProvider';\n\nexport interface AppProxyLinkProps extends React.DetailedHTMLProps<\n  React.AnchorHTMLAttributes<HTMLAnchorElement>,\n  HTMLAnchorElement\n> {\n  href: string;\n}\n\n/**\n * Sets up an `<a />` HTML element that works when rendered behind an app proxy.\n *\n * Supports any properties accepted by the `<a />` HTML element.\n *\n * @example\n * <caption>Link to a different route.</caption>\n * <description>Use an `AppProxyLink` within an `AppProxyProvider` to link to a different proxied route.</description>\n * ```ts\n * // /app/routes/**\\/*.ts\n * import {authenticate} from '~/shopify.server';\n * import {AppProxyProvider, AppProxyLink} from '@shopify/shopify-app-react-router/react';\n *\n * export async function loader({ request }) {\n *   await authenticate.public.appProxy(request);\n *\n *   return json({ appUrl: process.env.SHOPIFY_APP_URL });\n * }\n *\n * export default function App() {\n *   const { appUrl } = useLoaderData();\n *\n *   return (\n *     <AppProxyProvider appUrl={appUrl}>\n *       <AppProxyLink href=\"/other-proxy-route\">Link to another route</AppProxyLink>\n *     </AppProxyProvider>\n *   );\n * }\n * ```\n */\nexport function AppProxyLink(props: AppProxyLinkProps) {\n  const context = useContext(AppProxyProviderContext);\n\n  if (!context) {\n    throw new Error(\n      'AppProxyLink must be used within an AppProxyProvider component',\n    );\n  }\n\n  const {children, href, ...otherProps} = props;\n\n  return (\n    <a href={context.formatUrl(href)} {...otherProps}>\n      {children}\n    </a>\n  );\n}\n"],"names":["_jsx"],"mappings":";;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,YAAY,CAAC,KAAwB,EAAA;AACnD,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,uBAAuB,CAAC;IAEnD,IAAI,CAAC,OAAO,EAAE;AACZ,QAAA,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE;IACH;IAEA,MAAM,EAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,UAAU,EAAC,GAAG,KAAK;AAE7C,IAAA,QACEA,GAAA,CAAA,GAAA,EAAA,EAAG,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAM,UAAU,EAAA,QAAA,EAC7C,QAAQ,EAAA,CACP;AAER;;;;"}