-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
56 lines (46 loc) · 1.2 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
/**
* Internal dependencies
*/
import { registerBlock, query } from 'api';
import Editable from 'components/editable';
const { html, prop } = query;
registerBlock( 'core/heading', {
title: wp.i18n.__( 'Heading' ),
icon: 'heading',
category: 'common',
attributes: {
content: html( 'h1,h2,h3,h4,h5,h6' ),
tag: prop( 'h1,h2,h3,h4,h5,h6', 'nodeName' ),
align: prop( 'h1,h2,h3,h4,h5,h6', 'style.textAlign' )
},
controls: [
...'123456'.split( '' ).map( ( level ) => ( {
icon: 'heading',
title: wp.i18n.sprintf( wp.i18n.__( 'Heading %s' ), level ),
isActive: ( { tag } ) => 'H' + level === tag,
onClick( attributes, setAttributes ) {
setAttributes( { tag: 'H' + level } );
},
level
} ) )
],
edit( { attributes, setAttributes } ) {
const { content, tag, align } = attributes;
return (
<Editable
tagName={ tag }
value={ content }
onChange={ ( value ) => setAttributes( { content: value } ) }
style={ align ? { textAlign: align } : null }
/>
);
},
save( { attributes } ) {
const { align, tag: Tag, content } = attributes;
return (
<Tag
style={ align ? { textAlign: align } : null }
dangerouslySetInnerHTML={ { __html: content } } />
);
}
} );