1- import React from 'react'
2- import i18n from 'src/i18n/configs '
3- import { AppBar , Toolbar , Typography , Box } from '@mui/material'
1+ import React , { useState , useMemo } from 'react'
2+ import MenuRoundedIcon from '@mui/icons-material/MenuRounded '
3+ import { AppBar , Toolbar , Box , IconButton } from '@mui/material'
44import { Colors } from 'src/styles/color'
5- import { useTranslation } from 'react-i18next'
65import { Logo } from 'src/components/atoms'
76import { useScrollY , useSize } from 'src/modules/hooks'
7+ import { HeaderMenu } from 'src/components/molecules/HeaderMenu'
8+ import { ModalHeaderMenu } from 'src/components/modals/ModalHeaderMenu'
9+ import { handleChangeLanguage } from 'src/i18n/util'
10+ import { useTranslation } from 'react-i18next'
811
9- const handleChangeLanguage = ( ) => {
10- switch ( i18n . language ) {
11- case 'ja' :
12- i18n . changeLanguage ( 'en' )
13- return
14- case 'en' :
15- i18n . changeLanguage ( 'ja' )
16- return
17- }
18- }
19-
20- interface HeaderItemColors {
12+ export interface HeaderItemColor {
2113 default : string
2214 hover : string
2315 activeBg : string
2416}
2517
26- // TODO: 各ページへのリンクを実装, スマートフォンモード実装
18+ export type HeaderMenuItem = {
19+ href ?: string
20+ label : string
21+ onClick ?: ( ) => void
22+ }
23+
24+ export type HeaderItemBehaviorStyles = {
25+ '&:hover' : {
26+ cursor : string
27+ color : string
28+ }
29+ '&:active' : {
30+ color : string
31+ backgroundColor : string
32+ }
33+ }
34+
2735export const Header = ( ) => {
28- const isScrolled = useScrollY ( ) > 0
29- const headerItemColors : HeaderItemColors = isScrolled
30- ? { default : Colors . text . white , hover : Colors . text . white_hover , activeBg : Colors . header . active . white }
31- : { default : Colors . text . primary , hover : Colors . text . primary_hover , activeBg : Colors . header . active . default }
36+ const [ modalMenuOpen , setModalMenuOpen ] = useState ( false )
3237 const { t } = useTranslation ( )
38+ const isScrolled = useScrollY ( ) > 0
3339 const { isPCOrOver } = useSize ( )
3440 const isLogoDisplayed = isPCOrOver || isScrolled
35- const headerItemBehaviorStyles = {
41+ const headerItemColor : HeaderItemColor = isScrolled
42+ ? { default : Colors . text . white , hover : Colors . text . white_hover , activeBg : Colors . header . active . white }
43+ : { default : Colors . text . primary , hover : Colors . text . primary_hover , activeBg : Colors . header . active . default }
44+ const headerItemBehaviorStyles : HeaderItemBehaviorStyles = {
3645 '&:hover' : {
3746 cursor : 'pointer' ,
38- color : headerItemColors . hover
47+ color : headerItemColor . hover
3948 } ,
4049 '&:active' : {
41- color : headerItemColors . hover ,
42- backgroundColor : headerItemColors . activeBg
50+ color : headerItemColor . hover ,
51+ backgroundColor : headerItemColor . activeBg
4352 }
4453 }
4554
55+ const menuList : HeaderMenuItem [ ] = useMemo ( ( ) => {
56+ return [
57+ { href : '/' , label : 'Home' } ,
58+ { href : '/sessions' , label : 'Sessions' } ,
59+ { href : '/timetable' , label : 'Timetable' } ,
60+ { href : '/floor_guide' , label : 'Floor Guide' } ,
61+ {
62+ label : t ( 'change_language' ) ,
63+ onClick : handleChangeLanguage
64+ }
65+ ]
66+ } , [ t ] )
67+
4668 return (
4769 < AppBar position = "fixed" sx = { { backgroundColor : '#fff0' , height : '100px' , boxShadow : 0 } } >
4870 { /* グラデーション背景 */ }
@@ -62,30 +84,27 @@ export const Header = () => {
6284 < Box >
6385 < Logo
6486 sx = { {
65- width : '233px' ,
66- height : '40px' ,
67- color : headerItemColors . default ,
87+ width : isPCOrOver ? '233px' : '140px ',
88+ height : isPCOrOver ? '40px' : '24px ',
89+ color : headerItemColor . default ,
6890 marginLeft : '12px' ,
6991 borderRadius : '8px' ,
7092 ...headerItemBehaviorStyles
7193 } }
7294 />
7395 </ Box >
7496 ) }
75- < Box sx = { { margin : '0 24px 0 auto' } } >
76- < Typography
77- onClick = { handleChangeLanguage }
78- sx = { {
79- color : headerItemColors . default ,
80- p : '4px 8px' ,
81- borderRadius : '8px' ,
82- ...headerItemBehaviorStyles
83- } }
84- >
85- { t ( 'change_language' ) }
86- </ Typography >
87- </ Box >
97+ { isPCOrOver ? (
98+ < HeaderMenu itemColor = { headerItemColor } menuList = { menuList } itemBehaviorStyles = { headerItemBehaviorStyles } />
99+ ) : (
100+ < Box flex = { 1 } display = "flex" justifyContent = "flex-end" >
101+ < IconButton onClick = { ( ) => setModalMenuOpen ( true ) } >
102+ < MenuRoundedIcon sx = { { fontSize : 24 , color : headerItemColor . default } } />
103+ </ IconButton >
104+ </ Box >
105+ ) }
88106 </ Toolbar >
107+ < ModalHeaderMenu open = { modalMenuOpen } onClose = { ( ) => setModalMenuOpen ( false ) } menuList = { menuList } />
89108 </ AppBar >
90109 )
91110}
0 commit comments