UNPKG

@eristack/form-ui

Version:

Native React form controls wired to @eristack money, percent, and timestamp

118 lines (113 loc) • 3.49 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/index.ts var index_exports = {}; __export(index_exports, { FormField: () => FormField, MoneyInput: () => MoneyInput, PercentInput: () => PercentInput, TimestampWallInput: () => TimestampWallInput }); module.exports = __toCommonJS(index_exports); // src/form-field.tsx var import_jsx_runtime = require("react/jsx-runtime"); function FormField({ label, hint, error, children }) { return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "erista-form-field", children: [ label ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "erista-form-field__label", children: label }) : null, children, hint ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "erista-form-field__hint", children: hint }) : null, error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "erista-form-field__error", children: error }) : null ] }); } // src/money-input.tsx var import_react = require("@eristack/money/react"); var import_jsx_runtime2 = require("react/jsx-runtime"); function MoneyInput({ amount, currency, onAmountChange, onParsed, round, onBlur, ...rest }) { return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "input", { ...rest, type: "text", inputMode: "decimal", value: amount, "data-currency": currency, onChange: (event) => onAmountChange?.(event.target.value), onBlur: (event) => { onBlur?.(event); const raw = event.target.value; if (raw === "") return; const money = (0, import_react.submitAmountOnlyFormValue)(raw, currency, { round }); const normalized = money.toJSON().amount; onAmountChange?.(normalized); onParsed?.(normalized); } } ); } // src/percent-input.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); function PercentInput({ value, onValueChange, ...rest }) { return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( "input", { ...rest, type: "text", inputMode: "decimal", value, onChange: (event) => onValueChange?.(event.target.value) } ); } // src/timestamp-wall-input.tsx var import_jsx_runtime4 = require("react/jsx-runtime"); function TimestampWallInput({ value, onValueChange, ...rest }) { return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( "input", { ...rest, type: "date", value, onChange: (event) => onValueChange?.(event.target.value) } ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { FormField, MoneyInput, PercentInput, TimestampWallInput }); //# sourceMappingURL=index.cjs.map