UNPKG

lucid-ui

Version:

A UI component library from Xandr.

156 lines 6.92 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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; }; 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 }); var lodash_1 = __importDefault(require("lodash")); var react_1 = __importDefault(require("react")); var prop_types_1 = __importStar(require("prop-types")); var Validation_1 = __importDefault(require("../Validation/Validation")); var TextField_1 = __importDefault(require("../TextField/TextField")); var TextField_reducers_1 = __importDefault(require("../TextField/TextField.reducers")); var style_helpers_1 = require("../../util/style-helpers"); var component_types_1 = require("../../util/component-types"); var cx = style_helpers_1.lucidClassNames.bind('&-TextFieldValidated'); var any = prop_types_1.default.any, object = prop_types_1.default.object, string = prop_types_1.default.string, bool = prop_types_1.default.bool; var TextFieldValidatedError = function (_props) { return null; }; TextFieldValidatedError.displayName = 'TextFieldValidated.Error'; TextFieldValidatedError.peek = { description: "Content that will be displayed as an error message.", }; TextFieldValidatedError.propName = 'Error'; /** TODO: Remove the nonPassThroughs when the component is converted to a functional component */ var nonPassThroughs = [ 'style', 'className', 'Error', 'Info', 'Success', 'initialState', ]; var TextFieldValidated = /** @class */ (function (_super) { __extends(TextFieldValidated, _super); function TextFieldValidated() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.textFieldRef = react_1.default.createRef(); _this.focus = function () { _this.textFieldRef.current && _this.textFieldRef.current.focus(); }; return _this; } TextFieldValidated.prototype.render = function () { var _a = this.props, className = _a.className, style = _a.style, passThroughs = __rest(_a, ["className", "style"]); var childProps; if (this.props.Error) { childProps = lodash_1.default.map((0, component_types_1.findTypes)(this.props, TextFieldValidated.Error), 'props'); } else if (this.props.Info) { childProps = [this.props.Info]; } else if (this.props.Success && this.props.Success.message) { childProps = [this.props.Success.message]; } var isSuccess = !this.props.Error && !this.props.Info && this.props.Success; return (react_1.default.createElement(Validation_1.default, { className: cx('&', className, { '-info': !this.props.Error && this.props.Info, '-success': !this.props.Error && !this.props.Info && this.props.Success, '-disappearing': isSuccess && this.props.Success && this.props.Success.disappearing, }), style: style, Error: childProps }, react_1.default.createElement(TextField_1.default, __assign({}, lodash_1.default.omit(passThroughs, nonPassThroughs), { ref: this.textFieldRef })))); }; TextFieldValidated.displayName = 'TextFieldValidated'; TextFieldValidated.Error = TextFieldValidatedError; TextFieldValidated.peek = { description: "A composite of `TextField` and `Validation`.", categories: ['controls', 'text'], }; TextFieldValidated.reducers = TextField_reducers_1.default; TextFieldValidated.propTypes = { /** Passed to the root container. */ style: object, /** Passed to the root container. */ className: string, /** Prop alternative to Error child component */ Error: any, /** Optional information text that is styled less aggressively than an error */ Info: string, /** Optional information text that is styled as "success". Also contains `disappearing` prop for message that appears and fades away. */ Success: (0, prop_types_1.shape)({ message: string, disappearing: bool, }), }; TextFieldValidated.defaultProps = TextField_1.default.defaultProps; return TextFieldValidated; }(react_1.default.Component)); exports.default = TextFieldValidated; //# sourceMappingURL=TextFieldValidated.js.map