@wix/headless-stores 0.0.34 → 0.0.35
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/cjs/dist/react/ProductModifiers.d.ts +76 -0
- package/cjs/dist/react/ProductModifiers.js +81 -2
- package/cjs/dist/react/index.d.ts +0 -1
- package/cjs/dist/react/index.js +0 -1
- package/cjs/dist/services/index.d.ts +1 -2
- package/cjs/dist/services/index.js +1 -2
- package/dist/react/ProductModifiers.d.ts +76 -0
- package/dist/react/ProductModifiers.js +81 -2
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -1
- package/dist/services/index.d.ts +1 -2
- package/dist/services/index.js +1 -2
- package/package.json +1 -1
- package/cjs/dist/react/SocialSharing.d.ts +0 -194
- package/cjs/dist/react/SocialSharing.js +0 -170
- package/cjs/dist/services/social-sharing-service.d.ts +0 -34
- package/cjs/dist/services/social-sharing-service.js +0 -129
- package/dist/react/SocialSharing.d.ts +0 -194
- package/dist/react/SocialSharing.js +0 -170
- package/dist/services/social-sharing-service.d.ts +0 -34
- package/dist/services/social-sharing-service.js +0 -129
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useService } from "@wix/services-manager-react";
|
|
3
|
-
import { SocialSharingServiceDefinition, } from "../services/social-sharing-service.js";
|
|
4
|
-
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
5
|
-
/**
|
|
6
|
-
* Headless component for social sharing root
|
|
7
|
-
*
|
|
8
|
-
* @component
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
12
|
-
*
|
|
13
|
-
* function ShareProduct() {
|
|
14
|
-
* const productUrl = 'https://example.com/product/123';
|
|
15
|
-
* const productTitle = 'Amazing Product';
|
|
16
|
-
*
|
|
17
|
-
* return (
|
|
18
|
-
* <SocialSharing.Root>
|
|
19
|
-
* {({ platforms, shareCount, shareFacebook, shareTwitter, copyLink, shareNative }) => (
|
|
20
|
-
* <div>
|
|
21
|
-
* <p>Share this product ({shareCount} shares)</p>
|
|
22
|
-
* <div className="share-buttons">
|
|
23
|
-
* <button onClick={() => shareFacebook(productUrl, productTitle)}>
|
|
24
|
-
* Share on Facebook
|
|
25
|
-
* </button>
|
|
26
|
-
* <button onClick={() => shareTwitter(productUrl, `Check out ${productTitle}!`)}>
|
|
27
|
-
* Share on Twitter
|
|
28
|
-
* </button>
|
|
29
|
-
* <button onClick={() => copyLink(productUrl)}>
|
|
30
|
-
* Copy Link
|
|
31
|
-
* </button>
|
|
32
|
-
* <button onClick={() => shareNative({
|
|
33
|
-
* title: productTitle,
|
|
34
|
-
* text: 'Check this out!',
|
|
35
|
-
* url: productUrl
|
|
36
|
-
* })}>
|
|
37
|
-
* Share
|
|
38
|
-
* </button>
|
|
39
|
-
* </div>
|
|
40
|
-
* </div>
|
|
41
|
-
* )}
|
|
42
|
-
* </SocialSharing.Root>
|
|
43
|
-
* );
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export const Root = (props) => {
|
|
48
|
-
const service = useService(SocialSharingServiceDefinition);
|
|
49
|
-
const signalsService = useService(SignalsServiceDefinition);
|
|
50
|
-
const [platforms, setPlatforms] = React.useState([]);
|
|
51
|
-
const [shareCount, setShareCount] = React.useState(0);
|
|
52
|
-
const [lastShared, setLastShared] = React.useState(null);
|
|
53
|
-
React.useEffect(() => {
|
|
54
|
-
const effects = [
|
|
55
|
-
signalsService.effect(() => {
|
|
56
|
-
setPlatforms(service.availablePlatforms.get());
|
|
57
|
-
}),
|
|
58
|
-
signalsService.effect(() => {
|
|
59
|
-
setShareCount(service.shareCount.get());
|
|
60
|
-
}),
|
|
61
|
-
signalsService.effect(() => {
|
|
62
|
-
setLastShared(service.lastSharedPlatform.get());
|
|
63
|
-
}),
|
|
64
|
-
];
|
|
65
|
-
return () => effects.forEach((dispose) => dispose());
|
|
66
|
-
}, [service, signalsService]);
|
|
67
|
-
return props.children({
|
|
68
|
-
platforms,
|
|
69
|
-
shareCount,
|
|
70
|
-
lastShared,
|
|
71
|
-
shareFacebook: service.shareToFacebook,
|
|
72
|
-
shareTwitter: service.shareToTwitter,
|
|
73
|
-
shareLinkedIn: service.shareToLinkedIn,
|
|
74
|
-
shareWhatsApp: service.shareToWhatsApp,
|
|
75
|
-
shareEmail: service.shareToEmail,
|
|
76
|
-
copyLink: service.copyToClipboard,
|
|
77
|
-
shareNative: service.shareNative,
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Headless component for individual social platform
|
|
82
|
-
*
|
|
83
|
-
* @component
|
|
84
|
-
* @example
|
|
85
|
-
* ```tsx
|
|
86
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
87
|
-
*
|
|
88
|
-
* function SocialButton({ platform, onClick }) {
|
|
89
|
-
* return (
|
|
90
|
-
* <SocialSharing.Platform platform={platform} onClick={onClick}>
|
|
91
|
-
* {({ platform, onSelect }) => (
|
|
92
|
-
* <button
|
|
93
|
-
* onClick={onSelect}
|
|
94
|
-
* className={`social-btn social-btn-${platform.name.toLowerCase()}`}
|
|
95
|
-
* >
|
|
96
|
-
* <span className="icon">{platform.icon}</span>
|
|
97
|
-
* Share on {platform.name}
|
|
98
|
-
* </button>
|
|
99
|
-
* )}
|
|
100
|
-
* </SocialSharing.Platform>
|
|
101
|
-
* );
|
|
102
|
-
* }
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export const Platform = (props) => {
|
|
106
|
-
const { platform, onClick } = props;
|
|
107
|
-
return props.children({
|
|
108
|
-
platform,
|
|
109
|
-
onSelect: onClick,
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Headless component for social sharing platforms with logic
|
|
114
|
-
*
|
|
115
|
-
* @component
|
|
116
|
-
* @example
|
|
117
|
-
* ```tsx
|
|
118
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
119
|
-
*
|
|
120
|
-
* function SocialShareButtons() {
|
|
121
|
-
* return (
|
|
122
|
-
* <SocialSharing.Platforms
|
|
123
|
-
* url="https://example.com/product/123"
|
|
124
|
-
* title="Amazing Product"
|
|
125
|
-
* description="Check out this amazing product!"
|
|
126
|
-
* hashtags={['product', 'amazing']}
|
|
127
|
-
* >
|
|
128
|
-
* {({ platforms, shareFacebook, shareTwitter, shareLinkedIn, copyLink, shareNative }) => (
|
|
129
|
-
* <div className="social-platforms">
|
|
130
|
-
* <button onClick={shareFacebook}>Share on Facebook</button>
|
|
131
|
-
* <button onClick={shareTwitter}>Share on Twitter</button>
|
|
132
|
-
* <button onClick={shareLinkedIn}>Share on LinkedIn</button>
|
|
133
|
-
* <button onClick={() => copyLink()}>Copy Link</button>
|
|
134
|
-
* <button onClick={() => shareNative()}>Share</button>
|
|
135
|
-
* </div>
|
|
136
|
-
* )}
|
|
137
|
-
* </SocialSharing.Platforms>
|
|
138
|
-
* );
|
|
139
|
-
* }
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
export const Platforms = (props) => {
|
|
143
|
-
const { url, title, description = "", hashtags = [] } = props;
|
|
144
|
-
const service = useService(SocialSharingServiceDefinition);
|
|
145
|
-
const signalsService = useService(SignalsServiceDefinition);
|
|
146
|
-
const [platforms, setPlatforms] = React.useState([]);
|
|
147
|
-
React.useEffect(() => {
|
|
148
|
-
const dispose = signalsService.effect(() => {
|
|
149
|
-
setPlatforms(service.availablePlatforms.get());
|
|
150
|
-
});
|
|
151
|
-
return dispose;
|
|
152
|
-
}, [service, signalsService]);
|
|
153
|
-
const shareFacebook = () => service.shareToFacebook(url, title, description);
|
|
154
|
-
const shareTwitter = () => service.shareToTwitter(url, title, hashtags);
|
|
155
|
-
const shareLinkedIn = () => service.shareToLinkedIn(url, title, description);
|
|
156
|
-
const shareWhatsApp = () => service.shareToWhatsApp(url, `${title} - ${description}`);
|
|
157
|
-
const shareEmail = () => service.shareToEmail(url, title, description);
|
|
158
|
-
const copyLink = () => service.copyToClipboard(url);
|
|
159
|
-
const shareNative = () => service.shareNative({ title, text: description, url });
|
|
160
|
-
return props.children({
|
|
161
|
-
platforms,
|
|
162
|
-
shareFacebook,
|
|
163
|
-
shareTwitter,
|
|
164
|
-
shareLinkedIn,
|
|
165
|
-
shareWhatsApp,
|
|
166
|
-
shareEmail,
|
|
167
|
-
copyLink,
|
|
168
|
-
shareNative,
|
|
169
|
-
});
|
|
170
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
|
-
export interface SharingPlatform {
|
|
3
|
-
name: string;
|
|
4
|
-
icon: string;
|
|
5
|
-
color: string;
|
|
6
|
-
shareUrl: string;
|
|
7
|
-
}
|
|
8
|
-
export interface SocialSharingServiceAPI {
|
|
9
|
-
availablePlatforms: Signal<SharingPlatform[]>;
|
|
10
|
-
shareCount: Signal<number>;
|
|
11
|
-
lastSharedPlatform: Signal<string | null>;
|
|
12
|
-
shareToFacebook: (url: string, title: string, description?: string) => void;
|
|
13
|
-
shareToTwitter: (url: string, text: string, hashtags?: string[]) => void;
|
|
14
|
-
shareToLinkedIn: (url: string, title: string, summary?: string) => void;
|
|
15
|
-
shareToWhatsApp: (url: string, text: string) => void;
|
|
16
|
-
shareToEmail: (url: string, subject: string, body: string) => void;
|
|
17
|
-
copyToClipboard: (url: string) => Promise<boolean>;
|
|
18
|
-
shareNative: (data: {
|
|
19
|
-
title: string;
|
|
20
|
-
text: string;
|
|
21
|
-
url: string;
|
|
22
|
-
}) => Promise<boolean>;
|
|
23
|
-
trackShare: (platform: string) => void;
|
|
24
|
-
}
|
|
25
|
-
export declare const SocialSharingServiceDefinition: string & {
|
|
26
|
-
__api: SocialSharingServiceAPI;
|
|
27
|
-
__config: {};
|
|
28
|
-
isServiceDefinition?: boolean;
|
|
29
|
-
} & SocialSharingServiceAPI;
|
|
30
|
-
export declare const SocialSharingService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
31
|
-
__api: SocialSharingServiceAPI;
|
|
32
|
-
__config: {};
|
|
33
|
-
isServiceDefinition?: boolean;
|
|
34
|
-
} & SocialSharingServiceAPI, {}>;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
-
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
-
import { SocialPlatform, SocialPlatformShareUrl, } from "../enums/social-platform-enums.js";
|
|
4
|
-
export const SocialSharingServiceDefinition = defineService("socialSharing");
|
|
5
|
-
export const SocialSharingService = implementService.withConfig()(SocialSharingServiceDefinition, ({ getService }) => {
|
|
6
|
-
const signalsService = getService(SignalsServiceDefinition);
|
|
7
|
-
// Platform metadata is handled in components layer, only business logic here
|
|
8
|
-
const availablePlatforms = signalsService.signal([
|
|
9
|
-
{
|
|
10
|
-
name: "Facebook",
|
|
11
|
-
icon: "facebook",
|
|
12
|
-
color: "#1877F2",
|
|
13
|
-
shareUrl: SocialPlatformShareUrl.FACEBOOK,
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: "Twitter",
|
|
17
|
-
icon: "twitter",
|
|
18
|
-
color: "#1DA1F2",
|
|
19
|
-
shareUrl: SocialPlatformShareUrl.TWITTER,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: "LinkedIn",
|
|
23
|
-
icon: "linkedin",
|
|
24
|
-
color: "#0A66C2",
|
|
25
|
-
shareUrl: SocialPlatformShareUrl.LINKEDIN,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: "WhatsApp",
|
|
29
|
-
icon: "whatsapp",
|
|
30
|
-
color: "#25D366",
|
|
31
|
-
shareUrl: SocialPlatformShareUrl.WHATSAPP,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: "Email",
|
|
35
|
-
icon: "mail",
|
|
36
|
-
color: "#EA4335",
|
|
37
|
-
shareUrl: SocialPlatformShareUrl.EMAIL,
|
|
38
|
-
},
|
|
39
|
-
]);
|
|
40
|
-
const shareCount = signalsService.signal(0);
|
|
41
|
-
const lastSharedPlatform = signalsService.signal(null);
|
|
42
|
-
const openShareWindow = (url, platform) => {
|
|
43
|
-
const width = 600;
|
|
44
|
-
const height = 400;
|
|
45
|
-
const left = (window.screen.width - width) / 2;
|
|
46
|
-
const top = (window.screen.height - height) / 2;
|
|
47
|
-
window.open(url, `share-${platform}`, `width=${width},height=${height},left=${left},top=${top},scrollbars=yes,resizable=yes`);
|
|
48
|
-
trackShare(platform);
|
|
49
|
-
};
|
|
50
|
-
const shareToFacebook = (url, title, description) => {
|
|
51
|
-
const shareUrl = new URL(SocialPlatformShareUrl.FACEBOOK);
|
|
52
|
-
shareUrl.searchParams.set("u", url);
|
|
53
|
-
shareUrl.searchParams.set("quote", `${title}${description ? ` - ${description}` : ""}`);
|
|
54
|
-
openShareWindow(shareUrl.toString(), SocialPlatform.FACEBOOK);
|
|
55
|
-
};
|
|
56
|
-
const shareToTwitter = (url, text, hashtags) => {
|
|
57
|
-
const shareUrl = new URL(SocialPlatformShareUrl.TWITTER);
|
|
58
|
-
shareUrl.searchParams.set("url", url);
|
|
59
|
-
shareUrl.searchParams.set("text", text);
|
|
60
|
-
if (hashtags && hashtags.length > 0) {
|
|
61
|
-
shareUrl.searchParams.set("hashtags", hashtags.join(","));
|
|
62
|
-
}
|
|
63
|
-
openShareWindow(shareUrl.toString(), SocialPlatform.TWITTER);
|
|
64
|
-
};
|
|
65
|
-
const shareToLinkedIn = (url, title, summary) => {
|
|
66
|
-
const shareUrl = new URL(SocialPlatformShareUrl.LINKEDIN);
|
|
67
|
-
shareUrl.searchParams.set("url", url);
|
|
68
|
-
shareUrl.searchParams.set("title", title);
|
|
69
|
-
if (summary) {
|
|
70
|
-
shareUrl.searchParams.set("summary", summary);
|
|
71
|
-
}
|
|
72
|
-
openShareWindow(shareUrl.toString(), SocialPlatform.LINKEDIN);
|
|
73
|
-
};
|
|
74
|
-
const shareToWhatsApp = (url, text) => {
|
|
75
|
-
const message = `${text} ${url}`;
|
|
76
|
-
const shareUrl = `${SocialPlatformShareUrl.WHATSAPP}?text=${encodeURIComponent(message)}`;
|
|
77
|
-
openShareWindow(shareUrl, SocialPlatform.WHATSAPP);
|
|
78
|
-
};
|
|
79
|
-
const shareToEmail = (url, subject, body) => {
|
|
80
|
-
const emailBody = `${body}\n\n${url}`;
|
|
81
|
-
const mailtoUrl = `${SocialPlatformShareUrl.EMAIL}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(emailBody)}`;
|
|
82
|
-
window.location.href = mailtoUrl;
|
|
83
|
-
trackShare(SocialPlatform.EMAIL);
|
|
84
|
-
};
|
|
85
|
-
const copyToClipboard = async (url) => {
|
|
86
|
-
try {
|
|
87
|
-
await navigator.clipboard.writeText(url);
|
|
88
|
-
trackShare(SocialPlatform.CLIPBOARD);
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
console.error("Failed to copy to clipboard:", err);
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const shareNative = async (data) => {
|
|
97
|
-
try {
|
|
98
|
-
if (navigator.share) {
|
|
99
|
-
await navigator.share(data);
|
|
100
|
-
trackShare(SocialPlatform.NATIVE);
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
console.error("Failed to share natively:", err);
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const trackShare = (platform) => {
|
|
111
|
-
const currentCount = shareCount.get();
|
|
112
|
-
shareCount.set(currentCount + 1);
|
|
113
|
-
lastSharedPlatform.set(platform);
|
|
114
|
-
console.log(`Shared to ${platform} - Total shares: ${currentCount + 1}`);
|
|
115
|
-
};
|
|
116
|
-
return {
|
|
117
|
-
availablePlatforms,
|
|
118
|
-
shareCount,
|
|
119
|
-
lastSharedPlatform,
|
|
120
|
-
shareToFacebook,
|
|
121
|
-
shareToTwitter,
|
|
122
|
-
shareToLinkedIn,
|
|
123
|
-
shareToWhatsApp,
|
|
124
|
-
shareToEmail,
|
|
125
|
-
copyToClipboard,
|
|
126
|
-
shareNative,
|
|
127
|
-
trackShare,
|
|
128
|
-
};
|
|
129
|
-
});
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { type SharingPlatform } from "../services/social-sharing-service.js";
|
|
3
|
-
/**
|
|
4
|
-
* Props for Root headless component
|
|
5
|
-
*/
|
|
6
|
-
export interface RootProps {
|
|
7
|
-
/** Render prop function that receives sharing data */
|
|
8
|
-
children: (props: RootRenderProps) => React.ReactNode;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Render props for Root component
|
|
12
|
-
*/
|
|
13
|
-
export interface RootRenderProps {
|
|
14
|
-
/** Available sharing platforms */
|
|
15
|
-
platforms: SharingPlatform[];
|
|
16
|
-
/** Total share count */
|
|
17
|
-
shareCount: number;
|
|
18
|
-
/** Last shared platform */
|
|
19
|
-
lastShared: string | null;
|
|
20
|
-
/** Share to Facebook */
|
|
21
|
-
shareFacebook: (url: string, title: string, description?: string) => void;
|
|
22
|
-
/** Share to Twitter */
|
|
23
|
-
shareTwitter: (url: string, text: string, hashtags?: string[]) => void;
|
|
24
|
-
/** Share to LinkedIn */
|
|
25
|
-
shareLinkedIn: (url: string, title: string, summary?: string) => void;
|
|
26
|
-
/** Share to WhatsApp */
|
|
27
|
-
shareWhatsApp: (url: string, text: string) => void;
|
|
28
|
-
/** Share via Email */
|
|
29
|
-
shareEmail: (url: string, subject: string, body: string) => void;
|
|
30
|
-
/** Copy to clipboard */
|
|
31
|
-
copyLink: (url: string) => Promise<boolean>;
|
|
32
|
-
/** Native share API */
|
|
33
|
-
shareNative: (data: {
|
|
34
|
-
title: string;
|
|
35
|
-
text: string;
|
|
36
|
-
url: string;
|
|
37
|
-
}) => Promise<boolean>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Headless component for social sharing root
|
|
41
|
-
*
|
|
42
|
-
* @component
|
|
43
|
-
* @example
|
|
44
|
-
* ```tsx
|
|
45
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
46
|
-
*
|
|
47
|
-
* function ShareProduct() {
|
|
48
|
-
* const productUrl = 'https://example.com/product/123';
|
|
49
|
-
* const productTitle = 'Amazing Product';
|
|
50
|
-
*
|
|
51
|
-
* return (
|
|
52
|
-
* <SocialSharing.Root>
|
|
53
|
-
* {({ platforms, shareCount, shareFacebook, shareTwitter, copyLink, shareNative }) => (
|
|
54
|
-
* <div>
|
|
55
|
-
* <p>Share this product ({shareCount} shares)</p>
|
|
56
|
-
* <div className="share-buttons">
|
|
57
|
-
* <button onClick={() => shareFacebook(productUrl, productTitle)}>
|
|
58
|
-
* Share on Facebook
|
|
59
|
-
* </button>
|
|
60
|
-
* <button onClick={() => shareTwitter(productUrl, `Check out ${productTitle}!`)}>
|
|
61
|
-
* Share on Twitter
|
|
62
|
-
* </button>
|
|
63
|
-
* <button onClick={() => copyLink(productUrl)}>
|
|
64
|
-
* Copy Link
|
|
65
|
-
* </button>
|
|
66
|
-
* <button onClick={() => shareNative({
|
|
67
|
-
* title: productTitle,
|
|
68
|
-
* text: 'Check this out!',
|
|
69
|
-
* url: productUrl
|
|
70
|
-
* })}>
|
|
71
|
-
* Share
|
|
72
|
-
* </button>
|
|
73
|
-
* </div>
|
|
74
|
-
* </div>
|
|
75
|
-
* )}
|
|
76
|
-
* </SocialSharing.Root>
|
|
77
|
-
* );
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export declare const Root: (props: RootProps) => React.ReactNode;
|
|
82
|
-
/**
|
|
83
|
-
* Props for Platform headless component
|
|
84
|
-
*/
|
|
85
|
-
export interface PlatformProps {
|
|
86
|
-
/** Platform data */
|
|
87
|
-
platform: SharingPlatform;
|
|
88
|
-
/** Click handler */
|
|
89
|
-
onClick: () => void;
|
|
90
|
-
/** Render prop function that receives platform data */
|
|
91
|
-
children: (props: PlatformRenderProps) => React.ReactNode;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Render props for Platform component
|
|
95
|
-
*/
|
|
96
|
-
export interface PlatformRenderProps {
|
|
97
|
-
/** Platform data */
|
|
98
|
-
platform: SharingPlatform;
|
|
99
|
-
/** Platform click handler */
|
|
100
|
-
onSelect: () => void;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Headless component for individual social platform
|
|
104
|
-
*
|
|
105
|
-
* @component
|
|
106
|
-
* @example
|
|
107
|
-
* ```tsx
|
|
108
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
109
|
-
*
|
|
110
|
-
* function SocialButton({ platform, onClick }) {
|
|
111
|
-
* return (
|
|
112
|
-
* <SocialSharing.Platform platform={platform} onClick={onClick}>
|
|
113
|
-
* {({ platform, onSelect }) => (
|
|
114
|
-
* <button
|
|
115
|
-
* onClick={onSelect}
|
|
116
|
-
* className={`social-btn social-btn-${platform.name.toLowerCase()}`}
|
|
117
|
-
* >
|
|
118
|
-
* <span className="icon">{platform.icon}</span>
|
|
119
|
-
* Share on {platform.name}
|
|
120
|
-
* </button>
|
|
121
|
-
* )}
|
|
122
|
-
* </SocialSharing.Platform>
|
|
123
|
-
* );
|
|
124
|
-
* }
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
export declare const Platform: (props: PlatformProps) => React.ReactNode;
|
|
128
|
-
/**
|
|
129
|
-
* Props for Platforms headless component
|
|
130
|
-
*/
|
|
131
|
-
export interface PlatformsProps {
|
|
132
|
-
/** URL to share */
|
|
133
|
-
url: string;
|
|
134
|
-
/** Share title */
|
|
135
|
-
title: string;
|
|
136
|
-
/** Share description */
|
|
137
|
-
description?: string;
|
|
138
|
-
/** Hashtags for sharing */
|
|
139
|
-
hashtags?: string[];
|
|
140
|
-
/** Render prop function that receives platforms data */
|
|
141
|
-
children: (props: PlatformsRenderProps) => React.ReactNode;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Render props for Platforms component
|
|
145
|
-
*/
|
|
146
|
-
export interface PlatformsRenderProps {
|
|
147
|
-
/** Available platforms */
|
|
148
|
-
platforms: SharingPlatform[];
|
|
149
|
-
/** Share to Facebook */
|
|
150
|
-
shareFacebook: () => void;
|
|
151
|
-
/** Share to Twitter */
|
|
152
|
-
shareTwitter: () => void;
|
|
153
|
-
/** Share to LinkedIn */
|
|
154
|
-
shareLinkedIn: () => void;
|
|
155
|
-
/** Share to WhatsApp */
|
|
156
|
-
shareWhatsApp: () => void;
|
|
157
|
-
/** Share via Email */
|
|
158
|
-
shareEmail: () => void;
|
|
159
|
-
/** Copy link to clipboard */
|
|
160
|
-
copyLink: () => Promise<boolean>;
|
|
161
|
-
/** Share natively */
|
|
162
|
-
shareNative: () => Promise<boolean>;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Headless component for social sharing platforms with logic
|
|
166
|
-
*
|
|
167
|
-
* @component
|
|
168
|
-
* @example
|
|
169
|
-
* ```tsx
|
|
170
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
171
|
-
*
|
|
172
|
-
* function SocialShareButtons() {
|
|
173
|
-
* return (
|
|
174
|
-
* <SocialSharing.Platforms
|
|
175
|
-
* url="https://example.com/product/123"
|
|
176
|
-
* title="Amazing Product"
|
|
177
|
-
* description="Check out this amazing product!"
|
|
178
|
-
* hashtags={['product', 'amazing']}
|
|
179
|
-
* >
|
|
180
|
-
* {({ platforms, shareFacebook, shareTwitter, shareLinkedIn, copyLink, shareNative }) => (
|
|
181
|
-
* <div className="social-platforms">
|
|
182
|
-
* <button onClick={shareFacebook}>Share on Facebook</button>
|
|
183
|
-
* <button onClick={shareTwitter}>Share on Twitter</button>
|
|
184
|
-
* <button onClick={shareLinkedIn}>Share on LinkedIn</button>
|
|
185
|
-
* <button onClick={() => copyLink()}>Copy Link</button>
|
|
186
|
-
* <button onClick={() => shareNative()}>Share</button>
|
|
187
|
-
* </div>
|
|
188
|
-
* )}
|
|
189
|
-
* </SocialSharing.Platforms>
|
|
190
|
-
* );
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
export declare const Platforms: (props: PlatformsProps) => React.ReactNode;
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useService } from "@wix/services-manager-react";
|
|
3
|
-
import { SocialSharingServiceDefinition, } from "../services/social-sharing-service.js";
|
|
4
|
-
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
5
|
-
/**
|
|
6
|
-
* Headless component for social sharing root
|
|
7
|
-
*
|
|
8
|
-
* @component
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
12
|
-
*
|
|
13
|
-
* function ShareProduct() {
|
|
14
|
-
* const productUrl = 'https://example.com/product/123';
|
|
15
|
-
* const productTitle = 'Amazing Product';
|
|
16
|
-
*
|
|
17
|
-
* return (
|
|
18
|
-
* <SocialSharing.Root>
|
|
19
|
-
* {({ platforms, shareCount, shareFacebook, shareTwitter, copyLink, shareNative }) => (
|
|
20
|
-
* <div>
|
|
21
|
-
* <p>Share this product ({shareCount} shares)</p>
|
|
22
|
-
* <div className="share-buttons">
|
|
23
|
-
* <button onClick={() => shareFacebook(productUrl, productTitle)}>
|
|
24
|
-
* Share on Facebook
|
|
25
|
-
* </button>
|
|
26
|
-
* <button onClick={() => shareTwitter(productUrl, `Check out ${productTitle}!`)}>
|
|
27
|
-
* Share on Twitter
|
|
28
|
-
* </button>
|
|
29
|
-
* <button onClick={() => copyLink(productUrl)}>
|
|
30
|
-
* Copy Link
|
|
31
|
-
* </button>
|
|
32
|
-
* <button onClick={() => shareNative({
|
|
33
|
-
* title: productTitle,
|
|
34
|
-
* text: 'Check this out!',
|
|
35
|
-
* url: productUrl
|
|
36
|
-
* })}>
|
|
37
|
-
* Share
|
|
38
|
-
* </button>
|
|
39
|
-
* </div>
|
|
40
|
-
* </div>
|
|
41
|
-
* )}
|
|
42
|
-
* </SocialSharing.Root>
|
|
43
|
-
* );
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export const Root = (props) => {
|
|
48
|
-
const service = useService(SocialSharingServiceDefinition);
|
|
49
|
-
const signalsService = useService(SignalsServiceDefinition);
|
|
50
|
-
const [platforms, setPlatforms] = React.useState([]);
|
|
51
|
-
const [shareCount, setShareCount] = React.useState(0);
|
|
52
|
-
const [lastShared, setLastShared] = React.useState(null);
|
|
53
|
-
React.useEffect(() => {
|
|
54
|
-
const effects = [
|
|
55
|
-
signalsService.effect(() => {
|
|
56
|
-
setPlatforms(service.availablePlatforms.get());
|
|
57
|
-
}),
|
|
58
|
-
signalsService.effect(() => {
|
|
59
|
-
setShareCount(service.shareCount.get());
|
|
60
|
-
}),
|
|
61
|
-
signalsService.effect(() => {
|
|
62
|
-
setLastShared(service.lastSharedPlatform.get());
|
|
63
|
-
}),
|
|
64
|
-
];
|
|
65
|
-
return () => effects.forEach((dispose) => dispose());
|
|
66
|
-
}, [service, signalsService]);
|
|
67
|
-
return props.children({
|
|
68
|
-
platforms,
|
|
69
|
-
shareCount,
|
|
70
|
-
lastShared,
|
|
71
|
-
shareFacebook: service.shareToFacebook,
|
|
72
|
-
shareTwitter: service.shareToTwitter,
|
|
73
|
-
shareLinkedIn: service.shareToLinkedIn,
|
|
74
|
-
shareWhatsApp: service.shareToWhatsApp,
|
|
75
|
-
shareEmail: service.shareToEmail,
|
|
76
|
-
copyLink: service.copyToClipboard,
|
|
77
|
-
shareNative: service.shareNative,
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Headless component for individual social platform
|
|
82
|
-
*
|
|
83
|
-
* @component
|
|
84
|
-
* @example
|
|
85
|
-
* ```tsx
|
|
86
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
87
|
-
*
|
|
88
|
-
* function SocialButton({ platform, onClick }) {
|
|
89
|
-
* return (
|
|
90
|
-
* <SocialSharing.Platform platform={platform} onClick={onClick}>
|
|
91
|
-
* {({ platform, onSelect }) => (
|
|
92
|
-
* <button
|
|
93
|
-
* onClick={onSelect}
|
|
94
|
-
* className={`social-btn social-btn-${platform.name.toLowerCase()}`}
|
|
95
|
-
* >
|
|
96
|
-
* <span className="icon">{platform.icon}</span>
|
|
97
|
-
* Share on {platform.name}
|
|
98
|
-
* </button>
|
|
99
|
-
* )}
|
|
100
|
-
* </SocialSharing.Platform>
|
|
101
|
-
* );
|
|
102
|
-
* }
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export const Platform = (props) => {
|
|
106
|
-
const { platform, onClick } = props;
|
|
107
|
-
return props.children({
|
|
108
|
-
platform,
|
|
109
|
-
onSelect: onClick,
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Headless component for social sharing platforms with logic
|
|
114
|
-
*
|
|
115
|
-
* @component
|
|
116
|
-
* @example
|
|
117
|
-
* ```tsx
|
|
118
|
-
* import { SocialSharing } from '@wix/stores/components';
|
|
119
|
-
*
|
|
120
|
-
* function SocialShareButtons() {
|
|
121
|
-
* return (
|
|
122
|
-
* <SocialSharing.Platforms
|
|
123
|
-
* url="https://example.com/product/123"
|
|
124
|
-
* title="Amazing Product"
|
|
125
|
-
* description="Check out this amazing product!"
|
|
126
|
-
* hashtags={['product', 'amazing']}
|
|
127
|
-
* >
|
|
128
|
-
* {({ platforms, shareFacebook, shareTwitter, shareLinkedIn, copyLink, shareNative }) => (
|
|
129
|
-
* <div className="social-platforms">
|
|
130
|
-
* <button onClick={shareFacebook}>Share on Facebook</button>
|
|
131
|
-
* <button onClick={shareTwitter}>Share on Twitter</button>
|
|
132
|
-
* <button onClick={shareLinkedIn}>Share on LinkedIn</button>
|
|
133
|
-
* <button onClick={() => copyLink()}>Copy Link</button>
|
|
134
|
-
* <button onClick={() => shareNative()}>Share</button>
|
|
135
|
-
* </div>
|
|
136
|
-
* )}
|
|
137
|
-
* </SocialSharing.Platforms>
|
|
138
|
-
* );
|
|
139
|
-
* }
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
export const Platforms = (props) => {
|
|
143
|
-
const { url, title, description = "", hashtags = [] } = props;
|
|
144
|
-
const service = useService(SocialSharingServiceDefinition);
|
|
145
|
-
const signalsService = useService(SignalsServiceDefinition);
|
|
146
|
-
const [platforms, setPlatforms] = React.useState([]);
|
|
147
|
-
React.useEffect(() => {
|
|
148
|
-
const dispose = signalsService.effect(() => {
|
|
149
|
-
setPlatforms(service.availablePlatforms.get());
|
|
150
|
-
});
|
|
151
|
-
return dispose;
|
|
152
|
-
}, [service, signalsService]);
|
|
153
|
-
const shareFacebook = () => service.shareToFacebook(url, title, description);
|
|
154
|
-
const shareTwitter = () => service.shareToTwitter(url, title, hashtags);
|
|
155
|
-
const shareLinkedIn = () => service.shareToLinkedIn(url, title, description);
|
|
156
|
-
const shareWhatsApp = () => service.shareToWhatsApp(url, `${title} - ${description}`);
|
|
157
|
-
const shareEmail = () => service.shareToEmail(url, title, description);
|
|
158
|
-
const copyLink = () => service.copyToClipboard(url);
|
|
159
|
-
const shareNative = () => service.shareNative({ title, text: description, url });
|
|
160
|
-
return props.children({
|
|
161
|
-
platforms,
|
|
162
|
-
shareFacebook,
|
|
163
|
-
shareTwitter,
|
|
164
|
-
shareLinkedIn,
|
|
165
|
-
shareWhatsApp,
|
|
166
|
-
shareEmail,
|
|
167
|
-
copyLink,
|
|
168
|
-
shareNative,
|
|
169
|
-
});
|
|
170
|
-
};
|