UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

67 lines 2.48 kB
import _ from 'lodash'; import React from 'react'; import PropTypes from 'react-peek/prop-types'; import Validation from '../Validation/Validation'; import TextField from '../TextField/TextField'; import reducers from '../TextField/TextField.reducers'; import { lucidClassNames } from '../../util/style-helpers'; import { findTypes, omitProps } from '../../util/component-types'; const cx = lucidClassNames.bind('&-TextFieldValidated'); const { any, object, string } = PropTypes; const TextFieldValidatedError = (_props) => null; TextFieldValidatedError.displayName = 'TextFieldValidated.Error'; TextFieldValidatedError.peek = { description: ` Content that will be displayed as an error message. `, }; TextFieldValidatedError.propName = 'Error'; class TextFieldValidated extends React.Component { constructor() { super(...arguments); this.textFieldRef = React.createRef(); this.focus = () => { this.textFieldRef.current && this.textFieldRef.current.focus(); }; } render() { const { className, style, ...passThroughs } = this.props; let childProps; if (this.props.Error) { childProps = _.map(findTypes(this.props, TextFieldValidated.Error), 'props'); } else if (this.props.Info) { childProps = [this.props.Info]; } return (React.createElement(Validation, { className: cx('&', className, { '-info': !this.props.Error && this.props.Info, }), style: style, Error: childProps }, React.createElement(TextField, Object.assign({}, omitProps(passThroughs, undefined, _.keys(TextFieldValidated.propTypes), false), { ref: this.textFieldRef })))); } } TextFieldValidated.displayName = 'TextFieldValidated'; TextFieldValidated.Error = TextFieldValidatedError; TextFieldValidated.peek = { description: ` A composition of TextField and Validation. `, categories: ['controls', 'text'], }; TextFieldValidated.reducers = reducers; TextFieldValidated.propTypes = { style: object ` Passed to the root container. `, className: string ` Passed to the root container. `, Error: any ` Prop alternative to Error child component `, Info: string ` Optional information text that is styled less aggressively than an error `, }; TextFieldValidated.defaultProps = TextField.defaultProps; export default TextFieldValidated; //# sourceMappingURL=TextFieldValidated.js.map