react-sharesheet 1.0.0 → 1.1.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.
Files changed (41) hide show
  1. package/README.md +40 -53
  2. package/dist/content.d.mts +3 -3
  3. package/dist/content.d.ts +3 -3
  4. package/dist/content.js +192 -268
  5. package/dist/content.js.map +1 -1
  6. package/dist/content.mjs +194 -270
  7. package/dist/content.mjs.map +1 -1
  8. package/dist/drawer.d.mts +3 -3
  9. package/dist/drawer.d.ts +3 -3
  10. package/dist/drawer.js +194 -272
  11. package/dist/drawer.js.map +1 -1
  12. package/dist/drawer.mjs +196 -274
  13. package/dist/drawer.mjs.map +1 -1
  14. package/dist/headless.d.mts +22 -3
  15. package/dist/headless.d.ts +22 -3
  16. package/dist/headless.js +72 -0
  17. package/dist/headless.js.map +1 -1
  18. package/dist/headless.mjs +70 -1
  19. package/dist/headless.mjs.map +1 -1
  20. package/dist/index.d.mts +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +203 -272
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +202 -274
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/{platforms-DU1DVDFq.d.mts → platforms-CDJmSY8E.d.mts} +2 -19
  27. package/dist/{platforms-DU1DVDFq.d.ts → platforms-CDJmSY8E.d.ts} +2 -19
  28. package/package.json +12 -3
  29. package/src/ShareSheetContent.tsx +143 -306
  30. package/src/ShareSheetDrawer.tsx +2 -4
  31. package/src/__tests__/hooks.test.ts +213 -0
  32. package/src/__tests__/og-fetcher.test.ts +144 -0
  33. package/src/__tests__/platforms.test.ts +148 -0
  34. package/src/__tests__/setup.ts +22 -0
  35. package/src/__tests__/share-functions.test.ts +155 -0
  36. package/src/__tests__/utils.test.ts +64 -0
  37. package/src/headless.ts +4 -1
  38. package/src/hooks.ts +49 -1
  39. package/src/index.ts +4 -3
  40. package/src/og-fetcher.ts +64 -0
  41. package/src/types.ts +1 -20
