Download react-spring/docs/app/components/Text/Anchor.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 968 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Text/Anchor.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Text/Anchor.tsx
-
curl -L -o Anchor.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Text/Anchor.tsx
968 Bytes
| import { ReactNode } from 'react' | |
| import { Link } from '@remix-run/react' | |
| import { isValidHttpUrl } from '~/helpers/strings' | |
| import clsx from 'clsx' | |
| import { anchor } from './Anchor.css' | |
| export interface AnchorProps { | |
| href: string | |
| children: ReactNode | |
| className?: string | |
| onClick?: React.MouseEventHandler<HTMLAnchorElement> | |
| } | |
| export const Anchor = ({ href, children, className, onClick }: AnchorProps) => { | |
| const isExternal = isValidHttpUrl(href) | |
| const handleClick: React.MouseEventHandler<HTMLAnchorElement> = e => { | |
| if (onClick) { | |
| onClick(e) | |
| } | |
| } | |
| if (isExternal) { | |
| return ( | |
| <a | |
| className={clsx(anchor, className)} | |
| href={href} | |
| rel="noopener noreferrer" | |
| target="_blank" | |
| onClick={handleClick} | |
| > | |
| {children} | |
| </a> | |
| ) | |
| } else { | |
| return ( | |
| <Link className={clsx(anchor, className)} onClick={handleClick} to={href}> | |
| {children} | |
| </Link> | |
| ) | |
| } | |
| } | |