UNPKG

@tsc_tech/medusa-plugin-notification-template

Version:
57 lines (56 loc) 1.62 kB
import { jsx, Fragment, jsxs } from "react/jsx-runtime"; import { Controller } from "react-hook-form"; import React from "react"; import getInputElement from "./getInputElement.js"; import { Label, clx } from "@medusajs/ui"; import ErrorMessage from "./ErrorMessage.js"; const GenerateFormFields = ({ schema, form }) => { return /* @__PURE__ */ jsx(Fragment, { children: Object.entries(schema).map(([key, fields]) => { return /* @__PURE__ */ jsx( Controller, { control: form.control, name: key, rules: fields.validation, render: ({ field }) => { return /* @__PURE__ */ jsxs("div", { children: [ /* @__PURE__ */ jsx(Label, { htmlFor: key, children: /* @__PURE__ */ jsx( "span", { className: clx("mb-2 block font-sans font-medium", { ["sr-only"]: !fields.label }), children: fields.label || field.name } ) }), React.createElement( getInputElement(fields.fieldType), { ...fields.props, ...field, value: field.value || null, onChange: field.onChange, form } ), /* @__PURE__ */ jsx( ErrorMessage, { control: form.control, name: key, rules: fields.validation } ) ] }); } }, key ); }) }); }; export { GenerateFormFields as default };