Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

3.2 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import type { HTMLAttributes, TdHTMLAttributes, ThHTMLAttributes } from "react";
import { forwardRef } from "react";

import { cn } from "./utils/cn";

const Table = forwardRef<
  HTMLTableElement,
  HTMLAttributes<HTMLTableElement> & { full?: boolean }
>(({ className, full = false, ...props }, ref) =>
  full ? (
    <div className="w-full">
      <table
        ref={ref}
        className={cn("w-full caption-bottom text-sm", className)}
        {...props}
      />
    </div>
  ) : (
    <div className="rounded-md w-full overflow-hidden">
      <div className="relative w-full overflow-auto max-md:scroll-fade-x">
        <table
          ref={ref}
          className={cn("w-full caption-bottom text-sm", className)}
          {...props}
        />
      </div>
    </div>
  )
);
Table.displayName = "Table";

const Thead = forwardRef<
  HTMLTableSectionElement,
  HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
  <thead
    ref={ref}
    className={cn("bg-transparent [&_tr]:border-b border-border", className)}
    {...props}
  />
));
Thead.displayName = "Thead";

const Tbody = forwardRef<
  HTMLTableSectionElement,
  HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
  <tbody ref={ref} className={cn("", className)} {...props} />
));
Tbody.displayName = "Tbody";

const Tfoot = forwardRef<
  HTMLTableSectionElement,
  HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
  <tfoot
    ref={ref}
    className={cn("font-medium text-foreground", className)}
    {...props}
  />
));
Tfoot.displayName = "Tfoot";

const Tr = forwardRef<HTMLTableRowElement, HTMLAttributes<HTMLTableRowElement>>(
  ({ className, ...props }, ref) => (
    <tr
      ref={ref}
      className={cn(
        "group transition-colors data-[state=selected]:bg-muted",
        className
      )}
      {...props}
    />
  )
);
Tr.displayName = "Tr";

const Th = forwardRef<
  HTMLTableCellElement,
  ThHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
  <th
    ref={ref}
    className={cn(
      "group-hover:bg-muted h-11 px-6 text-left align-middle text-foreground/80 bg-transparent font-medium text-sm [&:has([role=checkbox])]:pr-0",
      className
    )}
    {...props}
  />
));
Th.displayName = "Th";

const Td = forwardRef<
  HTMLTableCellElement,
  TdHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
  <td
    ref={ref}
    className={cn(
      "group-hover:bg-muted text-foreground/80 px-6 bg-transparent align-middle [&:has([role=checkbox])]:pr-0 h-11",
      className
    )}
    {...props}
  />
));
Td.displayName = "Td";

const TableCaption = forwardRef<
  HTMLTableCaptionElement,
  HTMLAttributes<HTMLTableCaptionElement>
>(({ className, ...props }, ref) => (
  <caption
    ref={ref}
    className={cn("mt-4 text-sm text-muted-foreground", className)}
    {...props}
  />
));
TableCaption.displayName = "TableCaption";

export { Table, TableCaption, Tbody, Td, Tfoot, Th, Thead, Tr };