UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

39 lines 2.31 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 * as React from 'react'; import { isRequired } from "../form/validation/validate.js"; import { ValidationError } from "../form/validation/ValidationError.js"; import { useInput } from "../form/useInput.js"; import { FieldTitle } from "../util/FieldTitle.js"; export var TextInput = function (_a) { var multiline = _a.multiline, _b = _a.type, type = _b === void 0 ? 'text' : _b, props = __rest(_a, ["multiline", "type"]); var _c = useInput(props), id = _c.id, field = _c.field, _d = _c.fieldState, error = _d.error, invalid = _d.invalid; return (React.createElement("div", null, React.createElement("label", { htmlFor: id }, React.createElement(FieldTitle, { label: props.label, source: props.source, resource: props.resource, isRequired: isRequired(props.validate) })), React.createElement("br", null), multiline ? (React.createElement("textarea", __assign({ id: id }, field, { "aria-describedby": invalid ? "error-".concat(id) : undefined }))) : (React.createElement("input", __assign({ id: id }, field, { type: type, "aria-describedby": invalid ? "error-".concat(id) : undefined }))), invalid && (error === null || error === void 0 ? void 0 : error.message) ? (React.createElement("p", { style: { color: 'red' }, id: "error-".concat(id) }, React.createElement(ValidationError, { error: error.message }))) : null)); }; //# sourceMappingURL=TextInput.js.map