simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 1 | import { QuestionMark } from '@mui/icons-material'; |
| 2 | import { Box, ClickAwayListener, IconButton, Popper } from '@mui/material'; |
| 3 | import { styled } from '@mui/material/styles'; |
| 4 | import EmojiPicker from 'emoji-picker-react'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame^] | 5 | import React, { useCallback, useState } from 'react'; |
| 6 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 7 | import { |
| 8 | Arrow2Icon, |
| 9 | Arrow3Icon, |
| 10 | ArrowIcon, |
| 11 | CameraIcon, |
| 12 | CameraInBubbleIcon, |
| 13 | CancelIcon, |
| 14 | CrossedEyeIcon, |
| 15 | CrossIcon, |
| 16 | EmojiIcon, |
| 17 | EyeIcon, |
| 18 | FolderIcon, |
| 19 | InfoIcon, |
| 20 | MicroInBubbleIcon, |
| 21 | PaperClipIcon, |
| 22 | PenIcon, |
| 23 | SaltireIcon, |
| 24 | } from './svgIcons'; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 25 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 26 | const RoundButton = styled(({ Icon, ...props }) => ( |
| 27 | <IconButton {...props} disableRipple={true}> |
| 28 | <Icon fontSize="inherit" /> |
| 29 | </IconButton> |
| 30 | ))(({ theme }) => ({ |
| 31 | border: `1px solid ${theme.palette.primary.dark}`, |
| 32 | color: theme.palette.primary.dark, |
| 33 | fontSize: '15px', |
| 34 | '&:hover': { |
| 35 | background: theme.palette.primary.light, |
| 36 | }, |
| 37 | '&:active': { |
| 38 | color: '#FFF', |
| 39 | background: theme.palette.primary.dark, |
| 40 | }, |
| 41 | '&.MuiIconButton-sizeSmall': { |
| 42 | height: '15px', |
| 43 | width: '15px', |
| 44 | }, |
| 45 | '&.MuiIconButton-sizeMedium': { |
| 46 | height: '30px', |
| 47 | width: '30px', |
| 48 | }, |
| 49 | '&.MuiIconButton-sizeLarge': { |
| 50 | height: '53px', |
| 51 | width: '53px', |
| 52 | }, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 53 | })); |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 54 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 55 | export const CancelPictureButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 56 | return <RoundButton {...props} aria-label="remove picture" Icon={CancelIcon} size="large" />; |
| 57 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 58 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 59 | export const EditPictureButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 60 | return <RoundButton {...props} aria-label="edit picture" Icon={PenIcon} size="large" />; |
| 61 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 62 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 63 | export const UploadPictureButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 64 | return <RoundButton {...props} aria-label="upload picture" Icon={FolderIcon} size="large" />; |
| 65 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 66 | |
| 67 | export const TakePictureButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 68 | return <RoundButton {...props} aria-label="take picture" Icon={CameraIcon} size="large" />; |
| 69 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 70 | |
| 71 | export const InfoButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 72 | return <RoundButton {...props} aria-label="informations" Icon={InfoIcon} size="small" />; |
| 73 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 74 | |
| 75 | export const TipButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 76 | return <RoundButton {...props} aria-label="tip" Icon={QuestionMark} size="medium" />; |
| 77 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 78 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 79 | export const MoreButton = styled((props) => { |
| 80 | return ( |
| 81 | <IconButton {...props} disableRipple={true} aria-label="more"> |
| 82 | <CrossIcon fontSize="inherit" /> |
| 83 | </IconButton> |
| 84 | ); |
| 85 | })(({ theme }) => ({ |
| 86 | border: `1px solid ${theme.palette.primary.dark}`, |
| 87 | color: theme.palette.primary.dark, |
| 88 | fontSize: '10px', |
| 89 | height: '20px', |
| 90 | width: '20px', |
| 91 | '&:hover': { |
| 92 | background: theme.palette.primary.light, |
| 93 | }, |
| 94 | '&:active': { |
| 95 | color: '#FFF', |
| 96 | background: theme.palette.primary.dark, |
| 97 | }, |
| 98 | })); |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 99 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 100 | export const BackButton = styled((props) => { |
| 101 | return ( |
| 102 | <IconButton {...props} disableRipple={true} aria-label="back"> |
| 103 | <ArrowIcon fontSize="inherit" /> |
| 104 | </IconButton> |
| 105 | ); |
| 106 | })(({ theme }) => ({ |
| 107 | color: theme.palette.primary.dark, |
| 108 | fontSize: '15px', |
| 109 | height: '30px', |
| 110 | width: '51px', |
| 111 | borderRadius: '5px', |
| 112 | '&:hover': { |
| 113 | background: theme.palette.primary.light, |
| 114 | }, |
| 115 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 116 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 117 | export const CloseButton = styled((props) => { |
| 118 | return ( |
| 119 | <IconButton {...props} disableRipple={true} aria-label="close"> |
| 120 | <SaltireIcon fontSize="inherit" /> |
| 121 | </IconButton> |
| 122 | ); |
| 123 | })(({ theme }) => ({ |
| 124 | color: theme.palette.primary.dark, |
| 125 | fontSize: '15px', |
| 126 | height: '30px', |
| 127 | width: '30px', |
| 128 | borderRadius: '5px', |
| 129 | '&:hover': { |
| 130 | background: theme.palette.primary.light, |
| 131 | }, |
| 132 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 133 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 134 | export const ToggleVisibilityButton = styled(({ visible, ...props }) => { |
| 135 | const Icon = visible ? CrossedEyeIcon : EyeIcon; |
| 136 | return ( |
| 137 | <IconButton {...props} disableRipple={true}> |
| 138 | <Icon fontSize="inherit" /> |
| 139 | </IconButton> |
| 140 | ); |
| 141 | })(({ theme }) => ({ |
| 142 | color: theme.palette.primary.dark, |
| 143 | fontSize: '15px', |
| 144 | height: '15px', |
| 145 | width: '15px', |
| 146 | '&:hover': { |
| 147 | background: theme.palette.primary.light, |
| 148 | }, |
| 149 | })); |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 150 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 151 | const SquareButton = styled(({ Icon, ...props }) => ( |
| 152 | <IconButton {...props} disableRipple={true}> |
| 153 | <Icon fontSize="inherit" /> |
| 154 | </IconButton> |
| 155 | ))(({ theme }) => ({ |
| 156 | color: '#7E7E7E', |
| 157 | fontSize: '25px', |
| 158 | height: '36px', |
| 159 | width: '36px', |
| 160 | borderRadius: '5px', |
| 161 | '&:hover': { |
| 162 | background: '#E5E5E5', |
| 163 | }, |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 164 | })); |
| 165 | |
| 166 | export const RecordVideoMessageButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 167 | return <SquareButton {...props} aria-label="record video message" Icon={CameraInBubbleIcon} />; |
| 168 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 169 | |
| 170 | export const RecordVoiceMessageButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 171 | return <SquareButton {...props} aria-label="record voice message" Icon={MicroInBubbleIcon} />; |
| 172 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 173 | |
| 174 | export const UploadFileButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 175 | return <SquareButton {...props} aria-label="upload file" Icon={PaperClipIcon} />; |
| 176 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 177 | |
| 178 | export const SendMessageButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 179 | return <SquareButton {...props} aria-label="send message" Icon={Arrow2Icon} />; |
| 180 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 181 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 182 | export const ReplyMessageButton = styled(({ Icon, ...props }) => ( |
| 183 | <IconButton {...props} disableRipple={true} aria-label="send message"> |
| 184 | <Arrow3Icon fontSize="inherit" /> |
| 185 | </IconButton> |
| 186 | ))(({ theme }) => ({ |
| 187 | color: theme.palette.primary.dark, |
| 188 | fontSize: '20px', |
| 189 | height: '20px', |
| 190 | width: '20px', |
| 191 | borderRadius: '5px', |
| 192 | '&:hover': { |
| 193 | background: '#E5E5E5', |
| 194 | }, |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 195 | })); |
| 196 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 197 | export const EmojiButton = styled(({ emoji, ...props }) => ( |
| 198 | <IconButton {...props} disableRipple={true}> |
| 199 | {emoji} |
| 200 | </IconButton> |
| 201 | ))(({ theme }) => ({ |
| 202 | color: 'white', |
| 203 | fontSize: '20px', |
| 204 | height: '20px', |
| 205 | width: '20px', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 206 | })); |
| 207 | |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 208 | export const SelectEmojiButton = (props) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 209 | const [anchorEl, setAnchorEl] = useState(null); |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 210 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 211 | const handleOpenEmojiPicker = useCallback((e) => setAnchorEl(anchorEl ? null : e.currentTarget), [anchorEl]); |
| 212 | |
| 213 | const handleClose = useCallback(() => setAnchorEl(null), [setAnchorEl]); |
| 214 | |
| 215 | const onEmojiClick = useCallback( |
| 216 | (e, emojiObject) => { |
| 217 | props.onEmojiSelected(emojiObject.emoji); |
| 218 | handleClose(); |
| 219 | }, |
| 220 | [handleClose, props.onEmojiSelected] |
| 221 | ); |
| 222 | |
| 223 | const open = Boolean(anchorEl); |
| 224 | const id = open ? 'simple-popover' : undefined; |
| 225 | |
| 226 | return ( |
| 227 | <ClickAwayListener onClickAway={handleClose}> |
| 228 | <Box> |
| 229 | <SquareButton |
| 230 | aria-describedby={id} |
| 231 | aria-label="select emoji" |
| 232 | Icon={EmojiIcon} |
| 233 | onClick={handleOpenEmojiPicker} |
| 234 | /> |
| 235 | <Popper id={id} open={open} anchorEl={anchorEl} onClose={handleClose}> |
| 236 | <EmojiPicker.default |
| 237 | onEmojiClick={onEmojiClick} |
| 238 | disableAutoFocus={true} |
| 239 | disableSkinTonePicker={true} |
| 240 | native |
| 241 | /> |
| 242 | </Popper> |
| 243 | </Box> |
| 244 | </ClickAwayListener> |
| 245 | ); |
| 246 | }; |