UNPKG

@atlaskit/global-search

Version:

A cross-product search component (batteries included)

88 lines (74 loc) 4.35 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral"; var _templateObject, _templateObject2; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; import styled from 'styled-components'; // AFP-2532 TODO: Fix automatic suppressions below // eslint-disable-next-line @atlassian/tangerine/import/entry-points import { gridSize } from '@atlaskit/theme'; import { ResultItemGroup } from '@atlaskit/quick-search'; import Badge from '@atlaskit/badge'; import ResultList from './ResultList'; import { injectIntl } from 'react-intl'; import ShowMoreButton from './ShowMoreButton'; var TitlelessGroupWrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n margin-top: ", "px;\n"])), gridSize() * 1.5); var BadgeContainer = styled.span(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n margin-left: ", "px;\n"])), gridSize()); export var ResultGroup = /*#__PURE__*/function (_React$Component) { _inherits(ResultGroup, _React$Component); var _super = _createSuper(ResultGroup); function ResultGroup() { _classCallCheck(this, ResultGroup); return _super.apply(this, arguments); } _createClass(ResultGroup, [{ key: "render", value: function render() { var _this$props = this.props, title = _this$props.title, results = _this$props.results, sectionIndex = _this$props.sectionIndex, showTotalSize = _this$props.showTotalSize, totalSize = _this$props.totalSize, showMoreButton = _this$props.showMoreButton, onShowMoreClicked = _this$props.onShowMoreClicked, onSearchMoreAdvancedSearch = _this$props.onSearchMoreAdvancedSearch, query = _this$props.query; if (results.length === 0) { return null; } var moreButton = showMoreButton ? /*#__PURE__*/React.createElement(ShowMoreButton, { resultLength: results.length, onShowMoreClicked: onShowMoreClicked, onSearchMoreAdvancedSearch: onSearchMoreAdvancedSearch, totalSize: totalSize, query: query // this will force new show more button every click show more to fix scrolling , key: "show_more_".concat(results.length) }) : null; if (!title) { return /*#__PURE__*/React.createElement(TitlelessGroupWrapper, null, /*#__PURE__*/React.createElement(ResultList, { analyticsData: this.props.analyticsData, results: results, sectionIndex: sectionIndex }), moreButton); } var titleView = showTotalSize ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", null, title), /*#__PURE__*/React.createElement(BadgeContainer, null, /*#__PURE__*/React.createElement(Badge, { max: 99 }, totalSize))) : /*#__PURE__*/React.createElement("span", null, title); return /*#__PURE__*/React.createElement(ResultItemGroup, { title: titleView }, /*#__PURE__*/React.createElement(ResultList, { analyticsData: this.props.analyticsData, results: results, sectionIndex: sectionIndex }), moreButton); } }]); return ResultGroup; }(React.Component); export default injectIntl(ResultGroup);