Skip to content

Commit

Permalink
PinterestShareButton: add support for pinId
Browse files Browse the repository at this point in the history
  • Loading branch information
nygardk committed Nov 18, 2023
1 parent 65b53c5 commit 15fd50d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-lizards-run.md
@@ -0,0 +1,5 @@
---
"react-share": minor
---

Added `pinId` prop for `PinterestShareButton`.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -116,7 +116,7 @@ import {
| LivejournalShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page |
| MailruShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page<br/>**`imageUrl`** (string): An absolute link to the image that will be shared |
| OKShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page<br/>**`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<br/>**`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<br/> |
Expand Down
18 changes: 13 additions & 5 deletions src/PinterestShareButton.ts
Expand Up @@ -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');

Expand All @@ -19,12 +26,13 @@ function pinterestLink(
);
}

const PinterestShareButton = createShareButton<{ media: string; description?: string }>(
const PinterestShareButton = createShareButton<PinterestShareProps>(
'pinterest',
pinterestLink,
props => ({
media: props.media,
description: props.description,
pinId: props.pinId,
}),
{
windowWidth: 1000,
Expand Down

0 comments on commit 15fd50d

Please sign in to comment.