-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
96 lines (84 loc) · 2.52 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* WordPress dependencies
*/
import { Placeholder, Button, Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { navigation, Icon } from '@wordpress/icons';
import { speak } from '@wordpress/a11y';
import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import useNavigationEntities from '../../use-navigation-entities';
import PlaceholderPreview from './placeholder-preview';
import NavigationMenuSelector from '../navigation-menu-selector';
export default function NavigationPlaceholder( {
isSelected,
currentMenuId,
clientId,
canUserCreateNavigationMenu = false,
isResolvingCanUserCreateNavigationMenu,
onSelectNavigationMenu,
onSelectClassicMenu,
onCreateEmpty,
} ) {
const { isResolvingMenus, hasResolvedMenus } = useNavigationEntities();
useEffect( () => {
if ( ! isSelected ) {
return;
}
if ( isResolvingMenus ) {
speak( __( 'Loading Navigation block setup options.' ) );
}
if ( hasResolvedMenus ) {
speak( __( 'Navigation block setup options ready.' ) );
}
}, [ isResolvingMenus, isSelected ] );
const isResolvingActions =
isResolvingMenus && isResolvingCanUserCreateNavigationMenu;
return (
<>
<Placeholder className="wp-block-navigation-placeholder">
{
// The <PlaceholderPreview> component is displayed conditionally via CSS depending on
// whether the block is selected or not. This is achieved via CSS to avoid
// component re-renders
}
<PlaceholderPreview isVisible={ ! isSelected } />
<div
aria-hidden={ ! isSelected ? true : undefined }
className="wp-block-navigation-placeholder__controls"
>
<div className="wp-block-navigation-placeholder__actions">
<div className="wp-block-navigation-placeholder__actions__indicator">
<Icon icon={ navigation } /> { __( 'Navigation' ) }
</div>
<hr />
{ isResolvingActions && <Spinner /> }
<NavigationMenuSelector
currentMenuId={ currentMenuId }
clientId={ clientId }
onSelectNavigationMenu={ onSelectNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
toggleProps={ {
variant: 'tertiary',
iconPosition: 'right',
className:
'wp-block-navigation-placeholder__actions__dropdown',
} }
/>
<hr />
{ canUserCreateNavigationMenu && (
<Button
variant="tertiary"
onClick={ onCreateEmpty }
>
{ __( 'Start empty' ) }
</Button>
) }
</div>
</div>
</Placeholder>
</>
);
}