FormElement
The FormElement is a layout component used to arrange a label and its corresponding input field either vertically or horizontally.
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelPosition | "x" | "y" | "y" | The layout direction. y for vertical (default), x for horizontal. |
Usage
Vertical Layout (Default)
By default, FormElement arranges its children in a column.
import { FormElement, Label, Input } from "@kousta-ui/components";
<FormElement labelPosition="y">
<Label>Email Address</Label>
<Input placeholder="you@example.com" />
</FormElement>
Preview
Horizontal Layout
Set labelPosition="x" to arrange the label and input in a row. You may need to set a minWidth on the Label for proper alignment.
<FormElement labelPosition="x">
<Label style={{ minWidth: 120 }}>Email Address</Label>
<Input placeholder="you@example.com" />
</FormElement>
Preview
Styles & customization
FormElement is a layout component and has minimal styling. It applies flexbox properties to its container.
Runtime classes
kui-form-element: The base class applied to thedivcontainer.
CSS Properties
labelPosition="y": appliesflex-direction: columnandalign-items: start.labelPosition="x": appliesflex-direction: rowandalign-items: center.
Types (reference)
import { PropsWithChildren } from "react";
export type LabelPositionBase = "x" | "y";
export type FormElementProps = PropsWithChildren<{
labelPosition?: LabelPositionBase;
}>;