aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/components/LineIcon.tsx
blob: fc408249ac815a24fdaf1c40e60ae75d7b71234c (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
import React, { useMemo } from "react";
import "./LineIcon.css";

interface LineIconProps {
  line: string;
  mode?: "rounded" | "pill" | "default";
}

const LineIcon: React.FC<LineIconProps> = ({
  line,
  mode = "default",
}) => {
  const actualLine = useMemo(() => {
    return line.trim().replace('510', 'NAD');
  }, [line])

  const formattedLine = useMemo(() => {
    return /^[a-zA-Z]/.test(actualLine) ? actualLine : `L${actualLine}`;
  }, [actualLine]);

  const cssVarName = `--line-${formattedLine.toLowerCase()}`;
  const cssTextVarName = `--line-${formattedLine.toLowerCase()}-text`;

  return (
    <span
      className={`line-icon-${mode}`}
      style={
        {
          "--line-colour": `var(${cssVarName})`,
          "--line-text-colour": `var(${cssTextVarName}, #000000)`,
        } as React.CSSProperties
      }
    >
      {actualLine}
    </span>
  );
};

export default LineIcon;