react-kube
Version:
Kube CSS in React Components
55 lines (41 loc) • 2.35 kB
JavaScript
;
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; }; })();
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 _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) subClass.__proto__ = superClass; }
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var HighlightText = (function (_React$Component) {
function HighlightText() {
_classCallCheck(this, HighlightText);
if (_React$Component != null) {
_React$Component.apply(this, arguments);
}
}
_inherits(HighlightText, _React$Component);
_createClass(HighlightText, [{
key: "render",
value: function render() {
var text = this.props.text;
var query = this.props.query;
var searchIndex = text.toLowerCase().indexOf(query);
return _react2["default"].createElement(
"span",
null,
text.substring(0, searchIndex),
_react2["default"].createElement(
"span",
{ className: "highlight" },
text.substring(searchIndex, searchIndex + query.length)
),
text.substring(searchIndex + query.length, text.length)
);
}
}]);
return HighlightText;
})(_react2["default"].Component);
HighlightText.propTypes = {
query: _react2["default"].PropTypes.string.isRequired,
text: _react2["default"].PropTypes.string.isRequired
};
module.exports = HighlightText;