/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ /** * Quantity set display component for IFC element quantities. */ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { decodeIfcString } from './encodingUtils'; import type { QuantitySet } from './encodingUtils'; /** Maps quantity type to friendly name for tooltip */ const QUANTITY_TYPE_NAMES: Record = { 0: 'Length', 1: 'Area', 2: 'Volume', 3: 'Count', 4: 'Weight', 5: 'Time', }; export function QuantitySetCard({ qset }: { qset: QuantitySet }) { const formatValue = (value: number, type: number): string => { if (isNaN(value)) return '\u2014'; // em-dash for empty values const formatted = value.toLocaleString(undefined, { maximumFractionDigits: 3 }); switch (type) { case 0: return `${formatted} m`; case 1: return `${formatted} m\u00B2`; case 2: return `${formatted} m\u00B3`; case 3: return formatted; case 4: return `${formatted} kg`; case 5: return `${formatted} s`; default: return formatted; } }; return ( {decodeIfcString(qset.name)} {qset.quantities.length}
{qset.quantities.map((q: { name: string; value: number; type: number }, index: number) => { const decodedName = decodeIfcString(q.name); const typeName = QUANTITY_TYPE_NAMES[q.type]; return (
{/* Quantity name with type tooltip */} {typeName ? ( {decodedName} {/* bg-primary tooltip: derive from primary-foreground so it reads on the blue/purple surface and in dark mode (#1218) */} {typeName} ) : ( {decodedName} )} {/* Quantity value */} {formatValue(q.value, q.type)}
); })}
); }