react-sharesheet 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,581 @@
1
+ # react-sharesheet
2
+
3
+ [![npm version](https://img.shields.io/npm/v/react-sharesheet.svg)](https://www.npmjs.com/package/react-sharesheet)
4
+ [![npm downloads](https://img.shields.io/npm/dm/react-sharesheet.svg)](https://www.npmjs.com/package/react-sharesheet)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ A beautiful, fully customizable share sheet component for React. Supports 15+ social platforms with a modern drawer UI, CSS variable theming, and headless mode for complete control.
8
+
9
+ ## ✨ Features
10
+
11
+ - 🎨 **Fully themeable** — CSS variables + Tailwind class overrides
12
+ - 🧩 **Headless mode** — Use the hook to build your own UI
13
+ - 📱 **Mobile-first** — Beautiful drawer with native share API support
14
+ - 🔧 **Customizable** — Hide/show platforms, custom labels & icons
15
+ - 📦 **Tree-shakeable** — Import only what you need
16
+ - 🌐 **15+ platforms** — WhatsApp, X, Telegram, Instagram, and more
17
+
18
+ ## 📦 Installation
19
+
20
+ ```bash
21
+ npm install react-sharesheet
22
+ # or
23
+ pnpm add react-sharesheet
24
+ # or
25
+ yarn add react-sharesheet
26
+ ```
27
+
28
+ ### Peer Dependencies
29
+
30
+ ```bash
31
+ npm install react react-dom
32
+ ```
33
+
34
+ ### Tailwind CSS Setup
35
+
36
+ Add the package to your `tailwind.config.js` content array:
37
+
38
+ ```js
39
+ // tailwind.config.js
40
+ module.exports = {
41
+ content: [
42
+ "./src/**/*.{js,ts,jsx,tsx}",
43
+ "./node_modules/react-sharesheet/dist/**/*.{js,mjs}", // 👈 Add this
44
+ ],
45
+ // ...
46
+ }
47
+ ```
48
+
49
+ ## 🚀 Quick Start
50
+
51
+ ### Full Drawer (recommended)
52
+
53
+ ```tsx
54
+ import { ShareSheetDrawer } from "react-sharesheet";
55
+
56
+ function App() {
57
+ return (
58
+ <ShareSheetDrawer
59
+ title="Share this!"
60
+ shareUrl="https://example.com"
61
+ shareText="Check out this awesome page!"
62
+ >
63
+ <button>Share</button>
64
+ </ShareSheetDrawer>
65
+ );
66
+ }
67
+ ```
68
+
69
+ ### Content Only (for custom modals)
70
+
71
+ ```tsx
72
+ import { ShareSheetContent } from "react-sharesheet/content";
73
+
74
+ function CustomModal() {
75
+ return (
76
+ <Dialog>
77
+ <ShareSheetContent
78
+ shareUrl="https://example.com"
79
+ shareText="Check this out!"
80
+ />
81
+ </Dialog>
82
+ );
83
+ }
84
+ ```
85
+
86
+ ### Headless (full control)
87
+
88
+ ```tsx
89
+ import { useShareSheet } from "react-sharesheet/headless";
90
+
91
+ function CustomShareUI() {
92
+ const {
93
+ canNativeShare,
94
+ copied,
95
+ copyLink,
96
+ nativeShare,
97
+ shareWhatsApp,
98
+ shareX,
99
+ } = useShareSheet({
100
+ shareUrl: "https://example.com",
101
+ shareText: "Check this out!",
102
+ });
103
+
104
+ return (
105
+ <div className="flex gap-2">
106
+ {canNativeShare && <button onClick={nativeShare}>Share</button>}
107
+ <button onClick={copyLink}>{copied ? "Copied!" : "Copy"}</button>
108
+ <button onClick={shareWhatsApp}>WhatsApp</button>
109
+ <button onClick={shareX}>X</button>
110
+ </div>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ## 🖼️ Content Preview
116
+
117
+ The share sheet can display a preview of the content being shared. It automatically detects the content type based on the URL and displays an appropriate preview.
118
+
119
+ ### Auto-detection
120
+
121
+ ```tsx
122
+ // Image preview (detected from extension)
123
+ <ShareSheetDrawer preview="https://example.com/image.png" {...props} />
124
+
125
+ // Video preview (detected from extension)
126
+ <ShareSheetDrawer preview="https://example.com/video.mp4" {...props} />
127
+
128
+ // Audio file (shows icon + filename)
129
+ <ShareSheetDrawer preview="https://example.com/song.mp3" {...props} />
130
+
131
+ // Link (shows link icon + URL)
132
+ <ShareSheetDrawer preview="https://example.com/page" {...props} />
133
+ ```
134
+
135
+ ### Explicit Type
136
+
137
+ ```tsx
138
+ // Force image type (e.g., for API endpoints)
139
+ <ShareSheetDrawer
140
+ preview={{ url: "/api/og?id=123", type: "image" }}
141
+ {...props}
142
+ />
143
+
144
+ // Video with poster image
145
+ <ShareSheetDrawer
146
+ preview={{
147
+ url: "https://example.com/video.mp4",
148
+ type: "video",
149
+ poster: "https://example.com/thumbnail.jpg"
150
+ }}
151
+ {...props}
152
+ />
153
+
154
+ // File with custom filename
155
+ <ShareSheetDrawer
156
+ preview={{
157
+ url: "https://example.com/doc.pdf",
158
+ type: "file",
159
+ filename: "Report Q4 2024.pdf"
160
+ }}
161
+ {...props}
162
+ />
163
+ ```
164
+
165
+ ### PreviewConfig
166
+
167
+ ```ts
168
+ interface PreviewConfig {
169
+ url: string; // URL of the content
170
+ type?: PreviewType; // "image" | "video" | "audio" | "file" | "link" | "auto"
171
+ filename?: string; // Display name for file/audio types
172
+ alt?: string; // Alt text for images
173
+ poster?: string; // Poster image for videos
174
+ }
175
+ ```
176
+
177
+ ### Supported Formats
178
+
179
+ - **Images**: jpg, jpeg, png, gif, webp, svg, bmp, ico, avif
180
+ - **Videos**: mp4, webm, mov, avi, mkv, m4v, ogv
181
+ - **Audio**: mp3, wav, ogg, m4a, aac, flac, wma
182
+
183
+ ## 🎨 Theming
184
+
185
+ ### CSS Variables
186
+
187
+ Override these variables to match your theme:
188
+
189
+ ```css
190
+ :root {
191
+ /* Drawer */
192
+ --sharesheet-overlay-bg: rgba(0, 0, 0, 0.7);
193
+ --sharesheet-drawer-bg: #09090b;
194
+ --sharesheet-drawer-border: #27272a;
195
+ --sharesheet-handle-bg: #27272a;
196
+
197
+ /* Typography */
198
+ --sharesheet-title-color: #ffffff;
199
+ --sharesheet-subtitle-color: #a1a1aa;
200
+ --sharesheet-button-label-color: #ffffff;
201
+
202
+ /* Image Preview */
203
+ --sharesheet-preview-bg: rgba(255, 255, 255, 0.05);
204
+ --sharesheet-preview-shimmer: rgba(255, 255, 255, 0.1);
205
+
206
+ /* Platform colors (optional - defaults to brand colors) */
207
+ --sharesheet-whatsapp-bg: #25D366;
208
+ --sharesheet-telegram-bg: #229ED9;
209
+ /* ... see full list below */
210
+ }
211
+
212
+ /* Dark/Light mode support */
213
+ .dark {
214
+ --sharesheet-drawer-bg: #0a0a0a;
215
+ }
216
+
217
+ .light {
218
+ --sharesheet-drawer-bg: #ffffff;
219
+ --sharesheet-title-color: #09090b;
220
+ }
221
+ ```
222
+
223
+ <details>
224
+ <summary>All CSS Variables</summary>
225
+
226
+ ```css
227
+ /* Drawer */
228
+ --sharesheet-overlay-bg: rgba(0, 0, 0, 0.7);
229
+ --sharesheet-drawer-bg: #09090b;
230
+ --sharesheet-drawer-border: #27272a;
231
+ --sharesheet-handle-bg: #27272a;
232
+
233
+ /* Typography */
234
+ --sharesheet-title-color: #ffffff;
235
+ --sharesheet-subtitle-color: #a1a1aa;
236
+ --sharesheet-button-label-color: #ffffff;
237
+
238
+ /* Image Preview */
239
+ --sharesheet-preview-bg: rgba(255, 255, 255, 0.05);
240
+ --sharesheet-preview-shimmer: rgba(255, 255, 255, 0.1);
241
+
242
+ /* Platform backgrounds */
243
+ --sharesheet-native-bg: #7c3aed;
244
+ --sharesheet-copy-bg: #3b82f6;
245
+ --sharesheet-download-bg: #ef4444;
246
+ --sharesheet-whatsapp-bg: #25D366;
247
+ --sharesheet-telegram-bg: #229ED9;
248
+ --sharesheet-instagram-bg: #E1306C;
249
+ --sharesheet-facebook-bg: #1877F2;
250
+ --sharesheet-snapchat-bg: #FFFC00;
251
+ --sharesheet-sms-bg: #22c55e;
252
+ --sharesheet-email-bg: #f97316;
253
+ --sharesheet-linkedin-bg: #0A66C2;
254
+ --sharesheet-reddit-bg: #FF4500;
255
+ --sharesheet-x-bg: #000000;
256
+ --sharesheet-tiktok-bg: #000000;
257
+ --sharesheet-threads-bg: #000000;
258
+ ```
259
+
260
+ </details>
261
+
262
+ ### Tailwind Class Overrides
263
+
264
+ Override any part of the component with `classNames`:
265
+
266
+ ```tsx
267
+ <ShareSheetDrawer
268
+ shareUrl="..."
269
+ shareText="..."
270
+ classNames={{
271
+ // Drawer
272
+ overlay: "bg-black/80 backdrop-blur-sm",
273
+ drawer: "bg-background rounded-t-3xl",
274
+ drawerInner: "p-6",
275
+ handle: "bg-muted",
276
+
277
+ // Content
278
+ root: "max-w-lg",
279
+ header: "mb-6",
280
+ title: "text-3xl font-bold text-foreground",
281
+ subtitle: "text-muted-foreground",
282
+ grid: "gap-6",
283
+ button: "w-20",
284
+ buttonIcon: "rounded-xl shadow-lg",
285
+ buttonLabel: "font-medium",
286
+ }}
287
+ >
288
+ ```
289
+
290
+ ## ⚙️ API Reference
291
+
292
+ ### Props
293
+
294
+ #### ShareSheetContent / ShareSheetDrawer
295
+
296
+ | Prop | Type | Default | Description |
297
+ |------|------|---------|-------------|
298
+ | `title` | `string` | `"Share"` | Title displayed at the top |
299
+ | `shareUrl` | `string` | **required** | URL to share |
300
+ | `shareText` | `string` | **required** | Text to share |
301
+ | `preview` | `string \| PreviewConfig` | — | Preview of content (see Preview section below) |
302
+ | `downloadUrl` | `string` | — | URL for download button |
303
+ | `downloadFilename` | `string` | — | Filename for download |
304
+ | `className` | `string` | — | Class for root container |
305
+ | `classNames` | `object` | — | Override sub-component classes |
306
+ | `buttonSize` | `number` | `45` | Button size in pixels |
307
+ | `iconSize` | `number` | `22` | Icon size in pixels |
308
+ | `show` | `ShareOption[]` | — | Only show these platforms |
309
+ | `hide` | `ShareOption[]` | — | Hide these platforms |
310
+ | `labels` | `object` | — | Custom button labels |
311
+ | `icons` | `object` | — | Custom button icons |
312
+ | `onNativeShare` | `() => void` | — | Native share callback |
313
+ | `onCopy` | `() => void` | — | Copy callback |
314
+ | `onDownload` | `() => void` | — | Download callback |
315
+
316
+ #### ShareSheetDrawer (additional)
317
+
318
+ | Prop | Type | Default | Description |
319
+ |------|------|---------|-------------|
320
+ | `children` | `ReactNode` | **required** | Trigger element |
321
+ | `disabled` | `boolean` | `false` | Disable the trigger |
322
+ | `open` | `boolean` | — | Controlled open state |
323
+ | `onOpenChange` | `(open: boolean) => void` | — | Open state callback |
324
+
325
+ ### ShareOption
326
+
327
+ Available platform identifiers:
328
+
329
+ ```ts
330
+ type ShareOption =
331
+ | "native" // Native share API
332
+ | "copy" // Copy to clipboard
333
+ | "download" // Download file
334
+ | "whatsapp"
335
+ | "telegram"
336
+ | "instagram"
337
+ | "facebook"
338
+ | "snapchat"
339
+ | "sms"
340
+ | "email"
341
+ | "linkedin"
342
+ | "reddit"
343
+ | "x"
344
+ | "tiktok"
345
+ | "threads";
346
+ ```
347
+
348
+ ### useShareSheet Hook
349
+
350
+ ```ts
351
+ const {
352
+ canNativeShare, // boolean - browser supports native share
353
+ copied, // boolean - link was recently copied
354
+ downloading, // boolean - download in progress
355
+ safeUrl, // string - resolved share URL
356
+
357
+ // Actions
358
+ copyLink, // () => Promise<void>
359
+ nativeShare, // () => Promise<void>
360
+ downloadFile, // () => Promise<void>
361
+
362
+ // Platform share functions
363
+ shareWhatsApp, // () => void
364
+ shareTelegram, // () => void
365
+ shareX, // () => void
366
+ shareFacebook, // () => void
367
+ shareInstagram, // () => void
368
+ shareTikTok, // () => void
369
+ shareThreads, // () => void
370
+ shareSnapchat, // () => void
371
+ shareSMS, // () => void
372
+ shareEmail, // () => void
373
+ shareLinkedIn, // () => void
374
+ shareReddit, // () => void
375
+ } = useShareSheet({
376
+ shareUrl: string,
377
+ shareText: string,
378
+ downloadUrl?: string,
379
+ downloadFilename?: string,
380
+ emailSubject?: string,
381
+ onNativeShare?: () => void,
382
+ onCopy?: () => void,
383
+ onDownload?: () => void,
384
+ });
385
+ ```
386
+
387
+ ## 📦 Exports
388
+
389
+ ```ts
390
+ // Everything
391
+ import {
392
+ ShareSheetDrawer,
393
+ ShareSheetContent,
394
+ useShareSheet,
395
+ CSS_VARS,
396
+ CSS_VAR_DEFAULTS,
397
+ // Platform utilities
398
+ PLATFORMS,
399
+ PLATFORM_COLORS,
400
+ PLATFORM_ICONS,
401
+ PLATFORM_LABELS,
402
+ getPlatform,
403
+ getPlatformColor,
404
+ // Share functions
405
+ shareToWhatsApp,
406
+ shareToX,
407
+ // ...
408
+ } from "react-sharesheet";
409
+
410
+ // Content only (smaller bundle)
411
+ import { ShareSheetContent } from "react-sharesheet/content";
412
+
413
+ // Drawer only
414
+ import { ShareSheetDrawer } from "react-sharesheet/drawer";
415
+
416
+ // Headless (smallest bundle - no UI components)
417
+ import {
418
+ useShareSheet,
419
+ PLATFORM_COLORS,
420
+ PLATFORM_ICONS,
421
+ getPlatform,
422
+ shareToWhatsApp,
423
+ shareToX,
424
+ // ...
425
+ } from "react-sharesheet/headless";
426
+ ```
427
+
428
+ ## 🎨 Platform Utilities
429
+
430
+ Access platform colors, icons, and labels for custom UIs:
431
+
432
+ ```tsx
433
+ import {
434
+ PLATFORM_COLORS,
435
+ PLATFORM_ICONS,
436
+ PLATFORM_LABELS,
437
+ getPlatform,
438
+ getAllPlatforms,
439
+ } from "react-sharesheet";
440
+
441
+ // Get all platforms
442
+ const platforms = getAllPlatforms();
443
+ // [{ id: "whatsapp", label: "WhatsApp", colors: {...}, Icon: ... }, ...]
444
+
445
+ // Get single platform
446
+ const whatsapp = getPlatform("whatsapp");
447
+ // { id: "whatsapp", label: "WhatsApp", colors: { bg: "#25D366", text: "#fff" }, Icon: ... }
448
+
449
+ // Use colors directly
450
+ const bgColor = PLATFORM_COLORS.whatsapp.bg; // "#25D366"
451
+ const textColor = PLATFORM_COLORS.whatsapp.text; // "#ffffff"
452
+
453
+ // Use icons
454
+ const WhatsAppIcon = PLATFORM_ICONS.whatsapp;
455
+ <WhatsAppIcon size={24} className="text-white" />
456
+
457
+ // Use labels
458
+ const label = PLATFORM_LABELS.whatsapp; // "WhatsApp"
459
+ ```
460
+
461
+ ### Build a custom share button
462
+
463
+ ```tsx
464
+ import { getPlatform, shareToWhatsApp } from "react-sharesheet";
465
+
466
+ function WhatsAppButton({ url, text }: { url: string; text: string }) {
467
+ const { colors, Icon, label } = getPlatform("whatsapp");
468
+
469
+ return (
470
+ <button
471
+ onClick={() => shareToWhatsApp(url, text)}
472
+ style={{ backgroundColor: colors.bg, color: colors.text }}
473
+ >
474
+ <Icon size={20} />
475
+ {label}
476
+ </button>
477
+ );
478
+ }
479
+ ```
480
+
481
+ ## 🛠 Examples
482
+
483
+ ### Filter platforms
484
+
485
+ ```tsx
486
+ // Show only specific platforms
487
+ <ShareSheetContent
488
+ shareUrl="..."
489
+ shareText="..."
490
+ show={["copy", "whatsapp", "telegram", "x"]}
491
+ />
492
+
493
+ // Hide specific platforms
494
+ <ShareSheetContent
495
+ shareUrl="..."
496
+ shareText="..."
497
+ hide={["tiktok", "snapchat", "threads"]}
498
+ />
499
+ ```
500
+
501
+ ### Custom labels
502
+
503
+ ```tsx
504
+ <ShareSheetContent
505
+ shareUrl="..."
506
+ shareText="..."
507
+ labels={{
508
+ copy: "Copy Link",
509
+ native: "More options...",
510
+ whatsapp: "Send via WhatsApp",
511
+ }}
512
+ />
513
+ ```
514
+
515
+ ### With download
516
+
517
+ ```tsx
518
+ <ShareSheetDrawer
519
+ shareUrl="https://example.com/post/123"
520
+ shareText="Check out my video!"
521
+ downloadUrl="https://example.com/video.mp4"
522
+ downloadFilename="my-video.mp4"
523
+ >
524
+ <button>Share</button>
525
+ </ShareSheetDrawer>
526
+ ```
527
+
528
+ ### Controlled state
529
+
530
+ ```tsx
531
+ function ControlledExample() {
532
+ const [open, setOpen] = useState(false);
533
+
534
+ return (
535
+ <>
536
+ <button onClick={() => setOpen(true)}>Open Share Sheet</button>
537
+ <ShareSheetDrawer
538
+ open={open}
539
+ onOpenChange={setOpen}
540
+ shareUrl="..."
541
+ shareText="..."
542
+ >
543
+ <span /> {/* Hidden trigger */}
544
+ </ShareSheetDrawer>
545
+ </>
546
+ );
547
+ }
548
+ ```
549
+
550
+ ## 📋 Requirements
551
+
552
+ - React 18+
553
+ - Tailwind CSS (for default styling)
554
+
555
+ > **Note:** If you're not using Tailwind, you can use the headless hook to build your own UI, or override all classes via `classNames`.
556
+
557
+ ## 🔄 Migration from v0.x
558
+
559
+ If you're upgrading from `@gwendall/share-menu`:
560
+
561
+ ```tsx
562
+ // Old imports
563
+ import { ShareMenuDrawer, ShareMenuContent, useShareMenu } from "@gwendall/share-menu";
564
+
565
+ // New imports (backwards compatible aliases available)
566
+ import { ShareSheetDrawer, ShareSheetContent, useShareSheet } from "react-sharesheet";
567
+
568
+ // CSS variables changed from --share-menu-* to --sharesheet-*
569
+ // Old: --share-menu-drawer-bg
570
+ // New: --sharesheet-drawer-bg
571
+ ```
572
+
573
+ Legacy exports (`ShareMenuDrawer`, `ShareMenuContent`, `useShareMenu`) are still available but deprecated.
574
+
575
+ ## 🤝 Contributing
576
+
577
+ Contributions are welcome! Please feel free to submit a Pull Request.
578
+
579
+ ## 📄 License
580
+
581
+ MIT © [Gwendall](https://github.com/gwendall)
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { S as ShareSheetContentProps } from './platforms-DU1DVDFq.mjs';
3
+ export { m as CSS_VARS, C as CSS_VARS_UI, n as CSS_VAR_DEFAULTS, l as CSS_VAR_UI_DEFAULTS, q as PLATFORM_COLORS, t as PLATFORM_CSS_VARS, f as ShareMenuContentClassNames, d as ShareMenuContentProps, h as ShareOption, b as ShareSheetContentClassNames } from './platforms-DU1DVDFq.mjs';
4
+ import 'react';
5
+
6
+ declare function ShareSheetContent({ title, shareUrl, shareText, preview, downloadUrl, downloadFilename, className, classNames, buttonSize, iconSize, onNativeShare, onCopy, onDownload, hide, show, labels, icons, }: ShareSheetContentProps): react_jsx_runtime.JSX.Element;
7
+ /** @deprecated Use ShareSheetContent instead */
8
+ declare const ShareMenuContent: typeof ShareSheetContent;
9
+
10
+ export { ShareMenuContent, ShareSheetContent, ShareSheetContentProps };
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { S as ShareSheetContentProps } from './platforms-DU1DVDFq.js';
3
+ export { m as CSS_VARS, C as CSS_VARS_UI, n as CSS_VAR_DEFAULTS, l as CSS_VAR_UI_DEFAULTS, q as PLATFORM_COLORS, t as PLATFORM_CSS_VARS, f as ShareMenuContentClassNames, d as ShareMenuContentProps, h as ShareOption, b as ShareSheetContentClassNames } from './platforms-DU1DVDFq.js';
4
+ import 'react';
5
+
6
+ declare function ShareSheetContent({ title, shareUrl, shareText, preview, downloadUrl, downloadFilename, className, classNames, buttonSize, iconSize, onNativeShare, onCopy, onDownload, hide, show, labels, icons, }: ShareSheetContentProps): react_jsx_runtime.JSX.Element;
7
+ /** @deprecated Use ShareSheetContent instead */
8
+ declare const ShareMenuContent: typeof ShareSheetContent;
9
+
10
+ export { ShareMenuContent, ShareSheetContent, ShareSheetContentProps };