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

Implement notifications/dialogs RFCs #3584

Merged
merged 41 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fc26782
Implement notofications/dialogs RFCs
Janpot May 24, 2024
97343b9
Update pnpm-lock.yaml
Janpot May 24, 2024
6cc74ec
frwt
Janpot May 24, 2024
7170702
Update pnpm-lock.yaml
Janpot May 24, 2024
ad1773e
Merge remote-tracking branch 'upstream/master' into notifications-dia…
Janpot Jun 5, 2024
f2b8f68
Merge remote-tracking branch 'upstream/master' into notifications-dia…
Janpot Jun 12, 2024
5b437a6
Update notifications
Janpot Jun 12, 2024
910a9d3
revert
Janpot Jun 12, 2024
2cbe54b
fsrf
Janpot Jun 12, 2024
89b8848
ferg
Janpot Jun 12, 2024
e8ee153
slotprops
Janpot Jun 12, 2024
740b3a3
Merge remote-tracking branch 'upstream/master' into notifications-dia…
Janpot Jun 12, 2024
04bc70d
dew
Janpot Jun 12, 2024
45cd1f0
extra tests
Janpot Jun 12, 2024
948f457
dedupe
Janpot Jun 12, 2024
24c01dd
lint
Janpot Jun 12, 2024
05afa96
tests
Janpot Jun 12, 2024
f0874a2
ferger
Janpot Jun 12, 2024
4bcbe1d
let's go
Janpot Jun 12, 2024
4cf476d
Update useDialogs.tsx
Janpot Jun 12, 2024
25b6af9
Delete dashboard-layout.js
Janpot Jun 12, 2024
c136a86
Dialogs API reference
Janpot Jun 13, 2024
2b4762e
Merge remote-tracking branch 'upstream/master' into notifications-dia…
Janpot Jun 13, 2024
231815f
start
Janpot Jun 13, 2024
79201e5
Notifications API docs
Janpot Jun 13, 2024
5905ec8
Update use-notifications.md
Janpot Jun 13, 2024
ed77d44
clean up
Janpot Jun 13, 2024
32d8690
split files
Janpot Jun 13, 2024
1aa685a
More API docs
Janpot Jun 13, 2024
0b3b348
refactor
Janpot Jun 13, 2024
be94e88
wip
Janpot Jun 13, 2024
c12d09c
Add slot
Janpot Jun 13, 2024
6466ac3
finish
Janpot Jun 13, 2024
3d74b14
Update ScopedNotification.js
Janpot Jun 13, 2024
8caecda
dummy tests
Janpot Jun 13, 2024
34de819
Update docs/data/toolpad/core/components/use-dialogs/CustomDialog.js
Janpot Jun 14, 2024
7feadb9
Update docs/data/toolpad/core/components/use-dialogs/CustomDialogWith…
Janpot Jun 14, 2024
fb57280
typos
Janpot Jun 14, 2024
be6fc7a
some comments
Janpot Jun 18, 2024
fd26353
Merge remote-tracking branch 'upstream/master' into notifications-dia…
Janpot Jun 18, 2024
d5a8405
re
Janpot Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/data/toolpad/core/components/use-dialogs/AlertDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';

function DemoContent() {
const dialogs = useDialogs();
return (
<div>
<Button
onClick={async () => {
// preview-start
await dialogs.alert('Hello World');
// preview-end
}}
>
Alert
</Button>
</div>
);
}

export default function AlertDialog() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
28 changes: 28 additions & 0 deletions docs/data/toolpad/core/components/use-dialogs/AlertDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';

function DemoContent() {
const dialogs = useDialogs();
return (
<div>
<Button
onClick={async () => {
// preview-start
await dialogs.alert('Hello World');
// preview-end
}}
>
Alert
</Button>
</div>
);
}

export default function AlertDialog() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await dialogs.alert('Hello World');
36 changes: 36 additions & 0 deletions docs/data/toolpad/core/components/use-dialogs/ConfirmDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';

function DemoContent() {
const dialogs = useDialogs();
return (
<div>
<Button
onClick={async () => {
// preview-start
const confirmed = await dialogs.confirm('Are you sure?', {
okText: 'Yes',
cancelText: 'No',
});
if (confirmed) {
await dialogs.alert("Then let's do it!");
} else {
await dialogs.alert('Ok, forget about it!');
}
// preview-end
}}
>
Confirm
</Button>
</div>
);
}

export default function ConfirmDialog() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
36 changes: 36 additions & 0 deletions docs/data/toolpad/core/components/use-dialogs/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';

function DemoContent() {
const dialogs = useDialogs();
return (
<div>
<Button
onClick={async () => {
// preview-start
const confirmed = await dialogs.confirm('Are you sure?', {
okText: 'Yes',
cancelText: 'No',
});
if (confirmed) {
await dialogs.alert("Then let's do it!");
} else {
await dialogs.alert('Ok, forget about it!');
}
// preview-end
}}
>
Confirm
</Button>
</div>
);
}

