From 9874ab2528b0ec2b08ea61df15b3fc2463fac1a5 Mon Sep 17 00:00:00 2001 From: kangminguu <131148077+kangminguu@users.noreply.github.com> Date: Tue, 31 Dec 2024 11:14:05 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20NotificationBadge=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?constants=20=EB=B6=84=EB=A6=AC=20(#458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationBadge/NotificationBadge.tsx | 60 +++---------------- src/components/Common/Toggle/Toggle.tsx | 2 +- .../LetterContainer/LetterContainer.tsx | 2 +- .../SelectSlider/SelectSlider.tsx | 2 +- src/constants/maxNotificationCount.ts | 1 + .../toggleVariant.ts} | 0 src/pages/Home/HomePage.tsx | 2 +- 7 files changed, 14 insertions(+), 55 deletions(-) create mode 100644 src/constants/maxNotificationCount.ts rename src/{components/Common/Toggle/constants.ts => constants/toggleVariant.ts} (100%) diff --git a/src/components/Common/NotificationBadge/NotificationBadge.tsx b/src/components/Common/NotificationBadge/NotificationBadge.tsx index 2a267c56..3b4bce09 100644 --- a/src/components/Common/NotificationBadge/NotificationBadge.tsx +++ b/src/components/Common/NotificationBadge/NotificationBadge.tsx @@ -1,61 +1,19 @@ +import { MAX_NOTIFICATION_COUNT } from '@/constants/maxNotificationCount'; import React from 'react'; -interface NotificationBadgeProps { - badgeType: 'basic' | 'dday'; +type NotificationBadgeProps = { count: number; -} +}; -export const NotificationBadge = ({ - badgeType, - count -}: NotificationBadgeProps) => { - const MAX_COUNT = 99; - const BaseStyle = - 'inline-flex items-center justify-center text-center align-text-middle'; - const styleMap = { - basic: 'bg-red-600 px-2 py-1 rounded-full text-white font-semibold', - dday: 'bg-yellow-400 px-2 py-1 rounded-sm text-white font-semibold' - }; +export const NotificationBadge = ({ count }: NotificationBadgeProps) => { + if (count <= 0) return null; // count가 0개 이하일 경우 렌더링하지 않습니다. - const renderContent = (badgeType: 'basic' | 'dday', count: number) => { - switch (badgeType) { - case 'basic': - if (count > MAX_COUNT) { - return ( - <> - - + - - 99 - > - ); - } - return ( - <> - {count} - - + - - > - ); - case 'dday': - return ( - <> - D - - - - - {count} - > - ); - default: - return null; - } - }; + const renderCount = + count > MAX_NOTIFICATION_COUNT ? `${MAX_NOTIFICATION_COUNT}+` : count; return ( -