@findify/react-components
Version:
Findify react UI components
112 lines (100 loc) • 4.68 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/MobileSorting
*/
import Button from "../../Button";
import Text from "../../Text";
import Icon from "../../Icon";
import MapArray from "../../common/MapArray";
import { is } from 'immutable';
var styles = {
"root": "findify-components-search--mobile-sorting",
"header": "findify-components-search--mobile-sorting__header",
"body": "findify-components-search--mobile-sorting__body",
"footer": "findify-components-search--mobile-sorting__footer",
"title": "findify-components-search--mobile-sorting__title",
"item": "findify-components-search--mobile-sorting__item"
};
import useTranslations from "../../../helpers/useTranslations";
import useSortingLogic from "../../../helpers/useSortingLogic";
import { useCallback } from 'react';
/** Props that MobileSorting Item accepts */
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var Item = function Item(_ref) {
var item = _ref.item,
_ref$theme = _ref.theme,
theme = _ref$theme === void 0 ? styles : _ref$theme,
selected = _ref.selected,
onChange = _ref.onChange;
var onClick = useCallback(function (e) {
e.preventDefault();
onChange(item);
}, []);
var isSelected = is(selected, item);
return /*#__PURE__*/_jsx(Button, {
onClick: onClick,
disabled: isSelected,
className: theme.item,
children: /*#__PURE__*/_jsxs(Text, {
primary: true,
uppercase: true,
children: [/*#__PURE__*/_jsx(Icon, {
name: isSelected ? 'RadioFilled' : 'RadioEmpty',
title: isSelected ? 'Selected' : 'Not selected'
}), item.get('label')]
})
});
};
/** Props that MobileSorting view accepts */
export default (function (_ref2) {
var _ref2$theme = _ref2.theme,
theme = _ref2$theme === void 0 ? styles : _ref2$theme,
style = _ref2.style,
hideModal = _ref2.hideModal;
var _useSortingLogic = useSortingLogic(),
_useSortingLogic2 = _slicedToArray(_useSortingLogic, 3),
items = _useSortingLogic2[0],
selected = _useSortingLogic2[1],
onChange = _useSortingLogic2[2];
var translate = useTranslations();
return /*#__PURE__*/_jsxs("div", {
className: theme.root,
style: style,
children: [/*#__PURE__*/_jsxs("div", {
className: theme.header,
children: [/*#__PURE__*/_jsx("div", {
className: theme.title,
children: /*#__PURE__*/_jsx(Text, {
primary: true,
uppercase: true,
children: translate('actions.sorting')
})
}), /*#__PURE__*/_jsx(Button, {
onClick: hideModal,
children: /*#__PURE__*/_jsx(Icon, {
name: "ArrowBack",
title: translate('actions.back')
})
})]
}), /*#__PURE__*/_jsx("div", {
className: theme.body,
children: /*#__PURE__*/_jsx(MapArray, {
onChange: onChange,
theme: theme,
selected: selected,
array: items,
factory: Item
})
}), /*#__PURE__*/_jsx(Button, {
className: theme.footer,
onClick: hideModal,
children: translate('actions.seeResults')
})]
});
});