Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating AddCustomTemplateModalContent to use updated Composite implementation #55256

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,51 @@ import {
FlexItem,
SearchControl,
TextHighlight,
privateApis as componentsPrivateApis,
__experimentalText as Text,
__experimentalVStack as VStack,
__unstableComposite as Composite,
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
} from '@wordpress/components';
import { useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import useDebouncedInput from '../../utils/use-debounced-input';
import { mapToIHasNameAndId } from './utils';

const {
CompositeV2: Composite,
CompositeItemV2: CompositeItem,
useCompositeStoreV2: useCompositeStore,
} = unlock( componentsPrivateApis );

const EMPTY_ARRAY = [];

function SuggestionListItem( {
suggestion,
search,
onSelect,
entityForSuggestions,
composite,
} ) {
const baseCssClass =
'edit-site-custom-template-modal__suggestions_list__list-item';
return (
<CompositeItem
role="option"
as={ Button }
{ ...composite }
className={ baseCssClass }
onClick={ () =>
onSelect(
entityForSuggestions.config.getSpecificTemplate(
suggestion
)
)
render={
<Button
type="button"
andrewhayward marked this conversation as resolved.
Show resolved Hide resolved
role="option"
className={ baseCssClass }
onClick={ () =>
onSelect(
entityForSuggestions.config.getSpecificTemplate(
suggestion
)
)
}
/>
}
>
<Text
Expand Down Expand Up @@ -112,7 +119,7 @@ function useSearchSuggestions( entityForSuggestions, search ) {
}

function SuggestionList( { entityForSuggestions, onSelect } ) {
const composite = useCompositeState( { orientation: 'vertical' } );
const composite = useCompositeStore( { orientation: 'vertical' } );
const [ search, setSearch, debouncedSearch ] = useDebouncedInput();
const suggestions = useSearchSuggestions(
entityForSuggestions,
Expand All @@ -136,7 +143,7 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
) }
{ !! suggestions?.length && (
<Composite
{ ...composite }
store={ composite }
role="listbox"
className="edit-site-custom-template-modal__suggestions_list"
aria-label={ __( 'Suggestions list' ) }
Expand All @@ -148,7 +155,6 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
search={ debouncedSearch }
onSelect={ onSelect }
entityForSuggestions={ entityForSuggestions }
composite={ composite }
/>
) ) }
</Composite>
Expand Down
Loading