@ducor/react
Version:
admin template ui interface
43 lines (42 loc) • 2.69 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useField } from "../../hook";
import { twMerge } from "tailwind-merge";
import { useFieldName } from "./arrayField";
var Email = function (_a) {
var name = _a.name, placeholder = _a.placeholder, label = _a.label, defaultValue = _a.defaultValue, disabled = _a.disabled, props = __rest(_a, ["name", "placeholder", "label", "defaultValue", "disabled"]);
var _b = useFieldName(name), fieldName = _b.fieldName, _uid = _b._uid;
if (typeof fieldName !== "string") {
return null;
}
var _c = useField(fieldName), value = _c.value, error = _c.error, processing = _c.processing, setValue = _c.setValue;
var onChange = function (e) {
var value = e.target.value;
setValue(fieldName, value);
};
return (_jsxs("div", { className: "mb-4", children: [label ? (_jsx("label", { htmlFor: _uid, className: 'block text-sm font-semibold leading-6 text-gray-600 pb-1', children: label.charAt(0).toUpperCase() + label.slice(1) })) : null, _jsx("input", __assign({ id: _uid, name: fieldName, type: "email", onChange: onChange, className: twMerge("w-full p-2 border border-gray-300 rounded-md resize-none focus:outline-none focus:ring-0 focus:ring-blue-400", disabled ? "bg-gray-100 cursor-not-allowed" : ""),
// type={value === undefined || value.length === 0 ? "email" : "text"}
value: disabled ? defaultValue : value }, props, { disabled: disabled || processing, placeholder: placeholder })), typeof error === "string" ? (_jsx("p", { className: 'text-red-500 text-sm', children: error })) : Array.isArray(error) ? (error.map(function (err, index) { return (_jsx("p", { className: 'text-red-500 text-sm', children: err }, index)); })) : null] }));
};
export default Email;