UNPKG

@ducor/react

Version:

admin template ui interface

44 lines (43 loc) 2.96 kB
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 { useState } from "react"; import Button from "../button"; import FieldGroup from "./fieldGroup"; import { useFieldName } from "./arrayField"; var Password = function (_a) { var name = _a.name, placeholder = _a.placeholder, label = _a.label, defaultValue = _a.defaultValue, props = __rest(_a, ["name", "placeholder", "label", "defaultValue"]); var _b = useFieldName(name), fieldName = _b.fieldName, _uid = _b._uid; if (typeof fieldName !== "string") { return null; } var _c = useState("password"), type = _c[0], setType = _c[1]; var _d = useField(fieldName), processing = _d.processing, value = _d.value, setValue = _d.setValue, error = _d.error; var onChange = function (e) { var value = e.target.value; setValue(fieldName, value); }; return (_jsxs(FieldGroup, { 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, _jsxs("div", { className: 'relative', children: [_jsx("input", __assign({ id: _uid, name: fieldName, value: value, onChange: onChange, className: "".concat("w-full", " p-2 border border-gray-300 rounded-md resize-none focus:outline-none focus:ring-0 focus:ring-blue-400"), type: type, disabled: processing, placeholder: placeholder }, props)), _jsx(Button, { variant: 'transparent', className: "absolute right-0 h-full transition duration-200", onClick: function () { return setType(type === "text" ? "password" : "text"); }, children: type === "text" ? (_jsx("i", { className: 'feather-eye text-black' })) : (_jsx("i", { className: 'feather-eye-off text-black' })) })] }), 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 Password;