UNPKG

@vtaits/react-hook-form-schema

Version:

Integration of react-hook-form and @vtaits/form-schema

80 lines (78 loc) 1.74 kB
import { wrapOnChange } from "./chunk-7ZPD7GZF.js"; import { renderError } from "./chunk-XUSORK34.js"; // src/fields/checkbox/checkbox.tsx import { checkbox as checkboxBase } from "@vtaits/form-schema/fields/checkbox"; import { useUI } from "@vtaits/react-form-schema-base-ui"; import { Controller, get } from "react-hook-form"; import { jsx } from "react/jsx-runtime"; function CheckboxComponent({ renderParams: { fieldPath, fieldSchema: { checkboxLabel, disabled, hint, autoFocus, label, onChange = void 0, required } }, formResult, formResult: { control, formState: { errors } } }) { const { renderCheckbox, renderWrapper } = useUI(); const error = renderError(get(errors, fieldPath)); const wrapperParams = { error, hint, label, name: fieldPath, required }; return renderWrapper({ ...wrapperParams, children: /* @__PURE__ */ jsx( Controller, { name: fieldPath, control, render: ({ field }) => { const booleanValue = Boolean(field.value); return renderCheckbox({ children: checkboxLabel, disabled, checked: booleanValue, autoFocus, name: fieldPath, onChange: wrapOnChange( field.onChange, onChange, formResult, booleanValue ), wrapper: wrapperParams }); } } ) }); } var checkbox = { ...checkboxBase, render: (renderParams, formResult) => /* @__PURE__ */ jsx(CheckboxComponent, { renderParams, formResult }) }; export { checkbox }; //# sourceMappingURL=chunk-DQGVXVI7.js.map