Skip to content
Snippets Groups Projects
Header.tsx 3.15 KiB
Newer Older
  • Learn to ignore specific revisions
  • import BackArrowIcon from 'assets/icons/ico/back-arrow.svg'
    import FeedbackIcon from 'assets/icons/ico/feedback.svg'
    
    import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { useI18n } from 'cozy-ui/transpiled/react/I18n'
    
    import { ScreenType } from 'enums'
    
    import React, { useCallback, useEffect, useRef } from 'react'
    
    import { useNavigate } from 'react-router-dom'
    
    import { setHeaderHeight } from 'store/global/global.slice'
    
    import { useAppDispatch, useAppSelector } from 'store/hooks'
    
    import { openFeedbackModal } from 'store/modal/modal.slice'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import './header.scss'
    
      /** translation key used as t('key.value') */
    
      desktopTitleKey: string
    
      /** additional information to put below the main header */
    
      backFunction?: () => void
    
    const Header = ({
    
    }: HeaderProps) => {
    
      const navigate = useNavigate()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const header = useRef<HTMLDivElement>(null)
    
      const dispatch = useAppDispatch()
    
      const { screenType, headerHeight } = useAppSelector(
        state => state.ecolyo.global
      )
    
      const cozyBarHeight = 48
    
      const handleClickBack = useCallback(() => {
    
        if (backFunction) {
          backFunction()
        } else {
    
      }, [backFunction, navigate])
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        dispatch(openFeedbackModal(true))
    
        const refHeight = header.current?.clientHeight || 0
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const adjustment = screenType === ScreenType.MOBILE ? cozyBarHeight : 0
    
        const targetHeight = refHeight - adjustment
        if (targetHeight !== headerHeight) {
          dispatch(setHeaderHeight(targetHeight))
        }
      }, [screenType, children, dispatch, headerHeight])
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        <header ref={header}>
    
          <div className="header-top">
            <div className="header-content">
    
              <div className="header-content-top">
                {screenType !== ScreenType.MOBILE && displayBackArrow && (
    
                  <StyledIconButton
                    icon={BackArrowIcon}
                    onClick={handleClickBack}
    
                    aria-label={t('header.accessibility.button_back')}
                    className="header-back-button"
    
                    className={`${
                      displayBackArrow && desktopTitleKey
                        ? 'header-text-selection'
                        : 'header-text-desktop'
                    } ${
    
                      screenType === ScreenType.MOBILE
                        ? 'text-14-normal-uppercase'
                        : 'text-22-bold'
                    }`}
                  >
    
                    <span>{t(desktopTitleKey)}</span>
    
                <StyledIconButton
                  icon={FeedbackIcon}
                  sized={40}
                  onClick={handleClickFeedbacks}
    
                  aria-label={t('header.accessibility.button_open_feedbacks')}
    
                  className="header-feedbacks-button"
    
          <div className="header-bar" />
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        </header>