UNPKG

@findify/react-components

Version:
82 lines (69 loc) 4.24 kB
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 layouts/Search */ import { useEffect } from 'react'; import DesktopFacets from "../../components/search/DesktopFacets"; import MobileActions from "../../components/search/MobileActions"; import DesktopActions from "../../components/search/DesktopActions"; import Branch from "../../components/common/Branch"; import Banner from "../../components/Banner"; import Grid, { Column } from "../../components/common/Grid"; import { useMobile } from "../../helpers/useMobile"; import { useAnnouncement } from "../../components/common/Announcement"; import useScrollOnChange from "../../helpers/useScrollOnChange"; import { useItems } from '@findify/react-connect'; import useTranslations from "../../helpers/useTranslations"; var styles = { "root": "findify-layouts--search" }; import SearchResultsLayout from "../../components/search/SearchResultsLayout"; /** Props that search layout accepts */ import { jsx as _jsx } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var Search = function Search(_ref) { var isCollection = _ref.isCollection, _ref$theme = _ref.theme, theme = _ref$theme === void 0 ? styles : _ref$theme; var _useItems = useItems(), items = _useItems.items, config = _useItems.config; var translate = useTranslations(); var isMobile = useMobile(); var _useAnnouncement = useAnnouncement(), _useAnnouncement2 = _slicedToArray(_useAnnouncement, 2), announcement = _useAnnouncement2[0], setAnnouncement = _useAnnouncement2[1]; useScrollOnChange(items); useEffect(function () { return setAnnouncement(translate('search.accessibleUpdate')); }, [items]); if (!items.size) return null; return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsxs(Grid, { className: theme.root, gutter: 40, columns: config.getIn(['facets', 'position']) === 'top' ? 'full' : config.getIn(['breakpoints', 'layout'], 'fit|auto'), children: [!isMobile ? /*#__PURE__*/_jsx(Column, { order: config.getIn(['facets', 'position']) === 'right' && 2, children: /*#__PURE__*/_jsx(DesktopFacets, {}) }) : null, /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(Branch, { isCollection: isCollection, condition: isMobile, left: MobileActions, right: DesktopActions }), /*#__PURE__*/_jsx(Banner, {}), /*#__PURE__*/_jsx(SearchResultsLayout, { condition: config.getIn(['pagination', 'type']) })] })] }), announcement] }); }; export default process.env.HOT ? require('react-hot-loader').hot(module)(Search) : Search;