{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-link",
  "type": "registry:ui",
  "title": "react-tw/link.tsx",
  "description": "Carbon `Link` as a React + Tailwind component, the look of `<ui-link>`: link blue, underline on Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "class-variance-authority@0.7.1"
  ],
  "registryDependencies": [
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/link.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/link.tsx",
      "content": "import type { ComponentProps, ReactNode } from 'react';\nimport { cva } from 'class-variance-authority';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `Link` as a React + Tailwind component, the look of `<ui-link>`: link blue, underline on\n * hover / focus / press, the focus ring 1px outside on `:focus-visible`, sizes sm / md / lg, an\n * optional 16px icon 8px after the text, `inline` for links inside running text (always underlined,\n * no icon), `visited` colours visited links. `disabled` renders text with `role=\"link\"`.\n */\nexport const linkVariants = cva(\n    [\n        'inline-flex items-center text-link no-underline',\n        'rounded-[var(--ui-link-focus-radius,0px)] outline-[length:var(--ui-focus-width,2px)] outline-offset-1 outline-transparent transition-[color] duration-(--ui-duration-fast) ease-carbon',\n        '[&_svg]:size-4 [&_svg]:fill-current',\n        'forced-colors:text-[LinkText] forced-colors:focus-visible:outline-[Highlight]',\n    ],\n    {\n        variants: {\n            size: { sm: 'type-caption', md: 'type-body-sm', lg: 'type-body leading-[22px]! [&_svg]:size-5' },\n            inline: { true: 'inline underline', false: '' },\n            disabled: {\n                true: 'cursor-not-allowed text-ink-disabled forced-colors:text-[GrayText]',\n                false: 'hover:text-link-hover hover:underline focus-visible:underline focus-visible:outline-focus active:text-link active:underline',\n            },\n            visited: { true: '', false: '' },\n        },\n        compoundVariants: [{ visited: true, disabled: false, className: 'visited:text-link-visited visited:hover:text-link-hover' }],\n        defaultVariants: { size: 'md', inline: false, disabled: false, visited: false },\n    },\n);\n\nexport interface LinkProps extends ComponentProps<'a'> {\n    size?: 'sm' | 'md' | 'lg';\n    /** Inside a sentence: always underlined, no icon. */\n    inline?: boolean;\n    /** Show visited links in Carbon's visited colour. */\n    visited?: boolean;\n    disabled?: boolean;\n    /** Trailing icon, 8px after the text (16px, 20px for lg). */\n    icon?: ReactNode;\n}\n\nexport function Link({ size, inline, visited, disabled, icon, className, children, target, rel, ...rest }: Readonly<LinkProps>) {\n    const classes = cn(linkVariants({ size, inline, disabled: !!disabled, visited }), className);\n    const trailing = icon && !inline ? <span className=\"ms-2 inline-flex items-center\">{icon}</span> : null;\n    if (disabled) {\n        return (\n            <a /* NOSONAR: Carbon's disabled link: an <a> without href, so role=link with aria-disabled */ {...rest} href={undefined} role=\"link\" aria-disabled=\"true\" className={classes}>\n                {children}\n                {trailing}\n            </a>\n        );\n    }\n    return (\n        // tabIndex 0 (yours wins) as Carbon's cds-link: without it Safari neither focuses the link on click nor stops on it with Tab\n        <a /* NOSONAR: Safari focus, see the comment above */ tabIndex={rest.href ? 0 : undefined} {...rest} target={target} rel={rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined)} className={classes}>\n            {children}\n            {trailing}\n        </a>\n    );\n}\n"
    }
  ]
}
