From 561b0cacf2df1ee45d54b85e278c7e91abe7cfa7 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 24 Aug 2020 11:49:41 -0400 Subject: [PATCH 1/3] feat: added prop to open up link in a new tab --- src/ShareButton.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ShareButton.tsx b/src/ShareButton.tsx index fbc8de2c..35557e41 100644 --- a/src/ShareButton.tsx +++ b/src/ShareButton.tsx @@ -21,6 +21,7 @@ const getBoxPositionOnScreenCenter = (width: number, height: number) => ({ function windowOpen( url: string, { height, width, ...configRest }: { height: number; width: number; [key: string]: any }, + hasBlankTarget: boolean, onClose?: (dialog: Window | null) => void, ) { const config: { [key: string]: string | number } = { @@ -38,13 +39,18 @@ function windowOpen( ...configRest, }; - const shareDialog = window.open( - url, - '', - Object.keys(config) - .map(key => `${key}=${config[key]}`) - .join(', '), - ); + let shareDialog: Window; + if (hasBlankTarget) { + shareDialog = window.open(url, '_blank') as Window; + } else { + shareDialog = window.open( + url, + '', + Object.keys(config) + .map(key => `${key}=${config[key]}`) + .join(', '), + ) as Window; + } if (onClose) { const interval = window.setInterval(() => { @@ -98,6 +104,7 @@ interface CustomProps { */ onShareWindowClose?: () => void; resetButtonStyle?: boolean; + hasBlankTarget?: boolean; } export type Props = Omit< @@ -119,6 +126,7 @@ export default class ShareButton extends Component extends Component) => { From 267b43031b5f3e243b5b22862629c0d67de33d15 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 24 Aug 2020 11:55:07 -0400 Subject: [PATCH 2/3] add documentation for opening up share window in a new tab --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f32878b0..a7acd24d 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ import { | | Required props | Optional props | | ---------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| **All** | **`children`** (string/element): React node
**`url`** (string): URL of the shared page | **`disabled`** (bool): Disables click action and adds "disabled" class
**`disabledStyle`** (object, default=`{ opacity: 0.6 }`): Disabled style
**`windowWidth`, `windowHeight`** (number, different default for all share buttons): opened window dimensions
**`beforeOnClick`** (`() => Promise`/`() => void`): Takes a function that returns a Promise to be fulfilled before calling `onClick`. If you do not return promise, `onClick` is called immediately.
**`openShareDialogOnClick`** (boolean): Open dialog on click. Defaults to `true` except on EmailShareButton
**`onShareWindowClose`** (`() => void`): Takes a function to be called after closing share dialog.
**`resetButtonStyle`** (boolean, default=`true`): Reset `button` element style. Preferred to be set to `false` if you want to customize the button style. | +| **All** | **`children`** (string/element): React node
**`url`** (string): URL of the shared page | **`disabled`** (bool): Disables click action and adds "disabled" class
**`disabledStyle`** (object, default=`{ opacity: 0.6 }`): Disabled style
**`windowWidth`, `windowHeight`** (number, different default for all share buttons): opened window dimensions
**`beforeOnClick`** (`() => Promise`/`() => void`): Takes a function that returns a Promise to be fulfilled before calling `onClick`. If you do not return promise, `onClick` is called immediately.
**`openShareDialogOnClick`** (boolean): Open dialog on click. Defaults to `true` except on EmailShareButton
**`onShareWindowClose`** (`() => void`): Takes a function to be called after closing share dialog.
**`resetButtonStyle`** (boolean, default=`true`): Reset `button` element style. Preferred to be set to `false` if you want to customize the button style.
**`hasBlankTarget`** (boolean, default=`false`): Open up share window in a new tab if set to `true`. | | EmailShareButton | - | **`subject`** (string): Title of the shared page
**`body`** (string): Email, will be prepended to the url.
**`separator`** (string, default=`" "`): Separates body from the url | | FacebookShareButton | - | **`quote`** (string): A quote to be shared along with the link.
**`hashtag`** (string): A hashtag specified by the developer to be added to the shared content. People will still have the opportunity to remove this hashtag in the dialog. The hashtag should include the hash symbol. | | FacebookMessengerShareButton | **`appId`** (string): Facebook application id | **`redirectUri`** (string): The URL to redirect to after sharing (default: the shared url).
**`to`** (string): A user ID of a recipient. Once the dialog comes up, the sender can specify additional people as recipients. | From 908d892dad626ebb76e3ab3f509aecb7f66f4739 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 24 Aug 2020 14:17:44 -0400 Subject: [PATCH 3/3] fix: remove prop for opening window in new tab from props that are passed to button --- src/ShareButton.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ShareButton.tsx b/src/ShareButton.tsx index 35557e41..098aa84e 100644 --- a/src/ShareButton.tsx +++ b/src/ShareButton.tsx @@ -195,6 +195,7 @@ export default class ShareButton extends Component