lucid-ui
Version:
A UI component library from AppNexus.
185 lines (146 loc) • 10.5 kB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
import _keys from "lodash/keys";
import _isEmpty from "lodash/isEmpty";
import _isUndefined from "lodash/isUndefined";
import _get from "lodash/get";
import _noop from "lodash/noop";
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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import React, { createElement } from 'react';
import PropTypes from 'react-peek/prop-types';
import { lucidClassNames } from '../../util/style-helpers';
import { getFirst, omitProps } from '../../util/component-types';
import { buildModernHybridComponent } from '../../util/state-management';
import TextField from '../TextField/TextField';
import SearchIcon from '../Icon/SearchIcon/SearchIcon';
import reducers from './SearchField.reducers';
var cx = lucidClassNames.bind('&-SearchField');
var bool = PropTypes.bool,
func = PropTypes.func,
node = PropTypes.node,
number = PropTypes.number,
oneOfType = PropTypes.oneOfType,
string = PropTypes.string;
var SearchFieldIcon = function SearchFieldIcon(_props) {
return null;
};
SearchFieldIcon.peek = {
description: "\n\t\tIcon this is displayed on the right side of the SearchField. Any of the lucid `*Icon` components should work.\n\t"
};
SearchFieldIcon.displayName = 'SearchField.Icon';
SearchFieldIcon.propName = 'Icon';
var SearchFieldTextField = function SearchFieldTextField(_props) {
return null;
};
SearchFieldTextField.peek = {
description: "\n\t\tIcon this is displayed on the right side of the SearchField. Any of the lucid `*Icon` components should work.\n\t"
};
SearchFieldTextField.displayName = 'SearchField.TextField';
SearchFieldTextField.propName = 'TextField';
var SearchField = /*#__PURE__*/function (_React$Component) {
_inherits(SearchField, _React$Component);
var _super = _createSuper(SearchField);
function SearchField() {
_classCallCheck(this, SearchField);
return _super.apply(this, arguments);
}
_createClass(SearchField, [{
key: "render",
value: function render() {
var props = this.props,
_this$props = this.props,
className = _this$props.className,
isDisabled = _this$props.isDisabled,
isValid = _this$props.isValid,
onChange = _this$props.onChange,
onChangeDebounced = _this$props.onChangeDebounced,
debounceLevel = _this$props.debounceLevel,
onSubmit = _this$props.onSubmit,
placeholder = _this$props.placeholder,
value = _this$props.value,
autoComplete = _this$props.autoComplete,
passThroughs = _objectWithoutProperties(_this$props, ["className", "isDisabled", "isValid", "onChange", "onChangeDebounced", "debounceLevel", "onSubmit", "placeholder", "value", "autoComplete"]);
var Icon = SearchField.Icon;
var textFieldProps = _get(getFirst(props, SearchField.TextField), 'props') || {
isDisabled: isDisabled,
onChange: onChange,
onChangeDebounced: onChangeDebounced,
debounceLevel: debounceLevel,
onSubmit: onSubmit,
placeholder: placeholder,
isMultiLine: false,
value: value,
autoComplete: autoComplete
};
var textFieldElement = /*#__PURE__*/React.createElement(TextField, textFieldProps);
var isIconActive = _isUndefined(isValid) ? !_isEmpty(_get(textFieldElement, 'props.value')) : isValid;
var defaultIcon = /*#__PURE__*/React.createElement(SearchIcon, {
size: 12,
className: cx('&-Icon', {
'&-Icon-active': isIconActive
})
});
var iconElement = getFirst(props, Icon);
var iconChildren = _get(iconElement, 'props.children');
var icon = iconChildren ? /*#__PURE__*/createElement(iconChildren.type, _objectSpread(_objectSpread({}, iconChildren.props), {}, {
className: cx('&-Icon', {
'&-Icon-active': isIconActive
}, iconChildren.props.className)
})) : defaultIcon;
return /*#__PURE__*/React.createElement("div", _extends({}, omitProps(passThroughs, undefined, _keys(SearchField.propTypes)), {
className: cx('&', className)
}), textFieldElement, /*#__PURE__*/React.createElement("div", {
className: cx('&-Icon-container')
}, icon));
}
}]);
return SearchField;
}(React.Component);
_defineProperty(SearchField, "displayName", 'SearchField');
_defineProperty(SearchField, "TextField", SearchFieldTextField);
_defineProperty(SearchField, "Icon", SearchFieldIcon);
_defineProperty(SearchField, "peek", {
description: "\n\t\t\t\t\tThis is a wrapper around TextField that styles it for a search\n\t\t\t\t\tuse-case. The icon and TextField are customizable through child\n\t\t\t\t\tcomponents.\n\t\t\t\t",
categories: ['controls', 'text'],
madeFrom: ['TextField', 'SearchIcon']
});
_defineProperty(SearchField, "reducers", reducers);
_defineProperty(SearchField, "propTypes", {
onChange: func,
onChangeDebounced: func,
debounceLevel: number,
onSubmit: func,
value: oneOfType([number, string]),
isValid: bool,
isDisabled: bool,
placeholder: string,
className: string,
Icon: node,
TextField: node
});
_defineProperty(SearchField, "defaultProps", {
isDisabled: false,
onChange: _noop,
onChangeDebounced: _noop,
debounceLevel: 500,
onSubmit: _noop,
value: ''
});
export default buildModernHybridComponent(SearchField, {
reducers: reducers
});
export { SearchField as SearchFieldDumb };