fk-react-ui-components
Version:
Step 1 : Create a file in [ Seeds / Plants / Trees ] <br> Step 2 : It should export an Object with component name and story Component [Refer other components] <br> Step 3 : Story Component should return a react component <br> Step 3 : Created file should
153 lines (124 loc) • 6.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SimpleSearchBig = undefined;
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _Inputs = require('../FormElements/Inputs');
var _Inputs2 = _interopRequireDefault(_Inputs);
var _styles = require('./styles');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function createComponent(WrapperComponent, TimesCircleIconComponent, SearchIconComponent) {
var Search = function (_React$Component) {
_inherits(Search, _React$Component);
function Search(props) {
_classCallCheck(this, Search);
var _this = _possibleConstructorReturn(this, (Search.__proto__ || Object.getPrototypeOf(Search)).call(this, props));
_this.state = {
value: props.value,
isUndoApplicable: props.isUndoApplicable
};
_lodash2.default.bindAll(_this, 'onChange', 'undoSearch', 'handleKeyPress', 'onSearchClick');
return _this;
}
_createClass(Search, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value) {
this.setState({
value: nextProps.value,
isUndoApplicable: nextProps.value
});
}
}
}, {
key: 'onChange',
value: function onChange(e) {
this.setState({ value: e.target.value });
this.props.onChange(e.target.value);
}
}, {
key: 'onSearchClick',
value: function onSearchClick() {
this.triggerSearch(this.state.value);
}
}, {
key: 'handleKeyPress',
value: function handleKeyPress(e) {
var value = e.target.value;
if (e.key === 'Enter') {
this.triggerSearch(value);
}
}
}, {
key: 'triggerSearch',
value: function triggerSearch(value) {
this.setState({
isUndoApplicable: !!value
});
this.props.onSearch(value);
}
}, {
key: 'undoSearch',
value: function undoSearch() {
this.setState({
value: '',
isUndoApplicable: false
});
this.props.onSearch('');
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement(
WrapperComponent,
{ showUndo: this.state.isUndoApplicable },
_react2.default.createElement(_Inputs2.default, {
value: this.state.value,
type: 'text',
onChange: this.onChange,
placeholder: this.props.placeholder,
onKeyPress: this.handleKeyPress
}),
this.state.isUndoApplicable && _react2.default.createElement(TimesCircleIconComponent, {
className: 'fa fa-times-circle',
onClick: this.undoSearch
}),
_react2.default.createElement(SearchIconComponent, {
className: 'fa fa-search',
onClick: this.onSearchClick
})
);
}
}]);
return Search;
}(_react2.default.Component);
Search.propTypes = {
value: _propTypes2.default.string,
placeholder: _propTypes2.default.string,
isUndoApplicable: _propTypes2.default.bool,
onSearch: _propTypes2.default.func,
onChange: _propTypes2.default.func
};
Search.defaultProps = {
value: '',
placeholder: '',
isUndoApplicable: false,
onSearch: function onSearch() {},
onChange: function onChange() {}
};
return Search;
}
var SimpleSearch = createComponent(_styles.SimpleSearchContainer, _styles.TimesCircleStyledIcon, _styles.SearchStyledIcon);
var SimpleSearchBig = createComponent(_styles.SimpleSearchContainerBig, _styles.TimesCircleBigStyledIcon, _styles.SearchBigStyledIcon);
exports.default = SimpleSearch;
exports.SimpleSearchBig = SimpleSearchBig;