~james/core

core/ogre/src/components/shared/code-panel.tsx -rw-r--r-- 1.8 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
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
import { Row, Col } from "./layout";
import { CHIP, COLORS, TYPOGRAPHY } from "./constants";

interface CodePanelProps {
  lines: string[];
  maxLines: number;
  height: number;
  fontSize?: number;
}

export function CodePanel({
  lines,
  maxLines,
  height,
  fontSize = 24,
}: CodePanelProps) {
  const shown = lines.slice(0, maxLines);
  const gutter = String(shown.length).length;

  return (
    <div
      style={{
        display: "flex",
        width: "100%",
        height,
        padding: CHIP.border,
        borderRadius: CHIP.radius + 4,
        backgroundColor: COLORS.chip.background,
        backgroundImage: COLORS.chip.stroke,
        boxShadow: COLORS.chip.shadow,
      }}>
      <Col
        style={{
          flexGrow: 1,
          minWidth: 0,
          padding: "18px 24px",
          gap: fontSize * 0.45,
          borderRadius: CHIP.radius + 2,
          backgroundColor: COLORS.chip.background,
          overflow: "hidden",
        }}>
        {shown.map((line, i) => (
          <Row
            key={i}
            style={{ gap: 24, alignItems: "flex-start", overflow: "hidden" }}>
            <span
              style={{
                ...TYPOGRAPHY.body,
                fontSize,
                color: COLORS.textMuted,
                width: gutter * fontSize * 0.62,
                justifyContent: "flex-end",
                display: "flex",
              }}>
              {i + 1}
            </span>
            <span
              style={{
                ...TYPOGRAPHY.body,
                fontSize,
                color: COLORS.text,
                whiteSpace: "pre",
                flex: 1,
                minWidth: 0,
                overflow: "hidden",
              }}>
              {line.length > 0 ? line : " "}
            </span>
          </Row>
        ))}
      </Col>
    </div>
  );
}