diff --git a/src/components/common/Header/NotificationContent.tsx b/src/components/common/Header/NotificationContent.tsx index 536ce94..a11840f 100644 --- a/src/components/common/Header/NotificationContent.tsx +++ b/src/components/common/Header/NotificationContent.tsx @@ -1,3 +1,5 @@ +import { truncateByChar } from '@/utils/stringUtils'; + // 알림 콘텐츠 파싱 결과 타입 interface ParsedNotification { type: 'parsed' | 'raw'; @@ -64,7 +66,9 @@ const NotificationContent = ({ content }: { content: string }) => { return (

{parsed.status}

-

{parsed.title}

+

+ {truncateByChar(parsed.title, 13)} +

({parsed.time})

diff --git a/src/utils/stringUtils.ts b/src/utils/stringUtils.ts new file mode 100644 index 0000000..b9c0651 --- /dev/null +++ b/src/utils/stringUtils.ts @@ -0,0 +1,20 @@ +export const truncateByChar = (text: string | undefined, limit = 13) => { + if (!text) { + return ''; + } + + const chars = Array.from(text); + let nonSpaceCount = 0; + const truncateIndex = chars.findIndex((char) => { + if (char !== ' ') { + nonSpaceCount++; + } + return nonSpaceCount > limit; + }); + + if (truncateIndex === -1) { + return text; + } + + return chars.slice(0, truncateIndex).join('') + '…'; +};