Skip to content

Commit 8011a44

Browse files
authored
Add blankTarget props to open up a new tab instead of a new window ( #51 )
2 parents c3a32fe + f4bb5d4 commit 8011a44

File tree

6 files changed

+77
-11
lines changed

6 files changed

+77
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.19.0 (2022-10-17)
2+
3+
### ✨ Features
4+
5+
* Add blankTarget props to open up a new tab
6+
17
## 0.18.4 (2022-10-12)
28

39
### ✨ Features

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import {
8686
| hashtag | string | | Hashtag to be shared. ||
8787
| windowWidth | number | 550 | Opened window width. ||
8888
| windowHeight | number | 400 | Opened window height. ||
89+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
8990

9091
#### 📖 [FacebookIcon props](https://github.com/Bunlong/next-share#-icons-props)
9192

@@ -116,6 +117,7 @@ import {
116117
| title | string | | The title of the shared page. ||
117118
| windowWidth | number | 500 | Opened window width. ||
118119
| windowHeight | number | 500 | Opened window height. ||
120+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
119121

120122
#### 📖 [LineIcon props](https://github.com/Bunlong/next-share#-icons-props)
121123

@@ -147,6 +149,7 @@ import {
147149
| description | string | | The description of the shared media. ||
148150
| windowWidth | number | 1000 | Opened window width. ||
149151
| windowHeight | number | 730 | Opened window height. ||
152+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
150153

151154
#### 📖 [PinterestIcon props](https://github.com/Bunlong/next-share#-icons-props)
152155

@@ -177,6 +180,7 @@ import {
177180
| title | string | | The title of the shared page. ||
178181
| windowWidth | number | 660 | Opened window width. ||
179182
| windowHeight | number | 460 | Opened window height. ||
183+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
180184

181185
#### 📖 [RedditIcon props](https://github.com/Bunlong/next-share#-icons-props)
182186

@@ -207,6 +211,7 @@ import {
207211
| title | string | | The title of the shared page. ||
208212
| windowWidth | number | 550 | Opened window width. ||
209213
| windowHeight | number | 400 | Opened window height. ||
214+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
210215

211216
#### 📖 [TelegramIcon props](https://github.com/Bunlong/next-share#-icons-props)
212217

@@ -240,6 +245,7 @@ import {
240245
| posttype | string | <code>link</code> | ||
241246
| windowWidth | number | 660 | Opened window width. ||
242247
| windowHeight | number | 460 | Opened window height. ||
248+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
243249

244250
#### 📖 [TumblrIcon props](https://github.com/Bunlong/next-share#-icons-props)
245251

@@ -273,6 +279,7 @@ import {
273279
| related | array | | ||
274280
| windowWidth | number | 550 | Opened window width. ||
275281
| windowHeight | number | 400 | Opened window height. ||
282+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
276283

277284
#### 📖 [TwitterIcon props](https://github.com/Bunlong/next-share#-icons-props)
278285

@@ -304,6 +311,7 @@ import {
304311
| separator | | | ||
305312
| windowWidth | number | 660 | Opened window width. ||
306313
| windowHeight | number | 460 | Opened window height. ||
314+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
307315

308316
#### 📖 [ViberIcon props](https://github.com/Bunlong/next-share#-icons-props)
309317

@@ -336,6 +344,7 @@ import {
336344
| image | string | | The image URL that will be shared. ||
337345
| windowWidth | number | 660 | Opened window width. ||
338346
| windowHeight | number | 550 | Opened window height. ||
347+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
339348

340349
#### 📖 [WeiboIcon props](https://github.com/Bunlong/next-share#-icons-props)
341350

@@ -368,6 +377,7 @@ import {
368377
| separator | string | | ||
369378
| windowWidth | number | 550 | Opened window width. ||
370379
| windowHeight | number | 400 | Opened window height. ||
380+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
371381

372382
#### 📖 [WhatsappIcon props](https://github.com/Bunlong/next-share#-icons-props)
373383

@@ -394,6 +404,7 @@ import {
394404
| url | string | | The URL of the shared page. ||
395405
| windowWidth | number | 750 | Opened window width. ||
396406
| windowHeight | number | 600 | Opened window height. ||
407+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
397408
<!-- | title | string | | The title of the shared page. | ❌ |
398409
| summary | string | | Description of the shared page. | ❌ |
399410
| source | string | | Source of the content (e.g. your website or application name). | ❌ | -->
@@ -440,6 +451,7 @@ import {
440451
| noVkLinks | boolean | | If true is passed, there will be no links to the user's profile in the open window. Only for mobile devices. ||
441452
| windowWidth | number | 660 | Opened window width. ||
442453
| windowHeight | number | 460 | Opened window height. ||
454+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
443455

444456
#### 📖 [VKIcon props](https://github.com/Bunlong/next-share#-icons-props)
445457

@@ -472,6 +484,7 @@ import {
472484
| imageUrl | string | | Image url of the shared page. ||
473485
| windowWidth | number | 660 | Opened window width. ||
474486
| windowHeight | number | 460 | Opened window height. ||
487+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
475488

476489
#### 📖 [MailruIcon props](https://github.com/Bunlong/next-share#-icons-props)
477490

@@ -504,6 +517,7 @@ import {
504517
| description | string | | Description of the shared page. ||
505518
| windowWidth | number | 660 | Opened window width. ||
506519
| windowHeight | number | 460 | Opened window height. ||
520+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
507521

508522
#### 📖 [LivejournalIcon props](https://github.com/Bunlong/next-share#-icons-props)
509523

@@ -535,6 +549,7 @@ import {
535549
| hashtag | string | | ||
536550
| windowWidth | number | 550 | Opened window width. ||
537551
| windowHeight | number | 400 | Opened window height. ||
552+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
538553

539554
#### 📖 [WorkplaceIcon props](https://github.com/Bunlong/next-share#-icons-props)
540555

@@ -565,6 +580,7 @@ import {
565580
| title | string | | Title of the shared page. Note that if Pocket detects a title tag on the page being saved, this parameter will be ignored and the title tag of the saved page will be used instead. ||
566581
| windowWidth | number | 500 | Opened window width. ||
567582
| windowHeight | number | 500 | Opened window height. ||
583+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
568584

569585
#### 📖 [PocketIcon props](https://github.com/Bunlong/next-share#-icons-props)
570586

@@ -596,6 +612,7 @@ import {
596612
| description | string | | Description of the shared page. ||
597613
| windowWidth | number | 500 | Opened window width. ||
598614
| windowHeight | number | 500 | Opened window height. ||
615+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
599616

600617
#### 📖 [InstapaperIcon props](https://github.com/Bunlong/next-share#-icons-props)
601618

@@ -626,6 +643,7 @@ import {
626643
| title | string | | Title of the shared page. ||
627644
| windowWidth | number | 660 | Opened window width. ||
628645
| windowHeight | number | 460 | Opened window height. ||
646+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
629647

630648
#### 📖 [HatenaIcon props](https://github.com/Bunlong/next-share#-icons-props)
631649

@@ -658,6 +676,7 @@ import {
658676
| to | string | | A user ID of a recipient. Once the dialog comes up, the sender can specify additional people as recipients. ||
659677
| windowWidth | number | 1000 | Opened window width. ||
660678
| windowHeight | number | 820 | Opened window height. ||
679+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
661680

662681
#### 📖 [FacebookMessengerIcon props](https://github.com/Bunlong/next-share#-icons-props)
663682

@@ -689,6 +708,7 @@ import {
689708
| subject | string | | ||
690709
| body | string | | ||
691710
| separator | string | | ||
711+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
692712

693713
#### 📖 [EmailIcon props](https://github.com/Bunlong/next-share#-icons-props)
694714

@@ -731,6 +751,7 @@ import {
731751
| borderRadius | number | | Set rounded corners if using round icon. ||
732752
| bgStyle | object | | Customize background style. ||
733753
| iconFillColor | string | <code>white</code> | Customize icon fill color. ||
754+
| blankTarget | boolean | false | Open share window in a new tab if set to `true`. ||
734755

735756
## 💡 Usage of ShareCount
736757

@@ -778,9 +799,9 @@ import {
778799

779800
## 📜 Changelog
780801

781-
Latest version 0.18.4 (2022-10-12):
802+
Latest version 0.19.0 (2022-10-17):
782803

783-
* Upgrade Linkedin API
804+
* Add blankTarget props to open up a new tab
784805

785806
Details changes for each release are documented in the [CHANGELOG.md](https://github.com/Bunlong/next-share/blob/master/CHANGELOG.md).
786807

@@ -853,6 +874,15 @@ How to contribute:
853874
</tr>
854875
</table>
855876

877+
## 👨‍👩‍👦 Advertisement
878+
879+
You maybe interested.
880+
881+
* [React Patterns](https://github.com/reactpatterns/reactpatterns) – React patterns & techniques to use in development for React Developer.
882+
* [React Papaparse](https://github.com/Bunlong/react-papaparse) – The fastest in-browser CSV (or delimited text) parser for React.
883+
* [Next QRCode](https://github.com/bunlong/next-qrcode) – React hooks for generating QR code for your next React apps.
884+
* [Next Time Ago](https://github.com/Bunlong/next-time-ago) – A lightweight tiny time-ago component for your next React apps.
885+
856886
## ⚖️ License
857887

858888
The MIT License [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-share",
3-
"version": "0.18.4",
3+
"version": "0.19.0",
44
"description": "Social media share buttons for your next React apps.",
55
"author": "Bunlong <bunlong.van@gmail.com>",
66
"license": "MIT",

src/components/SocialShareButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface CustomProps<LinkOptions> {
4545
*/
4646
onShareWindowClose?: () => void;
4747
resetButtonStyle?: boolean;
48+
blankTarget?: boolean;
4849
}
4950

5051
export type Props<LinkOptions> = Omit<
@@ -68,6 +69,7 @@ export default class SocialShareButton<LinkOptions> extends Component<
6869
windowHeight = 400,
6970
windowPosition = 'windowCenter',
7071
windowWidth = 550,
72+
blankTarget = false,
7173
} = this.props;
7274

7375
const windowConfig = {
@@ -78,7 +80,7 @@ export default class SocialShareButton<LinkOptions> extends Component<
7880
: getPositionOnScreenCenter(windowWidth, windowHeight)),
7981
};
8082

81-
CustomWindow(link, windowConfig, onShareWindowClose);
83+
CustomWindow(link, windowConfig, blankTarget, onShareWindowClose);
8284
};
8385

8486
handleClick = async (event: React.MouseEvent<HTMLButtonElement>) => {

src/utils.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export function CustomWindow(
55
width,
66
...configRest
77
}: { height: number; width: number; [key: string]: any },
8+
blankTarget?: boolean,
89
onClose?: (dialog: Window | null) => void,
910
) {
1011
const config: { [key: string]: string | number } = {
@@ -22,13 +23,19 @@ export function CustomWindow(
2223
...configRest,
2324
};
2425

25-
const dialog = window.open(
26-
url,
27-
'',
28-
Object.keys(config)
29-
.map((key) => `${key}=${config[key]}`)
30-
.join(', '),
31-
);
26+
let dialog: Window;
27+
28+
if (blankTarget) {
29+
dialog = <Window>window.open(url, '_blank');
30+
} else {
31+
dialog = <Window>window.open(
32+
url,
33+
'',
34+
Object.keys(config)
35+
.map((key) => `${key}=${config[key]}`)
36+
.join(', '),
37+
);
38+
}
3239

3340
if (onClose) {
3441
const interval = window.setInterval(() => {

0 commit comments

Comments
 (0)