-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallout-block.js
80 lines (74 loc) · 2.6 KB
/
callout-block.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
wp.blocks.registerBlockType( 'jsforwp/callout-block', {
title: 'Callout Block',
icon: 'megaphone',
category: 'common',
attributes: {
content: {
source: 'html',
selector: 'h2',
},
backgroundColor: {
type: 'string',
default: '#900900',
},
textColor: {
type: 'string',
default: '#ffffff',
}
},
edit: function( props ) {
return wp.element.createElement(
wp.element.Fragment,
null,
wp.element.createElement(
wp.editor.InspectorControls,
null,
wp.element.createElement(
wp.editor.PanelColorSettings, {
title: wp.i18n.__("Color Settings", "jsforwp"),
colorSettings: [
{
label: wp.i18n.__("Background Color", "jsforwp"),
value: props.attributes.backgroundColor,
onChange: function( newBackgroundColor ) {
props.setAttributes({ backgroundColor: newBackgroundColor });
}
},
{
label: wp.i18n.__("Text Color", "jsforwp"),
value: props.attributes.textColor,
onChange: function( newColor ) {
props.setAttributes({ textColor: newColor });
}
}
]
}
)
),
wp.element.createElement(
wp.editor.RichText, {
tagName: 'h2',
className: props.className,
value: props.attributes.content,
style: {
backgroundColor: props.attributes.backgroundColor,
color: props.attributes.textColor
},
onChange: function( newContent ) {
props.setAttributes( { content: newContent } );
}
}
)
);
},
save: function( props ) {
return wp.element.createElement( wp.editor.RichText.Content, {
tagName: 'h2',
value: props.attributes.content,
style: {
backgroundColor: props.attributes.backgroundColor,
color: props.attributes.textColor
},
} );
}
} );