UNPKG

@wordpress/block-editor

Version:
107 lines (101 loc) 4.3 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.__experimentalLinkControlSearchResults = void 0; var _i18n = require("@wordpress/i18n"); var _components = require("@wordpress/components"); var _clsx = _interopRequireDefault(require("clsx")); var _searchCreateButton = _interopRequireDefault(require("./search-create-button")); var _searchItem = _interopRequireDefault(require("./search-item")); var _constants = require("./constants"); var _deprecated = _interopRequireDefault(require("@wordpress/deprecated")); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * External dependencies */ /** * Internal dependencies */ function LinkControlSearchResults({ withCreateSuggestion, currentInputValue, handleSuggestionClick, suggestionsListProps, buildSuggestionItemProps, suggestions, selectedSuggestion, isLoading, isInitialSuggestions, createSuggestionButtonText, suggestionsQuery }) { const resultsListClasses = (0, _clsx.default)('block-editor-link-control__search-results', { 'is-loading': isLoading }); const isSingleDirectEntryResult = suggestions.length === 1 && _constants.LINK_ENTRY_TYPES.includes(suggestions[0].type); const shouldShowCreateSuggestion = withCreateSuggestion && !isSingleDirectEntryResult && !isInitialSuggestions; // If the query has a specified type, then we can skip showing them in the result. See #24839. const shouldShowSuggestionsTypes = !suggestionsQuery?.type; const labelText = isInitialSuggestions ? (0, _i18n.__)('Suggestions') : (0, _i18n.sprintf)(/* translators: %s: search term. */ (0, _i18n.__)('Search results for "%s"'), currentInputValue); return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "block-editor-link-control__search-results-wrapper", children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { ...suggestionsListProps, className: resultsListClasses, "aria-label": labelText, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuGroup, { children: suggestions.map((suggestion, index) => { if (shouldShowCreateSuggestion && _constants.CREATE_TYPE === suggestion.type) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_searchCreateButton.default, { searchTerm: currentInputValue, buttonText: createSuggestionButtonText, onClick: () => handleSuggestionClick(suggestion) // Intentionally only using `type` here as // the constant is enough to uniquely // identify the single "CREATE" suggestion. , itemProps: buildSuggestionItemProps(suggestion, index), isSelected: index === selectedSuggestion }, suggestion.type); } // If we're not handling "Create" suggestions above then // we don't want them in the main results so exit early. if (_constants.CREATE_TYPE === suggestion.type) { return null; } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_searchItem.default, { itemProps: buildSuggestionItemProps(suggestion, index), suggestion: suggestion, index: index, onClick: () => { handleSuggestionClick(suggestion); }, isSelected: index === selectedSuggestion, isURL: _constants.LINK_ENTRY_TYPES.includes(suggestion.type), searchTerm: currentInputValue, shouldShowType: shouldShowSuggestionsTypes, isFrontPage: suggestion?.isFrontPage, isBlogHome: suggestion?.isBlogHome }, `${suggestion.id}-${suggestion.type}`); }) }) }) }); } var _default = exports.default = LinkControlSearchResults; const __experimentalLinkControlSearchResults = props => { (0, _deprecated.default)('wp.blockEditor.__experimentalLinkControlSearchResults', { since: '6.8' }); return /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkControlSearchResults, { ...props }); }; exports.__experimentalLinkControlSearchResults = __experimentalLinkControlSearchResults; //# sourceMappingURL=search-results.js.map