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