diff --git a/README.md b/README.md index bf8c605..526c221 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@
- > ⚠️ **IMPORTANT** > > All project discussions happens on **[Discord](https://discord.com/channels/1022871757289422898/1479012884209078365)**. @@ -73,7 +72,7 @@ Lightweight social sharing component for web applications. Zero dependencies, fr - 🌐 Multiple platforms: WhatsApp, Facebook, X, LinkedIn, Telegram, Reddit, Email - 🎯 Zero dependencies - pure vanilla JavaScript -- ⚛️ Framework support: React, Next.js, Vue, Angular, or plain HTML +- ⚛️ Framework support: React, Next.js, Vue, Angular, Rails, Django, Laravel, or plain HTML - 🔄 Auto-detects current URL and page title - 📱 Fully responsive and mobile-ready - 🎨 Customizable themes (dark/light) @@ -86,7 +85,10 @@ Lightweight social sharing component for web applications. Zero dependencies, fr ### Via CDN (Recommended) ```html - + ``` @@ -101,11 +103,11 @@ Lightweight social sharing component for web applications. Zero dependencies, fr No matter which framework you use, integration always follows the same 3 steps: -| Step | What to do | Where | -|------|-----------|-------| -| **1️⃣ Load Library** | Add CSS + JS (CDN links) | Global layout file — `index.html` / `layout.tsx` / `_document.tsx` | -| **2️⃣ Add Container** | Place `` | The UI component where you want the button to appear | -| **3️⃣ Initialize** | Call `new SocialShareButton({ container: "#share-button" })` | Inside that component, after the DOM is ready (e.g. `useEffect`, `mounted`, `ngAfterViewInit`) | +| Step | What to do | Where | +| -------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | +| **1️⃣ Load Library** | Add CSS + JS (CDN links) | Global layout file — `index.html` / `layout.tsx` / `_document.tsx` | +| **2️⃣ Add Container** | Place `` | The UI component where you want the button to appear | +| **3️⃣ Initialize** | Call `new SocialShareButton({ container: "#share-button" })` | Inside that component, after the DOM is ready (e.g. `useEffect`, `mounted`, `ngAfterViewInit`) | > 💡 Pick your framework below for the full copy-paste snippet: @@ -132,8 +134,8 @@ No matter which framework you use, integration always follows the same 3 steps: Open an **existing** component that renders on every page — typically `src/components/Header.jsx`, `src/layouts/MainLayout.jsx`, or your root `App.jsx`. Add the snippet below to that component so the share button is consistently available across your app. ```jsx -import { useEffect, useRef } from "react"; -import { useLocation } from "react-router-dom"; // omit if not using React Router +import { useEffect, useRef } from 'react'; +import { useLocation } from 'react-router-dom'; // omit if not using React Router // ⬇️ Replace 'Header' with the name of the component where you want the // share button to appear — e.g. Navbar, MainLayout, App, etc. @@ -146,7 +148,7 @@ function Header() { if (initRef.current || !window.SocialShareButton) return; shareButtonRef.current = new window.SocialShareButton({ - container: "#share-button", + container: '#share-button', }); initRef.current = true; @@ -184,13 +186,9 @@ function Header() { ### Step 1: Add CDN to `app/layout.tsx` ```tsx -import Script from "next/script"; +import Script from 'next/script'; -export default function RootLayout({ - children, -}: { - children: React.ReactNode; -}) { +export default function RootLayout({ children }: { children: React.ReactNode }) { return ( @@ -216,10 +214,10 @@ export default function RootLayout({ Because `SocialShareButton` manipulates the DOM, it must run inside a **Client Component** (note the `"use client"` directive at the top). Add the snippet below to an existing component such as `app/components/Header.tsx` or `app/components/Navbar.tsx` — any component already included in your layout. ```tsx -"use client"; +'use client'; -import { useEffect, useRef } from "react"; -import { usePathname } from "next/navigation"; +import { useEffect, useRef } from 'react'; +import { usePathname } from 'next/navigation'; // ⬇️ Replace 'Header' with the name of the component where you want the // share button to appear — e.g. Navbar, MainLayout, App, etc. @@ -231,11 +229,10 @@ export default function Header() { useEffect(() => { const initButton = () => { - if (initRef.current || !window.SocialShareButton || !containerRef.current) - return; + if (initRef.current || !window.SocialShareButton || !containerRef.current) return; shareButtonRef.current = new window.SocialShareButton({ - container: "#share-button", + container: '#share-button', }); initRef.current = true; }; @@ -299,7 +296,7 @@ declare global { ### Step 1: Add CDN to `pages/_document.tsx` ```tsx -import { Html, Head, Main, NextScript } from "next/document"; +import { Html, Head, Main, NextScript } from 'next/document'; export default function Document() { return ( @@ -325,8 +322,8 @@ export default function Document() { Open an existing component that is rendered on every page — typically `components/Header.tsx`, `components/Navbar.tsx`, or `components/Layout.tsx`. Since `_document.tsx` loads the script globally, the button is ready to initialize in any of these components. ```tsx -import { useEffect, useRef } from "react"; -import { useRouter } from "next/router"; +import { useEffect, useRef } from 'react'; +import { useRouter } from 'next/router'; // ⬇️ Replace 'Header' with the name of the component where you want the // share button to appear — e.g. Navbar, MainLayout, App, etc. @@ -338,11 +335,10 @@ export default function Header() { useEffect(() => { const initButton = () => { - if (initRef.current || !window.SocialShareButton || !containerRef.current) - return; + if (initRef.current || !window.SocialShareButton || !containerRef.current) return; shareButtonRef.current = new window.SocialShareButton({ - container: "#share-button", + container: '#share-button', }); initRef.current = true; }; @@ -426,12 +422,80 @@ Open your root or layout component (e.g., `App.vue`, `app.component.html`, or `A // Add to your component's template/HTML first, // then initialize once the DOM is ready (e.g., in mounted(), ngAfterViewInit(), or useEffect()): new window.SocialShareButton({ - container: "#share-button", + container: '#share-button', }); ``` +