From 574b8452d254ff40f681002dd05c503affa288a0 Mon Sep 17 00:00:00 2001 From: Irham Rahmat Saleh <138499395+Irhamrahmatsaleh@users.noreply.github.com> Date: Mon, 25 Nov 2024 19:30:53 +0700 Subject: [PATCH] Update TagCard.tsx --- components/cards/TagCard.tsx | 82 +++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/components/cards/TagCard.tsx b/components/cards/TagCard.tsx index ea345e5..6e84555 100644 --- a/components/cards/TagCard.tsx +++ b/components/cards/TagCard.tsx @@ -18,59 +18,65 @@ interface Props { handleRemove?: () => void; } -const TagCard = ({ +const TagCard: React.FC = ({ _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 = ( - <> - -
- - {name} -
+ const RenderBadge = () => ( + +
+ + {name} +
+ {remove && handleRemove && ( + close icon + )} +
+ ); - {remove && ( - close icon - )} -
+ const RenderQuestionsCount = () => + showCount && ( +

{questions}

+ ); - {showCount && ( -

{questions}

- )} + const RenderContent = () => ( + <> + + {RenderQuestionsCount()} ); if (compact) { - return isButton ? ( - - ) : ( - - {Content} - + const Container = isButton ? "button" : Link; + const containerProps = isButton + ? { onClick: handlePreventDefault } + : { href: ROUTES.TAGS(_id) }; + + return ( + + + ); } + + return null; // Return a default value if `compact` is false and no additional cases are provided. }; export default TagCard;