lucid-ui
Version:
A UI component library from AppNexus.
57 lines (49 loc) • 3.08 kB
JavaScript
import _keys from "lodash/keys";
import _get from "lodash/get";
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import PropTypes from 'react-peek/prop-types';
import { lucidClassNames } from '../../util/style-helpers';
import { getFirst, omitProps } from '../../util/component-types';
var cx = lucidClassNames.bind('&-Validation');
var string = PropTypes.string,
any = PropTypes.any;
var ValidationError = function ValidationError(_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
};
export var Validation = function Validation(props) {
var className = props.className,
children = props.children,
passThroughs = _objectWithoutProperties(props, ["className", "children"]);
var errorChildProps = _get(getFirst(props, Validation.Error), 'props');
return /*#__PURE__*/React.createElement("div", _extends({}, omitProps(passThroughs, undefined, _keys(Validation.propTypes)), {
className: cx('&', {
'&-is-error': errorChildProps && errorChildProps.children
}, className)
}), children, errorChildProps && errorChildProps.children && errorChildProps.children !== true ? /*#__PURE__*/React.createElement("div", _extends({}, omitProps(errorChildProps, undefined), {
className: cx('&-error-content', errorChildProps.className)
}), errorChildProps.children) : null);
};
Validation.displayName = 'Validation';
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']
};
Validation.propTypes = {
Error: any,
className: string,
children: any.isRequired
};
Validation.Error = ValidationError;
export default Validation;