@massds/mayflower-react
Version:
React versions of Mayflower design system UI components
81 lines • 4.19 kB
JavaScript
const _excluded = ["placeholder", "id", "queryInput"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
* GenTeaserSearch module.
* @module @massds/mayflower-react/GenTeaserSearch
* @requires module:@massds/mayflower-assets/scss/01-atoms/button-with-icon
* @requires module:@massds/mayflower-assets/scss/01-atoms/button-search
* @requires module:@massds/mayflower-assets/scss/01-atoms/input-typeahead
* @requires module:@massds/mayflower-assets/scss/01-atoms/svg-icons
* @requires module:@massds/mayflower-assets/scss/01-atoms/svg-loc-icons
*/
import React from "react";
import PropTypes from "prop-types";
import HeaderSearch from "../HeaderSearch/index.mjs";
let GenTeaserSearch = /*#__PURE__*/function (_React$Component) {
function GenTeaserSearch(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_defineProperty(_this, "onClick", e => {
e.preventDefault();
const _this$props = _this.props,
target = _this$props.target,
queryInput = _this$props.queryInput;
const query = _this.inputRef.current.value;
if (query.length > 0) {
const searchURL = queryInput ? target.replace("{" + queryInput + "}", query) : target;
_this.redirect(searchURL);
}
});
_defineProperty(_this, "redirect", searchURL => {
if (window.location !== window.parent.location) {
window.parent.location.assign(searchURL);
} else {
window.location.assign(searchURL);
}
});
_this.inputRef = /*#__PURE__*/React.createRef();
return _this;
}
_inheritsLoose(GenTeaserSearch, _React$Component);
var _proto = GenTeaserSearch.prototype;
_proto.render = function render() {
const _this$props2 = this.props,
placeholder = _this$props2.placeholder,
id = _this$props2.id,
queryInput = _this$props2.queryInput,
rest = _objectWithoutPropertiesLoose(_this$props2, _excluded);
return /*#__PURE__*/React.createElement(HeaderSearch, _extends({
buttonSearch: {
'aria-label': '',
onClick: e => this.onClick(e),
text: 'Search',
usage: ''
},
defaultText: "",
id: id,
label: "Search terms",
onSubmit: e => this.onSubmit(e),
inputRef: this.inputRef,
placeholder: placeholder
}, rest));
};
return GenTeaserSearch;
}(React.Component);
GenTeaserSearch.propTypes = process.env.NODE_ENV !== "production" ? {
/** The target url of the search bar */
target: PropTypes.string.isRequired,
/** The id of the search bar */
id: PropTypes.string.isRequired,
/** The query input variable to replace in the target url with the user entered term */
queryInput: PropTypes.string.isRequired,
/** Placeholder text of the search bar. */
placeholder: PropTypes.string.isRequired
} : {};
export default GenTeaserSearch;