Skip to content

Commit 2c26aae

Browse files
committed
refactor: extract notification item style fillers
1 parent e786276 commit 2c26aae

1 file changed

Lines changed: 40 additions & 35 deletions

File tree

src/NotificationList/index.tsx

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,40 @@ export interface NotificationListProps {
4040
onAllRemoved?: (placement: Placement) => void;
4141
}
4242

43+
const noticeSlotKeys = ['wrapper', 'root', 'icon', 'section', 'close', 'progress'] as const;
44+
45+
function fillClassNames(
46+
classNames?: NotificationClassNames,
47+
configClassNames?: NotificationClassNames,
48+
extraClassNames?: NotificationClassNames,
49+
): NotificationClassNames {
50+
return noticeSlotKeys.reduce<NotificationClassNames>((mergedClassNames, key) => {
51+
mergedClassNames[key] = clsx(
52+
classNames?.[key],
53+
configClassNames?.[key],
54+
extraClassNames?.[key],
55+
);
56+
57+
return mergedClassNames;
58+
}, {});
59+
}
60+
61+
function fillStyles(
62+
styles?: NotificationStyles,
63+
configStyles?: NotificationStyles,
64+
extraStyles?: NotificationStyles,
65+
): NotificationStyles {
66+
return noticeSlotKeys.reduce<NotificationStyles>((mergedStyles, key) => {
67+
mergedStyles[key] = {
68+
...styles?.[key],
69+
...configStyles?.[key],
70+
...extraStyles?.[key],
71+
};
72+
73+
return mergedStyles;
74+
}, {});
75+
}
76+
4377
interface NotificationListItemProps {
4478
config: NotificationListConfig;
4579
components?: ComponentsType;
@@ -101,41 +135,12 @@ const NotificationListItem: React.FC<NotificationListItemProps> = (props) => {
101135
stackInThreshold={stackInThreshold}
102136
className={clsx(contextClassNames?.notice, config.className)}
103137
style={config.style}
104-
classNames={{
105-
wrapper: clsx(classNames?.wrapper, config.classNames?.wrapper),
106-
root: clsx(classNames?.root, config.classNames?.root, motionClassName),
107-
icon: clsx(classNames?.icon, config.classNames?.icon),
108-
section: clsx(classNames?.section, config.classNames?.section),
109-
close: clsx(classNames?.close, config.classNames?.close),
110-
progress: clsx(classNames?.progress, config.classNames?.progress),
111-
}}
112-
styles={{
113-
wrapper: {
114-
...styles?.wrapper,
115-
...config.styles?.wrapper,
116-
},
117-
root: {
118-
...styles?.root,
119-
...config.styles?.root,
120-
...motionStyle,
121-
},
122-
icon: {
123-
...styles?.icon,
124-
...config.styles?.icon,
125-
},
126-
section: {
127-
...styles?.section,
128-
...config.styles?.section,
129-
},
130-
close: {
131-
...styles?.close,
132-
...config.styles?.close,
133-
},
134-
progress: {
135-
...styles?.progress,
136-
...config.styles?.progress,
137-
},
138-
}}
138+
classNames={fillClassNames(classNames, config.classNames, {
139+
root: motionClassName,
140+
})}
141+
styles={fillStyles(styles, config.styles, {
142+
root: motionStyle,
143+
})}
139144
components={{
140145
...components,
141146
...config.components,

0 commit comments

Comments
 (0)