Download react-spring/docs/app/components/Buttons/NavButton.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Buttons/NavButton.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Buttons/NavButton.tsx
-
curl -L -o NavButton.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Buttons/NavButton.tsx
1.77 kB
| import { | |
| ForwardRefExoticComponent, | |
| MouseEventHandler, | |
| RefAttributes, | |
| } from 'react' | |
| import { Link, useLocation } from '@remix-run/react' | |
| import * as Toolbar from '@radix-ui/react-toolbar' | |
| import { IconProps } from 'phosphor-react' | |
| import { useIsDarkTheme } from '~/hooks/useIsDarkTheme' | |
| import { navAnchor, navIconLabel, navIconWrapper } from './NavButton.css' | |
| export interface NavigationButtonProps { | |
| title: string | |
| href: string | |
| Icon: ForwardRefExoticComponent<IconProps & RefAttributes<SVGSVGElement>> | |
| isExternal?: boolean | |
| showLabel?: boolean | |
| onClick?: MouseEventHandler<HTMLAnchorElement> | |
| } | |
| export const NavigationButton = ({ | |
| Icon, | |
| title, | |
| href, | |
| isExternal, | |
| showLabel = false, | |
| onClick, | |
| }: NavigationButtonProps) => { | |
| const { pathname } = useLocation() | |
| const isRoute = (href !== '/' && pathname.includes(href)) || pathname === href | |
| const handleClick: MouseEventHandler<HTMLAnchorElement> = e => { | |
| if (onClick) { | |
| onClick(e) | |
| } | |
| } | |
| const externalLinkProps = isExternal | |
| ? { | |
| rel: 'noopener noreferrer', | |
| target: '_blank', | |
| } | |
| : {} | |
| const isDarkMode = useIsDarkTheme() | |
| /** | |
| * TODO: refactor to use `Link` component | |
| */ | |
| return ( | |
| <Toolbar.Link | |
| onClick={handleClick} | |
| href={href} | |
| className={navAnchor({ | |
| active: isRoute, | |
| variant: showLabel ? 'withLabel' : undefined, | |
| })} | |
| asChild | |
| {...externalLinkProps} | |
| > | |
| <Link to={href}> | |
| <span | |
| className={navIconWrapper({ | |
| isRoute, | |
| })} | |
| > | |
| <Icon size={20} weight={isDarkMode ? 'light' : 'regular'} /> | |
| {showLabel ? <span className={navIconLabel}>{title}</span> : null} | |
| </span> | |
| </Link> | |
| </Toolbar.Link> | |
| ) | |
| } | |