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