UNPKG

@eccenca/gui-elements

Version:

GUI elements based on other libraries, usable in React application, written in Typescript.

75 lines 3.66 kB
"use strict"; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextFieldReplacement = TextFieldReplacement; const react_1 = __importDefault(require("react")); const index_1 = require("./../../index"); const extendedOnChange = (onChangeFn, event) => { if (typeof onChangeFn === "function") { onChangeFn({ event, name: event.target.name, value: event.target.value, rawValue: event.target.value, }); } }; /** @deprecated (v25) all legacy component support will be removed, switch to `<TextField />`, `<TextArea />`, `<FieldItem />` */ function TextFieldReplacement(_a) { var { className, disabled = false, error, inputClassName, label, multiline = false, onChange, onClearValue, // reducedSize = false, required = false, stretch = true, value } = _a, otherProps = __rest(_a, ["className", "disabled", "error", "inputClassName", "label", "multiline", "onChange", "onClearValue", "required", "stretch", "value"]); if (process.env.NODE_ENV === "development") { const debugMsg = [ "This textfield element is a adhoc replacement for a legacy element. Usage is deprecated, please use a standard elements (FieldItem, TextField, TextArea).", ]; if (typeof otherProps.reducedSize !== "undefined") { debugMsg.push("TextField 'reducedSize' property is currently not supported on legacy replacement element."); delete otherProps.reducedSize; } // eslint-disable-next-line no-console debugMsg.forEach((element) => console.debug(element)); } if (typeof otherProps.reducedSize !== "undefined") { delete otherProps.reducedSize; } const InputElement = multiline ? index_1.TextArea : index_1.TextField; const fieldProperties = { className: className, messageText: error, labelProps: label ? { text: label } : {}, }; const inputProperties = { className: inputClassName, fullWidth: stretch, value: value, required: required, onChange: extendedOnChange.bind(null, onChange), }; if (multiline) { delete inputProperties.fullWidth; } if (multiline === false && !!onClearValue && !!value) { inputProperties["rightElement"] = (react_1.default.createElement(index_1.IconButton, { "data-test-id": otherProps["data-test-id"] && `${otherProps["data-test-id"]}-clear-btn`, name: "operation-clear", onClick: onClearValue })); } const sharedProperties = { hasStateDanger: error ? true : false, disabled: disabled, }; return !!error || !!label ? (react_1.default.createElement(index_1.FieldItem, Object.assign({}, sharedProperties, fieldProperties), react_1.default.createElement(InputElement, Object.assign({}, otherProps, sharedProperties, inputProperties)))) : (react_1.default.createElement(InputElement, Object.assign({}, otherProps, inputProperties))); } //# sourceMappingURL=TextField.js.map