Skip to content

Commit

Permalink
fix: πŸ› replace defaultProps with useDefaultProps (#2377)
Browse files Browse the repository at this point in the history
* fix: πŸ› πŸ› replace defaultProps with useDefaultProps

πŸ› replace defaultProps with useDefaultProps

* fix: πŸ› NotificationProps
  • Loading branch information
li-jia-nan authored Jul 26, 2023
1 parent 13d92be commit ced837e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/notification/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import useGlobalIcon from '../hooks/useGlobalIcon';
import { NotificationInstance, TdNotificationProps } from './type';
import { StyledProps } from '../common';
import { notificationDefaultProps } from './defaultProps';
import useDefaultProps from '../hooks/useDefaultProps';

export interface NotificationProps extends TdNotificationProps, StyledProps {
id?: string;
}

export const Notification = forwardRef<any, NotificationProps>((props, ref) => {
export const Notification = forwardRef<NotificationInstance, NotificationProps>((props, ref) => {
const {
title,
content,
Expand All @@ -32,7 +33,7 @@ export const Notification = forwardRef<any, NotificationProps>((props, ref) => {
style,
className,
id,
} = props;
} = useDefaultProps<NotificationProps>(props, notificationDefaultProps);

const { classPrefix } = useConfig();
const baseClassPrefix = `${classPrefix}-notification`;
Expand All @@ -43,24 +44,29 @@ export const Notification = forwardRef<any, NotificationProps>((props, ref) => {
});

const remove = useContext(NotificationRemoveContext);
React.useImperativeHandle(ref as React.Ref<NotificationInstance>, () => ({ close: () => remove(id) }));

React.useImperativeHandle(ref, () => ({ close: () => remove(id) }));

/* eslint-disable react-hooks/exhaustive-deps */
React.useEffect(() => {
let timer;
let timer: NodeJS.Timeout;
if (duration > 0) {
timer = setTimeout(() => {
clearTimeout(timer);
onDurationEnd();
}, duration);
}
return () => {
if (timer) clearTimeout(timer);
if (timer) {
clearTimeout(timer);
}
};
}, []);

const renderIcon = () => {
if (typeof icon === 'boolean' && !icon) return null;
if (typeof icon === 'boolean' && !icon) {
return null;
}

const IconWrapper = ({ children }) => <div className={`${baseClassPrefix}__icon`}>{children}</div>;

Expand Down Expand Up @@ -132,6 +138,5 @@ export const Notification = forwardRef<any, NotificationProps>((props, ref) => {
});

Notification.displayName = 'Notification';
Notification.defaultProps = notificationDefaultProps;

export default Notification;

0 comments on commit ced837e

Please sign in to comment.