Files
silo/web/src/components/items/WhereUsedTab.tsx
Forbes 07c4aa1c28 fix(web): align spacing values to style guide grid (#71)
- Replace 0.3rem padding/margin/gap with 0.25rem (xs)
- Replace 0.2rem margins with 0.25rem (xs)
- Replace 0.1rem padding with 0.15rem (badge spec)
- Replace 0.6rem margins/padding with 0.5rem (sm)
- Fix borderRadius 0.3rem to 0.375rem (6px per style guide)
- Preserve style-guide-specified values: 0.35rem button gap, 0.4rem cell padding, 0.45rem input padding
2026-02-13 14:37:40 -06:00

96 lines
2.4 KiB
TypeScript

import { useState, useEffect } from "react";
import { get } from "../../api/client";
import type { WhereUsedEntry } from "../../api/types";
interface WhereUsedTabProps {
partNumber: string;
}
export function WhereUsedTab({ partNumber }: WhereUsedTabProps) {
const [entries, setEntries] = useState<WhereUsedEntry[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
setLoading(true);
get<WhereUsedEntry[]>(
`/api/items/${encodeURIComponent(partNumber)}/bom/where-used`,
)
.then(setEntries)
.catch(() => setEntries([]))
.finally(() => setLoading(false));
}, [partNumber]);
if (loading)
return (
<div style={{ color: "var(--ctp-subtext0)" }}>Loading where-used...</div>
);
if (entries.length === 0) {
return (
<div style={{ color: "var(--ctp-subtext0)", padding: "1rem" }}>
Not used in any assemblies.
</div>
);
}
return (
<table
style={{
width: "100%",
borderCollapse: "collapse",
fontSize: "var(--font-table)",
}}
>
<thead>
<tr>
<th style={thStyle}>Parent PN</th>
<th style={thStyle}>Description</th>
<th style={thStyle}>Relationship</th>
<th style={thStyle}>QTY</th>
</tr>
</thead>
<tbody>
{entries.map((e, idx) => (
<tr
key={e.id}
style={{
backgroundColor:
idx % 2 === 0 ? "var(--ctp-base)" : "var(--ctp-surface0)",
}}
>
<td
style={{
...tdStyle,
fontFamily: "'JetBrains Mono', monospace",
color: "var(--ctp-peach)",
}}
>
{e.parent_part_number}
</td>
<td style={tdStyle}>{e.parent_description}</td>
<td style={tdStyle}>{e.rel_type}</td>
<td style={tdStyle}>{e.quantity ?? "—"}</td>
</tr>
))}
</tbody>
</table>
);
}
const thStyle: React.CSSProperties = {
padding: "0.25rem 0.5rem",
textAlign: "left",
borderBottom: "1px solid var(--ctp-surface1)",
color: "var(--ctp-subtext1)",
fontWeight: 600,
fontSize: "var(--font-sm)",
textTransform: "uppercase",
letterSpacing: "0.05em",
};
const tdStyle: React.CSSProperties = {
padding: "0.25rem 0.5rem",
borderBottom: "1px solid var(--ctp-surface0)",
whiteSpace: "nowrap",
};