-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement notifications/dialogs RFCs (#3584)
Signed-off-by: Jan Potoms <[email protected]> Co-authored-by: Pedro Ferreira <[email protected]>
- Loading branch information
1 parent
7c05759
commit a8fa780
Showing
75 changed files
with
4,161 additions
and
17 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
docs/data/toolpad/core/components/use-dialogs/AlertDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
docs/data/toolpad/core/components/use-dialogs/AlertDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
docs/data/toolpad/core/components/use-dialogs/AlertDialog.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await dialogs.alert('Hello World'); |
36 changes: 36 additions & 0 deletions
36
docs/data/toolpad/core/components/use-dialogs/ConfirmDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
docs/data/toolpad/core/components/use-dialogs/ConfirmDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
docs/data/toolpad/core/components/use-dialogs/ConfirmDialog.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
docs/data/toolpad/core/components/use-dialogs/CustomDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
docs/data/toolpad/core/components/use-dialogs/CustomDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
docs/data/toolpad/core/components/use-dialogs/CustomDialog.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await dialogs.open(MyCustomDialog); |
73 changes: 73 additions & 0 deletions
73
docs/data/toolpad/core/components/use-dialogs/CustomDialogWithPayload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "{payload}"</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> | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
docs/data/toolpad/core/components/use-dialogs/CustomDialogWithPayload.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "{payload}"</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> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
docs/data/toolpad/core/components/use-dialogs/CustomDialogWithPayload.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await dialogs.open(MyCustomDialog, payload); |
Oops, something went wrong.