File size: 2,354 Bytes
be54278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
107
108
109
110
111
112
113
114
import { useEffect, useState, type CSSProperties, type ReactNode } from "react";
import { THEME } from "../constants";

const ACTIVITY_BARS = [0, 1, 2, 3, 4];

const GRID_BACKGROUND_STYLE: CSSProperties = {
  backgroundColor: THEME.beigeLight,
  backgroundImage: `
    linear-gradient(${THEME.beigeDark} 1px, transparent 1px),
    linear-gradient(90deg, ${THEME.beigeDark} 1px, transparent 1px)
  `,
  backgroundSize: "40px 40px",
};

export const AppGridBackground = ({
  children,
  className,
  style,
}: {
  children: ReactNode;
  className: string;
  style?: CSSProperties;
}) => (
  <div className={className} style={{ ...GRID_BACKGROUND_STYLE, ...style }}>
    {children}
  </div>
);

export const MicrophoneIcon = ({
  className,
  strokeWidth = 2,
  style,
}: {
  className: string;
  strokeWidth?: number;
  style?: CSSProperties;
}) => (
  <svg
    className={className}
    style={style}
    fill="none"
    viewBox="0 0 24 24"
    stroke="currentColor"
    strokeWidth={strokeWidth}
  >
    <path
      strokeLinecap="round"
      strokeLinejoin="round"
      d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z"
    />
    <path
      strokeLinecap="round"
      strokeLinejoin="round"
      d="M19 10v2a7 7 0 01-14 0v-2"
    />
    <line x1="12" y1="19" x2="12" y2="23" />
    <line x1="8" y1="23" x2="16" y2="23" />
  </svg>
);

export const VoiceMeter = ({
  color,
  active = false,
}: {
  color: string;
  active?: boolean;
}) => (
  <div className="flex items-end justify-center gap-1.5">
    {ACTIVITY_BARS.map((bar) => (
      <span
        key={bar}
        className={`voice-meter-bar${active ? " is-active" : ""}`}
        style={{
          backgroundColor: color,
          animationDelay: `${bar * 120}ms`,
        }}
      />
    ))}
  </div>
);

export const useMountedTransition = () => {
  const [mounted, setMounted] = useState(false);

  useEffect(() => {
    setMounted(true);
  }, []);

  return mounted;
};

export const ErrorMessageBox = ({
  message,
  className,
}: {
  message: string;
  className?: string;
}) => (
  <div
    className={className}
    style={{
      backgroundColor: `${THEME.errorRed}0D`,
      borderColor: `${THEME.errorRed}33`,
    }}
  >
    <p
      className="font-mono text-xs break-words"
      style={{ color: THEME.errorRed }}
    >
      {`> Error: ${message}`}
    </p>
  </div>
);