Skip to content

Commit f1c39ea

Browse files
authored
Merge 30c140d into fb157e9
2 parents fb157e9 + 30c140d commit f1c39ea

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

src/NoticeList.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ const NoticeList: FC<NoticeListProps> = (props) => {
9696
nodeRef,
9797
) => {
9898
const { key, times } = config as InnerOpenConfig;
99-
const { className: configClassName, style: configStyle } = config as NoticeConfig;
99+
const {
100+
className: configClassName,
101+
style: configStyle,
102+
classNames: configClassNames,
103+
styles: configStyles,
104+
...restConfig
105+
} = config as NoticeConfig;
100106
const dataIndex = keys.findIndex((item) => item.key === key);
101107

102108
// If dataIndex is -1, that means this notice has been removed in data, but still in dom
@@ -132,19 +138,23 @@ const NoticeList: FC<NoticeListProps> = (props) => {
132138
return (
133139
<div
134140
ref={nodeRef}
135-
className={clsx(`${prefixCls}-notice-wrapper`, motionClassName)}
141+
className={clsx(
142+
`${prefixCls}-notice-wrapper`,
143+
motionClassName,
144+
configClassNames?.wrapper,
145+
)}
136146
style={{
137147
...motionStyle,
138148
...stackStyle,
139-
...configStyle,
149+
...configStyles?.wrapper,
140150
}}
141151
onMouseEnter={() =>
142152
setHoverKeys((prev) => (prev.includes(key) ? prev : [...prev, key]))
143153
}
144154
onMouseLeave={() => setHoverKeys((prev) => prev.filter((k) => k !== key))}
145155
>
146156
<Notice
147-
{...config}
157+
{...restConfig}
148158
ref={(node) => {
149159
if (dataIndex > -1) {
150160
dictRef.current[key] = node;
@@ -153,7 +163,10 @@ const NoticeList: FC<NoticeListProps> = (props) => {
153163
}
154164
}}
155165
prefixCls={prefixCls}
166+
classNames={configClassNames}
167+
styles={configStyles}
156168
className={clsx(configClassName, ctxCls?.notice)}
169+
style={configStyle}
157170
times={times}
158171
key={key}
159172
eventKey={key}

src/interface.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import type React from 'react';
22

33
export type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight';
44

5+
type NoticeSemanticProps = 'wrapper';
6+
57
export interface NoticeConfig {
68
content?: React.ReactNode;
79
duration?: number | null;
810
closeIcon?: React.ReactNode;
911
closable?: boolean;
1012
className?: string;
1113
style?: React.CSSProperties;
14+
classNames?: {
15+
[key in NoticeSemanticProps]?: string;
16+
};
17+
styles?: {
18+
[key in NoticeSemanticProps]?: React.CSSProperties;
19+
};
1220
/** @private Internal usage. Do not override in your code */
1321
props?: React.HTMLAttributes<HTMLDivElement> & Record<string, any>;
1422

tests/index.test.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,46 @@ describe('Notification.Basic', () => {
493493
});
494494
});
495495

496+
it('should open style and className work', () => {
497+
const { instance } = renderDemo();
498+
499+
act(() => {
500+
instance.open({
501+
style: {
502+
content: 'little',
503+
},
504+
className: 'bamboo',
505+
});
506+
});
507+
508+
expect(document.querySelector('.rc-notification-notice')).toHaveStyle({
509+
content: 'little',
510+
});
511+
expect(document.querySelector('.rc-notification-notice')).toHaveClass('bamboo');
512+
});
513+
514+
it('should open styles and classNames work', () => {
515+
const { instance } = renderDemo();
516+
517+
act(() => {
518+
instance.open({
519+
styles: {
520+
wrapper: {
521+
content: 'little',
522+
},
523+
},
524+
classNames: {
525+
wrapper: 'bamboo',
526+
},
527+
});
528+
});
529+
530+
expect(document.querySelector('.rc-notification-notice-wrapper')).toHaveStyle({
531+
content: 'little',
532+
});
533+
expect(document.querySelector('.rc-notification-notice-wrapper')).toHaveClass('bamboo');
534+
});
535+
496536
it('should className work', () => {
497537
const { instance } = renderDemo({
498538
className: (placement) => `bamboo-${placement}`,

0 commit comments

Comments
 (0)