Skip to content

Commit e013739

Browse files
zombieJclaude
andcommitted
refactor: extract content rendering logic in Notification component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b9a2a0e commit e013739

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

src/Notification.tsx

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,47 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
148148

149149
const mergedOffset = offset ?? offsetRef.current;
150150

151+
// ======================== Content =========================
152+
const titleNode =
153+
title !== undefined && title !== null ? (
154+
<div className={`${noticePrefixCls}-title`}>{title}</div>
155+
) : null;
156+
157+
const descNode =
158+
description !== undefined && description !== null ? (
159+
<div className={`${noticePrefixCls}-description`}>{description}</div>
160+
) : null;
161+
162+
let contentNode: React.ReactNode =
163+
titleNode !== null || descNode !== null ? (
164+
<>
165+
{titleNode}
166+
{descNode}
167+
</>
168+
) : null;
169+
170+
if (contentNode) {
171+
contentNode = (
172+
<div
173+
className={clsx(`${noticePrefixCls}-section`, classNames?.section)}
174+
style={styles?.section}
175+
>
176+
{contentNode}
177+
</div>
178+
);
179+
}
180+
181+
if (icon !== undefined && icon !== null) {
182+
contentNode = (
183+
<div className={classNames?.wrapper} style={styles?.wrapper}>
184+
<div className={clsx(`${noticePrefixCls}-icon`, classNames?.icon)} style={styles?.icon}>
185+
{icon}
186+
</div>
187+
{contentNode}
188+
</div>
189+
);
190+
}
191+
151192
// ========================= Render =========================
152193
return (
153194
<div
@@ -172,25 +213,7 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
172213
onMouseEnter={onInternalMouseEnter}
173214
onMouseLeave={onInternalMouseLeave}
174215
>
175-
<div className={classNames?.wrapper} style={styles?.wrapper}>
176-
{icon && (
177-
<div className={clsx(`${noticePrefixCls}-icon`, classNames?.icon)} style={styles?.icon}>
178-
{icon}
179-
</div>
180-
)}
181-
182-
<div
183-
className={clsx(`${noticePrefixCls}-section`, classNames?.section)}
184-
style={styles?.section}
185-
>
186-
{title !== undefined && title !== null && (
187-
<div className={`${noticePrefixCls}-title`}>{title}</div>
188-
)}
189-
{description !== undefined && description !== null && (
190-
<div className={`${noticePrefixCls}-description`}>{description}</div>
191-
)}
192-
</div>
193-
</div>
216+
{contentNode}
194217

195218
{mergedClosable && (
196219
<button

0 commit comments

Comments
 (0)