import { Children, useLayoutEffect, useRef, useState } from 'react'
import { cx } from '../internal/cx.js'
/**
* A row of fields that wraps (2026-11-21): each field keeps its least width (`min`) and the ones
* that don't fit go to a second line, in columns that line up from row to row. While a row is
* wrapped it is framed and (with `shade`, every other row) tinted, so its two lines read as one
* set; a row that fits on one line looks like any other row.
*
* … (alternate rows)
*/
export function FieldRow({ min = '10.5rem', shade = false, className, style, children, ...rest }) {
const ref = useRef(null)
const [wrapped, setWrapped] = useState(false)
const count = Children.count(children)
useLayoutEffect(() => {
const el = ref.current
if (!el) return undefined
const check = () => {
const kids = [...el.children].filter(k => k.offsetParent !== null || k.getClientRects().length)
setWrapped(kids.length > 1 && kids.some(k => k.offsetTop > kids[0].offsetTop + 2))
}
check()
const ro = new ResizeObserver(check)
ro.observe(el)
return () => ro.disconnect()
}, [count])
return (
{children}
)
}