@findify/react-components
Version:
Findify react UI components
96 lines (85 loc) • 4.56 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/DesktopActions
*/
import { useCallback, useState } from 'react';
import Breadcrumbs from "../../Breadcrumbs";
import Query from "../Query";
import Sorting from "../../Sorting";
import Button from "../../Button";
import Text from "../../Text";
import Icon from "../../Icon";
import Grid, { Column } from "../../common/Grid";
import useTranslations from "../../../helpers/useTranslations";
import { emit, useEvents } from "../../../helpers/emmiter";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var styles = {
"root": "findify-components-search--desktop-actions",
"block": "findify-components-search--desktop-actions__block",
"block-inner": "findify-components-search--desktop-actions__block-inner",
"sorting": "findify-components-search--desktop-actions__sorting",
"query": "findify-components-search--desktop-actions__query",
"breadcrumbs": "findify-components-search--desktop-actions__breadcrumbs",
"show-facets": "findify-components-search--desktop-actions__show-facets",
"blockInner": "findify-components-search--desktop-actions__block-inner",
"showFacets": "findify-components-search--desktop-actions__show-facets"
};
/** Props that DesktopActions view accepts */
var useFacetsLogic = function useFacetsLogic() {
var _useState = useState(true),
_useState2 = _slicedToArray(_useState, 2),
visible = _useState2[0],
setVisible = _useState2[1];
useEvents({
hideFacets: function hideFacets() {
return setVisible(false);
}
});
var showFacets = useCallback(function () {
setVisible(true);
emit('showFacets');
}, []);
return [visible, showFacets];
};
export default (function (_ref) {
var _ref$theme = _ref.theme,
theme = _ref$theme === void 0 ? styles : _ref$theme,
isCollection = _ref.isCollection;
var translate = useTranslations();
var _useFacetsLogic = useFacetsLogic(),
_useFacetsLogic2 = _slicedToArray(_useFacetsLogic, 2),
facetsVisible = _useFacetsLogic2[0],
showFacets = _useFacetsLogic2[1];
return /*#__PURE__*/_jsxs(Grid, {
className: theme.root,
columns: "auto|fit",
children: [/*#__PURE__*/_jsx(Column, {
className: theme.block,
children: /*#__PURE__*/_jsxs("div", {
className: theme.blockInner,
children: [!facetsVisible ? /*#__PURE__*/_jsx(Button, {
className: theme.showFacets,
onClick: showFacets,
children: /*#__PURE__*/_jsxs(Text, {
secondary: true,
uppercase: true,
children: [/*#__PURE__*/_jsx(Icon, {
name: "Filters",
title: "Filters",
className: theme.icon
}), translate('actions.showFilters')]
})
}) : null, !isCollection ? /*#__PURE__*/_jsx(Query, {}) : null, /*#__PURE__*/_jsx(Breadcrumbs, {})]
})
}), /*#__PURE__*/_jsx(Column, {
className: theme.sorting,
children: /*#__PURE__*/_jsx(Sorting, {})
})]
});
});