Skip to content

Commit 635a01f

Browse files
Added social-share buttons and product description (#36)
1 parent ecde83e commit 635a01f

File tree

9 files changed

+81
-8
lines changed

9 files changed

+81
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"react-script-hook": "^1.1.1",
2525
"react-scripts": "3.4.1",
2626
"serve": "^11.3.1",
27+
"sharethis-reactjs": "^1.5.0",
2728
"typescript": "^3.7.3"
2829
},
2930
"scripts": {

src/Product.scss

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@
8888
margin-top: 20px;
8989
}
9090

91-
#{$block}__separator {
92-
margin-top: 20px;
93-
border-top: 1px solid hsl(0, 0, 90%);
94-
}
95-
9691
#{$block}__addtocartbtn {
9792
margin-top: 20px;
9893
width: 200px;
@@ -101,6 +96,14 @@
10196
#{$block}__moltinbtncontainer {
10297
margin-top: 20px;
10398
}
99+
100+
#{$block}__description {
101+
margin-top: 20px;
102+
}
103+
104+
#{$block}__socialshare {
105+
margin-top: 20px;
106+
}
104107
}
105108
}
106109

src/Product.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom';
33
import { useResolve, useProductImages } from './hooks';
44
import { loadProductBySlug } from './service';
55
import { CompareCheck } from './CompareCheck';
6+
import { SocialShare } from './SocialShare';
67
import { useTranslation, useCurrency } from './app-state';
78
import { isProductAvailable } from './helper';
89

@@ -71,13 +72,18 @@ export const Product: React.FC = () => {
7172
<div className="product__comparecheck">
7273
<CompareCheck product={product} />
7374
</div>
74-
<div className="product__separator"></div>
7575
<div className="product__moltinbtncontainer">
7676
<span
7777
className="moltin-buy-button"
7878
data-moltin-product-id={product.id}
7979
></span>
8080
</div>
81+
<div className="product__description">
82+
{product.description}
83+
</div>
84+
<div className="product__socialshare">
85+
<SocialShare name={product.name} description={product.description} imageHref={productImageHrefs?.[0]} />
86+
</div>
8187
</div>
8288
</div>
8389
)}

src/SocialShare.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
.socialshare {
3+
width: 300px;
4+
}

src/SocialShare.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { InlineShareButtons } from 'sharethis-reactjs';
3+
import { useTranslation } from './app-state';
4+
5+
import './SocialShare.scss';
6+
7+
interface SocialShareProps {
8+
name: string;
9+
description: string;
10+
imageHref: string;
11+
}
12+
13+
export const SocialShare: React.FC<SocialShareProps> = (props) => {
14+
const { t } = useTranslation();
15+
16+
return (
17+
<div className="socialshare">
18+
<InlineShareButtons
19+
config={{
20+
alignment: 'left', // alignment of buttons (left, center, right)
21+
color: 'social', // set the color of buttons (social, white)
22+
enabled: true, // show/hide buttons (true, false)
23+
font_size: 16, // font size for the buttons
24+
labels: 'cta', // button labels (cta, counts, null)
25+
networks: [ // which networks to include (see SHARING NETWORKS)
26+
'facebook',
27+
'twitter',
28+
'pinterest',
29+
'email',
30+
],
31+
padding: 12, // padding within buttons (INTEGER)
32+
radius: 4, // the corner radius on each button (INTEGER)
33+
size: 40, // the size of each button (INTEGER)
34+
show_total: false,
35+
image: props.imageHref, // (defaults to og:image or twitter:image)
36+
description: props.description, // (defaults to og:description or twitter:description)
37+
title: t('social-share-title', { productName: props.name }), // (defaults to og:title or twitter:title)
38+
subject: t('social-share-subject', { productName: props.name }), // (defaults to og:title or twitter:title)
39+
message: t('social-share-message', { productName: props.name, description: props.description, link: window.location.href }), // (defaults to og:title or twitter:title)
40+
}}
41+
/>
42+
</div>
43+
);
44+
};

src/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@
9595
"required": "Required",
9696
"network-offline": "Network Offline",
9797
"previous-image": "Previous image",
98-
"next-image": "Next image"
98+
"next-image": "Next image",
99+
"social-share-title": "Check out this product: {productName}",
100+
"social-share-subject": "Check out this product: {productName}",
101+
"social-share-message": "{link}\n\n{productName}\n\n{description}"
99102
}

src/locales/fr.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@
9595
"required": "ŔŔéǫûîîŕéð",
9696
"network-offline": "ÑÑéţŵŵöŕķ ÖÖƒƒļļîñé",
9797
"previous-image": "ÞÞŕéṽîîöûš îîɱååĝé",
98-
"next-image": "ÑÑéẋţ îîɱååĝé"
98+
"next-image": "ÑÑéẋţ îîɱååĝé",
99+
"social-share-title": "ÇÇĥééçķ ööûţ ţţĥîš þþŕöðûûçţ∶ {productName}",
100+
"social-share-subject": "ÇÇĥééçķ ööûţ ţţĥîš þþŕöðûûçţ∶ {productName}",
101+
"social-share-message": "{link}{productName}{description}"
99102
}

src/types.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
declare module 'sharethis-reactjs' {
3+
export const InlineShareButtons: any;
4+
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10145,6 +10145,11 @@ shallow-clone@^3.0.0:
1014510145
dependencies:
1014610146
kind-of "^6.0.2"
1014710147

10148+
sharethis-reactjs@^1.5.0:
10149+
version "1.5.0"
10150+
resolved "https://registry.yarnpkg.com/sharethis-reactjs/-/sharethis-reactjs-1.5.0.tgz#9c6a563c9f89e4cc4ea633e993016bab84fe60df"
10151+
integrity sha512-aYbXxbKQZzf9m8iFtNkHJGrQXy9VX/tbJ2PWOOgMWB0XNZU3vwUfKq/obMg5hFDZ/fa4rAj7G+LxN5zvLufx4w==
10152+
1014810153
shebang-command@^1.2.0:
1014910154
version "1.2.0"
1015010155
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"

0 commit comments

Comments
 (0)