-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
58 lines (54 loc) · 1.59 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
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/element';
import { __, _n, sprintf } from '@wordpress/i18n';
import { withDispatch, withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import './style.scss';
import SidebarHeader from '../sidebar-header';
const SettingsHeader = ( { count, openDocumentSettings, openBlockSettings, sidebarName } ) => {
// Do not display "0 Blocks".
count = count === 0 ? 1 : count;
return (
<SidebarHeader
className="edit-post-sidebar__panel-tabs"
closeLabel={ __( 'Close settings' ) }
>
<button
onClick={ openDocumentSettings }
className={ `edit-post-sidebar__panel-tab ${ sidebarName === 'edit-post/document' ? 'is-active' : '' }` }
aria-label={ __( 'Document settings' ) }
>
{ __( 'Document' ) }
</button>
<button
onClick={ openBlockSettings }
className={ `edit-post-sidebar__panel-tab ${ sidebarName === 'edit-post/block' ? 'is-active' : '' }` }
aria-label={ __( 'Block settings' ) }
>
{ sprintf( _n( 'Block', '%d Blocks', count ), count ) }
</button>
</SidebarHeader>
);
};
export default compose(
withSelect( ( select ) => ( {
count: select( 'core/editor' ).getSelectedBlockCount(),
} ) ),
withDispatch( ( dispatch ) => {
const { openGeneralSidebar } = dispatch( 'core/edit-post' );
const { clearSelectedBlock } = dispatch( 'core/editor' );
return {
openDocumentSettings() {
openGeneralSidebar( 'edit-post/document' );
clearSelectedBlock();
},
openBlockSettings() {
openGeneralSidebar( 'edit-post/block' );
},
};
} ),
)( SettingsHeader );