UNPKG

@wordpress/block-editor

Version:
102 lines (101 loc) 3.52 kB
// packages/block-editor/src/components/link-control/search-results.js import { __, sprintf } from "@wordpress/i18n"; import { MenuGroup } from "@wordpress/components"; import clsx from "clsx"; import LinkControlSearchCreate from "./search-create-button"; import LinkControlSearchItem from "./search-item"; import { CREATE_TYPE, LINK_ENTRY_TYPES } from "./constants"; import deprecated from "@wordpress/deprecated"; import { jsx } from "react/jsx-runtime"; function LinkControlSearchResults({ withCreateSuggestion, currentInputValue, handleSuggestionClick, suggestionsListProps, buildSuggestionItemProps, suggestions, selectedSuggestion, isLoading, isInitialSuggestions, createSuggestionButtonText, suggestionsQuery }) { const resultsListClasses = clsx( "block-editor-link-control__search-results", { "is-loading": isLoading } ); const isSingleDirectEntryResult = suggestions.length === 1 && LINK_ENTRY_TYPES.includes(suggestions[0].type); const shouldShowCreateSuggestion = withCreateSuggestion && !isSingleDirectEntryResult && !isInitialSuggestions; const shouldShowSuggestionsTypes = !suggestionsQuery?.type; const labelText = isInitialSuggestions ? __("Suggestions") : sprintf( /* translators: %s: search term. */ __('Search results for "%s"'), currentInputValue ); return /* @__PURE__ */ jsx("div", { className: "block-editor-link-control__search-results-wrapper", children: /* @__PURE__ */ jsx( "div", { ...suggestionsListProps, className: resultsListClasses, "aria-label": labelText, children: /* @__PURE__ */ jsx(MenuGroup, { children: suggestions.map((suggestion, index) => { if (shouldShowCreateSuggestion && CREATE_TYPE === suggestion.type) { return /* @__PURE__ */ jsx( LinkControlSearchCreate, { searchTerm: currentInputValue, buttonText: createSuggestionButtonText, onClick: () => handleSuggestionClick(suggestion), itemProps: buildSuggestionItemProps( suggestion, index ), isSelected: index === selectedSuggestion }, suggestion.type ); } if (CREATE_TYPE === suggestion.type) { return null; } return /* @__PURE__ */ jsx( LinkControlSearchItem, { itemProps: buildSuggestionItemProps( suggestion, index ), suggestion, index, onClick: () => { handleSuggestionClick(suggestion); }, isSelected: index === selectedSuggestion, isURL: LINK_ENTRY_TYPES.includes( suggestion.type ), searchTerm: currentInputValue, shouldShowType: shouldShowSuggestionsTypes, isFrontPage: suggestion?.isFrontPage, isBlogHome: suggestion?.isBlogHome }, `${suggestion.id}-${suggestion.type}` ); }) }) } ) }); } var search_results_default = LinkControlSearchResults; var __experimentalLinkControlSearchResults = (props) => { deprecated("wp.blockEditor.__experimentalLinkControlSearchResults", { since: "6.8" }); return /* @__PURE__ */ jsx(LinkControlSearchResults, { ...props }); }; export { __experimentalLinkControlSearchResults, search_results_default as default }; //# sourceMappingURL=search-results.js.map