Skip to content

Commit

Permalink
refactor: Conditionally render component based on href prop in Button
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixpereira committed Dec 27, 2023
1 parent f6f7a4d commit 964ecdf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import React from 'react';
interface ButtonProps {
children: React.ReactNode;
colour: string;
href: string;
href?: string;
}

const Button = ({ children, colour, href }: ButtonProps) => {
const isAnchor = !!href;
const Component = isAnchor ? 'a' : 'button';

return (
<FancyRectangle colour="black" offset="4" filled={true}>
<a
href={href}
<Component
href={isAnchor ? href : undefined}
className={`whitespace-nowrap py-4 px-12 md:py-1 md:px-2 lg:py-2 lg:px-6 border-2 border-black font-bold hover:bg-yellow transition-colors duration-300 ${bgColours[colour]}`}
>
{children}
</a>
</Component>
</FancyRectangle>
);
};
Expand Down

0 comments on commit 964ecdf

Please sign in to comment.