Skip to content

Instantly share code, notes, and snippets.

@Daltonic
Last active May 30, 2021 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daltonic/235a9782b394870b5ed27cdaa09cea6a to your computer and use it in GitHub Desktop.
Save Daltonic/235a9782b394870b5ed27cdaa09cea6a to your computer and use it in GitHub Desktop.
Slack clone header component
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 0;
color: white;
background-color: #340e36;
}
.header .MuiSvgIcon-root {
opacity: 0.6;
}
.header__left {
flex: 0.3;
display: flex;
align-items: center;
margin-left: 20px;
}
.header__left > .MuiSvgIcon-root {
margin-left: auto;
margin-right: 20px;
}
.header__middle {
flex: 0.4;
background-color: #421f44;
text-align: center;
display: flex;
padding: 0 50px;
color: gray;
border: 1px solid gray;
border-radius: 6px;
}
.header__middle > input {
background-color: transparent;
border: none;
color: white;
text-align: center;
min-width: 35vw;
}
.header__middle > input:focus {
outline: none;
}
.header__right {
flex: 0.3;
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 20px;
}
.header__right .MuiAvatar-root {
border-radius: 20%;
width: 30px;
height: 30px;
cursor: pointer;
}
import './Header.css'
import { Avatar } from '@material-ui/core'
import AccessTimeIcon from '@material-ui/icons/AccessTime'
import SearchIcon from '@material-ui/icons/Search'
import HelpOutlineIcon from '@material-ui/icons/HelpOutline'
import { useState, useEffect } from 'react'
import { useHistory } from 'react-router-dom'
function Header() {
const history = useHistory()
const [user, setUser] = useState(null)
const moveToAcc = () => {
const user = JSON.parse(localStorage.getItem('user'))
history.push(`/users/${user.uid}`)
}
useEffect(() => {
const data = localStorage.getItem('user')
setUser(JSON.parse(data))
}, [])
return (
<div className="header">
<div className="header__left">
<AccessTimeIcon />
</div>
<div className="header__middle">
<SearchIcon />
<input placeholder="Search tutorial-daltonic" />
</div>
<div className="header__right">
<HelpOutlineIcon />
<Avatar
className="header__avatar"
src={user?.photoURL}
alt={user?.displayName}
onClick={moveToAcc}
/>
</div>
</div>
)
}
export default Header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment