Blocks / File type mark

File type mark

The square pixel mark of a file's kind, found from its name, and sizes for people.

import { FileTypeMark, fileKindOf, formatBytes, FILE_KINDS } from "@forgeron/ui";
/01 → Default
import { FILE_KINDS, FileTypeMark, type FileKind } from "@forgeron/ui";

export default function Default() {
  return (
    <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
      {(Object.keys(FILE_KINDS) as FileKind[]).map((kind) => (
        <FileTypeMark key={kind} kind={kind} label={FILE_KINDS[kind].label} />
      ))}
    </div>
  );
}
/02 → From names
  • Dock plan.pdfPDF · 240 KB
  • Tariffs 2027.xlsxSpreadsheet · 52 KB
  • Kick-off 2027.pptxPresentation · 3.4 MB
  • Forklift safety.mp4Video · 48 MB
  • deploy.yamlCode · 840 B
// The kind comes from the name; the size is written for people.
import { fileKindOf, FileTypeMark, FILE_KINDS, formatBytes } from "@forgeron/ui";

const files = [
  ["Dock plan.pdf", 240_000],
  ["Tariffs 2027.xlsx", 52_400],
  ["Kick-off 2027.pptx", 3_400_000],
  ["Forklift safety.mp4", 48_000_000],
  ["deploy.yaml", 840],
] as const;

export default function FromNames() {
  return (
    <ul style={{ display: "grid", gap: 8, margin: 0, padding: 0, listStyle: "none", width: 320 }}>
      {files.map(([name, size]) => {
        const kind = fileKindOf(name);
        return (
          <li key={name} style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <FileTypeMark kind={kind} />
            <span style={{ flex: 1 }}>{name}</span>
            <span style={{ color: "var(--ink-dim)", font: "400 11px/16px var(--font-mono)" }}>
              {FILE_KINDS[kind].label} · {formatBytes(size)}
            </span>
          </li>
        );
      })}
    </ul>
  );
}
/03 → Sizes
import { CrownIcon } from "@forgeron/icons";
import { FileTypeMark } from "@forgeron/ui";

// A row, a header and a preview; another icon and colour for a team drive.
export default function Sizes() {
  return (
    <div style={{ display: "flex", alignItems: "center", gap: 16 }}>
      <FileTypeMark kind="sheet" />
      <FileTypeMark kind="sheet" size="lg" />
      <FileTypeMark kind="sheet" size="xl" />
      <FileTypeMark
        kind="folder"
        size="lg"
        icon={CrownIcon}
        tone="var(--accent)"
        label="Direction"
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
kindFileKindfileKindOf(name)folder, pdf, image, sheet, doc, text, slides, video, audio, archive, code, other.
iconIconDefinition—Another icon: a team drive, an app.
tonestring—Another colour, a token.
size"sm" | "lg" | "xl""sm"22px in a row, 40px in a header, 64px unframed on a preview.
labelstring—Names it; decorative otherwise.
classNamestring—Extra classes.