lucid-ui
Version:
A UI component library from AppNexus.
75 lines • 4.81 kB
JavaScript
"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Validation = void 0;
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("react-peek/prop-types"));
var style_helpers_1 = require("../../util/style-helpers");
var component_types_1 = require("../../util/component-types");
var lodash_1 = __importDefault(require("lodash"));
var cx = style_helpers_1.lucidClassNames.bind('&-Validation');
var string = prop_types_1.default.string, any = prop_types_1.default.any;
var ValidationError = function (_props) { return null; };
ValidationError.displayName = 'Validation.Error';
ValidationError.peek = {
description: "\n\t\tContent that will be displayed as an error message.\n\t",
};
ValidationError.propName = 'Error';
ValidationError.propTypes = {
description: string,
children: any,
};
var Validation = function (props) {
var className = props.className, children = props.children, passThroughs = __rest(props, ["className", "children"]);
var errorChildProps = lodash_1.default.get(component_types_1.getFirst(props, exports.Validation.Error), 'props');
return (react_1.default.createElement("div", __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(exports.Validation.propTypes)), { className: cx('&', {
'&-is-error': errorChildProps && errorChildProps.children,
}, className) }),
children,
errorChildProps &&
errorChildProps.children &&
errorChildProps.children !== true ? (react_1.default.createElement("div", __assign({}, component_types_1.omitProps(errorChildProps, undefined), { className: cx('&-error-content', errorChildProps.className) }), errorChildProps.children)) : null));
};
exports.Validation = Validation;
exports.Validation.displayName = 'Validation';
exports.Validation.peek = {
description: "\n\t\tValidation is a wrapper component that's meant to be used by other\n\t\tcomponents. Wrap your form components in it and style them accordingly\n\t\tif there's an error.\n\t",
categories: ['helpers'],
};
exports.Validation.propTypes = {
Error: any(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tIn most cases this will be a string, but it also accepts any valid React\n\t\telement. If this is a falsey value, then no error message will be\n\t\tdisplayed. If this is the literal `true`, it will add the\n\t\t`-is-error` class to the wrapper div, but not render the\n\t\t`-error-content` `div`.\n\t"], ["\n\t\tIn most cases this will be a string, but it also accepts any valid React\n\t\telement. If this is a falsey value, then no error message will be\n\t\tdisplayed. If this is the literal \\`true\\`, it will add the\n\t\t\\`-is-error\\` class to the wrapper div, but not render the\n\t\t\\`-error-content\\` \\`div\\`.\n\t"]))),
className: string(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\tClasses that are appended to the component defaults. This prop is run\n\t\tthrough the `classnames` library.\n\t"], ["\n\t\tClasses that are appended to the component defaults. This prop is run\n\t\tthrough the \\`classnames\\` library.\n\t"]))),
children: any.isRequired(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\tAny valid React children.\n\t"], ["\n\t\tAny valid React children.\n\t"]))),
};
exports.Validation.Error = ValidationError;
exports.default = exports.Validation;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=Validation.js.map