Repository URL to install this package:
|
Version:
3.12.16 ▾
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useState, useEffect, useMemo } from 'react';
import { MenuItem } from '@scaleflex/ui/core';
import { PC } from '@filerobot/common';
import Styled from './styled';
import { jsx as _jsx } from "react/jsx-runtime";
var SearchSuggestionsMenu = function SearchSuggestionsMenu(_ref) {
var open = _ref.open,
searchInputFocused = _ref.searchInputFocused,
anchorEl = _ref.anchorEl,
theme = _ref.theme,
items = _ref.items,
placeholder = _ref.placeholder,
emptyItemsPlaceholder = _ref.emptyItemsPlaceholder,
mode = _ref.mode;
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
mouseOverMenu = _useState2[0],
setMouseOverMenu = _useState2[1];
/**
* The only reason why we update anchorElPosition is to update menu width.
* On @scaleflex/ui Menu component we run updateRect when anchorElPosition is updated.
* When on @scaleflex/ui we will have some clear way how to update rect we can refactror implementation here.
*/
var _useState3 = useState(),
_useState4 = _slicedToArray(_useState3, 2),
anchorElPosition = _useState4[0],
setAnchorElPosition = _useState4[1];
var resizeObserver = useMemo(function () {
return new ResizeObserver(function (entries) {
var _entries$, _entries$$target, _entries$$target$getB;
setAnchorElPosition((entries === null || entries === void 0 ? void 0 : (_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : (_entries$$target = _entries$.target) === null || _entries$$target === void 0 ? void 0 : (_entries$$target$getB = _entries$$target.getBoundingClientRect) === null || _entries$$target$getB === void 0 ? void 0 : _entries$$target$getB.call(_entries$$target)) || {});
});
}, []);
useEffect(function () {
if (anchorEl) {
resizeObserver.observe(anchorEl);
}
return function () {
if (anchorEl) {
resizeObserver.disconnect();
}
};
}, [resizeObserver, anchorEl]);
var renderContent = function renderContent() {
if (mode && items) {
if (Array.isArray(items) && items.length) {
return items;
} else if (emptyItemsPlaceholder) {
return /*#__PURE__*/_jsx(MenuItem, {
style: {
color: theme.palette[PC.TextSecondary]
},
children: emptyItemsPlaceholder
}, "placeholder");
}
return null;
}
return /*#__PURE__*/_jsx(MenuItem, {
style: {
color: theme.palette[PC.TextSecondary]
},
children: placeholder
}, "placeholder");
};
if (!open) {
return null;
}
if (!searchInputFocused && !mouseOverMenu) {
return null;
}
return /*#__PURE__*/_jsx(Styled.Menu, {
$width: anchorElPosition === null || anchorElPosition === void 0 ? void 0 : anchorElPosition.width,
open: true,
enableOverlay: false,
fullWidth: true,
anchorEl: anchorEl,
anchorElPosition: anchorElPosition,
onMouseEnter: function onMouseEnter() {
return setMouseOverMenu(true);
},
onMouseLeave: function onMouseLeave() {
return setMouseOverMenu(false);
},
zIndex: 1200,
position: "bottom-start",
children: renderContent()
});
};
export default SearchSuggestionsMenu;