david
2 years ago
8 changed files with 204 additions and 97 deletions
@ -1,48 +0,0 @@
|
||||
import { useState } from 'react'; |
||||
import { Box, AppBar, Typography, Toolbar, IconButton } from '@mui/material'; |
||||
import AccountCircle from '@mui/icons-material/AccountCircle'; |
||||
import { UserProfile } from './UserProfile'; |
||||
|
||||
export const Appbar = () => { |
||||
const [showDrawer, setShowDrawer] = useState(false); |
||||
|
||||
const toggleDrawer = () => (event) => { |
||||
if ( |
||||
event.type === 'keydown' && |
||||
(event.key === 'Tab' || event.key === 'Shift') |
||||
) { |
||||
return; |
||||
} |
||||
|
||||
setShowDrawer((showDrawer) => !showDrawer); |
||||
}; |
||||
|
||||
return ( |
||||
<Box> |
||||
<AppBar> |
||||
<Toolbar> |
||||
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}> |
||||
supachat |
||||
</Typography> |
||||
<div> |
||||
<IconButton |
||||
size="large" |
||||
aria-label="account of current user" |
||||
aria-controls="menu-appbar" |
||||
aria-haspopup="true" |
||||
onClick={toggleDrawer()} |
||||
color="inherit" |
||||
> |
||||
<AccountCircle /> |
||||
</IconButton> |
||||
<UserProfile |
||||
toggleDrawer={toggleDrawer} |
||||
showDrawer={showDrawer} |
||||
setShowDrawer={setShowDrawer} |
||||
/> |
||||
</div> |
||||
</Toolbar> |
||||
</AppBar> |
||||
</Box> |
||||
); |
||||
}; |
@ -0,0 +1,39 @@
|
||||
import { Box, Drawer, Toolbar, Divider, Typography } from '@mui/material'; |
||||
|
||||
export function Channels({ drawerWidth, showChannels, setShowChannels }) { |
||||
return ( |
||||
<Box sx={{ display: 'flex' }}> |
||||
<Drawer |
||||
PaperProps={{ |
||||
sx: { |
||||
width: 300, |
||||
}, |
||||
}} |
||||
anchor="left" |
||||
open={showChannels} |
||||
onClose={() => setShowChannels(false)} |
||||
sx={{ |
||||
width: drawerWidth, |
||||
flexShrink: 0, |
||||
'& .MuiDrawer-paper': { |
||||
width: drawerWidth, |
||||
}, |
||||
}} |
||||
variant="persistent" |
||||
> |
||||
<Toolbar variant="dense" sx={{ flexDirection: 'row' }}> |
||||
<Box sx={{ flexGrow: 1 }}> |
||||
<Typography |
||||
variant="subtitle2" |
||||
component="div" |
||||
sx={{ flexGrow: 1, textTransform: 'uppercase' }} |
||||
> |
||||
channels |
||||
</Typography> |
||||
</Box> |
||||
</Toolbar> |
||||
<Divider /> |
||||
</Drawer> |
||||
</Box> |
||||
); |
||||
} |
@ -1,19 +1,120 @@
|
||||
import { Box } from '@mui/material'; |
||||
import { Appbar } from './Appbar'; |
||||
import { useState } from 'react'; |
||||
import { Box, Typography, Toolbar, IconButton } from '@mui/material'; |
||||
import AccountCircle from '@mui/icons-material/AccountCircle'; |
||||
import MenuIcon from '@mui/icons-material/Menu'; |
||||
import { styled } from '@mui/material/styles'; |
||||
import MuiAppBar from '@mui/material/AppBar'; |
||||
import { UserProfile } from './UserProfile'; |
||||
import { Channels } from './Channels'; |
||||
import { Messages } from './Messages'; |
||||
|
||||
export const Home = () => { |
||||
const [showProfile, setShowProfile] = useState(false); |
||||
const [showChannels, setShowChannels] = useState(false); |
||||
|
||||
const toggleProfile = () => (event) => { |
||||
if ( |
||||
event.type === 'keydown' && |
||||
(event.key === 'Tab' || event.key === 'Shift') |
||||
) { |
||||
return; |
||||
} |
||||
|
||||
setShowProfile((showProfile) => !showProfile); |
||||
}; |
||||
|
||||
const toggleChannels = () => (event) => { |
||||
setShowChannels((showChannels) => !showChannels); |
||||
}; |
||||
|
||||
const drawerWidth = 200; |
||||
|
||||
const Main = styled('main', { shouldForwardProp: (prop) => prop !== 'open' })( |
||||
({ theme, open }) => ({ |
||||
flexGrow: 1, |
||||
transition: theme.transitions.create('margin', { |
||||
easing: theme.transitions.easing.sharp, |
||||
duration: theme.transitions.duration.leavingScreen, |
||||
}), |
||||
marginLeft: 0, |
||||
...(open && { |
||||
transition: theme.transitions.create('margin', { |
||||
easing: theme.transitions.easing.easeOut, |
||||
duration: theme.transitions.duration.enteringScreen, |
||||
}), |
||||
marginLeft: drawerWidth, |
||||
}), |
||||
}) |
||||
); |
||||
|
||||
const AppBar = styled(MuiAppBar, { |
||||
shouldForwardProp: (prop) => prop !== 'open', |
||||
})(({ theme, open }) => ({ |
||||
transition: theme.transitions.create(['margin', 'width'], { |
||||
easing: theme.transitions.easing.sharp, |
||||
duration: theme.transitions.duration.leavingScreen, |
||||
}), |
||||
...(open && { |
||||
width: `calc(100% - ${drawerWidth}px)`, |
||||
marginLeft: `${drawerWidth}px`, |
||||
transition: theme.transitions.create(['margin', 'width'], { |
||||
easing: theme.transitions.easing.easeOut, |
||||
duration: theme.transitions.duration.enteringScreen, |
||||
}), |
||||
}), |
||||
})); |
||||
|
||||
const DrawerHeader = styled('div')(({ theme }) => ({ |
||||
...theme.mixins.denseToolbar, |
||||
})); |
||||
|
||||
return ( |
||||
<> |
||||
<Appbar /> |
||||
<Box> |
||||
<br /> |
||||
<br /> |
||||
<br /> |
||||
<br /> |
||||
<br /> |
||||
<Box sx={{ display: 'flex' }}> |
||||
<AppBar position="fixed" open={showChannels}> |
||||
<Toolbar disableGutters variant="dense" sx={{ mx: 1 }}> |
||||
<IconButton |
||||
color="inherit" |
||||
aria-label="open drawer" |
||||
edge="start" |
||||
size="small" |
||||
onClick={toggleChannels()} |
||||
> |
||||
<MenuIcon /> |
||||
</IconButton> |
||||
|
||||
<Typography |
||||
variant="subtitle2" |
||||
component="div" |
||||
sx={{ flexGrow: 1, textTransform: 'uppercase' }} |
||||
> |
||||
supachat |
||||
</Typography> |
||||
<div> |
||||
<IconButton |
||||
color="inherit" |
||||
edge="end" |
||||
size="small" |
||||
aria-label="account of current user" |
||||
aria-controls="menu-appbar" |
||||
aria-haspopup="true" |
||||
onClick={toggleProfile()} |
||||
> |
||||
<AccountCircle /> |
||||
</IconButton> |
||||
</div> |
||||
</Toolbar> |
||||
</AppBar> |
||||
<DrawerHeader /> |
||||
<Main open={showChannels}> |
||||
<DrawerHeader /> |
||||
<Messages /> |
||||
</Box> |
||||
</> |
||||
</Main> |
||||
<Channels |
||||
showChannels={showChannels} |
||||
setShowChannels={setShowChannels} |
||||
drawerWidth={drawerWidth} |
||||
/> |
||||
<UserProfile showProfile={showProfile} setShowProfile={setShowProfile} /> |
||||
</Box> |
||||
); |
||||
}; |
||||
|
Loading…
Reference in new issue