@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
102 lines (82 loc) • 4.02 kB
JavaScript
;
exports.__esModule = true;
exports.default = undefined;
var _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; };
var _class, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
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; }
/**
* A search bar to include inside a Navbar component. This isn't connected to
* a Searcher component but is instead to be used for operations such as filtering.
*/
var NavbarSearch = (_temp = _class = function (_React$Component) {
_inherits(NavbarSearch, _React$Component);
function NavbarSearch(props) {
_classCallCheck(this, NavbarSearch);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.onChange = _this.onChange.bind(_this);
_this.onSearch = _this.onSearch.bind(_this);
return _this;
}
NavbarSearch.prototype.onChange = function onChange(e) {
if (e.target instanceof HTMLInputElement) {
this.props.updateSearchString(e.target.value);
}
};
NavbarSearch.prototype.onSearch = function onSearch() {
this.props.onSearch();
if (this.button) {
this.button.blur();
}
};
NavbarSearch.prototype.render = function render() {
var _this2 = this;
var _props = this.props,
placeholder = _props.placeholder,
value = _props.value,
updateSearchString = _props.updateSearchString,
onSearch = _props.onSearch,
otherProps = _objectWithoutProperties(_props, ['placeholder', 'value', 'updateSearchString', 'onSearch']);
return _react2.default.createElement(
'div',
_extends({ className: 'navbar-form navbar-left attivio-search' }, otherProps),
_react2.default.createElement(
'div',
{ className: 'form-group' },
_react2.default.createElement('input', {
type: 'text',
className: 'form-control',
placeholder: this.props.placeholder,
value: this.props.value,
onChange: this.onChange
})
),
_react2.default.createElement(
'button',
{
type: 'button',
className: 'btn btn-link attivio-icon-search',
onClick: this.onSearch,
ref: function ref(i) {
_this2.button = i;
}
},
_react2.default.createElement(
'span',
{ className: 'sr-only' },
'Search'
)
)
);
};
return NavbarSearch;
}(_react2.default.Component), _class.defaultProps = {
placeholder: 'Search\u2026'
}, _class.displayName = 'NavbarSearch', _temp);
exports.default = NavbarSearch;
module.exports = exports['default'];