From 8b22aa8df930661ae6b8026fdddd23fc72552365 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Fri, 2 Sep 2022 09:49:00 -0500 Subject: [PATCH] feat: implement theme toggling --- .../ChatTranscript/ChatTranscript.tsx | 10 ++++- src/components/Message/Message.tsx | 6 +-- src/components/Shell/Shell.tsx | 42 ++++++++++++++----- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/components/ChatTranscript/ChatTranscript.tsx b/src/components/ChatTranscript/ChatTranscript.tsx index 9714b27..ea7be1b 100644 --- a/src/components/ChatTranscript/ChatTranscript.tsx +++ b/src/components/ChatTranscript/ChatTranscript.tsx @@ -40,7 +40,15 @@ export const ChatTranscript = ({ }, [messageLog.length]) return ( - + ({ + display: 'flex', + flexDirection: 'column', + paddingTop: theme.spacing(1), + })} + > {messageLog.map(message => { return ( // This wrapper div is necessary for accurate layout calculations diff --git a/src/components/Message/Message.tsx b/src/components/Message/Message.tsx index fe5b37e..d10caa9 100644 --- a/src/components/Message/Message.tsx +++ b/src/components/Message/Message.tsx @@ -62,9 +62,9 @@ export const Message = ({ message, userId }: MessageProps) => { if (message.authorId === userId) { backgroundColor = isMessageReceived(message) ? 'primary.dark' - : 'primary.main' + : 'primary.light' } else { - backgroundColor = 'grey.700' + backgroundColor = 'secondary.light' } return ( @@ -72,7 +72,6 @@ export const Message = ({ message, userId }: MessageProps) => { { ({ justifyContent: 'flex-end', })) -const darkTheme = createTheme({ - palette: { - mode: 'dark', - }, -}) - export const Shell = ({ children }: ShellProps) => { - const theme = useTheme() const [isAlertShowing, setIsAlertShowing] = useState(false) const [isDrawerOpen, setIsDrawerOpen] = useState(false) const [doShowPeers, setDoShowPeers] = useState(false) @@ -131,6 +125,22 @@ export const Shell = ({ children }: ShellProps) => { [numberOfPeers, setDoShowPeers, setNumberOfPeers, setTitle, showAlert] ) + const [mode, setMode] = useState<'light' | 'dark'>('dark') + + const handleColorModeToggleClick = () => { + setMode(prevMode => (prevMode === 'light' ? 'dark' : 'light')) + } + + const theme = useMemo( + () => + createTheme({ + palette: { + mode, + }, + }), + [mode] + ) + const handleAlertClose = ( _event?: SyntheticEvent | Event, reason?: string @@ -156,7 +166,7 @@ export const Shell = ({ children }: ShellProps) => { return ( - + { + + + + {theme.palette.mode === 'dark' ? ( + + ) : ( + + )} + + + +