-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathOutgoingLightBox.tsx
More file actions
134 lines (114 loc) · 3.24 KB
/
OutgoingLightBox.tsx
File metadata and controls
134 lines (114 loc) · 3.24 KB
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
import { useRef } from 'react';
import styled from 'styled-components';
import useKey from 'react-use/lib/useKey';
import * as GoogleChrome from '../util/GoogleChrome';
import { AttachmentType } from '../types/Attachment';
import { AriaLabels } from '../util/hardcodedAriaLabels';
import { LUCIDE_ICONS_UNICODE } from './icon/lucide';
import { SessionLucideIconButton } from './icon/SessionIconButton';
import { SessionFocusTrap } from './SessionFocusTrap';
import type { OutgoingLightBoxOptions } from '../state/ducks/modalDialog';
type Props = {
attachment: AttachmentType;
url: string;
onClose: () => void;
};
const StyledCaptionEditorImage = styled.img`
width: 100%;
height: 100%;
object-fit: contain;
flex-grow: 1;
flex-shrink: 1;
`;
const StyledCaptionEditorVideo = styled.video`
max-width: 100%;
max-height: 100%;
object-fit: contain;
flex-grow: 1;
flex-shrink: 1;
`;
const StyledCaptionEditorPlaceholder = styled.div`
width: 100%;
height: 100%;
object-fit: contain;
flex-grow: 1;
flex-shrink: 1;
`;
const LightboxObject = (props: Props) => {
const { url, onClose, attachment } = props;
const { contentType } = attachment || { contentType: null };
const isImageTypeSupported = GoogleChrome.isImageTypeSupported(contentType);
if (isImageTypeSupported) {
return (
<StyledCaptionEditorImage src={url} onClick={onClose} alt={AriaLabels.imageAttachmentAlt} />
);
}
const isVideoTypeSupported = GoogleChrome.isVideoTypeSupported(contentType);
if (isVideoTypeSupported) {
return (
<StyledCaptionEditorVideo controls={true}>
<source src={url} />
</StyledCaptionEditorVideo>
);
}
return <StyledCaptionEditorPlaceholder />;
};
const StyledCaptionEditorContainer = styled.div`
flex-grow: 1;
flex-shrink: 1;
text-align: center;
margin: 50px;
overflow: hidden;
height: 100%;
`;
const StyledCaptionEditor = styled.div`
background-color: rgba(0, 0, 0, 0.8);
z-index: 20;
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
height: 100%;
.session-button {
margin-inline-start: 15px;
}
`;
/**
* This actually no longer allows to edit the caption as we do not support this feature anymore.
* This is just a lightbox to preview the attachments before sending them in a message
*/
export const OutgoingLightBox = (props: NonNullable<OutgoingLightBoxOptions>) => {
const { onClose } = props;
const ref = useRef<HTMLButtonElement>(null);
useKey('Escape', onClose);
return (
<SessionFocusTrap
focusTrapId="OutgoingLightBox"
initialFocus={() => ref.current}
allowOutsideClick={true}
returnFocusOnDeactivate={false}
>
<StyledCaptionEditor>
<SessionLucideIconButton
iconSize="huge"
iconColor="var(--white-color)"
unicode={LUCIDE_ICONS_UNICODE.X}
onClick={onClose}
style={{
position: 'absolute',
top: 'var(--margins-sm)',
right: 'var(--margins-sm)',
zIndex: 1,
}}
ref={ref}
/>
<StyledCaptionEditorContainer>
<LightboxObject {...props} />
</StyledCaptionEditorContainer>
</StyledCaptionEditor>
</SessionFocusTrap>
);
};