Skip to content

Update TagCard.tsx #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 44 additions & 38 deletions components/cards/TagCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,65 @@ interface Props {
handleRemove?: () => void;
}

const TagCard = ({
const TagCard: React.FC<Props> = ({
_id,
name,
questions,
showCount,
compact,
remove,
isButton,
showCount = false,
compact = false,
remove = false,
isButton = false,
handleRemove,
}: Props) => {
}) => {
const iconClass = getDeviconClassName(name);

const handleClick = (e: React.MouseEvent) => {
e.preventDefault();
};
const handlePreventDefault = (e: React.MouseEvent) => e.preventDefault();

const Content = (
<>
<Badge className="subtle-medium background-light800_dark300 text-light400_light500 flex flex-row gap-2 rounded-md border-none px-4 py-2 uppercase">
<div className="flex-center space-x-2">
<i className={`${iconClass} text-sm`}></i>
<span>{name}</span>
</div>
const RenderBadge = () => (
<Badge className="subtle-medium background-light800_dark300 text-light400_light500 flex flex-row gap-2 rounded-md border-none px-4 py-2 uppercase">
<div className="flex-center space-x-2">
<i className={`${iconClass} text-sm`}></i>
<span>{name}</span>
</div>
{remove && handleRemove && (
<Image
src="/icons/close.svg"
width={12}
height={12}
alt="close icon"
className="cursor-pointer object-contain invert-0 dark:invert"
onClick={handleRemove}
/>
)}
</Badge>
);

{remove && (
<Image
src="/icons/close.svg"
width={12}
height={12}
alt="close icon"
className="cursor-pointer object-contain invert-0 dark:invert"
onClick={handleRemove}
/>
)}
</Badge>
const RenderQuestionsCount = () =>
showCount && (
<p className="small-medium text-dark500_light700">{questions}</p>
);

{showCount && (
<p className="small-medium text-dark500_light700">{questions}</p>
)}
const RenderContent = () => (
<>
<RenderBadge />
{RenderQuestionsCount()}
</>
);

if (compact) {
return isButton ? (
<button onClick={handleClick} className="flex justify-between gap-2">
{Content}
</button>
) : (
<Link href={ROUTES.TAGS(_id)} className="flex justify-between gap-2">
{Content}
</Link>
const Container = isButton ? "button" : Link;
const containerProps = isButton
? { onClick: handlePreventDefault }
: { href: ROUTES.TAGS(_id) };

return (
<Container {...containerProps} className="flex justify-between gap-2">
<RenderContent />
</Container>
);
}

return null; // Return a default value if `compact` is false and no additional cases are provided.
};

export default TagCard;