Skip to content

Commit a3cffc8

Browse files
authored
Merge pull request #97 from swathi2006/feat-pinterest-support
feat: add Pinterest sharing support
2 parents 4bc9bcc + 9d00576 commit a3cffc8

4 files changed

Lines changed: 31 additions & 23 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Lightweight social sharing component for web applications. Zero dependencies, fr
7171

7272
## Features
7373

74-
- 🌐 Multiple platforms: WhatsApp, Facebook, X, LinkedIn, Telegram, Reddit, Email
74+
- 🌐 Multiple platforms: WhatsApp, Facebook, X, LinkedIn, Telegram, Reddit, Email, Pinterest
7575
- 🎯 Zero dependencies - pure vanilla JavaScript
7676
- ⚛️ Framework support: React, Next.js, Vue, Angular, or plain HTML
7777
- 🔄 Auto-detects current URL and page title
@@ -473,7 +473,7 @@ new SocialShareButton({
473473
| `onCopy` | function | `null` | Callback when user copies link: `(url) => {}` |
474474
475475
**Available Platforms:**
476-
`whatsapp`, `facebook`, `twitter`, `linkedin`, `telegram`, `reddit`, `email`
476+
`whatsapp`, `facebook`, `twitter`, `linkedin`, `telegram`, `reddit`, `email`, `pinterest`
477477
478478
### Customize Share Message/Post Text
479479
@@ -499,6 +499,7 @@ new SocialShareButton({
499499
- **LinkedIn:** `title` + `description` + link
500500
- **Reddit:** `title` - `description` (used as title)
501501
- **Email:** Subject = `title`, Body = `description` + link
502+
- **Pinterest:** `title` + `description` + `hashtags` + link
502503
503504
### Customize Button Color & Appearance
504505

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ <h2>✨ Key Features</h2>
277277
<div class="feature-card">
278278
<div class="feature-icon">🌐</div>
279279
<h3>7+ Platforms</h3>
280-
<p>WhatsApp, Facebook, X, LinkedIn, Telegram, Reddit, Email</p>
280+
<p>WhatsApp, Facebook, X, LinkedIn, Telegram, Reddit, Email, Pinterest</p>
281281
</div>
282282
<div class="feature-card">
283283
<div class="feature-icon">🎨</div>
@@ -380,7 +380,7 @@ <h3>Professional</h3>
380380
</div>
381381
<div class="demo-item">
382382
<h3>Social Media</h3>
383-
<p>Facebook, X, reddit</p>
383+
<p>Facebook, X, Reddit, Pinterest</p>
384384
<div id="demo-social"></div>
385385
</div>
386386
<div class="demo-item">
@@ -534,7 +534,7 @@ <h2 style="color: #fff; margin-bottom: 20px;">Ready to Get Started?</h2>
534534
container: '#demo-social',
535535
url: demoUrl,
536536
title: demoTitle,
537-
platforms: ['facebook', 'twitter', 'reddit'],
537+
platforms: ['facebook', 'twitter', 'reddit', 'pinterest'],
538538
buttonText: 'Share'
539539
});
540540

src/social-share-button-react.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const SocialShareButton = ({
1313
"linkedin",
1414
"telegram",
1515
"reddit",
16+
"pinterest"
1617
],
1718
theme = "dark",
1819
buttonText = "Share",

src/social-share-button.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ class SocialShareButton {
1919
description: options.description || "",
2020
hashtags: options.hashtags || [],
2121
via: options.via || "",
22-
platforms: options.platforms || [
23-
"whatsapp",
24-
"facebook",
25-
"twitter",
26-
"linkedin",
27-
"telegram",
28-
"reddit",
29-
],
22+
platforms: options.platforms || [
23+
"whatsapp",
24+
"facebook",
25+
"twitter",
26+
"linkedin",
27+
"telegram",
28+
"reddit",
29+
"pinterest"
30+
],
3031
theme: options.theme || "dark",
3132
buttonText: options.buttonText || "Share",
3233
customClass: options.customClass || "",
@@ -168,8 +169,13 @@ class SocialShareButton {
168169
},
169170
email: {
170171
name: "Email",
171-
color: "#7f7f7f",
172-
icon: '<path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/>',
172+
color: '#7f7f7f',
173+
icon: '<path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/>'
174+
},
175+
pinterest: {
176+
name: "Pinterest",
177+
color: '#E60023',
178+
icon: '<path d="M12 0C5.372 0 0 5.373 0 12c0 4.99 3.052 9.267 7.386 11.059-.102-.94-.194-2.385.04-3.413.211-.904 1.356-5.752 1.356-5.752s-.346-.693-.346-1.717c0-1.608.932-2.808 2.093-2.808.987 0 1.463.741 1.463 1.63 0 .993-.632 2.476-.958 3.853-.273 1.155.58 2.098 1.718 2.098 2.062 0 3.646-2.174 3.646-5.31 0-2.778-1.997-4.722-4.847-4.722-3.304 0-5.242 2.478-5.242 5.039 0 .997.384 2.066.865 2.647.095.115.109.215.08.331-.088.365-.282 1.155-.321 1.316-.05.212-.165.257-.381.155-1.418-.66-2.305-2.733-2.305-4.397 0-3.579 2.601-6.867 7.497-6.867 3.936 0 6.998 2.805 6.998 6.557 0 3.91-2.466 7.058-5.892 7.058-1.15 0-2.232-.597-2.6-1.302l-.707 2.692c-.255.983-.946 2.215-1.408 2.966A12.002 12.002 0 0024 12C24 5.373 18.627 0 12 0z"/>'
173179
},
174180
};
175181

@@ -197,13 +203,8 @@ class SocialShareButton {
197203
const hashtagString = hashtags.length ? "#" + hashtags.join(" #") : "";
198204

199205
// Build platform-specific messages with customizable parameters
200-
let whatsappMessage,
201-
facebookMessage,
202-
twitterMessage,
203-
telegramMessage,
204-
redditTitle,
205-
emailBody;
206-
206+
let whatsappMessage, facebookMessage, twitterMessage, telegramMessage, redditTitle, emailBody, pinterestText;
207+
207208
// WhatsApp: Casual with emoji
208209
whatsappMessage = `\u{1F680} ${title}${description ? "\n\n" + description : ""}${hashtagString ? "\n\n" + hashtagString : ""}\n\nLive on the site \u{1F440}\nClean UI, smooth flow \u{2014} worth peeking\n\u{1F447}`;
209210

@@ -221,13 +222,17 @@ class SocialShareButton {
221222

222223
// Email: Friendly greeting
223224
emailBody = `Hey \u{1F44B}\n\nSharing a clean project I came across:\n${title}${description ? "\n\n" + description : ""}\n\nLive, simple, and usable \u{2014} take a look \u{1F447}`;
224-
225+
226+
// Pinterest: Title + Description
227+
pinterestText = `${title || ''}${description ? ' - ' + description : ''}`;
228+
225229
const encodedWhatsapp = encodeURIComponent(whatsappMessage);
226230
const encodedFacebook = encodeURIComponent(facebookMessage);
227231
const encodedTwitter = encodeURIComponent(twitterMessage);
228232
const encodedTelegram = encodeURIComponent(telegramMessage);
229233
const encodedReddit = encodeURIComponent(redditTitle);
230234
const encodedEmail = encodeURIComponent(emailBody);
235+
const encodedPinterest = encodeURIComponent(pinterestText);
231236

232237
const urls = {
233238
whatsapp: `https://wa.me/?text=${encodedWhatsapp}%20${encodedUrl}`,
@@ -237,6 +242,7 @@ class SocialShareButton {
237242
telegram: `https://t.me/share/url?url=${encodedUrl}&text=${encodedTelegram}`,
238243
reddit: `https://reddit.com/submit?url=${encodedUrl}&title=${encodedReddit}`,
239244
email: `mailto:?subject=${encodedTitle}&body=${encodedEmail}%20${encodedUrl}`,
245+
pinterest: `https://pinterest.com/pin/create/button/?url=${encodedUrl}&description=${encodedPinterest}`,
240246
};
241247

242248
return urls[platform] || "";

0 commit comments

Comments
 (0)