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.
- package/README.md +40 -53
- package/dist/content.d.mts +3 -3
- package/dist/content.d.ts +3 -3
- package/dist/content.js +192 -268
- package/dist/content.js.map +1 -1
- package/dist/content.mjs +194 -270
- package/dist/content.mjs.map +1 -1
- package/dist/drawer.d.mts +3 -3
- package/dist/drawer.d.ts +3 -3
- package/dist/drawer.js +194 -272
- package/dist/drawer.js.map +1 -1
- package/dist/drawer.mjs +196 -274
- package/dist/drawer.mjs.map +1 -1
- package/dist/headless.d.mts +22 -3
- package/dist/headless.d.ts +22 -3
- package/dist/headless.js +72 -0
- package/dist/headless.js.map +1 -1
- package/dist/headless.mjs +70 -1
- package/dist/headless.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +203 -272
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -274
- package/dist/index.mjs.map +1 -1
- package/dist/{platforms-DU1DVDFq.d.mts → platforms-CDJmSY8E.d.mts} +2 -19
- package/dist/{platforms-DU1DVDFq.d.ts → platforms-CDJmSY8E.d.ts} +2 -19
- package/package.json +12 -3
- package/src/ShareSheetContent.tsx +143 -306
- package/src/ShareSheetDrawer.tsx +2 -4
- package/src/__tests__/hooks.test.ts +213 -0
- package/src/__tests__/og-fetcher.test.ts +144 -0
- package/src/__tests__/platforms.test.ts +148 -0
- package/src/__tests__/setup.ts +22 -0
- package/src/__tests__/share-functions.test.ts +155 -0
- package/src/__tests__/utils.test.ts +64 -0
- package/src/headless.ts +4 -1
- package/src/hooks.ts +49 -1
- package/src/index.ts +4 -3
- package/src/og-fetcher.ts +64 -0
- package/src/types.ts +1 -20
package/README.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/react-sharesheet)
|
|
4
4
|
[](https://www.npmjs.com/package/react-sharesheet)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](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
|
-
## 🖼️
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
<
|
|
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
|
-
|
|
129
|
-
|
|
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
|
-
|
|
132
|
-
<ShareSheetDrawer preview="https://example.com/page" {...props} />
|
|
133
|
-
```
|
|
136
|
+
### Using the OG Hook Directly
|
|
134
137
|
|
|
135
|
-
|
|
138
|
+
You can also use the `useOGData` hook for custom implementations:
|
|
136
139
|
|
|
137
140
|
```tsx
|
|
138
|
-
|
|
139
|
-
<ShareSheetDrawer
|
|
140
|
-
preview={{ url: "/api/og?id=123", type: "image" }}
|
|
141
|
-
{...props}
|
|
142
|
-
/>
|
|
141
|
+
import { useOGData } from "react-sharesheet/headless";
|
|
143
142
|
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
155
|
-
<
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
###
|
|
159
|
+
### OGData Type
|
|
166
160
|
|
|
167
161
|
```ts
|
|
168
|
-
interface
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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 |
|
package/dist/content.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { S as ShareSheetContentProps } from './platforms-
|
|
3
|
-
export {
|
|
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,
|
|
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-
|
|
3
|
-
export {
|
|
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,
|
|
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
|
|