Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,32 +1,31 @@
import { useState } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import { Button } from '@wordpress/components';
import { Spinner } from '@wordpress/ui';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import PatternsExplorerModal from '../block-patterns-explorer';
import MobileTabNavigation from '../mobile-tab-navigation';
import { PatternCategoryPreviews } from './pattern-category-previews';
import PatternsGrid from './patterns-grid';
import { usePatternCategories } from './use-pattern-categories';
import CategoryTabs from '../category-tabs';
import InserterNoResults from '../no-results';
import { store as blockEditorStore } from '../../../store';
import { unlock } from '../../../lock-unlock';
import type { BlockPatternsTabProps } from '../types';

/**
* The inserter's Patterns tab: one sidebar with a search, a settings menu, the
* pattern categories as tabs and the patterns of the selected one, starting on
* "All". It browses like the Media tab.
*/
function BlockPatternsTab( {
onSelectCategory,
selectedCategory,
onInsert,
rootClientId,
children,
}: BlockPatternsTabProps ) {
const [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );

const categories = usePatternCategories( rootClientId );

const isMobile = useViewportMatch( 'medium', '<' );

const isResolvingPatterns = useSelect(
( select ) =>
unlock( select( blockEditorStore ) ).isResolvingPatterns(),
Expand All @@ -45,15 +44,13 @@ function BlockPatternsTab( {

return (
<>
{ ! isMobile && (
<div className="block-editor-inserter__block-patterns-tabs-container">
<CategoryTabs
categories={ categories }
selectedCategory={ selectedCategory }
onSelectCategory={ onSelectCategory }
>
{ children }
</CategoryTabs>
<PatternsGrid
categories={ categories }
initialCategory={ selectedCategory }
onSelectCategory={ onSelectCategory }
onInsert={ onInsert }
rootClientId={ rootClientId }
footer={
<Button
__next40pxDefaultSize
className="block-editor-inserter__patterns-explore-button"
Expand All @@ -62,22 +59,8 @@ function BlockPatternsTab( {
>
{ __( 'Explore all patterns' ) }
</Button>
</div>
) }
{ isMobile && (
<MobileTabNavigation categories={ categories }>
{ ( category ) => (
<div className="block-editor-inserter__category-panel">
<PatternCategoryPreviews
key={ category.name }
onInsert={ onInsert }
rootClientId={ rootClientId }
category={ category }
/>
</div>
) }
</MobileTabNavigation>
) }
}
/>
{ showPatternsExplorer && (
<PatternsExplorerModal
initialCategory={ selectedCategory || categories[ 0 ] }
Expand Down

This file was deleted.

Loading
Loading