Skip to content

Commit

Permalink
Merge pull request #44 from CDCgov/jw/linkbutton
Browse files Browse the repository at this point in the history
Create LinkButton component
  • Loading branch information
jakewheeler authored Nov 7, 2024
2 parents 1df4f9f + a89140f commit 71dbdf3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 35 deletions.
57 changes: 57 additions & 0 deletions src/app/components/LinkButton/LinkButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Link, { LinkProps } from 'next/link';

interface LinkButtonProps extends LinkProps {
children: React.ReactNode;
variant: 'primary' | 'secondary';
disabled?: boolean;
}
export function LinkButton({
children,
variant,
href,
disabled = false,
...props
}: LinkButtonProps) {
if (variant === 'secondary') {
return (
<Link
href={href}
className="usa-button hover:bg-red items-center justify-start gap-2.5 rounded border-2 border-[#224a58] bg-white px-5 py-3 hover:border-2"
{...props}
>
<span className="text-center text-base font-bold leading-none text-[#224a58]">
{children}
</span>
</Link>
);
}

if (disabled) {
return <DisabledPrimaryLink>{children}</DisabledPrimaryLink>;
}

return (
<Link
href={href}
className="usa-button hover:bg-green self-end justify-self-start bg-[#224a58]"
{...props}
>
<span className="text-center text-base font-bold text-white">
{children}
</span>
</Link>
);
}

type DisabledLinkProps = Pick<LinkButtonProps, 'children'>;

function DisabledPrimaryLink({ children }: DisabledLinkProps) {
return (
<div
className="usa-button usa-button--disabled self-end justify-self-start bg-[#224a58]"
aria-disabled
>
<span className="text-base font-bold text-black">{children}</span>
</div>
);
}
11 changes: 0 additions & 11 deletions src/app/components/NavigationLink/NavigationLink.module.scss

This file was deleted.

9 changes: 4 additions & 5 deletions src/app/components/NavigationLink/NavigationLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import classNames from 'classnames';
import Link, { LinkProps } from 'next/link';
import { usePathname } from 'next/navigation';
import styles from './NavigationLink.module.scss';

interface NavigationLinkProps extends Pick<LinkProps, 'href' | 'onClick'> {
children: React.ReactNode;
Expand All @@ -12,13 +11,13 @@ export function NavigationLink({
children,
onClick,
}: NavigationLinkProps) {
const pathname = usePathname(); // Use usePathname hook to get the current path
const pathname = usePathname();
const isActive = pathname === href;
return (
<Link href={href} passHref className="usa-nav__link" onClick={onClick}>
<Link href={href} passHref onClick={onClick}>
<span
className={classNames(styles.navbarItemText, {
'navbar-item-active': isActive,
className={classNames('text-white', {
underline: isActive,
})}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/app/engage-with-us/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function Left() {
</Form>
<Button
type="submit"
className="mt-6 inline-flex h-11 items-center justify-start gap-2.5 rounded bg-[#224a58] px-5 py-3 text-right text-base font-bold text-white"
className="hover:bg-green mt-6 inline-flex h-11 items-center justify-start gap-2.5 rounded bg-[#224a58] px-5 py-3 text-right text-base font-bold text-white"
>
Send inquiry
</Button>
Expand Down
10 changes: 3 additions & 7 deletions src/app/our-products/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Image from 'next/image';
import Link from 'next/link';
import { basePath } from '../utils/constants';
import Hero from '../components/Hero/Hero';
import { ContentContainer } from '../components/ContentContainer/ContentContainer';
import { LinkButton } from '../components/LinkButton/LinkButton';

export default function OurProducts() {
return (
Expand Down Expand Up @@ -95,13 +95,9 @@ function ProductCard({
</p>
</div>
</div>
<Link
aria-disabled={linkToHref ? 'false' : 'true'}
href={linkToHref}
className="usa-button self-end justify-self-start bg-[#224a58]"
>
<LinkButton variant="primary" disabled={!linkToHref} href={linkToHref}>
{linkText}
</Link>
</LinkButton>
</div>
);
}
Expand Down
17 changes: 6 additions & 11 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { basePath } from './utils/constants';
import Carousel from './components/Carousel/Carousel';
import Hero from './components/Hero/Hero';
import { ContentContainer } from './components/ContentContainer/ContentContainer';
import Link from 'next/link';
import { LinkButton } from './components/LinkButton/LinkButton';

export default async function Home() {
return (
Expand Down Expand Up @@ -88,9 +88,9 @@ function SectionTwo() {
need for a direct connection, our products save jurisdictions time
and effort for case investigation and analysis.
</p>
<Link className="usa-button usa-button--active" href="/">
<LinkButton href="/our-products" variant="primary">
Find out more about our products
</Link>
</LinkButton>
</div>
<Image
className="max-h-[20rem] max-w-[30rem]"
Expand Down Expand Up @@ -141,14 +141,9 @@ function InvitationCta() {
Contact our team to learn more about how our products can help
improve your data workflows
</div>
<Link
href="/engage-with-us"
className="usa-btn inline-flex items-center justify-start gap-2.5 rounded border-2 border-[#224a58] bg-white px-5 py-3"
>
<span className="text-center text-base font-bold leading-none text-[#224a58]">
Engage with us
</span>
</Link>
<LinkButton href="/engage-with-us" variant="secondary">
Engage with us
</LinkButton>
</div>
</GridContainer>
</section>
Expand Down

0 comments on commit 71dbdf3

Please sign in to comment.