Skip to content

Commit 362793d

Browse files
zombieJclaude
andcommitted
docs: add JSDoc comments to hooks and update examples
- Add JSDoc documentation to useClosable, useListPosition, useSizes, useNoticeTimer, useNotification, and useStack - Update example files to use geek.less and inline motion config - Remove unused motion leave animations from hooks example Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fe6c8c5 commit 362793d

File tree

10 files changed

+61
-14
lines changed

10 files changed

+61
-14
lines changed

docs/examples/context.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
/* eslint-disable no-console */
22
import React from 'react';
3-
import '../../assets/index.less';
3+
import type { CSSMotionProps } from '@rc-component/motion';
4+
import '../../assets/geek.less';
45
import { useNotification } from '../../src';
5-
import motion from './motion';
6+
7+
const motion: CSSMotionProps = {
8+
motionName: 'notification-fade',
9+
motionAppear: true,
10+
motionEnter: true,
11+
motionLeave: true,
12+
};
613

714
const Context = React.createContext({ name: 'light' });
815

@@ -15,7 +22,10 @@ const NOTICE = {
1522
};
1623

1724
const Demo = () => {
18-
const [{ open }, holder] = useNotification({ motion });
25+
const [{ open }, holder] = useNotification({
26+
motion,
27+
prefixCls: 'notification',
28+
});
1929

2030
return (
2131
<Context.Provider value={{ name: 'bamboo' }}>

docs/examples/hooks.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ const motion: CSSMotionProps = {
99
motionAppear: true,
1010
motionEnter: true,
1111
motionLeave: true,
12-
onLeaveStart: (ele) => {
13-
const { offsetHeight } = ele;
14-
return { height: offsetHeight };
15-
},
16-
onLeaveActive: () => ({ height: 0, opacity: 0, margin: 0 }),
1712
};
1813

1914
const App = () => {

docs/examples/maxCount.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
/* eslint-disable no-console */
22
import React from 'react';
3-
import '../../assets/index.less';
3+
import type { CSSMotionProps } from '@rc-component/motion';
4+
import '../../assets/geek.less';
45
import { useNotification } from '../../src';
5-
import motion from './motion';
6+
7+
const motion: CSSMotionProps = {
8+
motionName: 'notification-fade',
9+
motionAppear: true,
10+
motionEnter: true,
11+
motionLeave: true,
12+
};
613

714
export default () => {
8-
const [notice, contextHolder] = useNotification({ motion, maxCount: 3 });
15+
const [notice, contextHolder] = useNotification({
16+
motion,
17+
maxCount: 3,
18+
prefixCls: 'notification',
19+
});
920

1021
return (
1122
<>

docs/examples/showProgress.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
/* eslint-disable no-console */
22
import React from 'react';
3-
import '../../assets/index.less';
3+
import type { CSSMotionProps } from '@rc-component/motion';
4+
import '../../assets/geek.less';
45
import { useNotification } from '../../src';
5-
import motion from './motion';
6+
7+
const motion: CSSMotionProps = {
8+
motionName: 'notification-fade',
9+
motionAppear: true,
10+
motionEnter: true,
11+
motionLeave: true,
12+
};
613

714
export default () => {
8-
const [notice, contextHolder] = useNotification({ motion, showProgress: true });
15+
const [notice, contextHolder] = useNotification({
16+
motion,
17+
showProgress: true,
18+
prefixCls: 'notification',
19+
});
920

1021
return (
1122
<>

src/hooks/useClosable.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export type ClosableType = boolean | ClosableConfig | null | undefined;
1212
export type ParsedClosableConfig = ClosableConfig &
1313
Required<Pick<ClosableConfig, 'closeIcon' | 'disabled'>>;
1414

15+
/**
16+
* Normalizes the closable option into a boolean flag, config, and aria props.
17+
*/
1518
export default function useClosable(
1619
closable?: ClosableType,
1720
): [boolean, ParsedClosableConfig, ReturnType<typeof pickAttrs>] {

src/hooks/useListPosition/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export type NodePosition = {
77
y: number;
88
};
99

10+
/**
11+
* Calculates each notification's position and the full list height.
12+
*/
1013
export default function useListPosition(
1114
configList: { key: React.Key }[],
1215
stack?: StackConfig,

src/hooks/useListPosition/useSizes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export type NodeSize = {
77

88
export type NodeSizeMap = Record<string, NodeSize>;
99

10+
/**
11+
* Stores measured node sizes by key and exposes a ref callback to update them.
12+
*/
1013
export default function useSizes() {
1114
const [sizeMap, setSizeMap] = React.useState<NodeSizeMap>({});
1215

src/hooks/useNoticeTimer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import * as React from 'react';
22
import raf from '@rc-component/util/es/raf';
33
import useEvent from '@rc-component/util/es/hooks/useEvent';
44

5+
/**
6+
* Runs the notice auto-close timer and reports progress updates.
7+
* Returns controls to pause and resume the timer.
8+
*/
59
export default function useNoticeTimer(
610
duration: number | false | null,
711
onClose: VoidFunction,

src/hooks/useNotification.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ function mergeConfig<T>(...objList: Partial<T>[]): T {
6969
return clone;
7070
}
7171

72+
/**
73+
* Creates the notification API and the React holder element.
74+
* Queueing is handled internally until the notification instance is ready.
75+
*/
7276
export default function useNotification(
7377
rootConfig: NotificationConfig = {},
7478
): [NotificationAPI, React.ReactElement] {

src/hooks/useStack.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ type StackParams = Required<StackConfig>;
77

88
type UseStack = (config?: boolean | StackConfig) => [boolean, StackParams];
99

10+
/**
11+
* Resolves the stack setting into an enabled flag and normalized stack params.
12+
*/
1013
const useStack: UseStack = (config) => {
1114
const result: StackParams = {
1215
offset: DEFAULT_OFFSET,

0 commit comments

Comments
 (0)