-
Notifications
You must be signed in to change notification settings - Fork 440
/
formatters.js
74 lines (57 loc) · 1.81 KB
/
formatters.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
// @flow
// NOTE: props aren't used by default for some getters but consumers may need
// them, this needs to be reflected in the flow type.
/* eslint-disable no-unused-vars */
import type { ViewsType } from './types';
type LabelProps = { currentIndex: number, views: ViewsType };
// ==============================
// Navigation
// ==============================
/* ARIA label for the next button */
function getNextLabel({ currentIndex, views }: LabelProps): string {
return `Show slide ${currentIndex + 2} of ${views.length}`;
}
/* ARIA label for the previous button */
function getPrevLabel({ currentIndex, views }: LabelProps): string {
return `Show slide ${currentIndex} of ${views.length}`;
}
/* HTML title for the next button */
function getNextTitle(props: Object): string {
return 'Next (right arrow)';
}
/* HTML title for the previous button */
function getPrevTitle(props: Object): string {
return 'Previous (left arrow)';
}
// ==============================
// Header
// ==============================
type FullscreenProps = { isFullscreen: boolean };
/* ARIA label for the close button */
function getCloseLabel(props: Object): string {
return 'Close (esc)';
}
/* ARIA label for the fullscreen button */
function getFullscreenLabel({ isFullscreen }: FullscreenProps): string {
return isFullscreen ? 'Exit fullscreen (f)' : 'Enter fullscreen (f)';
}
// ==============================
// View
// ==============================
/* alt text for each image in the carousel */
function getAltText({ data, index }): string {
if (data.caption) return data.caption;
return `Image ${index + 1}`;
}
// ==============================
// Exports
// ==============================
export default {
getAltText,
getNextLabel,
getPrevLabel,
getNextTitle,
getPrevTitle,
getCloseLabel,
getFullscreenLabel,
};