Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mui): configurable anchorOrigin for useNotificationProvider #5876

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core/src/contexts/notification/types.ts
Expand Up @@ -37,6 +37,12 @@ export type OpenNotificationParams = {
description?: string;
cancelMutation?: () => void;
undoableTimeout?: number;
anchorOrigin?: {
vertical: "top" | "bottom";
horizontal: "left" | "center" | "right";
};
preventDuplicate?: boolean;
disableWindowBlurListener?: boolean;
};

export interface INotificationContext {
Expand Down
23 changes: 16 additions & 7 deletions packages/mui/src/providers/notificationProvider/index.spec.tsx
Expand Up @@ -16,6 +16,12 @@ const mockNotification: OpenNotificationParams = {
message: "Test Notification Message",
type: "success",
description: "Test Notification Description",
anchorOrigin: {
vertical: "top",
horizontal: "right",
},
disableWindowBlurListener: true,
preventDuplicate: true,
};

const mockNotificationUndoable: OpenNotificationParams = {
Expand Down Expand Up @@ -65,11 +71,12 @@ describe("Notistack notificationProvider", () => {
{
key: mockNotification.key,
variant: "success",
anchorOrigin: {
anchorOrigin: mockNotification.anchorOrigin ?? {
vertical: "top",
horizontal: "right",
},
disableWindowBlurListener: true,
disableWindowBlurListener: mockNotification.disableWindowBlurListener,
preventDuplicate: mockNotification.preventDuplicate,
},
);
});
Expand All @@ -90,11 +97,12 @@ describe("Notistack notificationProvider", () => {
{
key: mockNotification.key,
variant: "error",
anchorOrigin: {
anchorOrigin: mockNotification.anchorOrigin ?? {
vertical: "top",
horizontal: "right",
},
disableWindowBlurListener: true,
disableWindowBlurListener: mockNotification.disableWindowBlurListener,
preventDuplicate: mockNotification.preventDuplicate,
},
);
});
Expand All @@ -114,14 +122,15 @@ describe("Notistack notificationProvider", () => {
</>,
{
action: expect.any(Function),
anchorOrigin: {
anchorOrigin: mockNotificationUndoable.anchorOrigin ?? {
vertical: "top",
horizontal: "right",
},
preventDuplicate: true,
preventDuplicate: mockNotificationUndoable.preventDuplicate,
key: "test-notification-undoable",
autoHideDuration: 5000,
disableWindowBlurListener: true,
disableWindowBlurListener:
mockNotificationUndoable.disableWindowBlurListener,
},
);
});
Expand Down
18 changes: 11 additions & 7 deletions packages/mui/src/providers/notificationProvider/index.tsx
Expand Up @@ -21,6 +21,9 @@ export const useNotificationProvider = (): NotificationProvider => {
key,
cancelMutation,
description,
anchorOrigin,
preventDuplicate,
disableWindowBlurListener,
}) => {
if (type === "progress") {
const action = (key: any) => (
Expand All @@ -43,14 +46,14 @@ export const useNotificationProvider = (): NotificationProvider => {
</>,
{
action,
anchorOrigin: {
key,
autoHideDuration: (undoableTimeout ?? 0) * 1000,
anchorOrigin: anchorOrigin ?? {
vertical: "top",
horizontal: "right",
},
preventDuplicate: true,
key,
autoHideDuration: (undoableTimeout ?? 0) * 1000,
disableWindowBlurListener: true,
preventDuplicate,
disableWindowBlurListener,
},
);
} else {
Expand All @@ -66,11 +69,12 @@ export const useNotificationProvider = (): NotificationProvider => {
{
key,
variant: type,
anchorOrigin: {
anchorOrigin: anchorOrigin ?? {
vertical: "top",
horizontal: "right",
},
disableWindowBlurListener: true,
preventDuplicate,
disableWindowBlurListener,
},
);
}
Expand Down