simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 18 | import { QuestionMark, RadioButtonChecked, RadioButtonUnchecked } from '@mui/icons-material'; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 19 | import { |
| 20 | Box, |
| 21 | ClickAwayListener, |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 22 | FormControlLabel, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 23 | IconButton, |
| 24 | IconButtonProps, |
| 25 | ListItemIcon, |
| 26 | ListItemText, |
| 27 | Menu, |
| 28 | MenuItem, |
| 29 | Popper, |
| 30 | Radio, |
| 31 | RadioGroup, |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 32 | RadioGroupProps, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 33 | SvgIconProps, |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 34 | Theme, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 35 | } from '@mui/material'; |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 36 | import { PaletteColor, styled } from '@mui/material/styles'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 37 | import EmojiPicker, { IEmojiData } from 'emoji-picker-react'; |
simon | daae910 | 2022-12-02 16:51:31 -0500 | [diff] [blame] | 38 | import { ComponentType, MouseEvent, ReactNode, useCallback, useState } from 'react'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 39 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 40 | import { |
| 41 | Arrow2Icon, |
| 42 | Arrow3Icon, |
| 43 | ArrowIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 44 | AudioCallIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 45 | CameraIcon, |
| 46 | CameraInBubbleIcon, |
| 47 | CancelIcon, |
| 48 | CrossedEyeIcon, |
| 49 | CrossIcon, |
| 50 | EmojiIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 51 | ExpandLessIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 52 | EyeIcon, |
| 53 | FolderIcon, |
| 54 | InfoIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 55 | ListIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 56 | MicroInBubbleIcon, |
| 57 | PaperClipIcon, |
| 58 | PenIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 59 | PeopleWithPlusSignIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 60 | SaltireIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 61 | VideoCallIcon, |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 62 | } from './SvgIcon'; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 63 | import CustomTooltip from './Tooltip'; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 64 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 65 | export type ShapedButtonProps = IconButtonProps & { |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 66 | Icon: ComponentType<SvgIconProps>; |
| 67 | }; |
| 68 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 69 | export const RoundButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 70 | <IconButton {...props} disableRipple={true}> |
| 71 | <Icon fontSize="inherit" /> |
| 72 | </IconButton> |
| 73 | ))(({ theme }) => ({ |
| 74 | border: `1px solid ${theme.palette.primary.dark}`, |
| 75 | color: theme.palette.primary.dark, |
| 76 | fontSize: '15px', |
idillon | b0ec86a | 2022-12-06 17:54:55 -0500 | [diff] [blame] | 77 | background: 'white', |
| 78 | opacity: 1, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 79 | '&:hover': { |
| 80 | background: theme.palette.primary.light, |
| 81 | }, |
| 82 | '&:active': { |
| 83 | color: '#FFF', |
| 84 | background: theme.palette.primary.dark, |
| 85 | }, |
| 86 | '&.MuiIconButton-sizeSmall': { |
| 87 | height: '15px', |
| 88 | width: '15px', |
| 89 | }, |
| 90 | '&.MuiIconButton-sizeMedium': { |
| 91 | height: '30px', |
| 92 | width: '30px', |
| 93 | }, |
| 94 | '&.MuiIconButton-sizeLarge': { |
| 95 | height: '53px', |
| 96 | width: '53px', |
| 97 | }, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 98 | })); |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 99 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 100 | type ExpandMenuOption = { |
| 101 | description: ReactNode; |
| 102 | icon?: ReactNode; |
| 103 | }; |
| 104 | |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 105 | export type ExpandMenuRadioOption = RadioGroupProps & { |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 106 | options: { |
| 107 | key: string; |
| 108 | description: ReactNode; |
| 109 | }[]; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | export type ExpandableButtonProps = IconButtonProps & { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 113 | isVertical?: boolean; |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 114 | expandMenuOnClick?: boolean; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 115 | Icon?: ComponentType<SvgIconProps>; |
| 116 | expandMenuOptions?: (ExpandMenuOption | ExpandMenuRadioOption)[]; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 117 | IconButtonComp?: ComponentType<IconButtonProps>; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 118 | }; |
| 119 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 120 | export const ExpandableButton = ({ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 121 | isVertical, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 122 | Icon, |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 123 | expandMenuOnClick, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 124 | expandMenuOptions = undefined, |
| 125 | IconButtonComp = IconButton, |
| 126 | ...props |
| 127 | }: ExpandableButtonProps) => { |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 128 | const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); |
| 129 | const handleClose = () => { |
| 130 | setAnchorEl(null); |
| 131 | }; |
| 132 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 133 | return ( |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 134 | <> |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 135 | {expandMenuOptions && ( |
| 136 | <Menu |
| 137 | anchorEl={anchorEl} |
| 138 | open={!!anchorEl} |
| 139 | onClose={handleClose} |
| 140 | anchorOrigin={{ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 141 | vertical: !isVertical ? 'top' : 'center', |
| 142 | horizontal: !isVertical ? 'center' : 'left', |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 143 | }} |
| 144 | transformOrigin={{ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 145 | vertical: !isVertical ? 'bottom' : 'center', |
| 146 | horizontal: !isVertical ? 'center' : 'right', |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 147 | }} |
| 148 | > |
| 149 | {expandMenuOptions?.map((option, id) => { |
| 150 | if ('options' in option) { |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 151 | const { options, ...radioGroupProps } = option; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 152 | return ( |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 153 | <RadioGroup key={id} {...radioGroupProps}> |
| 154 | {options.map(({ description, key }, i) => ( |
| 155 | <MenuItem key={i}> |
| 156 | <FormControlLabel |
| 157 | value={key} |
| 158 | control={<Radio value={key} />} |
| 159 | label={<ListItemText>{description}</ListItemText>} |
| 160 | sx={{ |
| 161 | width: '100%', |
| 162 | }} |
| 163 | /> |
| 164 | </MenuItem> |
| 165 | ))} |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 166 | </RadioGroup> |
| 167 | ); |
| 168 | } |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 169 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 170 | return ( |
| 171 | <MenuItem key={id} onClick={handleClose}> |
| 172 | <ListItemIcon>{option.icon}</ListItemIcon> |
| 173 | <ListItemText>{option.description}</ListItemText> |
| 174 | </MenuItem> |
| 175 | ); |
| 176 | })} |
| 177 | </Menu> |
| 178 | )} |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 179 | <Box position="relative" display="flex" justifyContent="center" alignItems="center"> |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 180 | {expandMenuOptions && ( |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 181 | <IconButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 182 | aria-label="expand options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 183 | onClick={(e) => setAnchorEl(e.currentTarget)} |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 184 | sx={{ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 185 | rotate: !isVertical ? '' : '-90deg', |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 186 | position: 'absolute', |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 187 | top: !isVertical ? '-55%' : 'auto', |
| 188 | left: !isVertical ? 'auto' : '-55%', |
| 189 | zIndex: 1, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 190 | }} |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 191 | className={props.className} |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 192 | > |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 193 | <ExpandLessIcon |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 194 | fontSize="small" |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 195 | sx={{ |
| 196 | backgroundColor: '#444444', |
| 197 | borderRadius: '5px', |
| 198 | }} |
| 199 | /> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 200 | </IconButton> |
| 201 | )} |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 202 | <IconButtonComp |
| 203 | onClick={ |
| 204 | expandMenuOnClick |
| 205 | ? (event) => { |
| 206 | setAnchorEl(event.currentTarget); |
| 207 | } |
| 208 | : undefined |
| 209 | } |
| 210 | {...props} |
| 211 | > |
| 212 | {Icon && <Icon />} |
| 213 | </IconButtonComp> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 214 | </Box> |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 215 | </> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 216 | ); |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 217 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 218 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 219 | export const CancelPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 220 | return <RoundButton {...props} aria-label="remove picture" Icon={CancelIcon} size="large" />; |
| 221 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 222 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 223 | export const EditPictureButton = (props: IconButtonProps) => { |
idillon | b0ec86a | 2022-12-06 17:54:55 -0500 | [diff] [blame] | 224 | return <RoundButton {...props} aria-label="edit picture" Icon={PenIcon} size="medium" />; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 225 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 226 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 227 | export const UploadPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 228 | return <RoundButton {...props} aria-label="upload picture" Icon={FolderIcon} size="large" />; |
| 229 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 230 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 231 | export const TakePictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 232 | return <RoundButton {...props} aria-label="take picture" Icon={CameraIcon} size="large" />; |
| 233 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 234 | |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 235 | type InfoButtonProps = IconButtonProps & { |
| 236 | tooltipTitle: string; |
| 237 | }; |
| 238 | export const InfoButton = ({ tooltipTitle, ...props }: InfoButtonProps) => { |
| 239 | return ( |
| 240 | <CustomTooltip className="tooltip" title={tooltipTitle}> |
| 241 | <RoundButton {...props} aria-label="informations" Icon={InfoIcon} size="small" /> |
| 242 | </CustomTooltip> |
| 243 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 244 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 245 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 246 | export const TipButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 247 | return <RoundButton {...props} aria-label="tip" Icon={QuestionMark} size="medium" />; |
| 248 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 249 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 250 | export const MoreButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 251 | return ( |
| 252 | <IconButton {...props} disableRipple={true} aria-label="more"> |
| 253 | <CrossIcon fontSize="inherit" /> |
| 254 | </IconButton> |
| 255 | ); |
| 256 | })(({ theme }) => ({ |
| 257 | border: `1px solid ${theme.palette.primary.dark}`, |
| 258 | color: theme.palette.primary.dark, |
| 259 | fontSize: '10px', |
| 260 | height: '20px', |
| 261 | width: '20px', |
| 262 | '&:hover': { |
| 263 | background: theme.palette.primary.light, |
| 264 | }, |
| 265 | '&:active': { |
| 266 | color: '#FFF', |
| 267 | background: theme.palette.primary.dark, |
| 268 | }, |
| 269 | })); |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 270 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 271 | export const BackButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 272 | return ( |
| 273 | <IconButton {...props} disableRipple={true} aria-label="back"> |
| 274 | <ArrowIcon fontSize="inherit" /> |
| 275 | </IconButton> |
| 276 | ); |
| 277 | })(({ theme }) => ({ |
| 278 | color: theme.palette.primary.dark, |
| 279 | fontSize: '15px', |
| 280 | height: '30px', |
| 281 | width: '51px', |
| 282 | borderRadius: '5px', |
| 283 | '&:hover': { |
| 284 | background: theme.palette.primary.light, |
| 285 | }, |
| 286 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 287 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 288 | export type ToggleIconButtonProps = IconButtonProps & { |
| 289 | selected: boolean; |
| 290 | toggle: () => void; |
| 291 | IconOn?: ComponentType<SvgIconProps>; |
| 292 | IconOff?: ComponentType<SvgIconProps>; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 293 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 294 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 295 | export const ToggleIconButton = ({ |
| 296 | IconOn = RadioButtonChecked, |
| 297 | IconOff = RadioButtonUnchecked, |
| 298 | selected, |
| 299 | toggle, |
| 300 | ...props |
| 301 | }: ToggleIconButtonProps) => { |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 302 | return ( |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 303 | <IconButton |
| 304 | {...props} |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 305 | sx={{ |
| 306 | color: selected ? 'white' : 'red', |
| 307 | ...props.sx, |
| 308 | }} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 309 | onClick={() => { |
| 310 | toggle(); |
| 311 | }} |
| 312 | > |
| 313 | {selected ? <IconOn /> : <IconOff />} |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 314 | </IconButton> |
| 315 | ); |
| 316 | }; |
| 317 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 318 | export const CloseButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 319 | return ( |
| 320 | <IconButton {...props} disableRipple={true} aria-label="close"> |
| 321 | <SaltireIcon fontSize="inherit" /> |
| 322 | </IconButton> |
| 323 | ); |
| 324 | })(({ theme }) => ({ |
| 325 | color: theme.palette.primary.dark, |
| 326 | fontSize: '15px', |
| 327 | height: '30px', |
| 328 | width: '30px', |
| 329 | borderRadius: '5px', |
| 330 | '&:hover': { |
| 331 | background: theme.palette.primary.light, |
| 332 | }, |
| 333 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 334 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 335 | type ToggleVisibilityButtonProps = IconButtonProps & { |
| 336 | visible: boolean; |
| 337 | }; |
| 338 | export const ToggleVisibilityButton = styled(({ visible, ...props }: ToggleVisibilityButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 339 | const Icon = visible ? CrossedEyeIcon : EyeIcon; |
| 340 | return ( |
| 341 | <IconButton {...props} disableRipple={true}> |
| 342 | <Icon fontSize="inherit" /> |
| 343 | </IconButton> |
| 344 | ); |
| 345 | })(({ theme }) => ({ |
| 346 | color: theme.palette.primary.dark, |
| 347 | fontSize: '15px', |
| 348 | height: '15px', |
| 349 | width: '15px', |
| 350 | '&:hover': { |
| 351 | background: theme.palette.primary.light, |
| 352 | }, |
| 353 | })); |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 354 | |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 355 | export const SquareButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 356 | <IconButton {...props} disableRipple={true}> |
| 357 | <Icon fontSize="inherit" /> |
| 358 | </IconButton> |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 359 | ))(() => ({ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 360 | color: '#7E7E7E', |
| 361 | fontSize: '25px', |
| 362 | height: '36px', |
| 363 | width: '36px', |
| 364 | borderRadius: '5px', |
| 365 | '&:hover': { |
| 366 | background: '#E5E5E5', |
| 367 | }, |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 368 | })); |
| 369 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 370 | export const AddParticipantButton = (props: IconButtonProps) => { |
| 371 | return <SquareButton {...props} aria-label="add participant" Icon={PeopleWithPlusSignIcon} />; |
| 372 | }; |
| 373 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 374 | export const RecordVideoMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 375 | return <SquareButton {...props} aria-label="record video message" Icon={CameraInBubbleIcon} />; |
| 376 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 377 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 378 | export const RecordVoiceMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 379 | return <SquareButton {...props} aria-label="record voice message" Icon={MicroInBubbleIcon} />; |
| 380 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 381 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 382 | export const ShowOptionsMenuButton = (props: IconButtonProps) => { |
| 383 | return <SquareButton {...props} aria-label="show options menu" Icon={ListIcon} />; |
| 384 | }; |
| 385 | |
| 386 | export const StartVideoCallButton = (props: IconButtonProps) => { |
simon | cd698c5 | 2022-11-08 19:21:38 -0500 | [diff] [blame] | 387 | return <SquareButton {...props} aria-label="start audio call" Icon={VideoCallIcon} />; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | export const StartAudioCallButton = (props: IconButtonProps) => { |
simon | cd698c5 | 2022-11-08 19:21:38 -0500 | [diff] [blame] | 391 | return <SquareButton {...props} aria-label="start video call" Icon={AudioCallIcon} />; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 392 | }; |
| 393 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 394 | export const UploadFileButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 395 | return <SquareButton {...props} aria-label="upload file" Icon={PaperClipIcon} />; |
| 396 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 397 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 398 | export const SendMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 399 | return <SquareButton {...props} aria-label="send message" Icon={Arrow2Icon} />; |
| 400 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 401 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 402 | export const ReplyMessageButton = styled((props: IconButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 403 | <IconButton {...props} disableRipple={true} aria-label="send message"> |
| 404 | <Arrow3Icon fontSize="inherit" /> |
| 405 | </IconButton> |
| 406 | ))(({ theme }) => ({ |
| 407 | color: theme.palette.primary.dark, |
| 408 | fontSize: '20px', |
| 409 | height: '20px', |
| 410 | width: '20px', |
| 411 | borderRadius: '5px', |
| 412 | '&:hover': { |
| 413 | background: '#E5E5E5', |
| 414 | }, |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 415 | })); |
| 416 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 417 | type EmojiButtonProps = IconButtonProps & { |
| 418 | emoji: string; |
| 419 | }; |
| 420 | export const EmojiButton = styled(({ emoji, ...props }: EmojiButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 421 | <IconButton {...props} disableRipple={true}> |
| 422 | {emoji} |
| 423 | </IconButton> |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 424 | ))(() => ({ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 425 | color: 'white', |
| 426 | fontSize: '20px', |
| 427 | height: '20px', |
| 428 | width: '20px', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 429 | })); |
| 430 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 431 | type SelectEmojiButtonProps = { |
| 432 | onEmojiSelected: (emoji: string) => void; |
| 433 | }; |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 434 | export const SelectEmojiButton = ({ onEmojiSelected }: SelectEmojiButtonProps) => { |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 435 | const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null); |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 436 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 437 | const handleOpenEmojiPicker = useCallback( |
| 438 | (e: MouseEvent<HTMLButtonElement>) => setAnchorEl(anchorEl ? null : e.currentTarget), |
| 439 | [anchorEl] |
| 440 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 441 | |
| 442 | const handleClose = useCallback(() => setAnchorEl(null), [setAnchorEl]); |
| 443 | |
| 444 | const onEmojiClick = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 445 | (e: MouseEvent, emojiObject: IEmojiData) => { |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 446 | onEmojiSelected(emojiObject.emoji); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 447 | handleClose(); |
| 448 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 449 | [handleClose, onEmojiSelected] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 450 | ); |
| 451 | |
| 452 | const open = Boolean(anchorEl); |
| 453 | const id = open ? 'simple-popover' : undefined; |
| 454 | |
| 455 | return ( |
| 456 | <ClickAwayListener onClickAway={handleClose}> |
| 457 | <Box> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 458 | <SquareButton |
| 459 | aria-describedby={id} |
| 460 | aria-label="select emoji" |
| 461 | Icon={EmojiIcon} |
| 462 | onClick={handleOpenEmojiPicker} |
| 463 | /> |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 464 | <Popper id={id} open={open} anchorEl={anchorEl}> |
| 465 | <EmojiPicker onEmojiClick={onEmojiClick} disableAutoFocus={true} disableSkinTonePicker={true} native /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 466 | </Popper> |
| 467 | </Box> |
| 468 | </ClickAwayListener> |
| 469 | ); |
| 470 | }; |
idillon | b0ec86a | 2022-12-06 17:54:55 -0500 | [diff] [blame] | 471 | |
| 472 | const RecordButtonSize = '50px'; |
| 473 | const RecordButtonOutlineWidth = '1px'; |
| 474 | const RecordButtonOutlineOffset = '4px'; |
| 475 | const RecordButtonInnerSize = |
| 476 | parseInt(RecordButtonSize) - parseInt(RecordButtonOutlineWidth) * 2 - parseInt(RecordButtonOutlineOffset) * 2 + 'px'; |
| 477 | export const RecordButton = styled((props: IconButtonProps) => ( |
| 478 | <IconButton {...props} disableRipple={true}> |
| 479 | <Box |
| 480 | sx={{ |
| 481 | width: RecordButtonInnerSize, |
| 482 | height: RecordButtonInnerSize, |
| 483 | borderRadius: '100%', |
| 484 | outline: `${RecordButtonOutlineWidth} solid #e57f90`, |
| 485 | outlineOffset: RecordButtonOutlineOffset, |
| 486 | backgroundColor: '#e57f90', |
| 487 | '&:hover': { |
| 488 | outlineColor: '#cc0022', |
| 489 | backgroundColor: '#cc0022', |
| 490 | }, |
| 491 | }} |
| 492 | /> |
| 493 | </IconButton> |
| 494 | ))({ |
| 495 | width: RecordButtonSize, |
| 496 | height: RecordButtonSize, |
| 497 | padding: 0, |
| 498 | }); |
| 499 | |
| 500 | export const CornerCloseButton = styled(({ ...props }: IconButtonProps) => ( |
| 501 | <IconButton {...props}> |
| 502 | <SaltireIcon fontSize="inherit" /> |
| 503 | </IconButton> |
| 504 | ))({ |
| 505 | position: 'absolute', |
| 506 | top: '20px', |
| 507 | right: '20px', |
| 508 | zIndex: 200, |
| 509 | color: 'white', |
| 510 | fontSize: '10px', |
| 511 | }); |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 512 | |
| 513 | export const ColoredRoundButton = styled( |
| 514 | ({ |
| 515 | paletteColor, |
| 516 | Icon, |
| 517 | ...props |
| 518 | }: ShapedButtonProps & { |
| 519 | paletteColor?: PaletteColor | ((theme: Theme) => PaletteColor); |
| 520 | }) => { |
| 521 | return ( |
| 522 | <IconButton {...props} disableRipple={true}> |
| 523 | <Icon fontSize="inherit" /> |
| 524 | </IconButton> |
| 525 | ); |
| 526 | } |
| 527 | )(({ theme, paletteColor = theme.palette.primary }) => { |
| 528 | if (typeof paletteColor === 'function') { |
| 529 | paletteColor = paletteColor(theme); |
| 530 | } |
| 531 | |
| 532 | return { |
| 533 | color: paletteColor.contrastText, |
| 534 | backgroundColor: paletteColor.dark, |
| 535 | '&:hover': { |
| 536 | backgroundColor: paletteColor.main, |
| 537 | }, |
| 538 | '&:disabled': { |
| 539 | backgroundColor: theme.palette.action.disabled, |
| 540 | }, |
| 541 | }; |
| 542 | }); |