useFormLayout
Converts a FormLayout configuration object into a CSS class string and optional inline style for the form grid container.
You probably don’t need this directly. The
<Form />component calls it internally. Use it when building a custom form container that needs the same grid layout.
Signature
import { useFormLayout } from '@saastro/forms';
const { gridClassName, gridStyle } = useFormLayout(layout);
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
layout | FormLayout | No | Layout configuration from config.layout |
Return Value
| Property | Type | Description |
|---|---|---|
gridClassName | string | Tailwind CSS classes for the grid container (e.g. 'grid gap-4 grid-cols-12') |
gridStyle | CSSProperties | Inline styles — carries gridTemplateColumns in auto mode; empty object in manual mode |
How It Works
This is a thin wrapper around getFormGridClass(layout):
- Manual mode: Generates
grid gap-{gap} grid-cols-{columns}classes (columns 1–12, default 1; gap 0–12, default 4 — a gap of0omits the gap class) - Auto mode:
gridClassNameis justgrid gap-{gap}; the column sizing comes from an inlinegrid-template-columns: repeat(auto-fit, minmax({minFieldWidth/16}rem, 1fr))style (minFieldWidthdefaults to 240px → 15rem). Ifcolumnsis also set, the minimum width is clamped withmax(...)and acalc()expression so the grid never exceeds that many columns. - Falls back to
grid grid-cols-1 gap-4whenlayoutis undefined
Example
import { useFormLayout } from '@saastro/forms';
function CustomFormGrid({ config, children }) {
const { gridClassName, gridStyle } = useFormLayout(config.layout);
return (
<div className={gridClassName} style={gridStyle}>
{children}
</div>
);
}
Related
- Layout System — Full guide on manual vs auto layout modes