From fc267827f9976f904ce92a6f3f8871be938fc9e4 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Fri, 24 May 2024 11:41:30 +0200 Subject: [PATCH 01/36] Implement notofications/dialogs RFCs --- .../core/components/dialogs/AlertDialog.js | 28 ++ .../core/components/dialogs/AlertDialog.tsx | 28 ++ .../dialogs/AlertDialog.tsx.preview | 1 + .../core/components/dialogs/ConfirmDialog.js | 36 ++ .../core/components/dialogs/ConfirmDialog.tsx | 36 ++ .../dialogs/ConfirmDialog.tsx.preview | 9 + .../core/components/dialogs/CustomDialog.js | 50 +++ .../core/components/dialogs/CustomDialog.tsx | 44 +++ .../dialogs/CustomDialog.tsx.preview | 1 + .../dialogs/CustomDialogWithPayload.js | 59 ++++ .../dialogs/CustomDialogWithPayload.tsx | 52 +++ .../CustomDialogWithPayload.tsx.preview | 1 + .../dialogs/CustomDialogWithResult.js | 63 ++++ .../dialogs/CustomDialogWithResult.tsx | 57 ++++ .../CustomDialogWithResult.tsx.preview | 2 + .../core/components/dialogs/PromptDialog.js | 31 ++ .../core/components/dialogs/PromptDialog.tsx | 31 ++ .../dialogs/PromptDialog.tsx.preview | 4 + .../core/components/dialogs/StackedDialog.js | 60 ++++ .../core/components/dialogs/StackedDialog.tsx | 53 +++ .../dialogs/StackedDialog.tsx.preview | 1 + .../core/components/dialogs/dialogs.md | 94 ++++++ .../notifications/AlertNotification.js | 51 +++ .../notifications/AlertNotification.tsx | 53 +++ .../AlertNotification.tsx.preview | 4 + .../notifications/BasicNotification.js | 26 ++ .../notifications/BasicNotification.tsx | 26 ++ .../BasicNotification.tsx.preview | 3 + .../notifications/CloseNotification.js | 46 +++ .../notifications/CloseNotification.tsx | 46 +++ .../CloseNotification.tsx.preview | 12 + .../notifications/DedupeNotification.js | 28 ++ .../notifications/DedupeNotification.tsx | 28 ++ .../DedupeNotification.tsx.preview | 4 + .../notifications/MultipleNotifications.js | 25 ++ .../notifications/MultipleNotifications.tsx | 25 ++ .../MultipleNotifications.tsx.preview | 2 + .../components/notifications/notifications.md | 69 ++++ docs/data/toolpad/core/pages.ts | 24 +- docs/pages/toolpad/core/components/dialogs.js | 7 + .../toolpad/core/components/notifications.js | 7 + .../src/AppProvider/AppProvider.tsx | 11 +- .../src/DashboardLayout/DashboardLayout.tsx | 12 - packages/toolpad-core/src/index.ts | 9 +- packages/toolpad-core/src/useDialogs/index.ts | 1 + .../src/useDialogs/useDialogs.tsx | 317 ++++++++++++++++++ .../src/useNotifications/index.ts | 1 + .../src/useNotifications/useNotifications.tsx | 234 +++++++++++++ packages/toolpad-utils/src/react.tsx | 10 +- pnpm-lock.yaml | 45 +++ 50 files changed, 1830 insertions(+), 37 deletions(-) create mode 100644 docs/data/toolpad/core/components/dialogs/AlertDialog.js create mode 100644 docs/data/toolpad/core/components/dialogs/AlertDialog.tsx create mode 100644 docs/data/toolpad/core/components/dialogs/AlertDialog.tsx.preview create mode 100644 docs/data/toolpad/core/components/dialogs/ConfirmDialog.js create mode 100644 docs/data/toolpad/core/components/dialogs/ConfirmDialog.tsx create mode 100644 docs/data/toolpad/core/components/dialogs/ConfirmDialog.tsx.preview create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialog.js create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialog.tsx create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialog.tsx.preview create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialogWithPayload.js create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialogWithPayload.tsx create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialogWithPayload.tsx.preview create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialogWithResult.js create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialogWithResult.tsx create mode 100644 docs/data/toolpad/core/components/dialogs/CustomDialogWithResult.tsx.preview create mode 100644 docs/data/toolpad/core/components/dialogs/PromptDialog.js create mode 100644 docs/data/toolpad/core/components/dialogs/PromptDialog.tsx create mode 100644 docs/data/toolpad/core/components/dialogs/PromptDialog.tsx.preview create mode 100644 docs/data/toolpad/core/components/dialogs/StackedDialog.js create mode 100644 docs/data/toolpad/core/components/dialogs/StackedDialog.tsx create mode 100644 docs/data/toolpad/core/components/dialogs/StackedDialog.tsx.preview create mode 100644 docs/data/toolpad/core/components/dialogs/dialogs.md create mode 100644 docs/data/toolpad/core/components/notifications/AlertNotification.js create mode 100644 docs/data/toolpad/core/components/notifications/AlertNotification.tsx create mode 100644 docs/data/toolpad/core/components/notifications/AlertNotification.tsx.preview create mode 100644 docs/data/toolpad/core/components/notifications/BasicNotification.js create mode 100644 docs/data/toolpad/core/components/notifications/BasicNotification.tsx create mode 100644 docs/data/toolpad/core/components/notifications/BasicNotification.tsx.preview create mode 100644 docs/data/toolpad/core/components/notifications/CloseNotification.js create mode 100644 docs/data/toolpad/core/components/notifications/CloseNotification.tsx create mode 100644 docs/data/toolpad/core/components/notifications/CloseNotification.tsx.preview create mode 100644 docs/data/toolpad/core/components/notifications/DedupeNotification.js create mode 100644 docs/data/toolpad/core/components/notifications/DedupeNotification.tsx create mode 100644 docs/data/toolpad/core/components/notifications/DedupeNotification.tsx.preview create mode 100644 docs/data/toolpad/core/components/notifications/MultipleNotifications.js create mode 100644 docs/data/toolpad/core/components/notifications/MultipleNotifications.tsx create mode 100644 docs/data/toolpad/core/components/notifications/MultipleNotifications.tsx.preview create mode 100644 docs/data/toolpad/core/components/notifications/notifications.md create mode 100644 docs/pages/toolpad/core/components/dialogs.js create mode 100644 docs/pages/toolpad/core/components/notifications.js create mode 100644 packages/toolpad-core/src/useDialogs/index.ts create mode 100644 packages/toolpad-core/src/useDialogs/useDialogs.tsx create mode 100644 packages/toolpad-core/src/useNotifications/index.ts create mode 100644 packages/toolpad-core/src/useNotifications/useNotifications.tsx diff --git a/docs/data/toolpad/core/components/dialogs/AlertDialog.js b/docs/data/toolpad/core/components/dialogs/AlertDialog.js new file mode 100644 index 00000000000..654b428f884 --- /dev/null +++ b/docs/data/toolpad/core/components/dialogs/AlertDialog.js @@ -0,0 +1,28 @@ +import * as React from 'react'; +import { DialogProvider, useDialogs } from '@toolpad/core/useDialogs'; +import Button from '@mui/material/Button'; + +function DemoContent() { + const dialogs = useDialogs(); + return ( +
Imperative APIs to open and interact with dialogs.
+ +Toolpad core offers a set of abstractions that makes interacting with dialogs simpler. It has an imperative API to open and close dialogs, and allows dialogs to be stacked on top of each other. + +First thing you need to do is install the DialogProvider at the root of your application. + +```tsx +import { DialogProvider } from '@toolpad/core/useDialogs'; + +function App({ children }) { + returnImperative APIs to show and interact with application notifications
+ +Toolpad core offers a set of abstractions that make it easier to interact with notifications. Notifications are used to give short updates to the user about things that are happening during the application lifetime. They appear at the bottom of the screen. The Toolpad API allows for opening multiple notifications concurrenlty. + +First thing you need to do to get access to the notifications APIs is install the NotificationsProvider. + +```js +import { NotificationsProvider } from '@toolpad/core/useNotifications'; + +function App({ children }) { + return ( + {
+ payload: P;
+ open: boolean;
+ onClose: (result: R) => Promise = React.ComponentType (
+ Component: DialogComponent ,
+ payload?: P,
+ options?: OpenDialogOptions (Component: DialogComponent , payload: P, options?: OpenDialogOptions {
+ key: string;
+ open: boolean;
+ promise: Promise ;
+ payload: P;
+ onClose: (result: R) => Promise (
+ Component: DialogComponent ,
+ payload: P,
+ options: OpenDialogOptions = {
+ key,
+ open: true,
+ promise,
+ Component,
+ payload,
+ onClose,
+ resolve,
+ };
+
+ setStack((prevStack) => [...prevStack, newEntry]);
+ return promise;
+ },
+ [keyPrefix],
+ );
+
+ const closeDialogUi = React.useCallback(function closeDialogUi