-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
index.js
141 lines (134 loc) · 3.25 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { navigateRegions } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
function useHTMLClass( className ) {
useEffect( () => {
const element =
document && document.querySelector( `html:not(.${ className })` );
if ( ! element ) {
return;
}
element.classList.toggle( className );
return () => {
element.classList.toggle( className );
};
}, [ className ] );
}
function InterfaceSkeleton( {
footer,
header,
sidebar,
leftSidebar,
content,
drawer,
actions,
labels,
className,
} ) {
useHTMLClass( 'interface-interface-skeleton__html-container' );
const defaultLabels = {
/* translators: accessibility text for the nav bar landmark region. */
drawer: __( 'Drawer' ),
/* translators: accessibility text for the top bar landmark region. */
header: __( 'Header' ),
/* translators: accessibility text for the content landmark region. */
body: __( 'Content' ),
/* translators: accessibility text for the left sidebar landmark region. */
leftSidebar: __( 'Left sidebar' ),
/* translators: accessibility text for the settings landmark region. */
sidebar: __( 'Settings' ),
/* translators: accessibility text for the publish landmark region. */
actions: __( 'Publish' ),
/* translators: accessibility text for the footer landmark region. */
footer: __( 'Footer' ),
};
const mergedLabels = { ...defaultLabels, ...labels };
return (
<div
className={ classnames(
className,
'interface-interface-skeleton'
) }
>
{ !! drawer && (
<div
className="interface-interface-skeleton__drawer"
role="region"
aria-label={ mergedLabels.drawer }
>
{ drawer }
</div>
) }
<div className="interface-interface-skeleton__editor">
{ !! header && (
<div
className="interface-interface-skeleton__header"
role="region"
aria-label={ mergedLabels.header }
tabIndex="-1"
>
{ header }
</div>
) }
<div className="interface-interface-skeleton__body">
{ !! leftSidebar && (
<div
className="interface-interface-skeleton__left-sidebar"
role="region"
aria-label={ mergedLabels.leftSidebar }
tabIndex="-1"
>
{ leftSidebar }
</div>
) }
<div
className="interface-interface-skeleton__content"
role="region"
aria-label={ mergedLabels.body }
tabIndex="-1"
>
{ content }
</div>
{ !! sidebar && (
<div
className="interface-interface-skeleton__sidebar"
role="region"
aria-label={ mergedLabels.sidebar }
tabIndex="-1"
>
{ sidebar }
</div>
) }
{ !! actions && (
<div
className="interface-interface-skeleton__actions"
role="region"
aria-label={ mergedLabels.actions }
tabIndex="-1"
>
{ actions }
</div>
) }
</div>
</div>
{ !! footer && (
<div
className="interface-interface-skeleton__footer"
role="region"
aria-label={ mergedLabels.footer }
tabIndex="-1"
>
{ footer }
</div>
) }
</div>
);
}
export default navigateRegions( InterfaceSkeleton );