aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/templates/layout/site-header/site-branding.tsx
blob: 76ab653c6ea14a3b8bd2f36862852aa71582165a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import NextImage from 'next/image';
import {
  type CSSProperties,
  forwardRef,
  type ForwardRefRenderFunction,
  useEffect,
  useRef,
} from 'react';
import { useIntl } from 'react-intl';
import { CONFIG } from '../../../../utils/config';
import { ROUTES } from '../../../../utils/constants';
import { Heading, Logo } from '../../../atoms';
import { Branding, FlippingLogo, type BrandingProps } from '../../../molecules';
import styles from './site-header.module.scss';

const brandingTitleStyles = {
  '--typing-animation': 'blink 0.7s ease-in-out 0s 2, typing 4.3s linear 0s 1',
} as CSSProperties;

const brandingBaselineStyles = {
  '--typing-animation':
    'hide-text 4.25s linear 0s 1, blink 0.8s ease-in-out 4.25s 2, typing 3.8s linear 4.25s 1',
} as CSSProperties;

export type SiteBrandingProps = Omit<
  BrandingProps,
  'baseline' | 'logo' | 'name' | 'url'
> & {
  isHome?: boolean;
};

const SiteBrandingWithRef: ForwardRefRenderFunction<
  HTMLDivElement,
  SiteBrandingProps
> = ({ isHome = false, ...props }, ref) => {
  const intl = useIntl();
  const isFirstRender = useRef(true);
  const photoAltText = intl.formatMessage(
    {
      defaultMessage: '{website} picture',
      description: 'SiteBranding: photo alternative text',
      id: 'dDwm38',
    },
    { website: CONFIG.name }
  );
  const logoTitle = intl.formatMessage(
    {
      defaultMessage: '{website} logo',
      description: 'SiteBranding: logo title',
      id: 'Vrw5/h',
    },
    { website: CONFIG.name }
  );

  useEffect(() => {
    isFirstRender.current = false;
  }, []);

  return (
    <Branding
      {...props}
      baseline={
        <div className={styles.baseline} style={brandingBaselineStyles}>
          {CONFIG.baseline}
        </div>
      }
      logo={
        <FlippingLogo
          back={<Logo heading={logoTitle} />}
          className={styles.logo}
          front={
            <NextImage
              alt={photoAltText}
              height={120}
              // eslint-disable-next-line react/jsx-no-literals
              src="/armand-philippot.jpg"
              width={120}
            />
          }
        />
      }
      name={
        <Heading
          className={styles.title}
          isFake={!isHome}
          level={1}
          style={
            isFirstRender.current ? brandingTitleStyles : { animation: 'none' }
          }
        >
          {CONFIG.name}
        </Heading>
      }
      ref={ref}
      url={ROUTES.HOME}
    />
  );
};

export const SiteBranding = forwardRef(SiteBrandingWithRef);