Added profile component

This commit is contained in:
maciekglowacki 2020-06-10 21:40:33 +02:00
parent 19f75f2253
commit a4ada5fb79
3 changed files with 97 additions and 99 deletions

View File

View File

@ -0,0 +1,27 @@
import { Menu, MenuItem } from "@material-ui/core";
import React, { FC } from "react";
interface ProfileProps {
anchorEl: HTMLElement | null;
handleClose: () => void
}
export const Profile : FC<ProfileProps> = ({anchorEl, handleClose, ...restProps}) => {
return (
<Menu
className="top-bar__menu"
id="simple-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem>Profile</MenuItem>
<MenuItem>My account</MenuItem>
<MenuItem>Logout</MenuItem>
</Menu>
);
};

View File

@ -9,17 +9,17 @@ import User from "./user.png";
import CloseIcon from "./close.svg"; import CloseIcon from "./close.svg";
import Menu from "@material-ui/core/Menu"; import Menu from "@material-ui/core/Menu";
import MenuItem from "@material-ui/core/MenuItem"; import MenuItem from "@material-ui/core/MenuItem";
import { Profile } from "../Profile";
interface TopBarProps { interface TopBarProps {
handleTransfer: (e: React.MouseEvent) => void; handleTransfer: (e: React.MouseEvent) => void;
onLangChange: (lang:boolean) => void; onLangChange: (lang: boolean) => void;
textChangeHandler: (e: React.ChangeEvent<HTMLInputElement>) => void; textChangeHandler: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
} }
interface TopBarState { interface TopBarState {
isOpenProfile: boolean;
anchorEl: HTMLElement | null;
isPolish: boolean; isPolish: boolean;
anchorEl: HTMLElement | null;
} }
export default class TopBar extends React.Component<TopBarProps, TopBarState> { export default class TopBar extends React.Component<TopBarProps, TopBarState> {
@ -30,13 +30,12 @@ export default class TopBar extends React.Component<TopBarProps, TopBarState> {
this.onLangChange = this.onLangChange.bind(this); this.onLangChange = this.onLangChange.bind(this);
this.handleTransfer = this.handleTransfer.bind(this); this.handleTransfer = this.handleTransfer.bind(this);
this.state = { this.state = {
isOpenProfile: false, isPolish: true,
anchorEl:null, anchorEl: null,
isPolish:true,
}; };
} }
handleChange(e: React.ChangeEvent<HTMLInputElement>) { handleChange(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {
this.props.textChangeHandler(e); this.props.textChangeHandler(e);
} }
@ -46,21 +45,20 @@ export default class TopBar extends React.Component<TopBarProps, TopBarState> {
onLangChange(e: React.MouseEvent) { onLangChange(e: React.MouseEvent) {
this.setState({ this.setState({
isPolish:!this.state.isPolish, isPolish: !this.state.isPolish,
}) });
this.props.onLangChange(this.state.isPolish); this.props.onLangChange(this.state.isPolish);
} }
handleProfile(e: React.MouseEvent) { handleProfile(event: React.MouseEvent<HTMLImageElement>) {
this.setState({ this.setState({
isOpenProfile: !this.state.isOpenProfile, anchorEl: event.currentTarget,
anchorEl:e.currentTarget as HTMLElement,
}); });
} }
handleClose(e: React.MouseEvent) { handleClose() {
this.setState({ this.setState({
isOpenProfile: !this.state.isOpenProfile, anchorEl: null,
}); });
} }
@ -68,11 +66,7 @@ export default class TopBar extends React.Component<TopBarProps, TopBarState> {
return ( return (
<div className="top-bar"> <div className="top-bar">
<div className="top-bar__logo"> <div className="top-bar__logo">
<img <img className="top-bar__logo-image" alt="logo" src="https://plannaplan.pl/img/logo.svg" />
className="top-bar__logo-image"
alt="logo"
src="https://plannaplan.pl/img/logo.svg"
/>
<div className="top-bar__tekst"> plan na plan </div> <div className="top-bar__tekst"> plan na plan </div>
</div> </div>
<div className="top-bar__input-div"> <div className="top-bar__input-div">
@ -81,43 +75,20 @@ export default class TopBar extends React.Component<TopBarProps, TopBarState> {
placeholder="Wyszukaj..." placeholder="Wyszukaj..."
inputProps={{ "aria-label": "description" }} inputProps={{ "aria-label": "description" }}
className="top-bar__input-field" className="top-bar__input-field"
onChange={(e) => onChange={(e) => this.handleChange(e)}
this.handleChange(e as ChangeEvent<HTMLInputElement>)
}
/> />
<img className="top-bar__input-icon" alt="close" src={CloseIcon} /> <img className="top-bar__input-icon" alt="close" src={CloseIcon} />
</div> </div>
<div className="top-bar__icon-box"> <div className="top-bar__icon-box">
<img <img className="top-bar__icon" alt="transfer" src={Transfer} onClick={this.handleTransfer} />
className="top-bar__icon"
alt="transfer"
src={Transfer}
onClick={this.handleTransfer}
/>
<img <img
className="top-bar__icon" className="top-bar__icon"
alt="change_language" alt="change_language"
src={this.state.isPolish ? UK : PL} src={this.state.isPolish ? UK : PL}
onClick={this.onLangChange} onClick={this.onLangChange}
/> />
<img <img className="top-bar__icon" alt="profile" src={User} onClick={this.handleProfile} />
className="top-bar__icon" <Profile anchorEl={this.state.anchorEl} handleClose={this.handleClose} />
alt="profile"
src={User}
onClick={this.handleProfile}
/>
<Menu
className="top-bar__menu"
id="simple-menu"
anchorEl={this.state.anchorEl}
keepMounted
open={this.state.isOpenProfile}
onClose={this.handleClose}
>
<MenuItem>Profile</MenuItem>
<MenuItem>My account</MenuItem>
<MenuItem>Logout</MenuItem>
</Menu>
</div> </div>
</div> </div>
); );