forked from vtex-apps/store-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
177 lines (166 loc) · 4.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { indexBy, prop } from 'ramda'
import React, { Component } from 'react'
import ContentLoader from 'react-content-loader'
import { FormattedMessage } from 'react-intl'
import SocialButton from './components/SocialButton'
import { SOCIAL_LIST } from './constants/social'
import styles from './styles.css'
class Share extends Component {
static propTypes = {
/** Social Networks configuration */
social: PropTypes.object,
/** Share buttons options */
options: PropTypes.shape({
/** Share buttons size in pixels */
size: PropTypes.number,
}),
/** Share URL title */
title: PropTypes.string,
/** Indcates if the component should render the Content Loader */
loading: PropTypes.bool,
/** Component and content loader styles */
styles: PropTypes.object,
/** Classes to be applied to root element */
className: PropTypes.string,
/** Classes to be applied to Share label */
shareLabelClass: PropTypes.string,
/** Classes to be applied to social button */
socialButtonClass: PropTypes.string,
/** Classes to be applied to container of the buttons */
buttonsContainerClass: PropTypes.string,
/** Classes to be applied to icon of the button */
socialIconClass: PropTypes.string,
/** Classes to be applied to the Content Loader container */
loaderContainerClass: PropTypes.string,
/** Classes to be applied to the Content Loader */
contentLoaderClass: PropTypes.string,
/** Image url for share in social medias */
imageUrl: PropTypes.string,
}
static Loader = (loaderProps = {}) => {
const {
'vtex-share__button--loader': button,
'vtex-share__button--loader-1': button1,
'vtex-share__button--loader-2': button2,
'vtex-share__button--loader-3': button3,
containerClass,
contentLoaderClass,
...rest
} = loaderProps
const loaderStyles = {
r: '1em',
height: '2em',
cy: '1em',
...button,
}
return (
<div
className={classNames(
styles.shareContainer,
styles.shareLoader,
containerClass
)}
>
<ContentLoader
className={contentLoaderClass}
style={{
width: '100%',
height: '100%',
}}
height="100"
width="100"
{...rest}
>
<circle cx="1em" {...loaderStyles} {...button1} />
<circle cx="3.5em" {...loaderStyles} {...button2} />
<circle cx="6em" {...loaderStyles} {...button3} />
</ContentLoader>
</div>
)
}
static defaultProps = {
social: {
Facebook: true,
Twitter: true,
WhatsApp: true,
Pinterest: true,
},
options: {},
className: 'flex flex-row flex-wrap w-100',
shareLabelClass: 'pv2 pr3 t-small',
buttonsContainerClass: 'flex flex-row',
}
static schema = {
title: 'admin/editor.share.title',
description: 'admin/editor.share.description',
type: 'object',
properties: {
social: {
title: 'admin/editor.share.social.title',
type: 'object',
properties: {
...indexBy(
prop('title'),
SOCIAL_LIST.map(socialNetwork => ({
type: 'boolean',
title: socialNetwork,
default: Share.defaultProps.social[socialNetwork],
}))
),
},
},
},
}
render() {
const {
social,
title,
loading,
options: { size },
className,
shareLabelClass,
buttonsContainerClass,
socialButtonClass,
socialIconClass,
loaderContainerClass,
contentLoaderClass,
imageUrl,
} = this.props
if (loading) {
return (
<Share.Loader
containerClass={loaderContainerClass}
contentLoaderClass={contentLoaderClass}
{...this.props.styles}
/>
)
}
return (
<div className={classNames(styles.shareContainer, className)}>
<div className={classNames(styles.shareLabel, shareLabelClass)}>
<FormattedMessage id="store/store-components.share.label" />
</div>
<div className={classNames(styles.shareButtons, buttonsContainerClass)}>
{Object.keys(social).map(
(socialNetwork, index) =>
social[socialNetwork] && (
<SocialButton
key={index}
imageUrl={imageUrl}
url={window.location && window.location.href}
message={title}
iconClass={socialIconClass}
buttonClass={socialButtonClass}
socialEnum={socialNetwork}
size={size}
/>
)
)}
</div>
</div>
)
}
}
export default Share