package/README.md CHANGED
@@ -3,9 +3,12 @@
3
3
  [![npm version](https://img.shields.io/npm/v/react-sharesheet.svg)](https://www.npmjs.com/package/react-sharesheet)
4
4
  [![npm downloads](https://img.shields.io/npm/dm/react-sharesheet.svg)](https://www.npmjs.com/package/react-sharesheet)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Demo](https://img.shields.io/badge/demo-live-brightgreen.svg)](https://react-sharesheet.vercel.app)
6
7
 
7
8
  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
 
10
+ **[🚀 Live Demo](https://react-sharesheet.vercel.app)**
11
+
9
12
  ## ✨ Features
10
13
 
11
14
  - 🎨 **Fully themeable** — CSS variables + Tailwind class overrides
@@ -112,74 +115,59 @@ function CustomShareUI() {
112
115
  }
113
116
  ```
114
117
 
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
+ ## 🖼️ Automatic Link Preview
118
119
 
119
- ### Auto-detection
120
+ The share sheet automatically fetches Open Graph (OG) metadata from the `shareUrl` and displays a rich preview — just like Twitter, Telegram, and other platforms do when you paste a link.
120
121
 
121
122
  ```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} />
123
+ <ShareSheetDrawer
124
+ shareUrl="https://gwendall.com" // OG data fetched automatically!
125
+ shareText="Check out this site!"
126
+ >
127
+ <button>Share</button>
128
+ </ShareSheetDrawer>
129
+ ```
127
130
 
128
- // Audio file (shows icon + filename)
129
- <ShareSheetDrawer preview="https://example.com/song.mp3" {...props} />
131
+ The component will:
132
+ 1. Fetch OG metadata (title, description, image) from the URL
133
+ 2. Display a loading shimmer while fetching
134
+ 3. Show the OG image if available, or a placeholder with the page title
130
135
 
131
- // Link (shows link icon + URL)
132
- <ShareSheetDrawer preview="https://example.com/page" {...props} />
133
- ```
136
+ ### Using the OG Hook Directly
134
137
 
135
- ### Explicit Type
138
+ You can also use the `useOGData` hook for custom implementations:
136
139
 
137
140
  ```tsx
138
- // Force image type (e.g., for API endpoints)
139
- <ShareSheetDrawer
140
- preview={{ url: "/api/og?id=123", type: "image" }}
141
- {...props}
142
- />
141
+ import { useOGData } from "react-sharesheet/headless";
143
142
 
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
- />
143
+ function CustomPreview({ url }: { url: string }) {
144
+ const { ogData, loading, error } = useOGData(url);
153
145
 
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
- />
146
+ if (loading) return <div>Loading...</div>;
147
+ if (!ogData) return <div>No preview available</div>;
148
+
149
+ return (
150
+ <div>
151
+ {ogData.image && <img src={ogData.image} alt={ogData.title} />}
152
+ <h3>{ogData.title}</h3>
153
+ <p>{ogData.description}</p>
154
+ </div>
155
+ );
156
+ }
163
157
  ```
164
158
 
165
- ### PreviewConfig
159
+ ### OGData Type
166
160
 
167
161
  ```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
162
+ interface OGData {
163
+ title?: string; // Page title
164
+ description?: string; // Page description
165
+ image?: string; // OG image URL
166
+ url?: string; // Canonical URL
167
+ siteName?: string; // Site name
174
168
  }
175
169
  ```
176
170
 
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
171
  ## 🎨 Theming
184
172
 
185
173
  ### CSS Variables
@@ -296,9 +284,8 @@ Override any part of the component with `classNames`:
296
284
  | Prop | Type | Default | Description |
297
285
  |------|------|---------|-------------|
298
286
  | `title` | `string` | `"Share"` | Title displayed at the top |
299
- | `shareUrl` | `string` | **required** | URL to share |
287
+ | `shareUrl` | `string` | **required** | URL to share (OG preview fetched automatically) |
300
288
  | `shareText` | `string` | **required** | Text to share |
301
- | `preview` | `string \| PreviewConfig` | — | Preview of content (see Preview section below) |
302
289
  | `downloadUrl` | `string` | — | URL for download button |
303
290
  | `downloadFilename` | `string` | — | Filename for download |
304
291
  | `className` | `string` | — | Class for root container |
@@ -1,9 +1,9 @@
1
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';
2
+ import { S as ShareSheetContentProps } from './platforms-CDJmSY8E.mjs';
3
+ export { l as CSS_VARS, C as CSS_VARS_UI, m as CSS_VAR_DEFAULTS, k as CSS_VAR_UI_DEFAULTS, o as PLATFORM_COLORS, r as PLATFORM_CSS_VARS, f as ShareMenuContentClassNames, d as ShareMenuContentProps, h as ShareOption, b as ShareSheetContentClassNames } from './platforms-CDJmSY8E.mjs';
4
4
  import 'react';
5
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;
6
+ declare function ShareSheetContent({ title, shareUrl, shareText, downloadUrl, downloadFilename, className, classNames, buttonSize, iconSize, onNativeShare, onCopy, onDownload, hide, show, labels, icons, }: ShareSheetContentProps): react_jsx_runtime.JSX.Element;
7
7
  /** @deprecated Use ShareSheetContent instead */
8
8
  declare const ShareMenuContent: typeof ShareSheetContent;
9
9
 
package/dist/content.d.ts CHANGED
@@ -1,9 +1,9 @@
1
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';
2
+ import { S as ShareSheetContentProps } from './platforms-CDJmSY8E.js';
3
+ export { l as CSS_VARS, C as CSS_VARS_UI, m as CSS_VAR_DEFAULTS, k as CSS_VAR_UI_DEFAULTS, o as PLATFORM_COLORS, r as PLATFORM_CSS_VARS, f as ShareMenuContentClassNames, d as ShareMenuContentProps, h as ShareOption, b as ShareSheetContentClassNames } from './platforms-CDJmSY8E.js';
4
4
  import 'react';
5
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;
6
+ declare function ShareSheetContent({ title, shareUrl, shareText, downloadUrl, downloadFilename, className, classNames, buttonSize, iconSize, onNativeShare, onCopy, onDownload, hide, show, labels, icons, }: ShareSheetContentProps): react_jsx_runtime.JSX.Element;
7
7
  /** @deprecated Use ShareSheetContent instead */
8
8
  declare const ShareMenuContent: typeof ShareSheetContent;
9
9