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
|
import styled from 'styled-components';
import { colors } from '../../config.json';
import { messages } from '../../shared/gettext';
export enum SecuredDisplayStyle {
secured,
blocked,
securing,
unsecured,
unsecuring,
failedToSecure,
}
const securedDisplayStyleColorMap = {
[SecuredDisplayStyle.securing]: colors.white,
[SecuredDisplayStyle.unsecuring]: colors.white,
[SecuredDisplayStyle.secured]: colors.green,
[SecuredDisplayStyle.blocked]: colors.green,
[SecuredDisplayStyle.unsecured]: colors.red,
[SecuredDisplayStyle.failedToSecure]: colors.red,
};
const StyledSecuredLabel = styled.span((props: { displayStyle: SecuredDisplayStyle }) => ({
display: 'inline-block',
minHeight: '22px',
color: securedDisplayStyleColorMap[props.displayStyle],
}));
interface ISecuredLabelProps {
displayStyle: SecuredDisplayStyle;
className?: string;
}
export default function SecuredLabel(props: ISecuredLabelProps) {
return (
<StyledSecuredLabel {...props} role="status" aria-live="polite">
{getLabelText(props.displayStyle)}
</StyledSecuredLabel>
);
}
function getLabelText(displayStyle: SecuredDisplayStyle) {
switch (displayStyle) {
case SecuredDisplayStyle.secured:
return messages.gettext('SECURE CONNECTION');
case SecuredDisplayStyle.blocked:
return messages.gettext('BLOCKED CONNECTION');
case SecuredDisplayStyle.securing:
return messages.gettext('CREATING SECURE CONNECTION');
case SecuredDisplayStyle.unsecured:
return messages.gettext('UNSECURED CONNECTION');
case SecuredDisplayStyle.unsecuring:
return '';
case SecuredDisplayStyle.failedToSecure:
return messages.gettext('FAILED TO SECURE CONNECTION');
}
}
|