From 15fd50d4d28c6a342dc913aff672cdbecfb194b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20Nyga=CC=8Ard?= Date: Sat, 18 Nov 2023 11:18:10 +0200 Subject: [PATCH] PinterestShareButton: add support for pinId https://github.com/nygardk/react-share/pull/332 --- .changeset/poor-lizards-run.md | 5 +++++ README.md | 2 +- src/PinterestShareButton.ts | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .changeset/poor-lizards-run.md diff --git a/.changeset/poor-lizards-run.md b/.changeset/poor-lizards-run.md new file mode 100644 index 00000000..80d9ec7c --- /dev/null +++ b/.changeset/poor-lizards-run.md @@ -0,0 +1,5 @@ +--- +"react-share": minor +--- + +Added `pinId` prop for `PinterestShareButton`. diff --git a/README.md b/README.md index aa7be266..0e06069e 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ import { | LivejournalShareButton | - | **`title`** (string): Title of the shared page
**`description`** (string): Description of the shared page | | MailruShareButton | - | **`title`** (string): Title of the shared page
**`description`** (string): Description of the shared page
**`imageUrl`** (string): An absolute link to the image that will be shared | | OKShareButton | - | **`title`** (string): Title of the shared page
**`description`** (string): Description of the shared page
**`image`** (string): An absolute link to the image that will be shared | -| PinterestShareButton | **`media`** (string): An absolute link to the image that will be pinned | **`description`** (string): Description for the shared media. | +| PinterestShareButton | **`media`** (string): An absolute link to the image that will be pinned | **`description`** (string): Description for the shared
**`pinId`** (string): Id of existing pin - If you’ve already pinned this page, use this to treat any new Pins of this page as repins of the original. Doing this can give you a better feel for engagement, because any Pins you create will count towards repins of your original Pin. | | PocketShareButton | - | **`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. | | RedditShareButton | - | **`title`** (string): Title of the shared page | | TelegramShareButton | - | **`title`** (string): Title of the shared page
| diff --git a/src/PinterestShareButton.ts b/src/PinterestShareButton.ts index 9582d05b..96e2674a 100644 --- a/src/PinterestShareButton.ts +++ b/src/PinterestShareButton.ts @@ -2,10 +2,17 @@ import assert from './utils/assert'; import objectToGetParams from './utils/objectToGetParams'; import createShareButton from './hocs/createShareButton'; -function pinterestLink( - url: string, - { media, description }: { media: string; description?: string }, -) { +interface PinterestShareProps { + media: string; + description?: string; + pinId?: string; +} + +function pinterestLink(url: string, { media, description, pinId }: PinterestShareProps) { + if (pinId) { + return `https://pinterest.com/pin/${pinId}/repin/x/`; + } + assert(url, 'pinterest.url'); assert(media, 'pinterest.media'); @@ -19,12 +26,13 @@ function pinterestLink( ); } -const PinterestShareButton = createShareButton<{ media: string; description?: string }>( +const PinterestShareButton = createShareButton( 'pinterest', pinterestLink, props => ({ media: props.media, description: props.description, + pinId: props.pinId, }), { windowWidth: 1000,