App patterns
FormSettingsRow
A react-hook-form field in a SettingsRow: label and description at the start, the control at the end, and the field's error message under the control. The control from render gets its id and the aria wiring from the row. Import it from @percentsa/ui/react-hook-form; react-hook-form is an optional peer. Use it inside a SettingsSection. For a Switch or Checkbox, which have their own label, pass group: the row is then a group named by the label and the error is in its description.
import { FormSettingsRow } from "@percentsa/ui/react-hook-form";Examples
Code
export function FormSettingsRowExample() {
const t = useT();
const { control, handleSubmit } = useForm({ defaultValues: { days: 14 as number | null } });
return (
<form noValidate onSubmit={handleSubmit(() => {})} className="w-full">
<SettingsSection title={t("Returns", "المرتجعات")} footer={<Button type="submit">{t("Save", "حفظ")}</Button>}>
<FormSettingsRow
control={control}
name="days"
label={t("Return period (days)", "مهلة إصدار المرتجع (بالأيام)")}
description={t("After this the invoice cannot be returned.", "بعدها لا يمكن إرجاع الفاتورة.")}
required
rules={{ validate: (v) => (v != null && v >= 1 && v <= 365) || t("Enter 1 to 365.", "أدخل من 1 إلى 365.") }}
render={({ field }) => <NumberInput value={field.value} onValueChange={field.onChange} onBlur={field.onBlur} name={field.name} min={1} max={365} />}
/>
</SettingsSection>
</form>
);
}