refactor HeaderBar

This commit is contained in:
Halit Aksoy 2022-07-15 17:45:48 +03:00
parent 1e092d9456
commit b59dbdc5c9

View File

@ -7,8 +7,10 @@ import { getColorByBrightness } from "../util/ColorUtil";
import Button from "./Button"; import Button from "./Button";
import "@szhsin/react-menu/dist/index.css"; import "@szhsin/react-menu/dist/index.css";
import "@szhsin/react-menu/dist/transitions/slide.css"; import "@szhsin/react-menu/dist/transitions/slide.css";
//@ts-ignore import HeaderbarIcon from "./headerbar/HeaderbarIcon";
import MancalaIcon from "jsx:../mancala.svg"; import HeaderbarTitle from "./headerbar/HeaderbarTitle";
import Row from "./Row";
import ThemeSwitchMenu from "./headerbar/ThemeSwitchMenu";
function renderNewGameButton( function renderNewGameButton(
context: Context, context: Context,
@ -54,15 +56,11 @@ const HeaderBar: FunctionComponent<{
); );
return ( return (
<div style={{ background: context.themeManager.theme.appBarBgColor }} className="header-bar"> <div style={{ background: context.themeManager.theme.appBarBgColor }} className="header-bar">
<div className="header-bar-left-panel"> <Row>
<div className="header-bar-icon-wrapper"> <HeaderbarIcon />
<MancalaIcon className="header-bar-icon" style={{ height: "30px", width: "30px" }} /> <HeaderbarTitle title={context.texts.Mancala} color={textColor} />
</div> </Row>
<h1 style={{ color: textColor }} className="header-bar-title"> <Row>
{context.texts.Mancala}
</h1>
</div>
<div className="header-bar-right-panel">
<ThemeSwitchMenu context={context} textColor={textColor} /> <ThemeSwitchMenu context={context} textColor={textColor} />
{renderNewGameButton(context, game, onNewGameClick, userKeyWhoLeave, crashMessage)} {renderNewGameButton(context, game, onNewGameClick, userKeyWhoLeave, crashMessage)}
{game && {game &&
@ -75,7 +73,7 @@ const HeaderBar: FunctionComponent<{
text={context.texts.Leave} text={context.texts.Leave}
onClick={onLeaveGameClick} /> onClick={onLeaveGameClick} />
)} )}
</div> </Row>
<style jsx>{` <style jsx>{`
.header-bar { .header-bar {
padding: 0px 4vw; padding: 0px 4vw;
@ -85,80 +83,7 @@ const HeaderBar: FunctionComponent<{
justify-content: space-between; justify-content: space-between;
align-self: stretch; align-self: stretch;
} }
.header-bar-title { `}</style>
margin: 10px 0px;
}
.header-bar-right-panel {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.header-bar-left-panel {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
}
.header-bar-icon-wrapper {
margin-right: 10px;
display: flex;
flex-direction: row;
align-items: center;
}
`}</style>
</div>) </div>)
} }
export default HeaderBar; export default HeaderBar;
const ThemeSwitchMenu: FunctionComponent<{ context: Context, textColor: string }> = (props) => {
const { context, textColor } = props;
const menuButton = <span
style={{ color: textColor }}
className="material-symbols-outlined">
light_mode
</span>;
const menuItems = context.themeManager.themes.map((theme, index) => {
const themeBackground = context.themeManager.theme.background;
return (
<MenuItem
key={index}
style={{ color: textColor }}
//@ts-ignore
onMouseOver={(event) => (event.target.style.background = themeBackground)}
//@ts-ignore
onMouseOut={(event) => (event.target.style.background = "transparent")}
onClick={() => (context.themeManager.theme = theme)}>
<div style={{ background: theme.boardColor }} className="theme-color-circle" />
{theme.name}
<style jsx>{`
.theme-color-circle {
border-radius: 5vw;
width: 1vw;
height: 1vw;
margin-right: 1vw;
}
`}</style>
</MenuItem>
);
})
return (
<div className="menu-container">
<Menu
menuStyle={{ background: context.themeManager.theme.appBarBgColor }}
menuButton={menuButton}
transition
align="end">
{menuItems}
</Menu>
<style jsx>{`
.menu-container {
margin: 0 1vh;
display: flex;
align-items: center;
}
`}</style>
</div>
);
}