-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor : NotificationBadge 컴포넌트 수정 및 constants 분리 (#458)
- Loading branch information
1 parent
e0187cf
commit 9874ab2
Showing
7 changed files
with
14 additions
and
55 deletions.
There are no files selected for viewing
60 changes: 9 additions & 51 deletions
60
src/components/Common/NotificationBadge/NotificationBadge.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<span style={{ position: 'relative', top: '-1px' }}> | ||
+ | ||
</span> | ||
99 | ||
</> | ||
); | ||
} | ||
return ( | ||
<> | ||
{count} | ||
<span style={{ position: 'relative', top: '-1px' }}> | ||
+ | ||
</span> | ||
</> | ||
); | ||
case 'dday': | ||
return ( | ||
<> | ||
D | ||
<span style={{ position: 'relative', top: '-1px' }}> | ||
- | ||
</span> | ||
{count} | ||
</> | ||
); | ||
default: | ||
return null; | ||
} | ||
}; | ||
const renderCount = | ||
count > MAX_NOTIFICATION_COUNT ? `${MAX_NOTIFICATION_COUNT}+` : count; | ||
|
||
return ( | ||
<div className={`${BaseStyle} ${styleMap[badgeType]}`}> | ||
{renderContent(badgeType, count)} | ||
<div className="absolute bg-[#FF6868] rounded-full text-white text-body1 flex-center h-6 px-3 leading-none"> | ||
{renderCount} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MAX_NOTIFICATION_COUNT = 99; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters