@findify/react-components
Version:
Findify react UI components
78 lines (65 loc) • 3.3 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/Breadcrumbs
*/
import MapArray from "../common/MapArray";
import Button from "../Button";
import Text from "../Text";
import Icon from "../Icon";
import { useMemo } from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var Item = function Item(_ref) {
var mapping = _ref.mapping,
theme = _ref.theme,
item = _ref.item,
name = _ref.name,
_config = _ref.config;
var _useMemo = useMemo(function () {
var facetConfig = _config.getIn(['facets', 'filters', name]);
var _type = (facetConfig === null || facetConfig === void 0 ? void 0 : facetConfig.get('type')) || item.get('type');
return [mapping[_type], _config.merge(facetConfig)];
}, [mapping]),
_useMemo2 = _slicedToArray(_useMemo, 2),
Content = _useMemo2[0],
config = _useMemo2[1];
return /*#__PURE__*/_jsxs(Button, {
className: theme.breadcrumb,
onClick: item.toggle,
children: [/*#__PURE__*/_jsx(Text, {
secondary: true,
uppercase: true,
className: theme.title,
children: /*#__PURE__*/_jsx(Content, {
item: item,
config: config,
theme: theme
})
}), /*#__PURE__*/_jsx(Icon, {
className: theme.cross,
name: "XDark",
title: "Remove filter"
})]
});
};
/** List of props that component returned by createBreadcrumb accepts */
export default (function (mapping) {
return function (_ref2) {
var item = _ref2.item,
theme = _ref2.theme,
config = _ref2.config;
return /*#__PURE__*/_jsx(MapArray, {
array: item.get('values'),
name: item.get('name'),
factory: Item,
theme: theme,
mapping: mapping,
config: config
});
};
});