idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 1 | import { QuestionMark } from "@mui/icons-material"; |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 2 | import { Box, ClickAwayListener, IconButton, Popper } from "@mui/material"; |
idillon | fb2af5b | 2022-09-16 13:40:08 -0400 | [diff] [blame] | 3 | import { styled } from "@mui/material/styles"; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 4 | import EmojiPicker from "emoji-picker-react"; |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 5 | import React, { useState, useCallback } from "react"; |
| 6 | import { Arrow2Icon, Arrow3Icon, ArrowIcon, CameraIcon, CameraInBubbleIcon, CancelIcon, CrossedEyeIcon, CrossIcon, EmojiIcon, EyeIcon, FolderIcon, InfoIcon, MicroInBubbleIcon, PaperClipIcon, PenIcon, SaltireIcon } from "./svgIcons"; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 7 | |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 8 | const RoundButton = styled( |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 9 | ({Icon, ...props}) => ( |
| 10 | <IconButton {...props} disableRipple={true}> |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 11 | <Icon fontSize="inherit"/> |
| 12 | </IconButton> |
| 13 | ) |
idillon-sfl | deabd28 | 2022-08-25 22:50:03 -0400 | [diff] [blame] | 14 | )(({theme}) => ({ |
| 15 | border: `1px solid ${theme.palette.primary.dark}`, |
| 16 | color: theme.palette.primary.dark, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 17 | fontSize: "15px", |
| 18 | "&:hover": { |
idillon-sfl | deabd28 | 2022-08-25 22:50:03 -0400 | [diff] [blame] | 19 | background: theme.palette.primary.light, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 20 | }, |
| 21 | "&:active": { |
| 22 | color: "#FFF", |
idillon-sfl | deabd28 | 2022-08-25 22:50:03 -0400 | [diff] [blame] | 23 | background: theme.palette.primary.dark, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 24 | }, |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 25 | "&.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-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 37 | })); |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 38 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 39 | export const CancelPictureButton = (props) => { |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 40 | return ( |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 41 | <RoundButton {...props} |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 42 | aria-label="remove picture" |
| 43 | Icon={CancelIcon} |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 44 | size="large" |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 45 | /> |
| 46 | ) |
| 47 | } |
| 48 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 49 | export const EditPictureButton = (props) => { |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 50 | return ( |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 51 | <RoundButton {...props} |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 52 | aria-label="edit picture" |
| 53 | Icon={PenIcon} |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 54 | size="large" |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 55 | /> |
| 56 | ) |
| 57 | } |
| 58 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 59 | export const UploadPictureButton = (props) => { |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 60 | return ( |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 61 | <RoundButton {...props} |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 62 | aria-label="upload picture" |
| 63 | Icon={FolderIcon} |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 64 | size="large" |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 65 | /> |
| 66 | ) |
| 67 | } |
| 68 | |
| 69 | export const TakePictureButton = (props) => { |
| 70 | return ( |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 71 | <RoundButton {...props} |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 72 | aria-label="take picture" |
| 73 | Icon={CameraIcon} |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 74 | size="large" |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 75 | /> |
| 76 | ) |
| 77 | } |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 78 | |
| 79 | export const InfoButton = (props) => { |
| 80 | return ( |
| 81 | <RoundButton {...props} |
| 82 | aria-label="informations" |
| 83 | Icon={InfoIcon} |
| 84 | size="small" |
| 85 | /> |
| 86 | ) |
| 87 | } |
| 88 | |
| 89 | export const TipButton = (props) => { |
| 90 | return ( |
| 91 | <RoundButton {...props} |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 92 | aria-label="tip" |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 93 | Icon={QuestionMark} |
| 94 | size="medium" |
| 95 | /> |
| 96 | ) |
| 97 | } |
| 98 | |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 99 | export 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 | |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 126 | export const BackButton = styled( |
| 127 | (props) => { |
| 128 | return ( |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 129 | <IconButton |
| 130 | {...props} |
| 131 | disableRipple={true} |
| 132 | aria-label="back" |
| 133 | > |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 134 | <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 | |
| 149 | export const CloseButton = styled( |
| 150 | (props) => { |
| 151 | return ( |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 152 | <IconButton |
| 153 | {...props} |
| 154 | disableRipple={true} |
| 155 | aria-label="close" |
| 156 | > |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 157 | <SaltireIcon fontSize="inherit"/> |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 158 | </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-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 172 | export 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 | }, |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 189 | })) |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 190 | |
| 191 | const 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 | |
| 208 | export const RecordVideoMessageButton = (props) => { |
| 209 | return ( |
| 210 | <SquareButton {...props} |
| 211 | aria-label="record video message" |
| 212 | Icon={CameraInBubbleIcon} |
| 213 | /> |
| 214 | ) |
| 215 | } |
| 216 | |
| 217 | export const RecordVoiceMessageButton = (props) => { |
| 218 | return ( |
| 219 | <SquareButton {...props} |
| 220 | aria-label="record voice message" |
| 221 | Icon={MicroInBubbleIcon} |
| 222 | /> |
| 223 | ) |
| 224 | } |
| 225 | |
| 226 | export const UploadFileButton = (props) => { |
| 227 | return ( |
| 228 | <SquareButton {...props} |
| 229 | aria-label="upload file" |
| 230 | Icon={PaperClipIcon} |
| 231 | /> |
| 232 | ) |
| 233 | } |
| 234 | |
| 235 | export const SendMessageButton = (props) => { |
| 236 | return ( |
| 237 | <SquareButton {...props} |
| 238 | aria-label="send message" |
| 239 | Icon={Arrow2Icon} |
| 240 | /> |
| 241 | ) |
| 242 | } |
| 243 | |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 244 | export 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 | |
| 265 | export 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 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 278 | export const SelectEmojiButton = (props) => { |
Adrien Béraud | 023f7cf | 2022-09-18 14:57:53 -0400 | [diff] [blame] | 279 | const [anchorEl, setAnchorEl] = useState(null) |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 280 | |
Adrien Béraud | 023f7cf | 2022-09-18 14:57:53 -0400 | [diff] [blame] | 281 | const handleOpenEmojiPicker = useCallback( |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 282 | e => setAnchorEl(anchorEl ? null : e.currentTarget), |
| 283 | [anchorEl], |
| 284 | ) |
| 285 | |
Adrien Béraud | 023f7cf | 2022-09-18 14:57:53 -0400 | [diff] [blame] | 286 | const handleClose = useCallback( |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 287 | () => setAnchorEl(null), |
| 288 | [setAnchorEl], |
| 289 | ) |
| 290 | |
Adrien Béraud | 023f7cf | 2022-09-18 14:57:53 -0400 | [diff] [blame] | 291 | const onEmojiClick = useCallback( |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 292 | (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 ( |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 303 | <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> |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 326 | ) |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 327 | } |
| 328 | |