aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/branding/branding.tsx
blob: bb88a04cad6e4660d98ae07a2a495074b63897cf (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
import {
  type HTMLAttributes,
  type ForwardRefRenderFunction,
  forwardRef,
  type ReactElement,
} from 'react';
import styles from './branding.module.scss';
import { Link } from 'src/components/atoms';

export type BrandingProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
  /**
   * The brand baseline.
   */
  baseline?: ReactElement | null;
  /**
   * The brand logo.
   *
   * The logo size should not exceed ~200px.
   */
  logo: ReactElement;
  /**
   * The brand name.
   */
  name: ReactElement;
  /**
   * The homepage url if you want to wrap the name with a link.
   */
  url?: string;
};

const BrandingWithRef: ForwardRefRenderFunction<
  HTMLDivElement,
  BrandingProps
> = ({ className = '', baseline, logo, name, url, ...props }, ref) => {
  const wrapperClass = `${styles.wrapper} ${className}`;

  return (
    <div {...props} className={wrapperClass} ref={ref}>
      {logo}
      {url ? (
        <Link className={styles.link} href={url}>
          {name}
        </Link>
      ) : (
        name
      )}
      {baseline}
    </div>
  );
};

/**
 * Branding component
 *
 * Render the branding logo, title and optional baseline.
 */
export const Branding = forwardRef(BrandingWithRef);