UNPKG

1.76 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
4import _defineProperty from "@babel/runtime/helpers/defineProperty";
5import cx from 'classnames';
6import React from 'react';
7import { getDisplayName, isSizeLarge, isSizeSmall } from '../utils';
8
9function withClassNames(Component) {
10 // Use a class instead of function component to support refs.
11
12 /* eslint-disable-next-line react/prefer-stateless-function */
13 var WrappedComponent = /*#__PURE__*/function (_React$Component) {
14 _inheritsLoose(WrappedComponent, _React$Component);
15
16 function WrappedComponent() {
17 return _React$Component.apply(this, arguments) || this;
18 }
19
20 var _proto = WrappedComponent.prototype;
21
22 _proto.render = function render() {
23 var _this$props = this.props,
24 className = _this$props.className,
25 isInvalid = _this$props.isInvalid,
26 isValid = _this$props.isValid,
27 size = _this$props.size,
28 props = _objectWithoutPropertiesLoose(_this$props, ["className", "isInvalid", "isValid", "size"]);
29
30 return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
31 className: cx('form-control', 'rbt-input', {
32 'form-control-lg': isSizeLarge(size),
33 'form-control-sm': isSizeSmall(size),
34 'is-invalid': isInvalid,
35 'is-valid': isValid
36 }, className)
37 }));
38 };
39
40 return WrappedComponent;
41 }(React.Component);
42
43 _defineProperty(WrappedComponent, "displayName", "withClassNames(" + getDisplayName(Component) + ")");
44
45 return WrappedComponent;
46}
47
48export default withClassNames;
\No newline at end of file