import { useId, type ReactNode } from 'react' import { Tag } from './Tag' import frm from './Form.module.css' /* A form row: label on the left, control on the right. It was written by hand 38 times, and on top of that existed TWICE as a component (in `screens/settings/parts.tsx` and in `screens/dhcp/parts.tsx`, byte-identical apart from one comment) without any of the other twelve screens using either. With the row loose, the pieces around it drifted apart too: the help under a field and the checkbox group were each defined three times. `modal` changes the grid: inside a dialog there is less room and fewer rows, so the label column is narrower and carries no separator. That is the only real difference between the two variants, which is why it is a parameter and not another component. */ export function Row({ label, help, modal = false, dependsOn, children, }: { label: string help?: ReactNode modal?: boolean /* The name of the switch that has this row turned off, if there is one. It is the master-switch signal, and it comes in THREE pieces with none to spare: an **amber edge** on the side (seen without reading), **opacity**, which already comes with the control's own `disabled`, and **a pill that NAMES it**, because "this is off" without saying who turned it off makes you hunt for the switch across the whole screen. Amber and not a padlock: *amber = you can*. A control turned off by its master can be switched on by the user themselves; one turned off by permission cannot. If both applied, **the padlock wins**: what you cannot touch does not need two explanations of why it is off. */ dependsOn?: string /** Receives the `id` to put on the control, so the label governs it. */ children: (id: string) => ReactNode }) { const id = useId() return (
{/* The pill goes OUTSIDE the `
) } /** * A row whose label governs no single control (checkbox and radio groups): * upstream uses a `