This repository was archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathSocialPreviewEditorWrapper.js
102 lines (97 loc) · 2.83 KB
/
SocialPreviewEditorWrapper.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
import React from "react";
import styled from "styled-components";
import { SocialPreviewEditor } from "@yoast/social-metadata-previews";
const Container = styled.div`
background-color: white;
padding: 16px;
margin: 20px;
`;
/**
* @returns {void} Void
*/
class SocialPreviewEditorWrapper extends React.Component {
/**
* The constructor
*
@param {Object} props The properties of this component.
*/
constructor( props ) {
super( props );
this.state = {
title: "Initial title state",
description: "Initial description state",
image: "",
isLarge: true,
};
this.setTitle = this.setStateAttribute.bind( this, "title" );
this.setDescription = this.setStateAttribute.bind( this, "description" );
this.setImage = this.setStateAttribute.bind( this, "image" );
this.removeImage = this.setStateAttribute.bind( this, "image", "" );
this.toggleLarge = this.setStateAttribute.bind( this, "isLarge" );
}
/**
* @returns {void} Void
*
* @param {Object} attr Attributes
* @param {string} value Value
*/
setStateAttribute( attr, value ) {
this.setState( state => ( {
...state,
[ attr ]: value,
} ) );
}
/**
* @returns {void} Void
*
@param {Object} props The properties of this component.
*/
render() {
return (
<Container className="yoast">
<h2>Facebook</h2>
<SocialPreviewEditor
title={ this.state.title }
onTitleChange={ this.setTitle }
description={ this.state.description }
onDescriptionChange={ this.setDescription }
siteUrl="some.site.com"
onRemoveImageClick={ this.removeImage }
alt="Alt text"
imageUrl={ this.state.image }
imageFallbackUrl=""
socialMediumName={ "Facebook" }
// eslint-disable-next-line react/jsx-no-bind
onSelectImageClick={ () => this.setImage(
"https://www.yarrah.com/en/wp-content/uploads/sites/10/2019/01/Puppy-aanschaffen-header-800x600.png"
) }
isPremium={ true }
socialPreviewLabel="Facebook share preview"
/>
<br />
<h2>Twitter</h2>
<button onClick={ () => this.toggleLarge( ! this.state.isLarge ) }>Toggle Large Summary Card</button>
<SocialPreviewEditor
title={ this.state.title }
onTitleChange={ this.setTitle }
description={ this.state.description }
onDescriptionChange={ this.setDescription }
siteUrl="some.site.com"
onRemoveImageClick={ this.removeImage }
alt="Alt text"
isLarge={ this.state.isLarge }
imageUrl={ this.state.image }
imageFallbackUrl=""
socialMediumName={ "Twitter" }
// eslint-disable-next-line react/jsx-no-bind
onSelectImageClick={ () => this.setImage(
"https://www.yarrah.com/en/wp-content/uploads/sites/10/2019/01/Puppy-aanschaffen-header-800x600.png"
) }
isPremium={ true }
socialPreviewLabel="Twitter share preview"
/>
</Container>
);
}
}
export default SocialPreviewEditorWrapper;