aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Branding/Branding.tsx
blob: 5c76fd26fe01a1b4935625003122f090e8fa8bfc (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
101
102
103
104
105
106
import photo from '@assets/images/armand-philippot.jpg';
import { settings } from '@utils/config';
import Image from 'next/image';
import Link from 'next/link';
import { useRouter } from 'next/router';
import Script from 'next/script';
import { ReactElement, useEffect, useRef } from 'react';
import { useIntl } from 'react-intl';
import { Person, WithContext } from 'schema-dts';
import styles from './Branding.module.scss';
import Logo from './Logo/Logo';

type BrandingReturn = ({ isHome }: { isHome: boolean }) => ReactElement;

const Branding: BrandingReturn = ({ isHome = false }) => {
  const intl = useIntl();
  const { locale } = useRouter();
  const TitleTag = isHome ? 'h1' : 'p';
  const logoRef = useRef<HTMLDivElement>(null);
  const titleRef = useRef<HTMLHeadingElement | HTMLParagraphElement>(null);
  const jobRef = useRef<HTMLParagraphElement>(null);

  useEffect(() => {
    if (logoRef.current) {
      logoRef.current.style.setProperty(
        '--branding-logo-animation',
        'flip-logo 9s ease-in 0s 1'
      );
    }
  }, []);

  useEffect(() => {
    if (titleRef.current) {
      titleRef.current.style.setProperty(
        '--branding-name-animation',
        'blink 0.8s ease-in-out 0s 2, typing 4.3s linear 0s 1'
      );
    }
  }, []);

  useEffect(() => {
    if (jobRef.current) {
      jobRef.current.style.setProperty(
        '--branding-job-animation',
        'hide-text 4.25s linear 0s 1, blink 0.8s ease-in-out 4.25s 2, typing 3.8s linear 4.25s 1'
      );
    }
  }, []);

  const schemaJsonLd: WithContext<Person> = {
    '@context': 'https://schema.org',
    '@type': 'Person',
    '@id': `${settings.url}/#branding`,
    name: settings.name,
    url: settings.url,
    jobTitle: locale?.startsWith('en')
      ? settings.baseline.en
      : settings.baseline.fr,
    image: photo.src,
    subjectOf: { '@id': `${settings.url}` },
  };

  return (
    <>
      <Script
        id="schema-branding"
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}
      />
      <div id="branding" className={styles.wrapper}>
        <div className={styles.logo} ref={logoRef}>
          <div className={styles.logo__front}>
            <Image
              src={photo}
              alt={intl.formatMessage(
                {
                  defaultMessage: '{brandingName} picture',
                  description: 'Branding: branding name picture.',
                },
                {
                  brandingName: settings.name,
                }
              )}
              layout="responsive"
            />
          </div>
          <div className={styles.logo__back}>
            <Logo />
          </div>
        </div>
        <TitleTag ref={titleRef} className={styles.name}>
          <Link href="/">
            <a className={styles.link}>{settings.name}</a>
          </Link>
        </TitleTag>
        <p ref={jobRef} className={styles.job}>
          {locale?.startsWith('en')
            ? settings.baseline.en
            : settings.baseline.fr}
        </p>
      </div>
    </>
  );
};

export default Branding;