-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
64 lines (56 loc) · 1.28 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
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
createSlotFill,
withFocusReturn,
Animate,
} from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { ifCondition, compose } from '@wordpress/compose';
const { Fill, Slot } = createSlotFill( 'Sidebar' );
/**
* Renders a sidebar with its content.
*
* @return {Object} The rendered sidebar.
*/
function Sidebar( { children, className } ) {
return (
<div className={ classnames( 'edit-post-sidebar', className ) }>
{ children }
</div>
);
}
Sidebar = withFocusReturn( {
onFocusReturn() {
const button = document.querySelector(
'.edit-post-header__settings [aria-label="Settings"]'
);
if ( button ) {
button.focus();
return false;
}
},
} )( Sidebar );
function AnimatedSidebarFill( props ) {
return (
<Fill>
<Animate type="slide-in" options={ { origin: 'left' } }>
{ () => <Sidebar { ...props } /> }
</Animate>
</Fill>
);
}
const WrappedSidebar = compose(
withSelect( ( select, { name } ) => ( {
isActive:
select( 'core/edit-post' ).getActiveGeneralSidebarName() === name,
} ) ),
ifCondition( ( { isActive } ) => isActive )
)( AnimatedSidebarFill );
WrappedSidebar.Slot = Slot;
export default WrappedSidebar;