Skip to content

Commit

Permalink
[@mantine/notifications] Add static methods to Notifications (mantine…
Browse files Browse the repository at this point in the history
…dev#3689)

Co-authored-by: Ilya Krasov <krasov@addamant.ru>
  • Loading branch information
ForeshadowRU and Ilya Krasov authored Mar 8, 2023
1 parent eaf1202 commit 10b6648
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/mantine-notifications/src/Notifications/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Transition, TransitionGroup } from 'react-transition-group';
import { DefaultProps, Portal, getDefaultZIndex, Box, PortalProps, rem } from '@mantine/core';
import { useReducedMotion, useForceUpdate, useDidUpdate } from '@mantine/hooks';
import { NotificationsPositioning } from '../types';
import { useNotificationsEvents } from '../events';
import {
notifications as GlobalNotifications,
NotificationsEvents,
useNotificationsEvents,
} from '../events';
import getPositionStyles from './get-position-styles/get-position-styles';
import getNotificationStateStyles from './get-notification-state-styles/get-notification-state-styles';
import NotificationContainer from '../NotificationContainer/NotificationContainer';
Expand All @@ -19,6 +23,8 @@ const POSITIONS = [
'bottom-center',
] as const;

type NotificationsStaticMethods = NotificationsEvents;

export interface NotificationsProps
extends Omit<DefaultProps, 'style'>,
React.ComponentPropsWithoutRef<'div'> {
Expand Down Expand Up @@ -53,7 +59,7 @@ export interface NotificationsProps
target?: PortalProps['target'];
}

export function Notifications({
export const Notifications: React.FC<NotificationsProps> & NotificationsStaticMethods = ({
className,
position = 'bottom-right',
autoClose = 4000,
Expand All @@ -66,7 +72,7 @@ export function Notifications({
children,
target,
...others
}: NotificationsProps) {
}) => {
const forceUpdate = useForceUpdate();
const refs = useRef<Record<string, HTMLDivElement>>({});
const previousLength = useRef<number>(0);
Expand Down Expand Up @@ -149,6 +155,11 @@ export function Notifications({
</Box>
</Portal>
);
}
};

Notifications.displayName = '@mantine/notifications/Notifications';
Notifications.show = GlobalNotifications.show;
Notifications.hide = GlobalNotifications.hide;
Notifications.update = GlobalNotifications.update;
Notifications.clean = GlobalNotifications.clean;
Notifications.cleanQueue = GlobalNotifications.cleanQueue;
2 changes: 1 addition & 1 deletion src/mantine-notifications/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const cleanNotifications = createEvent('clean');
export const cleanNotificationsQueue = createEvent('cleanQueue');
export const updateNotification = createEvent('update');

export const notifications = {
export const notifications: NotificationsEvents = {
show: showNotification,
hide: hideNotification,
clean: cleanNotifications,
Expand Down

0 comments on commit 10b6648

Please sign in to comment.