-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock1.js
72 lines (63 loc) · 2.04 KB
/
block1.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
wp.blocks.registerBlockType( 'gutenberg-boilerplate-es5/hello-world-step-01', {
title: 'Hello World (Step 4)',
icon: 'universal-access-alt',
category: 'layout',
attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
},
alignment: {
type: 'string',
},
},
edit: function(props) {
var content = props.attributes.content,
alignment = props.attributes.alignment;
function onChangeContent( newContent ) {
props.setAttributes( { content: newContent } );
}
function onChangeAlignment( newAlignment ) {
props.setAttributes( { alignment: newAlignment } );
}
return (
wp.element.createElement(
wp.element.Fragment,
null,
wp.element.createElement(
wp.editor.BlockControls,
null,
wp.element.createElement(
wp.editor.AlignmentToolbar,
{
value: alignment,
onChange: onChangeAlignment,
}
)
),
wp.element.createElement(
wp.editor.RichText,
{
key: 'editable',
tagName: 'p',
className: props.className,
style: { textAlign: alignment },
onChange: onChangeContent,
value: content,
}
)
)
);
},
save: function(props) {
var content = props.attributes.content,
alignment = props.attributes.alignment;
return wp.element.createElement( wp.editor.RichText.Content, {
tagName: 'p',
className: props.className,
style: { textAlign: alignment },
value: content
} );
},
} );