-
-
Notifications
You must be signed in to change notification settings - Fork 41
docs: move framework-specific guides from README to /docs #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Callbacks | ||
|
|
||
| ```jsx | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| onShare: (platform, url) => { | ||
| console.log(`Shared on ${platform}: ${url}`); | ||
| }, | ||
| onCopy: (url) => { | ||
| console.log('Link copied:', url); | ||
| } | ||
| }); | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| # Customization & Configuration | ||
|
|
||
| ## Basic Options | ||
|
|
||
| ```jsx | ||
| new SocialShareButton({ | ||
| container: '#share-button', // Required: CSS selector or DOM element | ||
| url: 'https://example.com', // Optional: defaults to window.location.href | ||
| title: 'Custom Title', // Optional: defaults to document.title | ||
| buttonText: 'Share', // Optional: button label text | ||
| buttonStyle: 'primary', // default | primary | compact | icon-only | ||
| theme: 'dark', // dark | light | ||
| platforms: ['twitter', 'linkedin'] // Optional: defaults to all platforms | ||
| }); | ||
| ``` | ||
|
|
||
| ## All Available Options | ||
|
|
||
| | Option | Type | Default | Description | | ||
| |--------|------|---------|-------------| | ||
| | `container` | string/Element | - | **Required.** CSS selector or DOM element | | ||
| | `url` | string | `window.location.href` | URL to share | | ||
| | `title` | string | `document.title` | Share title/headline | | ||
| | `description` | string | `''` | Additional description text | | ||
| | `hashtags` | array | `[]` | Hashtags for posts (e.g., `['js', 'webdev']`) | | ||
| | `via` | string | `''` | Twitter handle (without @) | | ||
| | `platforms` | array | All platforms | Platforms to show (see below) | | ||
| | `buttonText` | string | `'Share'` | Button label text | | ||
| | `buttonStyle` | string | `'default'` | `default`, `primary`, `compact`, `icon-only` | | ||
| | `buttonColor` | string | `''` | Custom button background color | | ||
| | `buttonHoverColor` | string | `''` | Custom button hover color | | ||
| | `customClass` | string | `''` | Additional CSS class for button | | ||
| | `theme` | string | `'dark'` | `dark` or `light` | | ||
| | `modalPosition` | string | `'center'` | Modal position on screen | | ||
| | `showButton` | boolean | `true` | Show/hide the share button | | ||
| | `onShare` | function | `null` | Callback when user shares: `(platform, url) => {}` | | ||
| | `onCopy` | function | `null` | Callback when user copies link: `(url) => {}` | | ||
|
|
||
| **Available Platforms:** | ||
| `whatsapp`, `facebook`, `twitter`, `linkedin`, `telegram`, `reddit`, `email` | ||
|
|
||
| ## Customize Share Message/Post Text | ||
|
|
||
| Control the text that appears when users share to social platforms: | ||
|
|
||
| ```jsx | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| url: 'https://myproject.com', | ||
| title: 'Check out my awesome project!', // Main title/headline | ||
| description: 'An amazing tool for developers', // Additional description | ||
| hashtags: ['javascript', 'webdev', 'opensource'], // Hashtags included in posts | ||
| via: 'MyProjectHandle' // Your Twitter handle | ||
| }); | ||
| ``` | ||
|
|
||
| **How messages are customized per platform:** | ||
| - **WhatsApp:** `title` + `description` + `hashtags` + link | ||
| - **Facebook:** `title` + `description` + `hashtags` + link | ||
| - **Twitter/X:** `title` + `description` + `hashtags` + `via` handle + link | ||
| - **Telegram:** `title` + `description` + `hashtags` + link | ||
| - **LinkedIn:** `title` + `description` + link | ||
| - **Reddit:** `title` - `description` (used as title) | ||
| - **Email:** Subject = `title`, Body = `description` + link | ||
|
|
||
| ## Customize Button Color & Appearance | ||
|
|
||
| **Option 1: Use Pre-built Styles** (Easiest) | ||
|
|
||
| ```jsx | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| buttonStyle: 'primary' // or 'default', 'compact', 'icon-only' | ||
| }); | ||
| ``` | ||
|
|
||
| **Option 2: Programmatic Color Customization** (Recommended) | ||
|
|
||
| Pass `buttonColor` and `buttonHoverColor` to match your project's color scheme: | ||
|
|
||
| ```jsx | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| buttonColor: '#ff6b6b', // Button background color | ||
| buttonHoverColor: '#ff5252' // Hover state color | ||
| }); | ||
| ``` | ||
|
|
||
| **Option 3: CSS Class Customization** (Advanced) | ||
|
|
||
| For more complex styling, use a custom CSS class: | ||
|
|
||
| ```jsx | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| buttonStyle: 'primary', | ||
| customClass: 'my-custom-button' | ||
| }); | ||
| ``` | ||
|
|
||
| Then in your CSS file: | ||
|
|
||
| ```css | ||
| /* Override the button background color */ | ||
| .my-custom-button.social-share-btn { | ||
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | ||
| color: white; | ||
| } | ||
|
|
||
| /* Customize hover state */ | ||
| .my-custom-button.social-share-btn:hover { | ||
| background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); | ||
| } | ||
| ``` | ||
|
|
||
| **Color Examples:** | ||
|
|
||
| ```jsx | ||
| // Material Design Red | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| buttonColor: '#f44336', | ||
| buttonHoverColor: '#da190b' | ||
| }); | ||
|
|
||
| // Tailwind Blue | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| buttonColor: '#3b82f6', | ||
| buttonHoverColor: '#2563eb' | ||
| }); | ||
|
|
||
| // Custom Brand Color | ||
| new SocialShareButton({ | ||
| container: '#share-button', | ||
| buttonColor: '#your-brand-color', | ||
| buttonHoverColor: '#your-brand-color-dark' | ||
| }); | ||
| ``` | ||
|
|
||
| ## Button Styles | ||
|
|
||
| | Style | Description | | ||
| |-------|-------------| | ||
| | `default` | Standard button with icon and text | | ||
| | `primary` | Gradient button (recommended) | | ||
| | `compact` | Smaller size for tight spaces | | ||
| | `icon-only` | Icon without text | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # 📚 Documentation | ||
|
|
||
| ## Installation | ||
|
|
||
| - [Installation via CDN](./installation-cdn.md) | ||
| - [Installation via npm](./installation-npm.md) | ||
|
|
||
| ## Framework Guides | ||
|
|
||
| - [Vanilla JavaScript](./vanilla-js.md) | ||
| - [React](./react.md) | ||
| - [Next.js (App Router)](./nextjs-app-router.md) | ||
| - [Next.js (Pages Router)](./nextjs-pages-router.md) | ||
| - [Vue / Angular / Vite](./vue-angular.md) | ||
|
|
||
| ## Configuration & Customization | ||
|
|
||
| - [Customization & Configuration](./customization.md) | ||
| - [Callbacks](./callbacks.md) | ||
| - [Dynamic URL Updates (SPA)](./spa-dynamic-url.md) | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| - [Troubleshooting Guide](./troubleshooting.md) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Installation via CDN | ||
|
|
||
| ### Via CDN (Recommended) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```html | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.css"> | ||
| <script src="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.js"></script> | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Installation via npm | ||
|
|
||
| ### Using npm Package | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```javascript | ||
| import SocialShareButton from 'social-share-button-aossie'; | ||
| import 'social-share-button-aossie/src/social-share-button.css'; | ||
|
|
||
| new SocialShareButton({ | ||
| container: '#share-button' | ||
| }); | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Next.js (App Router) | ||
|
|
||
| ### Step 1: Add CDN to `app/layout.tsx` | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```tsx | ||
| import Script from 'next/script'; | ||
|
|
||
| export default function RootLayout({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <html lang="en"> | ||
| <head> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.css" | ||
| /> | ||
| </head> | ||
| <body> | ||
| {children} | ||
| <Script | ||
| src="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.js" | ||
| strategy="beforeInteractive" | ||
| /> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### Step 2: In your component: | ||
|
|
||
| ```tsx | ||
| 'use client'; | ||
|
|
||
| import { useEffect } from 'react'; | ||
|
|
||
| export default function Header() { | ||
| useEffect(() => { | ||
| new window.SocialShareButton({ | ||
| container: '#share-button' | ||
| }); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <header> | ||
| <div id="share-button"></div> | ||
| </header> | ||
| ); | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Next.js (Pages Router) | ||
|
|
||
| ### Step 1: Add CDN to `pages/_document.tsx` | ||
|
|
||
| ```tsx | ||
| import { Html, Head, Main, NextScript } from 'next/document'; | ||
|
|
||
| export default function Document() { | ||
| return ( | ||
| <Html> | ||
| <Head> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.css" | ||
| /> | ||
| </Head> | ||
| <body> | ||
| <Main /> | ||
| <NextScript /> | ||
| <script src="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.js"></script> | ||
| </body> | ||
| </Html> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### Step 2: In your component: | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```tsx | ||
| import { useEffect } from 'react'; | ||
|
|
||
| export default function Header() { | ||
| useEffect(() => { | ||
| new window.SocialShareButton({ | ||
| container: '#share-button' | ||
| }); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <header> | ||
| <div id="share-button"></div> | ||
| </header> | ||
| ); | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # React (Create React App) | ||
|
|
||
| ### Step 1: Add CDN to `public/index.html` | ||
|
|
||
| ```html | ||
| <head> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.css"> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script src="https://cdn.jsdelivr.net/gh/AOSSIE-Org/SocialShareButton@v1.0.3/src/social-share-button.js"></script> | ||
| </body> | ||
| ``` | ||
|
|
||
| ### Step 2: In your component: | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```jsx | ||
| import { useEffect } from 'react'; | ||
|
|
||
| function Header() { | ||
| useEffect(() => { | ||
| new window.SocialShareButton({ | ||
| container: '#share-button' | ||
| }); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <header> | ||
| <div id="share-button"></div> | ||
| </header> | ||
| ); | ||
| } | ||
|
|
||
| export default Header; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Update URL Dynamically (SPA) | ||
|
|
||
| ```jsx | ||
| const shareButton = useRef(null); | ||
|
|
||
| useEffect(() => { | ||
| shareButton.current = new window.SocialShareButton({ | ||
| container: '#share-button' | ||
| }); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (shareButton.current) { | ||
| shareButton.current.updateOptions({ | ||
| url: window.location.href | ||
| }); | ||
| } | ||
| }, [pathname]); // Update on route change | ||
|
Comment on lines
+18
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n docs/spa-dynamic-url.mdRepository: AOSSIE-Org/SocialShareButton Length of output: 580 🏁 Script executed: find . -name "README*" -o -name "INSTALL*" | head -20Repository: AOSSIE-Org/SocialShareButton Length of output: 83 🏁 Script executed: ls -la docs/ 2>/dev/null | head -20Repository: AOSSIE-Org/SocialShareButton Length of output: 970 🏁 Script executed: rg "usePathname|useRouter|pathname" docs/ -A 2 -B 2Repository: AOSSIE-Org/SocialShareButton Length of output: 227 🏁 Script executed: cat -n docs/react.mdRepository: AOSSIE-Org/SocialShareButton Length of output: 999 🏁 Script executed: cat -n docs/nextjs-app-router.mdRepository: AOSSIE-Org/SocialShareButton Length of output: 1389 🏁 Script executed: head -50 README.mdRepository: AOSSIE-Org/SocialShareButton Length of output: 2120 🏁 Script executed: cat -n docs/nextjs-pages-router.mdRepository: AOSSIE-Org/SocialShareButton Length of output: 1296 The snippet references undefined The code at line 18 depends on Since this appears to be a framework-agnostic SPA example, clarify how to obtain 🤖 Prompt for AI Agents |
||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add demo section in it.