blob: d0db1c0a31f41f10158ca04228edfee4e0ee1325 [file] [log] [blame]
idillon-sfl37c18df2022-08-26 18:44:27 -04001import { QuestionMark } from "@mui/icons-material";
idillon1664bb22022-09-14 17:18:15 -04002import { Box, ClickAwayListener, IconButton, Popper } from "@mui/material";
idillonfb2af5b2022-09-16 13:40:08 -04003import { styled } from "@mui/material/styles";
idillonaedab942022-09-01 14:29:43 -04004import EmojiPicker from "emoji-picker-react";
idillon927b7592022-09-15 12:56:45 -04005import React, { useState, useCallback } from "react";
6import { Arrow2Icon, Arrow3Icon, ArrowIcon, CameraIcon, CameraInBubbleIcon, CancelIcon, CrossedEyeIcon, CrossIcon, EmojiIcon, EyeIcon, FolderIcon, InfoIcon, MicroInBubbleIcon, PaperClipIcon, PenIcon, SaltireIcon } from "./svgIcons";
idillon-sfl44b05342022-08-24 15:46:42 -04007
idillon-sfl37c18df2022-08-26 18:44:27 -04008const RoundButton = styled(
idillon-sfld5cc7862022-08-25 11:11:34 -04009 ({Icon, ...props}) => (
10 <IconButton {...props} disableRipple={true}>
idillon-sfl44b05342022-08-24 15:46:42 -040011 <Icon fontSize="inherit"/>
12 </IconButton>
13 )
idillon-sfldeabd282022-08-25 22:50:03 -040014)(({theme}) => ({
15 border: `1px solid ${theme.palette.primary.dark}`,
16 color: theme.palette.primary.dark,
idillon-sfld5cc7862022-08-25 11:11:34 -040017 fontSize: "15px",
18 "&:hover": {
idillon-sfldeabd282022-08-25 22:50:03 -040019 background: theme.palette.primary.light,
idillon-sfld5cc7862022-08-25 11:11:34 -040020 },
21 "&:active": {
22 color: "#FFF",
idillon-sfldeabd282022-08-25 22:50:03 -040023 background: theme.palette.primary.dark,
idillon-sfld5cc7862022-08-25 11:11:34 -040024 },
idillon-sfl37c18df2022-08-26 18:44:27 -040025 "&.MuiIconButton-sizeSmall": {
26 height: "15px",
27 width: "15px",
28 },
29 "&.MuiIconButton-sizeMedium": {
30 height: "30px",
31 width: "30px",
32 },
33 "&.MuiIconButton-sizeLarge": {
34 height: "53px",
35 width: "53px",
36 }
idillon-sfld5cc7862022-08-25 11:11:34 -040037}));
idillon-sfl44b05342022-08-24 15:46:42 -040038
idillonaedab942022-09-01 14:29:43 -040039export const CancelPictureButton = (props) => {
idillon-sfl44b05342022-08-24 15:46:42 -040040 return (
idillon-sfl37c18df2022-08-26 18:44:27 -040041 <RoundButton {...props}
idillon-sfl44b05342022-08-24 15:46:42 -040042 aria-label="remove picture"
43 Icon={CancelIcon}
idillon-sfl37c18df2022-08-26 18:44:27 -040044 size="large"
idillon-sfl44b05342022-08-24 15:46:42 -040045 />
46 )
47}
48
idillonaedab942022-09-01 14:29:43 -040049export const EditPictureButton = (props) => {
idillon-sfl44b05342022-08-24 15:46:42 -040050 return (
idillon-sfl37c18df2022-08-26 18:44:27 -040051 <RoundButton {...props}
idillon-sfl44b05342022-08-24 15:46:42 -040052 aria-label="edit picture"
53 Icon={PenIcon}
idillon-sfl37c18df2022-08-26 18:44:27 -040054 size="large"
idillon-sfl44b05342022-08-24 15:46:42 -040055 />
56 )
57}
58
idillonaedab942022-09-01 14:29:43 -040059export const UploadPictureButton = (props) => {
idillon-sfl44b05342022-08-24 15:46:42 -040060 return (
idillon-sfl37c18df2022-08-26 18:44:27 -040061 <RoundButton {...props}
idillon-sfl44b05342022-08-24 15:46:42 -040062 aria-label="upload picture"
63 Icon={FolderIcon}
idillon-sfl37c18df2022-08-26 18:44:27 -040064 size="large"
idillon-sfl44b05342022-08-24 15:46:42 -040065 />
66 )
67}
68
69export const TakePictureButton = (props) => {
70 return (
idillon-sfl37c18df2022-08-26 18:44:27 -040071 <RoundButton {...props}
idillon-sfl44b05342022-08-24 15:46:42 -040072 aria-label="take picture"
73 Icon={CameraIcon}
idillon-sfl37c18df2022-08-26 18:44:27 -040074 size="large"
idillon-sfl44b05342022-08-24 15:46:42 -040075 />
76 )
77}
idillon-sfl37c18df2022-08-26 18:44:27 -040078
79export const InfoButton = (props) => {
80 return (
81 <RoundButton {...props}
82 aria-label="informations"
83 Icon={InfoIcon}
84 size="small"
85 />
86 )
87}
88
89export const TipButton = (props) => {
90 return (
91 <RoundButton {...props}
idillonaedab942022-09-01 14:29:43 -040092 aria-label="tip"
idillon-sfl37c18df2022-08-26 18:44:27 -040093 Icon={QuestionMark}
94 size="medium"
95 />
96 )
97}
98
idillon927b7592022-09-15 12:56:45 -040099export const MoreButton = styled(
100 (props) => {
101 return (
102 <IconButton
103 {...props}
104 disableRipple={true}
105 aria-label="more"
106 >
107 <CrossIcon fontSize="inherit"/>
108 </IconButton>
109 )
110 }
111)(({theme}) => ({
112 border: `1px solid ${theme.palette.primary.dark}`,
113 color: theme.palette.primary.dark,
114 fontSize: "10px",
115 height: "20px",
116 width: "20px",
117 "&:hover": {
118 background: theme.palette.primary.light,
119 },
120 "&:active": {
121 color: "#FFF",
122 background: theme.palette.primary.dark,
123 },
124}))
125
idillonb3788bf2022-08-29 15:57:57 -0400126export const BackButton = styled(
127 (props) => {
128 return (
idillonaedab942022-09-01 14:29:43 -0400129 <IconButton
130 {...props}
131 disableRipple={true}
132 aria-label="back"
133 >
idillonb3788bf2022-08-29 15:57:57 -0400134 <ArrowIcon fontSize="inherit"/>
135 </IconButton>
136 )
137 }
138)(({theme}) => ({
139 color: theme.palette.primary.dark,
140 fontSize: "15px",
141 height: "30px",
142 width: "51px",
143 borderRadius: "5px",
144 "&:hover": {
145 background: theme.palette.primary.light,
146 },
147}))
148
149export const CloseButton = styled(
150 (props) => {
151 return (
idillonaedab942022-09-01 14:29:43 -0400152 <IconButton
153 {...props}
154 disableRipple={true}
155 aria-label="close"
156 >
idillon927b7592022-09-15 12:56:45 -0400157 <SaltireIcon fontSize="inherit"/>
idillonb3788bf2022-08-29 15:57:57 -0400158 </IconButton>
159 )
160 }
161)(({theme}) => ({
162 color: theme.palette.primary.dark,
163 fontSize: "15px",
164 height: "30px",
165 width: "30px",
166 borderRadius: "5px",
167 "&:hover": {
168 background: theme.palette.primary.light,
169 },
170}))
171
idillon-sfl37c18df2022-08-26 18:44:27 -0400172export const ToggleVisibilityButton = styled(
173 ({visible, ...props}) => {
174 const Icon = visible ? CrossedEyeIcon : EyeIcon
175 return (
176 <IconButton {...props} disableRipple={true}>
177 <Icon fontSize="inherit"/>
178 </IconButton>
179 )
180 }
181)(({theme}) => ({
182 color: theme.palette.primary.dark,
183 fontSize: "15px",
184 height: "15px",
185 width: "15px",
186 "&:hover": {
187 background: theme.palette.primary.light,
188 },
idillonb3788bf2022-08-29 15:57:57 -0400189}))
idillonaedab942022-09-01 14:29:43 -0400190
191const SquareButton = styled(
192 ({Icon, ...props}) => (
193 <IconButton {...props} disableRipple={true}>
194 <Icon fontSize="inherit"/>
195 </IconButton>
196 )
197)(({theme}) => ({
198 color: "#7E7E7E",
199 fontSize: "25px",
200 height: "36px",
201 width: "36px",
202 borderRadius: "5px",
203 "&:hover": {
204 background: "#E5E5E5",
205 },
206}));
207
208export const RecordVideoMessageButton = (props) => {
209 return (
210 <SquareButton {...props}
211 aria-label="record video message"
212 Icon={CameraInBubbleIcon}
213 />
214 )
215}
216
217export const RecordVoiceMessageButton = (props) => {
218 return (
219 <SquareButton {...props}
220 aria-label="record voice message"
221 Icon={MicroInBubbleIcon}
222 />
223 )
224}
225
226export const UploadFileButton = (props) => {
227 return (
228 <SquareButton {...props}
229 aria-label="upload file"
230 Icon={PaperClipIcon}
231 />
232 )
233}
234
235export const SendMessageButton = (props) => {
236 return (
237 <SquareButton {...props}
238 aria-label="send message"
239 Icon={Arrow2Icon}
240 />
241 )
242}
243
idillon927b7592022-09-15 12:56:45 -0400244export const ReplyMessageButton = styled(
245 ({Icon, ...props}) => (
246 <IconButton
247 {...props}
248 disableRipple={true}
249 aria-label="send message"
250 >
251 <Arrow3Icon fontSize="inherit"/>
252 </IconButton>
253 )
254)(({theme}) => ({
255 color: theme.palette.primary.dark,
256 fontSize: "20px",
257 height: "20px",
258 width: "20px",
259 borderRadius: "5px",
260 "&:hover": {
261 background: "#E5E5E5",
262 },
263}));
264
265export const EmojiButton = styled(
266 ({emoji, ...props}) => (
267 <IconButton {...props} disableRipple={true}>
268 {emoji}
269 </IconButton>
270 )
271)(({theme}) => ({
272 color: "white",
273 fontSize: "20px",
274 height: "20px",
275 width: "20px",
276}));
277
idillonaedab942022-09-01 14:29:43 -0400278export const SelectEmojiButton = (props) => {
Adrien Béraud023f7cf2022-09-18 14:57:53 -0400279 const [anchorEl, setAnchorEl] = useState(null)
idillonaedab942022-09-01 14:29:43 -0400280
Adrien Béraud023f7cf2022-09-18 14:57:53 -0400281 const handleOpenEmojiPicker = useCallback(
idillonaedab942022-09-01 14:29:43 -0400282 e => setAnchorEl(anchorEl ? null : e.currentTarget),
283 [anchorEl],
284 )
285
Adrien Béraud023f7cf2022-09-18 14:57:53 -0400286 const handleClose = useCallback(
idillonaedab942022-09-01 14:29:43 -0400287 () => setAnchorEl(null),
288 [setAnchorEl],
289 )
290
Adrien Béraud023f7cf2022-09-18 14:57:53 -0400291 const onEmojiClick = useCallback(
idillonaedab942022-09-01 14:29:43 -0400292 (e, emojiObject) => {
293 props.onEmojiSelected(emojiObject.emoji)
294 handleClose()
295 },
296 [handleClose, props.onEmojiSelected],
297 )
298
299 const open = Boolean(anchorEl)
300 const id = open ? 'simple-popover' : undefined
301
302 return (
idillon1664bb22022-09-14 17:18:15 -0400303 <ClickAwayListener onClickAway={handleClose}>
304 <Box>
305 <SquareButton
306 aria-describedby={id}
307 aria-label="select emoji"
308 Icon={EmojiIcon}
309 onClick={handleOpenEmojiPicker}
310 />
311 <Popper
312 id={id}
313 open={open}
314 anchorEl={anchorEl}
315 onClose={handleClose}
316 >
317 <EmojiPicker.default
318 onEmojiClick={onEmojiClick}
319 disableAutoFocus={true}
320 disableSkinTonePicker={true}
321 native
322 />
323 </Popper>
324 </Box>
325 </ClickAwayListener>
idillonaedab942022-09-01 14:29:43 -0400326 )
idillon1664bb22022-09-14 17:18:15 -0400327}
328