From 012bb43897750d047924cdc6ad6f9d784d402dac Mon Sep 17 00:00:00 2001 From: iansummerlin <38192940+iansummerlin@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:06:17 +0000 Subject: [PATCH 1/6] dialog onBeforeClose --- index.d.ts | 5 ++++- src/dialog/src/Dialog.js | 9 +++++++++ src/dialog/stories/index.stories.js | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index bd01f37d4..00b002db1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -833,7 +833,10 @@ export interface CornerDialogProps { export declare const CornerDialog: React.FC export interface DialogProps - extends Pick { + extends Pick< + OverlayProps, + 'isShown' | 'preventBodyScrolling' | 'shouldAutoFocus' | 'shouldCloseOnEscapePress' | 'onBeforeClose' + > { /** * Children can be a string, node or a function accepting `({ close })`. * When passing a string, is used to wrap the string. diff --git a/src/dialog/src/Dialog.js b/src/dialog/src/Dialog.js index 2d7a63ebf..24097d468 100644 --- a/src/dialog/src/Dialog.js +++ b/src/dialog/src/Dialog.js @@ -77,6 +77,7 @@ const Dialog = memo(function Dialog({ isConfirmLoading = false, isShown = false, minHeightContent = 80, + onBeforeClose, onCancel = closeHandler, onCloseComplete, onConfirm = closeHandler, @@ -195,6 +196,7 @@ const Dialog = memo(function Dialog({ justifyContent: 'center', ...overlayProps }} + onBeforeClose={onBeforeClose} preventBodyScrolling={preventBodyScrolling} > {({ close, state }) => ( @@ -403,6 +405,13 @@ Dialog.propTypes = { */ preventBodyScrolling: PropTypes.bool, + /** + * Function called when dialog is about to close. + * Return `false` to prevent the sheet from closing. + * type: `Function -> Boolean` + */ + onBeforeClose: PropTypes.func, + /** * Props that are passed to the Overlay component. */ diff --git a/src/dialog/stories/index.stories.js b/src/dialog/stories/index.stories.js index eae01423a..2d31585e1 100644 --- a/src/dialog/stories/index.stories.js +++ b/src/dialog/stories/index.stories.js @@ -396,3 +396,22 @@ storiesOf('dialog', module) )) + .add('Dialog with onBeforeClose', () => ( + + + {({ hide, isShown, show }) => ( + + confirm('Are you sure you want to close?')} + onCloseComplete={hide} + > + onBeforeClose >> are you sure you want to close? + + + + )} + + + )) From efc5761f1061c973a588c2629ccdd4c1ddb6b0c3 Mon Sep 17 00:00:00 2001 From: iansummerlin <38192940+iansummerlin@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:10:06 +0000 Subject: [PATCH 2/6] storybook tidy --- src/dialog/stories/index.stories.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dialog/stories/index.stories.js b/src/dialog/stories/index.stories.js index 2d31585e1..8850a53c2 100644 --- a/src/dialog/stories/index.stories.js +++ b/src/dialog/stories/index.stories.js @@ -403,11 +403,11 @@ storiesOf('dialog', module) confirm('Are you sure you want to close?')} onCloseComplete={hide} > - onBeforeClose >> are you sure you want to close? + onBeforeClose: are you sure you want to close? From 71f8cee630ffaa11321d11c02a8726bf87b514b7 Mon Sep 17 00:00:00 2001 From: iansummerlin <38192940+iansummerlin@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:20:45 +0000 Subject: [PATCH 3/6] docs --- docs/documentation/components/dialog.mdx | 53 ++++++++++++++---------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/docs/documentation/components/dialog.mdx b/docs/documentation/components/dialog.mdx index a144e1b2f..54a3663b1 100644 --- a/docs/documentation/components/dialog.mdx +++ b/docs/documentation/components/dialog.mdx @@ -53,7 +53,6 @@ function DefaultDialogExample() { } ``` - ## Default with a danger intent The `intent` prop determines the appearance of the confirm button, `danger` is red. @@ -92,11 +91,7 @@ function InternalScrollingDialogExample() { return ( - setIsShown(false)} - > + setIsShown(false)}> @@ -113,11 +108,7 @@ function SelfManagedCloseDialogExample() { const [isShown, setIsShown] = React.useState(false) return ( - setIsShown(false)} - > + setIsShown(false)}> {({ close }) => ( Manage your own buttons and close interaction @@ -144,12 +135,7 @@ function NoFooterDialogExample() { const [isShown, setIsShown] = React.useState(false) return ( - setIsShown(false)} - hasFooter={false} - > + setIsShown(false)} hasFooter={false}> No footer @@ -169,12 +155,7 @@ function NoHeaderDialogExample() { const [isShown, setIsShown] = React.useState(false) return ( - setIsShown(false)} - hasHeader={false} - > + setIsShown(false)} hasHeader={false}> No header @@ -209,3 +190,29 @@ function PreserveBodyScrollingDialogExample() { ) } ``` + +## Handle overlay/close clicks + +Use the `onBeforeClose` prop to handle overlay/close clicks. It is executed +when dialog is about to close. Return `false` to prevent the sheet from closing. + +```jsx +function PreserveBodyScrollingDialogExample() { + const [isShown, setIsShown] = React.useState(false) + + return ( + + - setIsShown(false)}> + setIsShown(false)} + > @@ -108,7 +113,11 @@ function SelfManagedCloseDialogExample() { const [isShown, setIsShown] = React.useState(false) return ( - setIsShown(false)}> + setIsShown(false)} + > {({ close }) => ( Manage your own buttons and close interaction @@ -135,7 +144,12 @@ function NoFooterDialogExample() { const [isShown, setIsShown] = React.useState(false) return ( - setIsShown(false)} hasFooter={false}> + setIsShown(false)} + hasFooter={false} + > No footer @@ -155,7 +169,12 @@ function NoHeaderDialogExample() { const [isShown, setIsShown] = React.useState(false) return ( - setIsShown(false)} hasHeader={false}> + setIsShown(false)} + hasHeader={false} + > No header @@ -190,29 +209,3 @@ function PreserveBodyScrollingDialogExample() { ) } ``` - -## Handle overlay/close clicks - -Use the `onBeforeClose` prop to handle overlay/close clicks. It is executed -when dialog is about to close. Return `false` to prevent the sheet from closing. - -```jsx -function PreserveBodyScrollingDialogExample() { - const [isShown, setIsShown] = React.useState(false) - - return ( - - confirm('Are you sure you want to close?')} + onCloseComplete={() => setIsShown(false)} + > + Dialog content + + + + + ) +} +``` + From 0e882d44fb9e6c9438bf825270967d3799401938 Mon Sep 17 00:00:00 2001 From: iansummerlin <38192940+iansummerlin@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:34:46 +0000 Subject: [PATCH 6/6] Update dialog.mdx --- docs/documentation/components/dialog.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/documentation/components/dialog.mdx b/docs/documentation/components/dialog.mdx index a943024a9..7f985298c 100644 --- a/docs/documentation/components/dialog.mdx +++ b/docs/documentation/components/dialog.mdx @@ -216,7 +216,7 @@ Use the `onBeforeClose` prop to handle overlay/close clicks. It is executed when dialog is about to close. Return `false` to prevent the sheet from closing. ```jsx -function PreserveBodyScrollingDialogExample() { +function OnBeforeCloseExample() { const [isShown, setIsShown] = React.useState(false) return (