All files / src/packlets/toolbar index.tsx

0% Statements 0/10
0% Branches 0/6
0% Functions 0/9
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182                                                                                                                                                                                                                                                                                                                                                                           
/**
 * @packageDocumentation
 *
 * Ribbon-style toolbar components for the editor. Provides `Toolbar`,
 * `ToolbarGroup`, `ToolbarButton`, `ToolbarDropdown`, `ToolbarDivider`,
 * and `TransportDisplay`.
 */
 
import { Box, Flex, Text, DropdownMenu, Button, Separator, Card } from "@radix-ui/themes";
import { ChevronDown } from "lucide-react";
import type { ReactNode } from "react";
 
interface ToolbarProps {
  children: ReactNode;
}
 
export function Toolbar({ children }: ToolbarProps) {
  return (
    <Box
      style={{
        borderBottom: "1px solid var(--gray-5)",
        padding: "8px 12px",
        flexShrink: 0,
      }}
    >
      <Flex align="center" gap="0">
        {children}
      </Flex>
    </Box>
  );
}
 
interface ToolbarGroupProps {
  label: string;
  children: ReactNode;
}
 
export function ToolbarGroup({ label, children }: ToolbarGroupProps) {
  return (
    <Flex direction="column" align="center" gap="1" px="3">
      <Flex align="center" gap="1" style={{ height: 32 }}>
        {children}
      </Flex>
      <Text size="1" color="gray" weight="medium" style={{ opacity: 0.5, fontSize: 10 }}>
        {label}
      </Text>
    </Flex>
  );
}
 
export function ToolbarDivider() {
  return <Separator orientation="vertical" style={{ margin: "0 4px" }} />;
}
 
interface ToolbarButtonProps {
  icon: ReactNode;
  label?: string;
  active?: boolean;
  onClick?: () => void;
}
 
export function ToolbarButton({ icon, label, active, onClick }: ToolbarButtonProps) {
  return (
    <Button
      variant="surface"
      size="1"
      color="gray"
      title={label}
      onClick={onClick}
      style={{
        width: 32,
        height: 32,
        padding: 0,
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        background: active ? "var(--accent-5)" : undefined,
        color: active ? "var(--accent-11)" : undefined,
      }}
    >
      {icon}
    </Button>
  );
}
 
interface DropdownSelectProps {
  value: string;
  options: string[];
  onSelect?: (value: string) => void;
  testId?: string;
}
 
export function ToolbarDropdown({ value, options, onSelect, testId }: DropdownSelectProps) {
  return (
    <DropdownMenu.Root>
      <DropdownMenu.Trigger>
        <Box
          data-testid={testId}
          style={{
            display: "flex",
            alignItems: "center",
            gap: 2,
            minWidth: 56,
            height: 32,
            borderRadius: 4,
            background: "var(--gray-3)",
            color: "var(--gray-11)",
            cursor: "pointer",
            padding: "0 8px",
          }}
        >
          <Text size="2" weight="bold" style={{ fontFamily: "monospace" }}>
            {value}
          </Text>
          <ChevronDown size={12} />
        </Box>
      </DropdownMenu.Trigger>
      <DropdownMenu.Content>
        {options.map((option) => (
          <DropdownMenu.Item key={option} onSelect={() => onSelect?.(option)}>
            {option}
          </DropdownMenu.Item>
        ))}
      </DropdownMenu.Content>
    </DropdownMenu.Root>
  );
}
 
interface TransportDisplayProps {
  time: string;
  pulse: string;
  measure: string;
}
 
export function TransportDisplay({ time, pulse, measure }: TransportDisplayProps) {
  const items = [
    { label: "TIME", value: time, width: 96 },
    { label: "PULSE", value: pulse, width: 64 },
    { label: "MEASURE", value: measure, width: 64 },
  ];
 
  return (
    <Card size="1" style={{ height: 32, padding: 0, overflow: "hidden" }}>
      <Flex style={{ height: "100%" }}>
        {items.map((item, i) => (
          <Flex
            key={item.label}
            direction="column"
            align="center"
            justify="center"
            style={{
              height: 32,
              padding: "0 4px",
              width: item.width,
              flexShrink: 0,
              borderRight: i < items.length - 1 ? "1px solid var(--gray-5)" : "none",
            }}
          >
            <Text size="1" color="gray" style={{ lineHeight: 1, opacity: 0.6, fontSize: 8 }}>
              {item.label}
            </Text>
            <Text
              size="2"
              weight="bold"
              style={{
                fontFamily: "monospace",
                lineHeight: 1,
                width: "100%",
                textAlign: "center",
                overflow: "hidden",
                whiteSpace: "nowrap",
              }}
            >
              {item.value}
            </Text>
          </Flex>
        ))}
      </Flex>
    </Card>
  );
}