-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inserter: Add block pattern category selection dropdown in main inser…
…ter (#24954) * Add dropdown for patterns in the main inserter to select and view one specific category at a time. * Remove the viewing: text, and increase the target size of the dropdown button. * Fix scss lint errors. * Fix the lazy loading of patterns when specific categories are selected. * Make sure quick inserter searches work for patterns and select all categories for the search. * switch to filtering patterns in component rather than hook * Improve performance of pattern search with large pattern sets * Also change filtered patterns if pattern array changes * Fix casing error * Add uncategorized back * Switch to native select control * Prevent duplicate 'uncategorized' categories being added * remove unused arg * Design cleanup. * Switch to useMemo to filter patterns instead of storing in component state * remove empty categories * Remove arguments that are no longer used. Co-authored-by: Glen Davies <[email protected]>
- Loading branch information
Showing
4 changed files
with
179 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/block-editor/src/components/inserter/pattern-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SelectControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
function PatternInserterPanel( { | ||
selectedCategory, | ||
patternCategories, | ||
onClickCategory, | ||
children, | ||
} ) { | ||
const categoryOptions = () => { | ||
const options = []; | ||
|
||
patternCategories.map( ( patternCategory ) => { | ||
return options.push( { | ||
value: patternCategory.name, | ||
label: patternCategory.label, | ||
} ); | ||
} ); | ||
|
||
return options; | ||
}; | ||
|
||
const onChangeSelect = ( selected ) => { | ||
onClickCategory( | ||
patternCategories.find( | ||
( patternCategory ) => selected === patternCategory.name | ||
) | ||
); | ||
}; | ||
|
||
const getPanelHeaderClassName = () => { | ||
return classnames( | ||
'block-editor-inserter__panel-header', | ||
'block-editor-inserter__panel-header-patterns' | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className={ getPanelHeaderClassName() }> | ||
<SelectControl | ||
className="block-editor-inserter__panel-dropdown" | ||
label={ __( 'Filter patterns' ) } | ||
hideLabelFromVision | ||
value={ selectedCategory.name } | ||
onChange={ onChangeSelect } | ||
options={ categoryOptions() } | ||
/> | ||
</div> | ||
<div className="block-editor-inserter__panel-content"> | ||
{ children } | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default PatternInserterPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters