@findify/react-components
Version:
Findify react UI components
150 lines (134 loc) • 6.04 kB
JavaScript
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(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
* @module components/search/MobileActions
*/
import { withDrawer } from "../../../helpers/withDrawer";
import MobileFacets from "../MobileFacets";
import MobileSorting from "../MobileSorting";
import Query from "../Query";
import Button from "../../Button";
import Text from "../../Text";
import Icon from "../../Icon";
import { useQuery } from '@findify/react-connect';
import useTranslations from "../../../helpers/useTranslations";
import { memo, useMemo } from 'react';
import { emit, useEvents } from "../../../helpers/emmiter";
var styles = {
"root": "findify-components-search--mobile-actions",
"bottom-row": "findify-components-search--mobile-actions__bottom-row",
"icon": "findify-components-search--mobile-actions__icon",
"button": "findify-components-search--mobile-actions__button",
"facet-count": "findify-components-search--mobile-actions__facet-count",
"divider": "findify-components-search--mobile-actions__divider",
"query": "findify-components-search--mobile-actions__query",
"bottomRow": "findify-components-search--mobile-actions__bottom-row",
"facetCount": "findify-components-search--mobile-actions__facet-count"
};
import useSortingLogic from "../../../helpers/useSortingLogic";
/** Props that MobileActionsView accepts */
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var showFacets = function showFacets() {
return emit('showMobileFacets');
};
var showSort = function showSort() {
return emit('showMobileSort');
};
var MobileActions = /*#__PURE__*/memo(function (_ref) {
var isCollection = _ref.isCollection,
_ref$theme = _ref.theme,
theme = _ref$theme === void 0 ? styles : _ref$theme,
showModal = _ref.showModal,
hideModal = _ref.hideModal;
var _useSortingLogic = useSortingLogic(),
_useSortingLogic2 = _slicedToArray(_useSortingLogic, 2),
sortItems = _useSortingLogic2[0],
currentSort = _useSortingLogic2[1];
var _useQuery = useQuery(),
query = _useQuery.query;
var translate = useTranslations();
useEvents({
showMobileFacets: function showMobileFacets() {
return showModal('Filters');
},
showMobileSort: function showMobileSort() {
return showModal('Sorting');
},
hideMobileFacets: function hideMobileFacets() {
return hideModal('Filters');
},
hideMobileSort: function hideMobileSort() {
return hideModal('Sorting');
}
});
var total = useMemo(function () {
return query.get('filters') ? query.get('filters').reduce(function (acc, filter) {
return acc + (/category[2-9]/.test(filter.get('name')) ? 0 : filter.get('values').size);
}, 0) : 0;
}, [query]);
return /*#__PURE__*/_jsxs("div", {
className: theme.root,
children: [!isCollection ? /*#__PURE__*/_jsx(Query, {
theme: {
root: theme.query
}
}) : null, /*#__PURE__*/_jsxs("div", {
className: theme.bottomRow,
children: [/*#__PURE__*/_jsx(Button, {
onClick: showSort,
className: theme.button,
children: /*#__PURE__*/_jsxs(Text, {
primary: true,
uppercase: true,
children: [/*#__PURE__*/_jsx(Icon, {
name: "Sorting",
title: "Sorting",
className: theme.icon
}), currentSort.get('label')]
})
}), /*#__PURE__*/_jsx("div", {
className: theme.divider
}), /*#__PURE__*/_jsx(Button, {
onClick: showFacets,
className: theme.button,
children: /*#__PURE__*/_jsxs(Text, {
primary: true,
uppercase: true,
children: [/*#__PURE__*/_jsx(Icon, {
name: "Filters",
title: "Filters"
}), translate('actions.filter'), /*#__PURE__*/_jsxs("span", {
className: theme.facetCount,
children: ["(", total, ")"]
})]
})
})]
})]
});
});
var transform = {
from: {
transform: "translate3d(-100%, 0, 0)"
},
to: {
transform: "translate3d(0%, 0, 0)"
}
};
var compose = function compose() {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return funcs.reduce(function (a, b) {
return function () {
return a(b.apply(void 0, arguments));
};
}, function (arg) {
return arg;
});
};
export default compose(withDrawer('Filters', MobileFacets, transform), withDrawer('Sorting', MobileSorting, transform))(MobileActions);