-
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.
Edit Post: Add block management modal (#14224)
- Loading branch information
1 parent
e205195
commit 7417eb5
Showing
21 changed files
with
830 additions
and
40 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
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
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
103 changes: 103 additions & 0 deletions
103
packages/edit-post/src/components/manage-blocks-modal/category.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,103 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { without, map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { compose, withInstanceId } from '@wordpress/compose'; | ||
import { CheckboxControl } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockTypesChecklist from './checklist'; | ||
|
||
function BlockManagerCategory( { | ||
instanceId, | ||
category, | ||
blockTypes, | ||
hiddenBlockTypes, | ||
toggleVisible, | ||
toggleAllVisible, | ||
} ) { | ||
if ( ! blockTypes.length ) { | ||
return null; | ||
} | ||
|
||
const checkedBlockNames = without( | ||
map( blockTypes, 'name' ), | ||
...hiddenBlockTypes | ||
); | ||
|
||
const titleId = 'edit-post-manage-blocks-modal__category-title-' + instanceId; | ||
|
||
const isAllChecked = checkedBlockNames.length === blockTypes.length; | ||
|
||
let ariaChecked; | ||
if ( isAllChecked ) { | ||
ariaChecked = 'true'; | ||
} else if ( checkedBlockNames.length > 0 ) { | ||
ariaChecked = 'mixed'; | ||
} else { | ||
ariaChecked = 'false'; | ||
} | ||
|
||
return ( | ||
<div | ||
role="group" | ||
aria-labelledby={ titleId } | ||
className="edit-post-manage-blocks-modal__category" | ||
> | ||
<CheckboxControl | ||
checked={ isAllChecked } | ||
onChange={ toggleAllVisible } | ||
className="edit-post-manage-blocks-modal__category-title" | ||
aria-checked={ ariaChecked } | ||
label={ <span id={ titleId }>{ category.title }</span> } | ||
/> | ||
<BlockTypesChecklist | ||
blockTypes={ blockTypes } | ||
value={ checkedBlockNames } | ||
onItemChange={ toggleVisible } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withInstanceId, | ||
withSelect( ( select ) => { | ||
const { getPreference } = select( 'core/edit-post' ); | ||
|
||
return { | ||
hiddenBlockTypes: getPreference( 'hiddenBlockTypes' ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps ) => { | ||
const { | ||
showBlockTypes, | ||
hideBlockTypes, | ||
} = dispatch( 'core/edit-post' ); | ||
|
||
return { | ||
toggleVisible( blockName, nextIsChecked ) { | ||
if ( nextIsChecked ) { | ||
showBlockTypes( blockName ); | ||
} else { | ||
hideBlockTypes( blockName ); | ||
} | ||
}, | ||
toggleAllVisible( nextIsChecked ) { | ||
const blockNames = map( ownProps.blockTypes, 'name' ); | ||
if ( nextIsChecked ) { | ||
showBlockTypes( blockNames ); | ||
} else { | ||
hideBlockTypes( blockNames ); | ||
} | ||
}, | ||
}; | ||
} ), | ||
] )( BlockManagerCategory ); |
37 changes: 37 additions & 0 deletions
37
packages/edit-post/src/components/manage-blocks-modal/checklist.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,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { partial } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { BlockIcon } from '@wordpress/block-editor'; | ||
import { CheckboxControl } from '@wordpress/components'; | ||
|
||
function BlockTypesChecklist( { blockTypes, value, onItemChange } ) { | ||
return ( | ||
<ul className="edit-post-manage-blocks-modal__checklist"> | ||
{ blockTypes.map( ( blockType ) => ( | ||
<li | ||
key={ blockType.name } | ||
className="edit-post-manage-blocks-modal__checklist-item" | ||
> | ||
<CheckboxControl | ||
label={ ( | ||
<Fragment> | ||
{ blockType.title } | ||
<BlockIcon icon={ blockType.icon } /> | ||
</Fragment> | ||
) } | ||
checked={ value.includes( blockType.name ) } | ||
onChange={ partial( onItemChange, blockType.name ) } | ||
/> | ||
</li> | ||
) ) } | ||
</ul> | ||
); | ||
} | ||
|
||
export default BlockTypesChecklist; |
Oops, something went wrong.