Skip to content

Commit 1b8edb1

Browse files
committed
refactor: colocate stack config and add list content semantics
1 parent dab1056 commit 1b8edb1

5 files changed

Lines changed: 46 additions & 13 deletions

File tree

src/NotificationList/index.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@ import { useComposeRef } from '@rc-component/util/lib/ref';
44
import { clsx } from 'clsx';
55
import * as React from 'react';
66
import useListPosition from '../hooks/useListPosition';
7-
import useStack from '../hooks/useStack';
8-
import type { StackConfig } from '../interface';
7+
import useStack, { type StackConfig } from '../hooks/useStack';
98
import Notification, {
109
type ComponentsType,
11-
type NotificationClassNames,
10+
type NotificationClassNames as NoticeClassNames,
1211
type NotificationProps,
13-
type NotificationStyles,
12+
type NotificationStyles as NoticeStyles,
1413
} from '../Notification';
1514
import { NotificationContext, type NotificationContextProps } from '../NotificationProvider';
1615
import Content from './Content';
1716

1817
export type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight';
19-
export type { StackConfig } from '../interface';
18+
export type { StackConfig } from '../hooks/useStack';
2019

2120
export interface NotificationListConfig extends Omit<NotificationProps, 'prefixCls'> {
2221
key: React.Key;
2322
placement?: Placement;
2423
times?: number;
2524
}
2625

26+
export interface NotificationClassNames extends NoticeClassNames {
27+
listContent?: string;
28+
}
29+
30+
export interface NotificationStyles extends NoticeStyles {
31+
listContent?: React.CSSProperties;
32+
}
33+
2734
export interface NotificationListProps {
2835
configList?: NotificationListConfig[];
2936
prefixCls?: string;
@@ -244,7 +251,13 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
244251
}}
245252
style={style}
246253
>
247-
<Content listPrefixCls={listPrefixCls} height={totalHeight} ref={contentRef}>
254+
<Content
255+
listPrefixCls={listPrefixCls}
256+
height={totalHeight}
257+
className={classNames?.listContent}
258+
style={styles?.listContent}
259+
ref={contentRef}
260+
>
248261
<CSSMotionList
249262
component={false}
250263
keys={keys}
@@ -292,4 +305,3 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
292305
};
293306

294307
export default NotificationList;
295-
export type { NotificationClassNames, NotificationStyles } from '../Notification';

src/hooks/useListPosition/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import type { StackConfig } from '../../interface';
2+
import type { StackConfig } from '../useStack';
33
import useSizes from './useSizes';
44

55
/**

src/hooks/useStack.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { StackConfig } from '../interface';
1+
export interface StackConfig {
2+
threshold?: number;
3+
offset?: number;
4+
}
25

36
const DEFAULT_OFFSET = 8;
47
const DEFAULT_THRESHOLD = 3;

src/interface.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/index.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,28 @@ describe('Notification.Basic', () => {
653653
expect(document.querySelector('.bamboo-topRight')).toBeTruthy();
654654
});
655655

656+
it('should listContent styles and classNames work', () => {
657+
const { instance } = renderDemo({
658+
classNames: {
659+
listContent: 'bamboo',
660+
},
661+
styles: {
662+
listContent: {
663+
content: 'little',
664+
},
665+
},
666+
});
667+
668+
act(() => {
669+
instance.open({});
670+
});
671+
672+
expect(document.querySelector('.rc-notification-list-content')).toHaveStyle({
673+
content: 'little',
674+
});
675+
expect(document.querySelector('.rc-notification-list-content')).toHaveClass('bamboo');
676+
});
677+
656678
it('placement', () => {
657679
const { instance } = renderDemo();
658680

0 commit comments

Comments
 (0)