{"version":3,"file":"Link.mjs","sources":["../../../src/components/Link/Link.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React, { forwardRef } from 'react';\nimport { assertEdsUsage } from '../../util/logging';\nimport type { Emphasis, Size } from '../../util/variant-types';\nimport {\n  hasSlotContent,\n  IconSlot,\n  useSemanticIcon,\n  type SemanticIconName,\n} from '../Icon';\n\nimport styles from './Link.module.css';\n\nexport type LinkProps<ExtendedElement = unknown> =\n  React.AnchorHTMLAttributes<HTMLAnchorElement> & {\n    // Component API\n    /**\n     * Component used to render the element. Meant to support interaction with framework navigation libraries.\n     *\n     * **Default is `\"a\"`**.\n     */\n    as?: string | React.ElementType;\n    /**\n     * The link contents or label. Using ReactNode to support customized text treatments\n     */\n    children: React.ReactNode;\n    // Design API\n    /**\n     * Where `Link` sits alongside other text and content:\n     *\n     * * **inline** - Inline link inherits the text size/color established within the `<p>` or other tag they are embedded in.\n     * * **standalone** - Users can choose from the available sizes, select variants, and add a trailing icon.\n     *\n     * **Default is `\"inline\"`**.\n     *\n     * ----\n     *\n     * **Note**: This will only apply when `\"standalone\"` is used\n     */\n    context?: 'inline' | 'standalone';\n    /**\n     * The role of the trailing icon on the link (when `context` is `\"standalone\"`)\n     *\n     * This names which of two roles the link is filling rather than picking a glyph:\n     * `\"open-in-new\"` marks a link that leaves the site, and `\"forward\"` a low-emphasis\n     * link that carries the reader onward. Both glyphs come from `IconProvider`, so an app\n     * changes either one everywhere at once.\n     */\n    icon?: Extract<SemanticIconName, 'forward' | 'open-in-new'>;\n    /**\n     * Extra or lowered colors added to a link\n     */\n    emphasis?: Emphasis | 'default';\n    /**\n     * Whether to render the link text at bold weight. Applies in both contexts, and holds\n     * across every emphasis, variant, and state.\n     *\n     * **Default is `false`**.\n     */\n    isBold?: boolean;\n    /**\n     * The size of the link (when its context is `\"standalone\"`).\n     *\n     * ----\n     *\n     * **Note**: This will only apply when `\"standalone\"` is used\n     */\n    size?: Extract<Size, 'xs' | 'sm' | 'md' | 'lg' | 'xl'>;\n    /**\n     * The variant treatment for **standalone** links (use \"inverse\" on dark backgrounds).\n     *\n     * **Default is `\"default\"`**.\n     *\n     * ----\n     *\n     * **Note**: This will only apply when `\"standalone\"` is used\n     */\n    variant?: 'default' | 'inverse';\n  } & ExtendedElement;\n\n/**\n * ## Usage\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Inline | Embedded in body text, styled with an underline. | Reference external docs, \"Learn more\" links, citing sources. |\n * | Standalone | Appears on its own, often in navs or action areas. | Footer links, header navigation, CTA-style links (when not using a button). |\n * | External | Opens to a different domain or website; often includes an icon or notice. | Links to external sites, third-party tools, privacy policy or support articles. |\n * | Internal navigation | Navigates within the app or website (SPA routing or anchor-based). | Page-to-page navigation, in-page jump links. |\n * | Breadcrumb | Represents a step in a navigation trail. | Hierarchical navigation, backtracking in nested pages. |\n * | Disabled | Styled like a link but non-interactive. | Unavailable destinations, permission-based restrictions. |\n *\n * ### Best Practices\n *\n * * **Do** use links primarily to support navigation, directing users to another page or a different portion of the same page.\n * * **Don't** use links as actions that change data or state, or that trigger a high-emphasis action; use `Button` instead.\n * * **Do** display the external (\"open-in-new\") icon when the link text needs support to convey an external domain.\n * * **Don't** use other icons to represent an external link.\n * * **Do** display an underline on inline links to reinforce interactivity and accessibility.\n * * **Don't** use the low emphasis variant in inline contexts, as it can fail to convey interactivity.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Use a meaningful, descriptive label that clearly indicates the link's destination.\n * * Make sure the link reflects the content people will find at the destination.\n * * Use \"Learn more\" for links to more information, ensuring the preceding content provides context.\n *\n * ### Don'ts\n *\n * * Don't use generic phrases like \"click here\".\n * * Don't include leading spaces or end punctuation within the link.\n * * Don't use the same link text for different destinations on the same page.\n * * Don't use excessively long link text.\n */\nexport const Link = forwardRef<HTMLAnchorElement, LinkProps>(\n  (\n    {\n      as: Component = 'a',\n      children,\n      className,\n      context,\n      emphasis = 'default',\n      icon,\n      isBold = false,\n      size,\n      variant = 'default',\n      ...other\n    },\n    ref,\n  ) => {\n    const iconSize = size && (['xl', 'lg'].includes(size) ? '24px' : '16px');\n\n    // TODO(next-major): remove, with the assert below. Before v19 this prop took the glyph\n    // name `'chevron-right'`; it now names the `forward` role. The codemod rewrites the\n    // value, but untyped code can still pass the old one, where it matches no role, resolves\n    // to nothing, and leaves the link with its spacing and no icon. Treated as `forward`\n    // until then, so the affordance survives.\n    const isLegacyChevron = (icon as string) === 'chevron-right';\n\n    // TODO(next-major): remove.\n    assertEdsUsage(\n      [isLegacyChevron],\n      'Link no longer takes `icon=\"chevron-right\"`. That glyph is now the `forward` role, so pass `icon=\"forward\"` and set `forward` on an `IconProvider` to change it. Run `npx eds-migrate 18-to-19` to update the value.',\n    );\n\n    // The role the link is actually filling, which is what the rules below are about. The\n    // raw prop is not: a legacy `chevron-right` fills `forward`, and checking the prop let\n    // that slip past the low-emphasis rule while still drawing the affordance.\n    const role = isLegacyChevron ? 'forward' : icon;\n\n    const iconToUse = useSemanticIcon(role);\n\n    // One condition for the icon and the space it sits in, so neither can outlive the other.\n    // `iconToUse` is empty when no `icon` was given, and when one names something that is\n    // not a role at all — which untyped code can still pass. A role that is real always\n    // draws something, since `IconProvider` rejects an entry that would not.\n    const showsIcon = context === 'standalone' && hasSlotContent(iconToUse);\n\n    const componentClassName = clsx(\n      className,\n      styles['link'],\n      context && styles[`link--context-${context}`],\n      emphasis && styles[`link--emphasis-${emphasis}`],\n      isBold && styles['link--isBold'],\n      size && styles[`link--size-${size}`],\n      variant === 'inverse' && styles[`link--variant-${variant}`],\n    );\n\n    assertEdsUsage(\n      [context === 'inline' && emphasis === 'low'],\n      'Inline links cannot have \"low\" emphasis',\n    );\n\n    assertEdsUsage(\n      [context === 'inline' && !!icon],\n      'Inline links cannot show icons',\n    );\n\n    assertEdsUsage(\n      [context === 'inline' && variant === 'inverse'],\n      'Variant can only be used when context is \"standalone\"',\n    );\n\n    assertEdsUsage(\n      [context === 'inline' && typeof size !== 'undefined'],\n      'Size can only be used when context is \"standalone\"',\n    );\n\n    assertEdsUsage(\n      [role === 'forward' && emphasis !== 'low'],\n      'Icon \"forward\" only allowed when emphasis is \"low\"',\n    );\n\n    return (\n      <Component className={componentClassName} ref={ref} {...other}>\n        {children}\n        {showsIcon && (\n          <IconSlot\n            className={styles['link__icon']}\n            content={iconToUse}\n            purpose=\"decorative\"\n            size={iconSize}\n          />\n        )}\n      </Component>\n    );\n  },\n);\n\nLink.displayName = 'Link';\n"],"names":["React"],"mappings":";;;;;;;;AAgFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;AACI,MAAM,IAAI,GAAG,UAAU,CAC5B,CACE,EACE,EAAE,EAAE,SAAS,GAAG,GAAG,EACnB,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,GAAG,SAAS,EACpB,IAAI,EACJ,MAAM,GAAG,KAAK,EACd,IAAI,EACJ,OAAO,GAAG,SAAS,EACnB,GAAG,KAAK,EACT,EACD,GAAG,KACD;IACF,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC;;;;;;AAOxE,IAAA,MAAM,eAAe,GAAI,IAAe,KAAK,eAAe;;AAG5D,IAAA,cAAc,CACZ,CAAC,eAAe,CAAC,EACjB,sNAAsN,CACvN;;;;IAKD,MAAM,IAAI,GAAG,eAAe,GAAG,SAAS,GAAG,IAAI;AAE/C,IAAA,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC;;;;;IAMvC,MAAM,SAAS,GAAG,OAAO,KAAK,YAAY,IAAI,cAAc,CAAC,SAAS,CAAC;IAEvE,MAAM,kBAAkB,GAAG,IAAI,CAC7B,SAAS,EACT,MAAM,CAAC,MAAM,CAAC,EACd,OAAO,IAAI,MAAM,CAAC,CAAA,cAAA,EAAiB,OAAO,CAAA,CAAE,CAAC,EAC7C,QAAQ,IAAI,MAAM,CAAC,C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