UNPKG

@undermuz/use-form

Version:
73 lines (71 loc) 3.03 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/components/form-submit.tsx var form_submit_exports = {}; __export(form_submit_exports, { EnumFormSubmitStatus: () => EnumFormSubmitStatus, FormSubmit: () => FormSubmit }); module.exports = __toCommonJS(form_submit_exports); var import_ifForm = require("../utils/ifForm.cjs"); var import_common = require("../utils/common.cjs"); var import_useFormSubmit = require("../utils/useFormSubmit.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); var EnumFormSubmitStatus = /* @__PURE__ */ ((EnumFormSubmitStatus2) => { EnumFormSubmitStatus2["Default"] = "default"; EnumFormSubmitStatus2["Succeed"] = "succeed"; EnumFormSubmitStatus2["Canceling"] = "canceling"; EnumFormSubmitStatus2["Sending"] = "sending"; return EnumFormSubmitStatus2; })(EnumFormSubmitStatus || {}); var FormSubmit = (props) => { const { as: Component = "button", children, disableWhenErrors = false, onSend, onSucceed, onError, disabled = false, ...otherProps } = props; const hasErrors = (0, import_common.useIsFormHasErrors)(); const isSending = (0, import_common.useIsFormSending)(); const submit = (0, import_useFormSubmit.useFormSubmit)(onSend, onSucceed, onError); return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( Component, { ...otherProps, disabled: isSending || hasErrors && disableWhenErrors || disabled, type: "submit", onClick: submit, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ifForm.IfForm, { children: children ? children("default" /* Default */) : "Send" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ifForm.IfForm, { isSuccess: true, children: children ? children("succeed" /* Succeed */) : "Succeed" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ifForm.IfForm, { isCanceling: true, children: children ? children("canceling" /* Canceling */) : "Failed" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ifForm.IfForm, { isSending: true, children: children ? children("sending" /* Sending */) : "Sending..." }) ] } ); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { EnumFormSubmitStatus, FormSubmit });