kitten-components
Version:
Front-end components library
135 lines (106 loc) • 5.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Search = 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 _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _elementHelper = require('kitten/helpers/dom/element-helper');
var _textInput = require('kitten/components/form/text-input');
var _searchIcon = require('kitten/components/icons/search-icon');
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; }
var Search = exports.Search = function (_Component) {
_inherits(Search, _Component);
function Search(props) {
_classCallCheck(this, Search);
var _this = _possibleConstructorReturn(this, (Search.__proto__ || Object.getPrototypeOf(Search)).call(this, props));
_this.state = {
focus: false,
hover: false
// These listeners help us to handle the text input display depending on the
// submit input state (as we cannot handle it directly in css).
};_this.handleSubmitFocus = _this.handleSubmitFocus.bind(_this);
_this.handleSubmitBlur = _this.handleSubmitBlur.bind(_this);
_this.handleSubmitMouseOver = _this.handleSubmitMouseOver.bind(_this);
_this.handleSubmitMouseOut = _this.handleSubmitMouseOut.bind(_this);
return _this;
}
// Component listeners callbacks.
_createClass(Search, [{
key: 'handleSubmitFocus',
value: function handleSubmitFocus() {
this.setState({ focus: true });
}
}, {
key: 'handleSubmitBlur',
value: function handleSubmitBlur() {
this.setState({ focus: false });
}
}, {
key: 'handleSubmitMouseOver',
value: function handleSubmitMouseOver() {
this.setState({ hover: true });
}
}, {
key: 'handleSubmitMouseOut',
value: function handleSubmitMouseOut() {
this.setState({ hover: false });
}
// Rendering.
}, {
key: 'render',
value: function render() {
var _props = this.props,
className = _props.className,
actionUrl = _props.actionUrl,
inputId = _props.inputId,
inputName = _props.inputName,
inputPlaceholder = _props.inputPlaceholder,
inputLabel = _props.inputLabel,
submitLabel = _props.submitLabel,
others = _objectWithoutProperties(_props, ['className', 'actionUrl', 'inputId', 'inputName', 'inputPlaceholder', 'inputLabel', 'submitLabel']);
var inputClassName = (0, _classnames2.default)('k-TextInput', 'k-TextInput--tiny', 'k-SearchInput__input', { 'is-active': this.state.focus }, { 'is-hover': this.state.hover });
return _react2.default.createElement(
'form',
{
className: 'k-SearchInput',
role: 'search',
action: actionUrl,
acceptCharset: 'UTF-8',
method: 'get'
},
_react2.default.createElement(_textInput.TextInput, {
className: inputClassName,
type: 'search',
id: inputId,
name: inputName,
placeholder: inputPlaceholder,
'aria-label': inputLabel
}),
_react2.default.createElement(
'button',
{
type: 'submit',
'aria-label': submitLabel,
className: 'k-SearchInput__submit k-SearchInput__submit--tiny',
onFocus: this.handleSubmitFocus,
onBlur: this.handleSubmitBlur,
onMouseOver: this.handleSubmitMouseOver,
onMouseOut: this.handleSubmitMouseOut
},
_react2.default.createElement(_searchIcon.SearchIcon, { width: '14', height: '14' })
)
);
}
}]);
return Search;
}(_react.Component);
// DEPRECATED: do not use default export.
exports.default = Search;