From 36d5f9b4055c4d8990224c02100fcb12572a3078 Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Mon, 22 Apr 2024 12:43:39 -0500 Subject: [PATCH 1/8] Start on converting media to tabs pattern --- .../inserter/media-tab/media-tab.js | 113 ++++++++++-------- .../src/components/inserter/menu.js | 37 +++--- 2 files changed, 89 insertions(+), 61 deletions(-) diff --git a/packages/block-editor/src/components/inserter/media-tab/media-tab.js b/packages/block-editor/src/components/inserter/media-tab/media-tab.js index b448ae2a406499..0bea662e166c31 100644 --- a/packages/block-editor/src/components/inserter/media-tab/media-tab.js +++ b/packages/block-editor/src/components/inserter/media-tab/media-tab.js @@ -9,11 +9,10 @@ import classNames from 'classnames'; import { __, isRTL } from '@wordpress/i18n'; import { useViewportMatch } from '@wordpress/compose'; import { - __experimentalItemGroup as ItemGroup, - __experimentalItem as Item, __experimentalHStack as HStack, FlexBlock, Button, + privateApis as componentsPrivateApis, } from '@wordpress/components'; import { useCallback, useMemo } from '@wordpress/element'; import { Icon, chevronRight, chevronLeft } from '@wordpress/icons'; @@ -27,14 +26,18 @@ import MediaUpload from '../../media-upload'; import { useMediaCategories } from './hooks'; import { getBlockAndPreviewFromMedia } from './utils'; import MobileTabNavigation from '../mobile-tab-navigation'; +import { unlock } from '../../../lock-unlock'; const ALLOWED_MEDIA_TYPES = [ 'image', 'video', 'audio' ]; +const { Tabs } = unlock( componentsPrivateApis ); + function MediaTab( { rootClientId, selectedCategory, onSelectCategory, onInsert, + children, } ) { const mediaCategories = useMediaCategories( rootClientId ); const isMobile = useViewportMatch( 'medium', '<' ); @@ -57,28 +60,36 @@ function MediaTab( { } ) ), [ mediaCategories ] ); + return ( <> { ! isMobile && (
- + + { mediaCategories.map( ( mediaCategory ) => ( + + { children } + + ) ) } + + + ( + + ) } + /> +
) } { isMobile && ( diff --git a/packages/block-editor/src/components/inserter/menu.js b/packages/block-editor/src/components/inserter/menu.js index f42a7f06019cc3..ad1f6f856f182e 100644 --- a/packages/block-editor/src/components/inserter/menu.js +++ b/packages/block-editor/src/components/inserter/menu.js @@ -123,7 +123,11 @@ function InserterMenu( __experimentalOnPatternCategorySelection(); } }, - [ setSelectedPatternCategory, __experimentalOnPatternCategorySelection ] + [ + setSelectedPatternCategory, + __experimentalOnPatternCategorySelection, + isZoomedOutViewExperimentEnabled, + ] ); const showPatternPanel = @@ -131,6 +135,11 @@ function InserterMenu( ! delayedFilterValue && selectedPatternCategory; + const showMediaPanel = + selectedTab === 'media' && + ! delayedFilterValue && + selectedMediaCategory; + const blocksTab = useMemo( () => ( <> @@ -183,8 +192,10 @@ function InserterMenu( ), [ destinationRootClientId, + onHoverPattern, onInsertPattern, onClickPatternCategory, + patternFilter, selectedPatternCategory, showPatternPanel, ] @@ -197,13 +208,22 @@ function InserterMenu( selectedCategory={ selectedMediaCategory } onSelectCategory={ setSelectedMediaCategory } onInsert={ onInsert } - /> + > + { showMediaPanel && ( + + ) } + ), [ destinationRootClientId, onInsert, selectedMediaCategory, setSelectedMediaCategory, + showMediaPanel, ] ); @@ -224,10 +244,6 @@ function InserterMenu( } ) ); const showAsTabs = ! delayedFilterValue && ( showPatterns || showMedia ); - const showMediaPanel = - selectedTab === 'media' && - ! delayedFilterValue && - selectedMediaCategory; // When the pattern panel is showing, we want to use zoom out mode useZoomOut( showPatternPanel ); @@ -243,7 +259,7 @@ function InserterMenu( return (
) }
- { showMediaPanel && ( - - ) } { showInserterHelpPanel && hoveredItem && ( Date: Mon, 22 Apr 2024 14:28:13 -0500 Subject: [PATCH 2/8] Convert block patterns tablist into catebory tabs component --- .../inserter/block-patterns-tab/index.js | 75 +++---------------- .../inserter/category-tabs/index.js | 74 ++++++++++++++++++ .../src/components/inserter/style.scss | 37 ++++----- 3 files changed, 100 insertions(+), 86 deletions(-) create mode 100644 packages/block-editor/src/components/inserter/category-tabs/index.js diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab/index.js b/packages/block-editor/src/components/inserter/block-patterns-tab/index.js index 34993fc6db87fa..d2f302683ed2da 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab/index.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab/index.js @@ -2,15 +2,9 @@ * WordPress dependencies */ import { useState } from '@wordpress/element'; -import { __, isRTL } from '@wordpress/i18n'; import { useViewportMatch } from '@wordpress/compose'; -import { - __experimentalHStack as HStack, - FlexBlock, - Button, - privateApis as componentsPrivateApis, -} from '@wordpress/components'; -import { Icon, chevronRight, chevronLeft } from '@wordpress/icons'; +import { Button } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; /** * Internal dependencies @@ -19,9 +13,7 @@ import PatternsExplorerModal from '../block-patterns-explorer'; import MobileTabNavigation from '../mobile-tab-navigation'; import { PatternCategoryPreviews } from './pattern-category-previews'; import { usePatternCategories } from './use-pattern-categories'; -import { unlock } from '../../../lock-unlock'; - -const { Tabs } = unlock( componentsPrivateApis ); +import CategoryTabs from '../category-tabs'; function BlockPatternsTab( { onSelectCategory, @@ -40,60 +32,13 @@ function BlockPatternsTab( { <> { ! isMobile && (
- { - // Pass the full category object - onSelectCategory( - categories.find( - ( category ) => category.name === categoryId - ) - ); - } } + - - { categories.map( ( category ) => ( - - - - { category.label } - - - - - ) ) } - - { categories.map( ( category ) => ( - - { children } - - ) ) } - + { children } +