PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.9.0
GenerateBlocks v1.9.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / pattern-library / components / category-list.js
generateblocks / src / pattern-library / components Last commit date
add-library.js 2 years ago category-list.js 2 years ago insert-pattern.js 2 years ago library-cache.js 2 years ago library-layout.js 2 years ago library-provider.js 2 years ago library-selector.js 2 years ago manage-libraries.js 2 years ago pattern-details-header.js 2 years ago pattern-details.js 2 years ago pattern-list.js 2 years ago pattern-search.js 2 years ago pattern.js 2 years ago selected-patterns.js 2 years ago
category-list.js
79 lines
1 import { Button, DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
2 import { useLibrary } from './library-provider';
3 import { __, sprintf } from '@wordpress/i18n';
4 import { check, chevronDown } from '@wordpress/icons';
5
6 export default function CategoryList( { bulkInsertEnabled } ) {
7 const { categories, activeCategory, setActiveCategory } = useLibrary();
8
9 const getNameById = ( id ) => {
10 const item = categories.find( ( element ) => element.id === id );
11 return item ? item.name : null;
12 };
13
14 return (
15 <div className="pattern-category-list" style={ { background: !! bulkInsertEnabled ? 'none' : '' } }>
16 { !! bulkInsertEnabled ? (
17 <DropdownMenu
18 className="pattern-category-dropdown"
19 icon={ chevronDown }
20 toggleProps={ {
21 variant: 'secondary',
22 children: sprintf(
23 /* translators: %s: category name */
24 __( 'Category: %s', 'generateblocks' ),
25 getNameById( activeCategory ) || __( 'All', 'generateblocks' )
26 ),
27 } }
28 >
29 { ( { onClose } ) => (
30 <MenuGroup>
31 <MenuItem
32 isPressed={ '' === activeCategory }
33 onClick={ () => {
34 setActiveCategory( '' );
35 onClose();
36 } }
37 >
38 { __( 'All', 'generateblocks' ) }
39 </MenuItem>
40 { categories && categories.map( ( category ) => (
41 <MenuItem
42 key={ category.id }
43 icon={ category.id === activeCategory ? check : null }
44 onClick={ () => {
45 setActiveCategory( category.id );
46 onClose();
47 } }
48 >
49 { category.name }
50 </MenuItem>
51 ) ) }
52 </MenuGroup>
53 ) }
54 </DropdownMenu>
55 ) : (
56 <>
57 <Button
58 id="pattern-category-all"
59 isPressed={ '' === activeCategory }
60 onClick={ () => setActiveCategory( '' ) }
61 >
62 { __( 'All', 'generateblocks' ) }
63 </Button>
64 { categories && categories.map( ( category ) => (
65 <Button
66 id={ `pattern-category-${ category.id }` }
67 key={ category.id }
68 isPressed={ category.id === activeCategory }
69 onClick={ () => setActiveCategory( category.id ) }
70 >
71 { category.name }
72 </Button>
73 ) ) }
74 </>
75 ) }
76 </div>
77 );
78 }
79