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 +581 -0
- package/dist/content.d.mts +10 -0
- package/dist/content.d.ts +10 -0
- package/dist/content.js +833 -0
- package/dist/content.js.map +1 -0
- package/dist/content.mjs +813 -0
- package/dist/content.mjs.map +1 -0
- package/dist/drawer.d.mts +10 -0
- package/dist/drawer.d.ts +10 -0
- package/dist/drawer.js +960 -0
- package/dist/drawer.js.map +1 -0
- package/dist/drawer.mjs +940 -0
- package/dist/drawer.mjs.map +1 -0
- package/dist/headless.d.mts +51 -0
- package/dist/headless.d.ts +51 -0
- package/dist/headless.js +405 -0
- package/dist/headless.js.map +1 -0
- package/dist/headless.mjs +364 -0
- package/dist/headless.mjs.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1040 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +991 -0
- package/dist/index.mjs.map +1 -0
- package/dist/platforms-DU1DVDFq.d.mts +280 -0
- package/dist/platforms-DU1DVDFq.d.ts +280 -0
- package/package.json +88 -0
- package/src/ShareSheetContent.tsx +538 -0
- package/src/ShareSheetDrawer.tsx +128 -0
- package/src/content.ts +4 -0
- package/src/drawer.ts +4 -0
- package/src/headless.ts +45 -0
- package/src/hooks.ts +192 -0
- package/src/index.ts +68 -0
- package/src/platforms.tsx +186 -0
- package/src/share-functions.ts +63 -0
- package/src/types.ts +236 -0
- package/src/utils.ts +15 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
/** CSS variable names for UI elements (non-platform specific) */
|
|
4
|
+
export const CSS_VARS_UI = {
|
|
5
|
+
// Drawer
|
|
6
|
+
overlayBg: "--sharesheet-overlay-bg",
|
|
7
|
+
drawerBg: "--sharesheet-drawer-bg",
|
|
8
|
+
drawerBorder: "--sharesheet-drawer-border",
|
|
9
|
+
handleBg: "--sharesheet-handle-bg",
|
|
10
|
+
// Content
|
|
11
|
+
titleColor: "--sharesheet-title-color",
|
|
12
|
+
subtitleColor: "--sharesheet-subtitle-color",
|
|
13
|
+
buttonLabelColor: "--sharesheet-button-label-color",
|
|
14
|
+
// Preview
|
|
15
|
+
previewBg: "--sharesheet-preview-bg",
|
|
16
|
+
previewShimmer: "--sharesheet-preview-shimmer",
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
/** Default values for UI CSS variables */
|
|
20
|
+
export const CSS_VAR_UI_DEFAULTS = {
|
|
21
|
+
[CSS_VARS_UI.overlayBg]: "rgba(0, 0, 0, 0.7)",
|
|
22
|
+
[CSS_VARS_UI.drawerBg]: "#09090b",
|
|
23
|
+
[CSS_VARS_UI.drawerBorder]: "#27272a",
|
|
24
|
+
[CSS_VARS_UI.handleBg]: "#27272a",
|
|
25
|
+
[CSS_VARS_UI.titleColor]: "#ffffff",
|
|
26
|
+
[CSS_VARS_UI.subtitleColor]: "#a1a1aa",
|
|
27
|
+
[CSS_VARS_UI.buttonLabelColor]: "#ffffff",
|
|
28
|
+
[CSS_VARS_UI.previewBg]: "rgba(255, 255, 255, 0.05)",
|
|
29
|
+
[CSS_VARS_UI.previewShimmer]: "rgba(255, 255, 255, 0.1)",
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
/** Available share options */
|
|
33
|
+
export type ShareOption =
|
|
34
|
+
| "native"
|
|
35
|
+
| "copy"
|
|
36
|
+
| "download"
|
|
37
|
+
| "whatsapp"
|
|
38
|
+
| "telegram"
|
|
39
|
+
| "instagram"
|
|
40
|
+
| "facebook"
|
|
41
|
+
| "snapchat"
|
|
42
|
+
| "sms"
|
|
43
|
+
| "email"
|
|
44
|
+
| "linkedin"
|
|
45
|
+
| "reddit"
|
|
46
|
+
| "x"
|
|
47
|
+
| "tiktok"
|
|
48
|
+
| "threads";
|
|
49
|
+
|
|
50
|
+
/** Class name overrides for ShareSheetContent */
|
|
51
|
+
export interface ShareSheetContentClassNames {
|
|
52
|
+
/** Root container */
|
|
53
|
+
root?: string;
|
|
54
|
+
/** Title container */
|
|
55
|
+
header?: string;
|
|
56
|
+
/** Main title text */
|
|
57
|
+
title?: string;
|
|
58
|
+
/** Subtitle/share text */
|
|
59
|
+
subtitle?: string;
|
|
60
|
+
/** Preview container */
|
|
61
|
+
preview?: string;
|
|
62
|
+
/** Preview skeleton/loading wrapper */
|
|
63
|
+
previewSkeleton?: string;
|
|
64
|
+
/** Preview image element */
|
|
65
|
+
previewImage?: string;
|
|
66
|
+
/** Preview video element */
|
|
67
|
+
previewVideo?: string;
|
|
68
|
+
/** Preview file/audio container */
|
|
69
|
+
previewFile?: string;
|
|
70
|
+
/** Preview file icon */
|
|
71
|
+
previewFileIcon?: string;
|
|
72
|
+
/** Preview filename text */
|
|
73
|
+
previewFilename?: string;
|
|
74
|
+
/** Preview link container */
|
|
75
|
+
previewLink?: string;
|
|
76
|
+
/** Buttons grid container */
|
|
77
|
+
grid?: string;
|
|
78
|
+
/** Individual button wrapper */
|
|
79
|
+
button?: string;
|
|
80
|
+
/** Button icon container */
|
|
81
|
+
buttonIcon?: string;
|
|
82
|
+
/** Button label text */
|
|
83
|
+
buttonLabel?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Class name overrides for ShareSheetDrawer */
|
|
87
|
+
export interface ShareSheetDrawerClassNames extends ShareSheetContentClassNames {
|
|
88
|
+
/** Drawer overlay */
|
|
89
|
+
overlay?: string;
|
|
90
|
+
/** Drawer content panel */
|
|
91
|
+
drawer?: string;
|
|
92
|
+
/** Drawer inner content wrapper */
|
|
93
|
+
drawerInner?: string;
|
|
94
|
+
/** Drawer handle */
|
|
95
|
+
handle?: string;
|
|
96
|
+
/** Trigger wrapper */
|
|
97
|
+
trigger?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Preview content type */
|
|
101
|
+
export type PreviewType = "image" | "video" | "audio" | "file" | "link" | "auto";
|
|
102
|
+
|
|
103
|
+
/** Preview configuration */
|
|
104
|
+
export interface PreviewConfig {
|
|
105
|
+
/** URL of the content to preview */
|
|
106
|
+
url: string;
|
|
107
|
+
/** Type of content (auto-detected if not provided) */
|
|
108
|
+
type?: PreviewType;
|
|
109
|
+
/** Filename to display (for file/audio types) */
|
|
110
|
+
filename?: string;
|
|
111
|
+
/** Alt text for images */
|
|
112
|
+
alt?: string;
|
|
113
|
+
/** Poster image for videos */
|
|
114
|
+
poster?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface ShareSheetContentProps {
|
|
118
|
+
/** Title displayed at the top of the sheet */
|
|
119
|
+
title?: string;
|
|
120
|
+
/** URL to share */
|
|
121
|
+
shareUrl: string;
|
|
122
|
+
/** Text to share alongside the URL */
|
|
123
|
+
shareText: string;
|
|
124
|
+
/** Preview of content being shared (string URL or config object) */
|
|
125
|
+
preview?: string | PreviewConfig | null;
|
|
126
|
+
/** Optional URL for download functionality */
|
|
127
|
+
downloadUrl?: string | null;
|
|
128
|
+
/** Filename for downloaded file */
|
|
129
|
+
downloadFilename?: string;
|
|
130
|
+
/** Custom class name for the container (shorthand for classNames.root) */
|
|
131
|
+
className?: string;
|
|
132
|
+
/** Override class names for sub-components */
|
|
133
|
+
classNames?: ShareSheetContentClassNames;
|
|
134
|
+
/** Button size in pixels */
|
|
135
|
+
buttonSize?: number;
|
|
136
|
+
/** Icon size in pixels */
|
|
137
|
+
iconSize?: number;
|
|
138
|
+
/** Called when native share is triggered */
|
|
139
|
+
onNativeShare?: () => void;
|
|
140
|
+
/** Called when link is copied */
|
|
141
|
+
onCopy?: () => void;
|
|
142
|
+
/** Called when download starts */
|
|
143
|
+
onDownload?: () => void;
|
|
144
|
+
/** Hide specific share options */
|
|
145
|
+
hide?: ShareOption[];
|
|
146
|
+
/** Show only specific share options */
|
|
147
|
+
show?: ShareOption[];
|
|
148
|
+
/** Custom labels for buttons */
|
|
149
|
+
labels?: Partial<Record<ShareOption, string>>;
|
|
150
|
+
/** Custom icons for buttons */
|
|
151
|
+
icons?: Partial<Record<ShareOption, ReactNode>>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface ShareSheetDrawerProps extends ShareSheetContentProps {
|
|
155
|
+
/** Whether the drawer is disabled */
|
|
156
|
+
disabled?: boolean;
|
|
157
|
+
/** Trigger element for the drawer */
|
|
158
|
+
children: React.ReactNode;
|
|
159
|
+
/** Controlled open state */
|
|
160
|
+
open?: boolean;
|
|
161
|
+
/** Callback when open state changes */
|
|
162
|
+
onOpenChange?: (open: boolean) => void;
|
|
163
|
+
/** Override class names for sub-components */
|
|
164
|
+
classNames?: ShareSheetDrawerClassNames;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Share button configuration (internal) */
|
|
168
|
+
export interface ShareButtonConfig {
|
|
169
|
+
id: ShareOption;
|
|
170
|
+
label: string;
|
|
171
|
+
icon: ReactNode;
|
|
172
|
+
bgColor: string;
|
|
173
|
+
textColor?: string;
|
|
174
|
+
onClick: () => void;
|
|
175
|
+
condition?: boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Return type of useShareSheet hook */
|
|
179
|
+
export interface UseShareSheetReturn {
|
|
180
|
+
/** Whether the browser supports native share */
|
|
181
|
+
canNativeShare: boolean;
|
|
182
|
+
/** Whether the link was recently copied */
|
|
183
|
+
copied: boolean;
|
|
184
|
+
/** Whether a download is in progress */
|
|
185
|
+
downloading: boolean;
|
|
186
|
+
/** The safe URL (falls back to current page URL) */
|
|
187
|
+
safeUrl: string;
|
|
188
|
+
/** Copy the share URL to clipboard */
|
|
189
|
+
copyLink: () => Promise<void>;
|
|
190
|
+
/** Trigger native share dialog */
|
|
191
|
+
nativeShare: () => Promise<void>;
|
|
192
|
+
/** Download the file from downloadUrl */
|
|
193
|
+
downloadFile: () => Promise<void>;
|
|
194
|
+
/** Share to WhatsApp */
|
|
195
|
+
shareWhatsApp: () => void;
|
|
196
|
+
/** Share to Telegram */
|
|
197
|
+
shareTelegram: () => void;
|
|
198
|
+
/** Share to X (Twitter) */
|
|
199
|
+
shareX: () => void;
|
|
200
|
+
/** Share to Facebook */
|
|
201
|
+
shareFacebook: () => void;
|
|
202
|
+
/** Open Instagram app */
|
|
203
|
+
shareInstagram: () => void;
|
|
204
|
+
/** Open TikTok app */
|
|
205
|
+
shareTikTok: () => void;
|
|
206
|
+
/** Open Threads app */
|
|
207
|
+
shareThreads: () => void;
|
|
208
|
+
/** Share to Snapchat */
|
|
209
|
+
shareSnapchat: () => void;
|
|
210
|
+
/** Share via SMS */
|
|
211
|
+
shareSMS: () => void;
|
|
212
|
+
/** Share via Email */
|
|
213
|
+
shareEmail: () => void;
|
|
214
|
+
/** Share to LinkedIn */
|
|
215
|
+
shareLinkedIn: () => void;
|
|
216
|
+
/** Share to Reddit */
|
|
217
|
+
shareReddit: () => void;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Legacy exports for backwards compatibility
|
|
221
|
+
/** @deprecated Use CSS_VARS_UI instead */
|
|
222
|
+
export const CSS_VARS = CSS_VARS_UI;
|
|
223
|
+
/** @deprecated Use CSS_VAR_UI_DEFAULTS instead */
|
|
224
|
+
export const CSS_VAR_DEFAULTS = CSS_VAR_UI_DEFAULTS;
|
|
225
|
+
|
|
226
|
+
// Legacy type aliases for backwards compatibility
|
|
227
|
+
/** @deprecated Use ShareSheetContentClassNames instead */
|
|
228
|
+
export type ShareMenuContentClassNames = ShareSheetContentClassNames;
|
|
229
|
+
/** @deprecated Use ShareSheetDrawerClassNames instead */
|
|
230
|
+
export type ShareMenuDrawerClassNames = ShareSheetDrawerClassNames;
|
|
231
|
+
/** @deprecated Use ShareSheetContentProps instead */
|
|
232
|
+
export type ShareMenuContentProps = ShareSheetContentProps;
|
|
233
|
+
/** @deprecated Use ShareSheetDrawerProps instead */
|
|
234
|
+
export type ShareMenuDrawerProps = ShareSheetDrawerProps;
|
|
235
|
+
/** @deprecated Use UseShareSheetReturn instead */
|
|
236
|
+
export type UseShareMenuReturn = UseShareSheetReturn;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { clsx, type ClassValue } from "clsx";
|
|
2
|
+
import { twMerge } from "tailwind-merge";
|
|
3
|
+
|
|
4
|
+
export function cn(...inputs: ClassValue[]) {
|
|
5
|
+
return twMerge(clsx(inputs));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function openUrl(url: string) {
|
|
9
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getSafeUrl(shareUrl: string): string {
|
|
13
|
+
return shareUrl || (typeof window !== "undefined" ? window.location.href : "");
|
|
14
|
+
}
|
|
15
|
+
|