@conductionnl/nl-design-system
Version:
NL design system components created by Conduction
69 lines (68 loc) • 3.73 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenericInputComponent = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var _ = __importStar(require("lodash"));
require("../../style/genericInput.css");
var InfoTooltip_1 = require("../../InfoTooltip/InfoTooltip");
/**
* This component generates a input element with the specified type.
*
* @returns Jsx of the generated form.
*/
var GenericInputComponent = function (_a) {
var id = _a.id, data = _a.data, type = _a.type, name = _a.name, nameOverride = _a.nameOverride, required = _a.required, minLength = _a.minLength, maxLength = _a.maxLength, disabled = _a.disabled, togglePassword = _a.togglePassword, eyeLeft = _a.eyeLeft, eyeTop = _a.eyeTop, infoTooltip = _a.infoTooltip;
var handleTogglePassword = function (e) {
e.target.classList.toggle("fa-eye");
e.target.classList.toggle("fa-eye-slash");
var input = document.getElementById(id);
if (input.type === "password") {
input.type = "text";
}
else {
input.type = "password";
}
};
return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: "input-group" }, { children: [(0, jsx_runtime_1.jsxs)("label", __assign({ htmlFor: id, className: "utrecht-form-label" }, { children: [_.upperFirst(nameOverride !== null && nameOverride !== void 0 ? nameOverride : name), required && " *", infoTooltip && ((0, jsx_runtime_1.jsx)(InfoTooltip_1.InfoTooltip, { content: infoTooltip.content, placement: infoTooltip.placement, layoutClassName: "genericInput-tooltip" }, void 0))] }), void 0), (0, jsx_runtime_1.jsx)("input", { className: "utrecht-textbox utrecht-textbox--html-input", name: name, id: id, defaultValue: data === null ? undefined : data, type: type, required: required, minLength: minLength === null ? undefined : minLength, maxLength: maxLength === null ? undefined : maxLength, disabled: disabled }, void 0), togglePassword === true && ((0, jsx_runtime_1.jsx)("i", { className: "fas fa-eye-slash", id: "togglePassword", style: { cursor: "pointer", position: "relative", left: eyeLeft, top: eyeTop }, onClick: handleTogglePassword }, void 0))] }), void 0));
};
exports.GenericInputComponent = GenericInputComponent;
exports.GenericInputComponent.defaultProps = {
data: undefined,
disabled: false,
required: false,
minLength: null,
maxLength: null,
togglePassword: false,
eyeLeft: "92%",
eyeTop: "-27px",
};