@shopify/shopify-app-remix
Version:
Shopify Remix - to simplify the building of Shopify Apps with Remix
1 lines • 2.37 kB
Source Map (JSON)
{"version":3,"file":"AppProxyLink.mjs","sources":["../../../../../../src/react/components/AppProxyLink/AppProxyLink.tsx"],"sourcesContent":["import {forwardRef, 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-remix/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 * @publicDocs\n */\nexport const AppProxyLink = forwardRef<HTMLAnchorElement, AppProxyLinkProps>(\n function AppProxyLink(props, ref) {\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} ref={ref}>\n {children}\n </a>\n );\n },\n);\n"],"names":["_jsx"],"mappings":";;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACI,MAAM,YAAY,GAAG,UAAU,CACpC,SAAS,YAAY,CAAC,KAAK,EAAE,GAAG,EAAA;AAC9B,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;IAE7C,QACEA,WAAG,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAM,UAAU,EAAE,GAAG,EAAE,GAAG,YACvD,QAAQ,EAAA,CACP;AAER,CAAC;;;;"}