FormRow Component
The <FormRow> component is designed to structure form elements within a row layout. It adapts its layout based on screen size.
Basic Usage
The component arranges its children in a row, with responsive gap behavior.
- Basic
- One Item Only
import { FormRow, InputField } from "react-better-html";
function App() {
return (
<FormRow>
<InputField label="First Name" />
<InputField label="Last Name" />
</FormRow>
);
}
import { FormRow, InputField } from "react-better-html";
function App() {
return (
<FormRow oneItemOnly>
<InputField label="Full Name" />
</FormRow>
);
}
The component is responsive and will render on two lines if in mobile mode.
Common Props
oneItemOnly- renders an empty element after the children so a single field takes only half of the rownoBreakingPoint- keeps the items on the same line on mobileasColumn- always renders the items one under anothergap- the gap between the items
Subcomponents
A number of components in the library have a subcomponent feature witch is like a preset of the same component that is frequently used.
FormRow.withTitle
Renders a form row with an optional icon, title, and description at the beginning of the row, followed by the one element inside. It is mostly used for settings pages.
import { FormRow, InputField } from "react-better-html";
function App() {
return (
<FormRow.withTitle icon="user" title="Personal Information" description="Enter your personal details">
<InputField label="Full Name" />
</FormRow.withTitle>
);
}
icon- an icon rendered before the titletitle/titleAs/titleFontSize- the title and its tag (defaults toh3)description/descriptionFontSize- the text underneath the titlerequired- renders a red asterisk after the titlealignChildren- thejustify-contentof the children (defaults toflex-start)isLoading- renders a loader before the children
The component has the option to render save and clear buttons if the value is changed. You can pass withActions prop that will render the save button. To capture the events onClickSave and onClickReset props can be passed. The onClickReset will render clear button.
import { FormRow, InputField } from "react-better-html";
function App() {
return (
<FormRow.withTitle
icon="user"
title="Personal Information"
description="Enter your personal details"
withActions
onClickSave={() => {
console.log("Save button clicked");
}}
>
<InputField label="Full Name" />
</FormRow.withTitle>
);
}
The buttons are submit and button types by default. This can be changed with saveButtonType and resetButtonType. Loading state can be shown on them with saveButtonLoaderName and resetButtonLoaderName.