-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
70 lines (60 loc) · 1.46 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
/**
* Internal dependencies
*/
import { registerBlock, query } from 'api';
import Editable from 'components/editable';
const { html, prop } = query;
registerBlock( 'core/text', {
title: wp.i18n.__( 'Text' ),
icon: 'text',
category: 'common',
attributes: {
content: html( 'p' ),
align: prop( 'p', 'style.textAlign' )
},
controls: [
{
icon: 'editor-alignleft',
title: wp.i18n.__( 'Align left' ),
isActive: ( { align } ) => ! align || 'left' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: undefined } );
}
},
{
icon: 'editor-aligncenter',
title: wp.i18n.__( 'Align center' ),
isActive: ( { align } ) => 'center' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'center' } );
}
},
{
icon: 'editor-alignright',
title: wp.i18n.__( 'Align right' ),
isActive: ( { align } ) => 'right' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'right' } );
}
}
],
edit( { attributes, setAttributes } ) {
const { content, align } = attributes;
return (
<Editable
tagName="p"
value={ content }
onChange={ ( value ) => setAttributes( { content: value } ) }
style={ align ? { textAlign: align } : null }
/>
);
},
save( { attributes } ) {
const { align, content } = attributes;
return (
<p
style={ align ? { textAlign: align } : null }
dangerouslySetInnerHTML={ { __html: content } } />
);
}
} );