infinity-forge
Version:
54 lines • 2.88 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSelectComponents = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var components_1 = require("../components/index.js");
var useSelectComponents = function (props) {
(0, react_1.useEffect)(function () {
var handleClickOutside = function (e) {
var _a;
if (!props.menuIsOpen)
return;
var safeId = CSS.escape(props.id);
var menuPortal = document.querySelector(".".concat(safeId, "__menu-portal"));
var menu = document.querySelector(".".concat(safeId, "__menu"));
if (props.selectRef.current &&
!props.selectRef.current.contains(e.target) &&
(!menuPortal || !menuPortal.contains(e.target)) &&
(!menu || !menu.contains(e.target))) {
props.setMenuIsOpen(false);
(_a = props === null || props === void 0 ? void 0 : props.onCloseMenu) === null || _a === void 0 ? void 0 : _a.call(props);
}
};
document.addEventListener('mousedown', handleClickOutside);
return function () { return document.removeEventListener('mousedown', handleClickOutside); };
}, [props.menuIsOpen, props.id]);
return __assign(__assign(__assign({}, (props.selectPropsInfinityForge.CustomOption
? {
Option: props.selectPropsInfinityForge.CustomOption,
SingleValue: props.selectPropsInfinityForge.CustomOption,
}
: __assign({}, (props.selectPropsInfinityForge.isMultiple || props.selectPropsInfinityForge.multiple
? { Option: components_1.CustomOptionCheckbox }
: {})))), (props.selectPropsInfinityForge.isMultiple || props.selectPropsInfinityForge.multiple
? {
MultiValue: function (multiValueProps) {
return (0, components_1.CustomMultiValue)(__assign(__assign({}, multiValueProps), props));
},
}
: {})), { Input: function () { return null; }, MenuList: function (propsSelect) { return (0, jsx_runtime_1.jsx)(components_1.MenuListWithSearch, __assign({}, propsSelect, props)); }, ValueContainer: function (valueContainerProps) { return (0, jsx_runtime_1.jsx)(components_1.CustomValueContainer, __assign({}, valueContainerProps, props)); } });
};
exports.useSelectComponents = useSelectComponents;
//# sourceMappingURL=use-select-components.js.map