@ducor/react
Version:
admin template ui interface
37 lines (36 loc) • 2.43 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";
var Input = function (_a) {
var name = _a.name, _b = _a.type, type = _b === void 0 ? "text" : _b, placeholder = _a.placeholder, label = _a.label, disabled = _a.disabled, defaultValue = _a.defaultValue, props = __rest(_a, ["name", "type", "placeholder", "label", "disabled", "defaultValue"]);
var _c = useField(name), id = _c.id, absolateName = _c.absolateName, value = _c.value, setValue = _c.setValue, error = _c.error, processing = _c.processing;
var onChange = function (e) {
var value = e.target.value;
if (value) {
setValue(absolateName, value);
}
};
return (_jsxs("div", { className: "mb-4", children: [label ? (_jsx("label", { htmlFor: id, 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: id, type: type, name: absolateName, value: disabled ? defaultValue : value, className: "".concat("w-full", " p-2 border border-gray-300 rounded-md resize-none focus:outline-none focus:ring-0 focus:ring-blue-400"), onChange: onChange }, props, { 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 Input;