Skip to content

Commit

Permalink
feat(media): [closes #157] Improve media button styling (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn authored Sep 12, 2023
1 parent d06bbcf commit 29a20a9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 27 deletions.
49 changes: 49 additions & 0 deletions src/components/Room/MediaButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Fab, { FabProps } from '@mui/material/Fab'
import { forwardRef } from 'react'

interface MediaButtonProps extends Partial<FabProps> {
isActive: boolean
}

export const MediaButton = forwardRef<HTMLButtonElement, MediaButtonProps>(
({ isActive, ...props }: MediaButtonProps, ref) => {
return (
<Fab
{...props}
ref={ref}
sx={theme =>
theme.palette.mode === 'dark'
? isActive
? {
color: theme.palette.common.white,
background: theme.palette.success.main,
'&:hover': {
background: theme.palette.success.dark,
},
}
: {
background: theme.palette.grey[500],
'&:hover': {
background: theme.palette.grey[600],
},
}
: isActive
? {
color: theme.palette.common.white,
background: theme.palette.success.main,
'&:hover': {
background: theme.palette.success.dark,
},
}
: {
color: theme.palette.common.black,
background: theme.palette.grey[400],
'&:hover': {
background: theme.palette.grey[500],
},
}
}
/>
)
}
)
10 changes: 5 additions & 5 deletions src/components/Room/RoomAudioControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import ListItem from '@mui/material/ListItem'
import ListItemText from '@mui/material/ListItemText'
import Menu from '@mui/material/Menu'
import MenuItem from '@mui/material/MenuItem'
import Fab from '@mui/material/Fab'
import Tooltip from '@mui/material/Tooltip'

import { PeerRoom } from 'services/PeerRoom/PeerRoom'

import { useRoomAudio } from './useRoomAudio'
import { MediaButton } from './MediaButton'

export interface RoomAudioControlsProps {
peerRoom: PeerRoom
Expand Down Expand Up @@ -70,13 +70,13 @@ export function RoomAudioControls({ peerRoom }: RoomAudioControlsProps) {
: 'Turn on microphone and speak to room'
}
>
<Fab
color={isSpeakingToRoom ? 'error' : 'success'}
<MediaButton
isActive={isSpeakingToRoom}
aria-label="call"
onClick={handleVoiceCallClick}
>
{isSpeakingToRoom ? <VoiceOverOff /> : <RecordVoiceOver />}
</Fab>
{isSpeakingToRoom ? <RecordVoiceOver /> : <VoiceOverOff />}
</MediaButton>
</Tooltip>
{audioDevices.length > 0 && (
<Box sx={{ mt: 1 }}>
Expand Down
14 changes: 7 additions & 7 deletions src/components/Room/RoomFileUploadControls.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ChangeEventHandler, useContext, useRef } from 'react'
import Box from '@mui/material/Box'
import UploadFile from '@mui/icons-material/UploadFile'
import Cancel from '@mui/icons-material/Cancel'
import Fab from '@mui/material/Fab'
import Folder from '@mui/icons-material/Folder'
import FolderOff from '@mui/icons-material/FolderOff'
import Tooltip from '@mui/material/Tooltip'
import CircularProgress from '@mui/material/CircularProgress'

import { RoomContext } from 'contexts/RoomContext'
import { PeerRoom } from 'services/PeerRoom/PeerRoom'

import { useRoomFileShare } from './useRoomFileShare'
import { MediaButton } from './MediaButton'

export interface RoomFileUploadControlsProps {
onInlineMediaUpload: (files: File[]) => void
Expand Down Expand Up @@ -61,7 +61,7 @@ export function RoomFileUploadControls({

const disableFileUpload = !isFileSharingEnabled || isMessageSending

const buttonIcon = isSharingFile ? <Cancel /> : <UploadFile />
const buttonIcon = isSharingFile ? <Folder /> : <FolderOff />

return (
<Box
Expand All @@ -88,8 +88,8 @@ export function RoomFileUploadControls({
: 'Share files with the room'
}
>
<Fab
color={isSharingFile ? 'error' : 'success'}
<MediaButton
isActive={isSharingFile}
aria-label="share screen"
onClick={handleToggleScreenShareButtonClick}
disabled={disableFileUpload}
Expand All @@ -99,7 +99,7 @@ export function RoomFileUploadControls({
) : (
<CircularProgress variant="indeterminate" color="inherit" />
)}
</Fab>
</MediaButton>
</Tooltip>
</Box>
)
Expand Down
10 changes: 5 additions & 5 deletions src/components/Room/RoomScreenShareControls.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Box from '@mui/material/Box'
import ScreenShare from '@mui/icons-material/ScreenShare'
import StopScreenShare from '@mui/icons-material/StopScreenShare'
import Fab from '@mui/material/Fab'
import Tooltip from '@mui/material/Tooltip'

import { PeerRoom } from 'services/PeerRoom/PeerRoom'

import { useRoomScreenShare } from './useRoomScreenShare'
import { MediaButton } from './MediaButton'

export interface RoomFileUploadControlsProps {
peerRoom: PeerRoom
Expand Down Expand Up @@ -47,13 +47,13 @@ export function RoomScreenShareControls({
isSharingScreen ? 'Stop sharing screen' : 'Share screen with room'
}
>
<Fab
color={isSharingScreen ? 'error' : 'success'}
<MediaButton
isActive={isSharingScreen}
aria-label="share screen"
onClick={handleToggleScreenShareButtonClick}
>
{isSharingScreen ? <StopScreenShare /> : <ScreenShare />}
</Fab>
{isSharingScreen ? <ScreenShare /> : <StopScreenShare />}
</MediaButton>
</Tooltip>
</Box>
)
Expand Down
11 changes: 6 additions & 5 deletions src/components/Room/RoomShowMessagesControls.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useContext } from 'react'

import Fab from '@mui/material/Fab'
import Tooltip from '@mui/material/Tooltip'
import { Comment, CommentsDisabled } from '@mui/icons-material'
import { Badge, Box } from '@mui/material'

import { RoomContext } from 'contexts/RoomContext'

import { MediaButton } from './MediaButton'

export function RoomShowMessagesControls() {
const { isShowingMessages, setIsShowingMessages, unreadMessages } =
useContext(RoomContext)
Expand All @@ -22,15 +23,15 @@ export function RoomShowMessagesControls() {
}}
>
<Tooltip title={isShowingMessages ? 'Hide messages' : 'Show messages'}>
<Fab
color={isShowingMessages ? 'error' : 'success'}
<MediaButton
isActive={isShowingMessages}
aria-label="show messages"
onClick={() => setIsShowingMessages(!isShowingMessages)}
>
<Badge color="error" badgeContent={unreadMessages}>
{isShowingMessages ? <CommentsDisabled /> : <Comment />}
{isShowingMessages ? <Comment /> : <CommentsDisabled />}
</Badge>
</Fab>
</MediaButton>
</Tooltip>
</Box>
)
Expand Down
10 changes: 5 additions & 5 deletions src/components/Room/RoomVideoControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import ListItem from '@mui/material/ListItem'
import ListItemText from '@mui/material/ListItemText'
import Menu from '@mui/material/Menu'
import MenuItem from '@mui/material/MenuItem'
import Fab from '@mui/material/Fab'
import Tooltip from '@mui/material/Tooltip'

import { PeerRoom } from 'services/PeerRoom/PeerRoom'

import { useRoomVideo } from './useRoomVideo'
import { MediaButton } from './MediaButton'

export interface RoomVideoControlsProps {
peerRoom: PeerRoom
Expand Down Expand Up @@ -64,13 +64,13 @@ export function RoomVideoControls({ peerRoom }: RoomVideoControlsProps) {
}}
>
<Tooltip title={isCameraEnabled ? 'Turn off camera' : 'Turn on camera'}>
<Fab
color={isCameraEnabled ? 'error' : 'success'}
<MediaButton
isActive={isCameraEnabled}
aria-label="toggle camera"
onClick={handleEnableCameraClick}
>
{isCameraEnabled ? <VideocamOff /> : <Videocam />}
</Fab>
{isCameraEnabled ? <Videocam /> : <VideocamOff />}
</MediaButton>
</Tooltip>
{videoDevices.length > 0 && (
<Box sx={{ mt: 1 }}>
Expand Down

1 comment on commit 29a20a9

@vercel
Copy link

@vercel vercel bot commented on 29a20a9 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chitchatter – ./

chitchatter-git-main-jeremyckahn.vercel.app
chitchatter.vercel.app
chitchatter-jeremyckahn.vercel.app

Please sign in to comment.