export default function ConfirmDialog() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const confirmed = await dialogs.confirm('Are you sure?', {
okText: 'Yes',
cancelText: 'No',
});
if (confirmed) {
await dialogs.alert("Then let's do it!");
} else {
await dialogs.alert('Ok, forget about it!');
}
61 changes: 61 additions & 0 deletions docs/data/toolpad/core/components/use-dialogs/CustomDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';

function MyCustomDialog({ open, onClose }) {
return (
<Dialog fullWidth open={open} onClose={() => onClose()}>
<DialogTitle>Custom dialog</DialogTitle>
<DialogContent>I am a custom dialog</DialogContent>
<DialogActions>
<Button onClick={() => onClose()}>Close me</Button>
</DialogActions>
</Dialog>
);
}

MyCustomDialog.propTypes = {
/**
* A function to call when the dialog should be closed. If the dialog has a return
* value, it should be passed as an argument to this function. You should use the promise
* that is returned to show a loading state while the dialog is performing async actions
* on close.
* @param result The result to return from the dialog.
* @returns A promise that resolves when the dialog can be fully closed.
*/
onClose: PropTypes.func.isRequired,
/**
* Whether the dialog is open.
*/
open: PropTypes.bool.isRequired,
};

function DemoContent() {
const dialogs = useDialogs();
return (
<div>
<Button
onClick={async () => {
// preview-start
await dialogs.open(MyCustomDialog);
// preview-end
}}
>
Open custom
</Button>
</div>
);
}

export default function CustomDialog() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
44 changes: 44 additions & 0 deletions docs/data/toolpad/core/components/use-dialogs/CustomDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as React from 'react';
import { DialogsProvider, useDialogs, DialogProps } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';

function MyCustomDialog({ open, onClose }: DialogProps) {
return (
<Dialog fullWidth open={open} onClose={() => onClose()}>
<DialogTitle>Custom dialog</DialogTitle>
<DialogContent>I am a custom dialog</DialogContent>
<DialogActions>
<Button onClick={() => onClose()}>Close me</Button>
</DialogActions>
</Dialog>
);
}

function DemoContent() {
const dialogs = useDialogs();
return (
<div>
<Button
onClick={async () => {
// preview-start
await dialogs.open(MyCustomDialog);
// preview-end
}}
>
Open custom
</Button>
</div>
);
}

export default function CustomDialog() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await dialogs.open(MyCustomDialog);
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';
import TextField from '@mui/material/TextField';
import Stack from '@mui/material/Stack';

function MyCustomDialog({ payload, open, onClose }) {
return (
<Dialog fullWidth open={open} onClose={() => onClose()}>
<DialogTitle>Dialog with payload</DialogTitle>
<DialogContent>The payload is &quot;{payload}&quot;</DialogContent>
<DialogActions>
<Button onClick={() => onClose()}>Close me</Button>
</DialogActions>
</Dialog>
);
}

MyCustomDialog.propTypes = {
/**
* A function to call when the dialog should be closed. If the dialog has a return
* value, it should be passed as an argument to this function. You should use the promise
* that is returned to show a loading state while the dialog is performing async actions
* on close.
* @param result The result to return from the dialog.
* @returns A promise that resolves when the dialog can be fully closed.
*/
onClose: PropTypes.func.isRequired,
/**
* Whether the dialog is open.
*/
open: PropTypes.bool.isRequired,
/**
* The payload that was passed when the dialog was opened.
*/
payload: PropTypes.string.isRequired,
};

function DemoContent() {
const dialogs = useDialogs();
const [payload, setPayload] = React.useState('Some payload');
return (
<Stack spacing={2}>
<TextField
label="Payload"
value={payload}
onChange={(event) => setPayload(event.currentTarget.value)}
/>
<Button
onClick={async () => {
// preview-start
await dialogs.open(MyCustomDialog, payload);
// preview-end
}}
>
Open
</Button>
</Stack>
);
}

export default function CustomDialogWithPayload() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react';
import { DialogsProvider, useDialogs, DialogProps } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';
import TextField from '@mui/material/TextField';
import Stack from '@mui/material/Stack';

function MyCustomDialog({ payload, open, onClose }: DialogProps<string>) {
return (
<Dialog fullWidth open={open} onClose={() => onClose()}>
<DialogTitle>Dialog with payload</DialogTitle>
<DialogContent>The payload is &quot;{payload}&quot;</DialogContent>
<DialogActions>
<Button onClick={() => onClose()}>Close me</Button>
</DialogActions>
</Dialog>
);
}

function DemoContent() {
const dialogs = useDialogs();
const [payload, setPayload] = React.useState('Some payload');
return (
<Stack spacing={2}>
<TextField
label="Payload"
value={payload}
onChange={(event) => setPayload(event.currentTarget.value)}
/>
<Button
onClick={async () => {
// preview-start
await dialogs.open(MyCustomDialog, payload);
// preview-end
}}
>
Open
</Button>
</Stack>
);
}

export default function CustomDialogWithPayload() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await dialogs.open(MyCustomDialog, payload);
Loading
Loading