UNPKG

gather-content-ui

Version:
133 lines (132 loc) 9.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.SearchDropdown = void 0; var _react = _interopRequireWildcard(require("react")); var _classnames = _interopRequireDefault(require("classnames")); var _Icon = _interopRequireDefault(require("../Icon")); var _SearchResults = _interopRequireDefault(require("./SearchResults")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } var SearchDropdown = exports.SearchDropdown = /*#__PURE__*/function (_Component) { _inherits(SearchDropdown, _Component); var _super = _createSuper(SearchDropdown); function SearchDropdown() { var _this; _classCallCheck(this, SearchDropdown); // @ts-expect-error TS(2554): Expected 1-2 arguments, but got 0. _this = _super.call(this); _defineProperty(_assertThisInitialized(_this), "input", void 0); _defineProperty(_assertThisInitialized(_this), "updateInputValue", function (event) { // @ts-expect-error TS(2339): Property 'handleOnChange' does not exist on type '... Remove this comment to see the full error message _this.props.handleOnChange(event); _this.setState({ inputValue: event.target.value }); }); _defineProperty(_assertThisInitialized(_this), "clearInputValue", function () { _this.setState({ inputValue: "" }); // @ts-expect-error TS(2339): Property 'onInputClear' does not exist on type 'Re... Remove this comment to see the full error message _this.props.onInputClear(); }); _this.state = { inputValue: "" }; _this.input = /*#__PURE__*/_react["default"].createRef(); return _this; } _createClass(SearchDropdown, [{ key: "render", value: function render() { var _this$props = this.props, alignRight = _this$props.alignRight, className = _this$props.className, listClassName = _this$props.listClassName, fullWidth = _this$props.fullWidth, resultsTitle = _this$props.resultsTitle, focusOnMount = _this$props.focusOnMount, placeholder = _this$props.placeholder; var showResults = // @ts-expect-error TS(2339): Property 'results' does not exist on type 'Readonl... Remove this comment to see the full error message this.props.results.length > 0 && this.state.inputValue.length > 0; var menuClass = (0, _classnames["default"])("gui-search-dropdown ".concat(className), { // @ts-expect-error TS(2339): Property 'direction' does not exist on type 'Reado... Remove this comment to see the full error message "gui-dropup": this.props.direction === "up", "gui-full-width": fullWidth, "gui-open": showResults }); var listClass = (0, _classnames["default"])("gui-dropdown-menu ".concat(listClassName), { "gui-align-right": alignRight }); return /*#__PURE__*/_react["default"].createElement("div", { className: menuClass }, /*#__PURE__*/_react["default"].createElement("input", { // @ts-expect-error TS(2339): Property 'inputValue' does not exist on type 'Read... Remove this comment to see the full error message value: this.state.inputValue, onChange: this.updateInputValue, type: "text", className: "gui-dropdown-search__input", placeholder: placeholder, autoFocus: focusOnMount // eslint-disable-line jsx-a11y/no-autofocus , ref: this.input }), showResults && /*#__PURE__*/_react["default"].createElement("ul", { className: listClass }, /*#__PURE__*/_react["default"].createElement("li", { className: "gui-dropdown__item dropdown__item--title" }, /*#__PURE__*/_react["default"].createElement("button", { type: "button", className: "gui-dropdown__link dropdown__title", onClick: this.clearInputValue }, /*#__PURE__*/_react["default"].createElement("span", { className: "gui-dropdown__item--name" }, resultsTitle), /*#__PURE__*/_react["default"].createElement("span", { className: "gui-dropdown__item--additional" }, /*#__PURE__*/_react["default"].createElement(_Icon["default"], { name: "cross", text: "close", hideText: true })))), /*#__PURE__*/_react["default"].createElement(_SearchResults["default"] // @ts-expect-error TS(2769): No overload matches this call. , { results: this.props.results, input: this.input.current, hideResults: this.clearInputValue }))); } }]); return SearchDropdown; }(_react.Component); // @ts-expect-error TS(2339): Property 'defaultProps' does not exist on type 'ty... Remove this comment to see the full error message SearchDropdown.defaultProps = { placeholder: "Search...", alignRight: false, results: [], className: "", listClassName: "", fullWidth: false, resultsTitle: "Results", handleOnChange: function handleOnChange() {}, onInputClear: function onInputClear() {}, direction: "down", focusOnMount: false }; var _default = exports["default"] = SearchDropdown; //# sourceMappingURL=index.js.map