-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContextualHelpDialog.tsx
338 lines (313 loc) · 9.07 KB
/
ContextualHelpDialog.tsx
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import * as React from 'react';
import { Header, Button, Dialog, Breadcrumb, Text, Table, List, Accordion } from '@fluentui/react-northstar';
import { CloseIcon } from '@fluentui/react-icons-northstar';
const version1change: React.CSSProperties = {
height: '90vh',
};
const srOnlyCSS: React.CSSProperties = {
position: 'absolute',
left: '-10000px',
top: 'auto',
width: '1px',
height: '1px',
overflow: 'hidden',
}; // End srOnlyCss
const navigateTo = (page, setPage, event) => {
event.preventDefault();
setPage(page);
}; // End navigateTo
const tableHeader = {
items: ['Action', 'Keys'],
}; // End tableHeader
const generalTableRows = [
{
key: 1,
items: ['Start new chat', 'Ctrl+N'],
},
{
key: 2,
items: ['Pop out new chat', 'Ctrl+Shift+N'],
},
{
key: 3,
items: ['Open Settings', 'Ctrl+, (comma)'],
},
{
key: 4,
items: ['Open Help', 'F1'],
},
{
key: 5,
items: ['Close', 'Escape'],
},
{
key: 6,
items: ['Show keyboard shortcuts', 'Ctrl+. (period)'],
},
{
key: 7,
items: ['Go to Search', 'Ctrl+E'],
},
{
key: 8,
items: ['Show commands', 'Ctrl+/ (slash)'],
},
]; // End generalTableRows
const getPanels = count => [
{
key: 'chatsList',
title: {
as: 'h2',
className: 'firstFocusable',
tabIndex: -1,
content: (
<>
<Text>Chats list</Text>
<Text style={srOnlyCSS}>, 1 of {count}</Text>
</>
),
},
content: (
<>
<Header as="h3" content="Navigation" />
<List>
<List.Item
index={0}
content="To move to the compose field, press Enter, or Alt + Shift + C, or Ctrl + Shift + R."
/>
<List.Item
index={1}
content="To Move to the messages list for the currently selected chat, press Space bar."
/>
</List>
</>
),
},
{
key: 'messagesList',
title: {
as: 'h2',
content: (
<>
<Text>Messages list</Text>
<Text style={srOnlyCSS}>, 2 of {count}</Text>
</>
),
},
content: (
<>
<Header as="h3" content="Navigation" />
<List>
<List.Item index={0} content="To move to the compose field, press Alt + Shift + C, or Ctrl + Shift + R." />
<List.Item index={1} content="To move to the chats list, press Escape, or Ctrl + L." />
</List>
<Header as="h3" content="Interaction" />
<List>
<List.Item
index={0}
content="To react to a message, press Enter, then select the reaction (such as Like) using the Right or Left arrow keys.), and confirm with Enter."
/>
<List.Item
index={1}
content="To reply to a message, press Shift + F10, then select Reply using the Down or Up arrow keys, and confirm with Enter."
/>
<List.Item index={2} content="To copy a message, press Ctrl + C." />
</List>
</>
),
},
{
key: 'composeField',
title: {
as: 'h2',
content: (
<>
<Text>Message compose field</Text>
<Text style={srOnlyCSS}>, 3 of {count}</Text>
</>
),
},
content: (
<>
<Header as="h3" content="Navigation" />
<List>
<List.Item index={0} content="To move to the messages list, press Escape." />
<List.Item index={1} content="To move to the chats list, press Ctrl + L." />
</List>
<Header as="h3" content="Interaction" />
<List>
<List.Item
index={0}
content="To attach a file, press Tab, then Right arrow key until you reach the Attach button, and confirm with Enter."
/>
<List.Item index={1} content="" />
</List>
</>
),
},
{
key: 'global',
title: {
as: 'h2',
content: (
<>
<Text>Global keyboar shortcuts</Text>
<Text style={srOnlyCSS}>, 4 of {count}</Text>
</>
),
},
content: (
<>
<Text>Keyboard language is: English (United States).</Text>
<Header as="h3" content="General" />
<Table header={tableHeader} rows={generalTableRows} />
<Header as="h3" content="Navigation" />
<Table header={tableHeader} rows={generalTableRows} />
<Header as="h3" content="Messaging" />
<Table header={tableHeader} rows={generalTableRows} />
<Header as="h3" content="Meetings, Calls and Calendar" />
<Table header={tableHeader} rows={generalTableRows} />
<Header as="h3" content="Debug" />
<Table header={tableHeader} rows={generalTableRows} />
</>
),
},
]; // End getPanels
const fourPanels = getPanels(4);
const panels1 = [fourPanels[0], fourPanels[1], fourPanels[2], fourPanels[3]]; // End panels1
const threePanels = getPanels(3);
const panels2 = [threePanels[0], threePanels[1], threePanels[2]]; // End panels2
interface ContextualHelpDialog1Props {
defaultPanelIndex: number;
triggerText: string;
}
export const ContextualHelpDialog1: React.FunctionComponent<ContextualHelpDialog1Props> = (
props: ContextualHelpDialog1Props,
) => {
const { defaultPanelIndex, triggerText } = props;
const [dialogOpened, setDialogOpened] = React.useState(false);
return (
<Dialog
style={version1change}
trapFocus={{ firstFocusableSelector: '[aria-expanded="true"][data-aa-class="AccordionTitle__content"]' }}
open={dialogOpened}
onOpen={() => {
setDialogOpened(true);
}}
onCancel={() => {
setDialogOpened(false);
}}
header={<Header as="h1" content="Chats keyboard help" />}
headerAction={{
icon: <CloseIcon />,
title: 'Close',
onClick: () => {
setDialogOpened(false);
},
}}
footer={{
children: (Component, props) => (
<>
<Text as="a" href="">
See shortcuts for all platforms
</Text>
<Text as="a" href="">
Office Accessibility Center
</Text>
</>
),
}}
trigger={<Button content={triggerText} />}
content={<Accordion panels={panels1} defaultActiveIndex={defaultPanelIndex} exclusive={true} />}
/>
);
}; // End ContextualHelpDialog1
interface ContextualHelpDialog2Props {
defaultPage: number | string;
triggerText: string;
}
export const ContextualHelpDialog2: React.FunctionComponent<ContextualHelpDialog2Props> = (
props: ContextualHelpDialog2Props,
) => {
const { defaultPage, triggerText } = props;
const [dialogOpened, setDialogOpened] = React.useState(false);
const [page, setPage] = React.useState('contexts');
const [defaultPanel, setDefaultPanel] = React.useState(defaultPage as number);
React.useEffect(() => {
if (typeof defaultPage === 'string') {
setPage(defaultPage);
}
}, [defaultPage]); // End useEffect
React.useEffect(() => {
const first = document.querySelector('.firstFocusable');
if (first) {
(first as HTMLElement).focus();
}
if (page === 'shortcuts') {
setDefaultPanel(undefined);
}
}, [page]); // End useEffect
let header;
let content;
if (page === 'shortcuts') {
header = <Header as="h1" content="Keyboard shortcuts" className="firstFocusable" tabIndex={-1} />;
content = fourPanels[3].content;
} else if (page === 'contexts') {
header = (
<Breadcrumb aria-label="Breadcrumb">
<Breadcrumb.Item>
<Breadcrumb.Link href="#shortcuts" onClick={event => navigateTo('shortcuts', setPage, event)}>
Keyboard shortcuts
</Breadcrumb.Link>
</Breadcrumb.Item>
<Breadcrumb.Item aria-current="page">Contextual keyboard help</Breadcrumb.Item>
</Breadcrumb>
);
content = <Accordion panels={panels2} defaultActiveIndex={defaultPanel} exclusive={true} />;
}
return (
<Dialog
style={dialogCSS}
aria-labelledby=""
aria-label="Keyboard shortcuts"
trapFocus={{
firstFocusableSelector:
page === 'contexts' ? '[aria-expanded="true"][data-aa-class="AccordionTitle__content"]' : '.firstFocusable',
}}
open={dialogOpened}
onOpen={() => {
setDialogOpened(true);
}}
onCancel={() => {
setDialogOpened(false);
}}
header={header}
headerAction={{
icon: <CloseIcon />,
title: 'Close',
onClick: () => {
setDialogOpened(false);
},
}}
footer={{
children: (Component, props) => (
<>
<Text as="a" href="">
See shortcuts for all platforms
</Text>
<Text as="a" href="">
Office Accessibility Center
</Text>
{page === 'shortcuts' && (
<Text as="a" href="#contexts" onClick={event => navigateTo('contexts', setPage, event)}>
See chats contextual keyboard help
</Text>
)}
</>
),
}}
trigger={<Button content={triggerText} />}
content={content}
/>
);
}; // End ContextualHelpDialog2