Skip to content

Commit

Permalink
OPHJOD-313: Add href prop to ColorCard component
Browse files Browse the repository at this point in the history
  • Loading branch information
ketsappi authored and sauanto committed Apr 8, 2024
1 parent 926fdc8 commit 42b7ac3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/components/ColorCard/ColorCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ describe('ColorCard', () => {

it('renders ColorCard with a link when actionContent is provided', () => {
render(
<ColorCard title={title} content={content} actionContent={actionContent} backgroundColor={backgroundColor} />,
<ColorCard
title={title}
content={content}
actionContent={actionContent}
backgroundColor={backgroundColor}
href="/"
/>,
);

// Assert ColorCard is wrapped in a link
Expand All @@ -47,7 +53,7 @@ describe('ColorCard', () => {
});

it('renders ColorCard with a link when actionContent is not provided', () => {
render(<ColorCard title={title} content={content} backgroundColor={backgroundColor} />);
render(<ColorCard title={title} content={content} backgroundColor={backgroundColor} href="/" />);

// Assert ColorCard is wrapped in a link
const linkElement = screen.getByRole('link');
Expand Down
20 changes: 14 additions & 6 deletions lib/components/ColorCard/ColorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ export interface ColorCardProps {
actionContent?: string;
/** Background color of the card */
backgroundColor?: string;
/** Link to page */
href?: string;
}

export const ColorCard = ({ title, content, actionContent, backgroundColor = '#444BACF2' }: ColorCardProps) => (
export const ColorCard = ({ title, content, actionContent, backgroundColor = '#444BACF2', href }: ColorCardProps) => (
<>
{actionContent ? (
<BaseCard title={title} content={content} actionContent={actionContent} backgroundColor={backgroundColor} />
<BaseCard
title={title}
content={content}
actionContent={actionContent}
backgroundColor={backgroundColor}
href={href}
/>
) : (
<a href="/" className="flex rounded-[28px] outline-none transition-transform hover:scale-105 focus:scale-105">
<BaseCard title={title} content={content} actionContent={actionContent} backgroundColor={backgroundColor} />
<a href={href} className="flex rounded-[28px] outline-none transition-transform hover:scale-105 focus:scale-105">
<BaseCard title={title} content={content} backgroundColor={backgroundColor} />
</a>
)}
</>
);

const BaseCard = ({ title, content, actionContent, backgroundColor }: ColorCardProps) => {
const BaseCard = ({ title, content, actionContent, backgroundColor, href }: ColorCardProps) => {
const Heading = actionContent ? 'h1' : 'h2';
return (
<div
Expand All @@ -32,7 +40,7 @@ const BaseCard = ({ title, content, actionContent, backgroundColor }: ColorCardP
{content && <p>{content}</p>}
{actionContent ? (
<a
href="/"
href={href}
className="absolute bottom-0 right-[32px] translate-y-2/4 rounded-[40px] outline-none transition-transform hover:scale-105 focus:scale-105"
>
<div
Expand Down

0 comments on commit 42b7ac3

Please sign in to comment.