lucid-ui
Version:
A UI component library from Xandr.
109 lines • 4.76 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;
};
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 lodash_1 = __importStar(require("lodash"));
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var style_helpers_1 = require("../../util/style-helpers");
var component_types_1 = require("../../util/component-types");
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: "Content that will be displayed as an error message.",
};
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((0, component_types_1.getFirst)(props, exports.Validation.Error), 'props');
return (react_1.default.createElement("div", __assign({}, (0, lodash_1.omit)(passThroughs, [
'Error',
'className',
'children',
'initialState',
'callbackId',
]), { className: cx('&', {
'&-is-error': errorChildProps && errorChildProps.children,
}, className) }),
children,
errorChildProps &&
errorChildProps.children &&
errorChildProps.children !== true ? (react_1.default.createElement("div", __assign({}, (0, lodash_1.omit)(errorChildProps, ['initialState', 'callbackId']), { className: cx('&-error-content', errorChildProps.className) }), errorChildProps.children)) : null));
};
exports.Validation = Validation;
exports.Validation.displayName = 'Validation';
exports.Validation.peek = {
description: "`Validation` is a wrapper component that's meant to be used by other components. Wrap your form components in one, and, if there's an error, style them accordingly.",
categories: ['helpers'],
};
exports.Validation.propTypes = {
/**
In most cases this will be a string, but it also accepts any valid React
element. If this is a falsey value, then no error message will be
displayed. If this is the literal \`true\`, it will add the
\`-is-error\` class to the wrapper div, but not render the
\`-error-content\` \`div\`.
*/
Error: any,
/**
Classes that are appended to the component defaults. This prop is run
through the \`classnames\` library.
*/
className: string,
/**
Any valid React children.
*/
children: any.isRequired,
};
exports.Validation.Error = ValidationError;
exports.default = exports.Validation;
//# sourceMappingURL=Validation.js.map