import React from "react"; import Heading from "@theme/Heading"; import { HardwareMetadata } from "../hardware-metadata"; import { groupedMetadata, InterconnectDetails } from "./hardware-utils"; interface HardwareListProps { items: HardwareMetadata[]; } type ElementOrString = JSX.Element | string; function itemHasMultiple(item: HardwareMetadata) { return ( (item.type == "board" || item.type == "shield") && (item.siblings?.length ?? 1) > 1 ); } function itemIds(item: HardwareMetadata) { if (item.type == "board" || item.type == "shield") { let nodes = (item.siblings ?? [item.id]) .map((id) => {id}) .reduce( (prev, curr, index) => [...prev, index > 0 ? ", " : "", curr], [] as ElementOrString[] ); return {nodes}; } else { return {item.id}; } } const TYPE_LABELS: Record< HardwareMetadata["type"], Record<"singular" | "plural", string> > = { board: { plural: "Boards: ", singular: "Board: " }, shield: { singular: "Shield: ", plural: "Shields: " }, interconnect: { singular: "Interconnect: ", plural: "Interconnects: " }, }; function HardwareLineItem({ item }: { item: HardwareMetadata }) { return (
  • {item.name} ( {TYPE_LABELS[item.type][itemHasMultiple(item) ? "plural" : "singular"]}{" "} {itemIds(item)})
  • ); } function mapInterconnect({ interconnect, boards, shields, }: InterconnectDetails) { if (!interconnect) { return null; } return (
    {interconnect.name} Interconnect {interconnect.description &&

    {interconnect.description}

    } Boards Shields
    ); } function HardwareList({ items }: HardwareListProps) { let grouped = groupedMetadata(items); return ( <>
    Onboard Controller Keyboards

    Keyboards with onboard controllers are single PCBs that contain all the components of a keyboard, including the controller chip, switch footprints, etc.

    Composite Keyboards

    Composite keyboards are composed of two main PCBs: a small controller board with exposed pads, and a larger keyboard PCB (a shield, in ZMK lingo) with switch footprints and a location where the controller is added. This location is called an interconnect. Multiple interconnects can be found below.

    {Object.values(grouped.interconnects).map(mapInterconnect)}
    ); } export default HardwareList;