Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Post: Add block management modal #14224

Merged
merged 40 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
86c88a1
Edit Post: Provide default preferences by higher-order reducer
aduth Mar 4, 2019
8af0287
Edit Post: Add block management modal
aduth Mar 4, 2019
f83be63
Edit Post: Rephrase block disable as block hide
aduth Mar 8, 2019
8fc50d9
Edit Post: Update "Hide All" to "Hide all blocks"
aduth Mar 8, 2019
c61ccd7
Edit Post: Remove block manager autoFocus
aduth Mar 8, 2019
9ac28ec
Edit Post: Close Block Manager panels by default
aduth Mar 8, 2019
ae02300
Edit Post: Show visible label for Block Manager search
aduth Mar 8, 2019
40ffefe
Edit Post: Generalize block search to blocks selector
aduth Mar 8, 2019
c8d5b98
Edit Post: Show hidden block types in Block Manager as labelled
aduth Mar 8, 2019
b28cbb0
Edit Post: Avoid generating unnecessary hasChildBlocksWithInserterSup…
aduth Mar 8, 2019
b681ecb
Edit Post: Split Block Manager category render to own component
aduth Mar 8, 2019
f8a1874
Edit Post: Filter Block Manager items by inserter support
aduth Mar 8, 2019
98e55eb
Edit Post: Render Block Manager item as toggle button
aduth Mar 8, 2019
32e2490
Edit Post: Render Block Manager results as labelled region
aduth Mar 8, 2019
2de9a7e
Edit Post: Constrain Block Manager width to 485px
aduth Mar 8, 2019
8671702
Components: Add className prop support for ToggleControl
aduth Mar 8, 2019
fccc796
Edit Post: Add margin surrounding Hide all checkbox
aduth Mar 8, 2019
f092ff6
Edit Post: Avoid changing label in toggle button
aduth Mar 8, 2019
25b185c
Blocks: Regenerate docs for isMatchingSearchTerm
aduth Mar 8, 2019
fbf5410
Update components CHANGELOG to use "class name" phrasing
gziolo Mar 12, 2019
9ce3def
Edit Post: Use consistent "Manage Block Visibility" label
aduth Mar 12, 2019
bfc1a38
Blocks: Add unit tests for isMatchingSearchTerm
aduth Mar 12, 2019
6171177
Edit Post: Add "No Results" text for empty Manage Blocks search
aduth Mar 12, 2019
c0b9a23
Edit Post: Render Manage Blocks Visibility as checklist
aduth Mar 12, 2019
fc978e5
Edit Post: Reverse behavior of "all" visible toggle to show
aduth Mar 12, 2019
9297f8d
Components: Add mirror prop support to CheckboxControl
aduth Mar 12, 2019
e194aa0
Edit Post: Mirror checkboxes in Manage Blocks modal
aduth Mar 12, 2019
1555f58
Edit Post: Fix Firefox scroll overflow in Manage Blocks
aduth Mar 13, 2019
2d9b379
Edit Post: Render Manage Blocks group as role=group
aduth Mar 13, 2019
6798964
Checkbox margin adjustment.
mapk Mar 13, 2019
76fb031
Merge branch 'add/block-manager' of github.com:WordPress/gutenberg in…
mapk Mar 13, 2019
ac202ff
Icon colors changed to -gray-500
mapk Mar 13, 2019
a71f799
Changed title back to Block Manager based on design feedback
mapk Mar 13, 2019
3d7de09
Edit Post: Fix Block Manager "Show All" toggle checked as all checked
aduth Mar 13, 2019
6e8072a
Edit Post: Refactor Block Manager checkbox margin as precise override
aduth Mar 13, 2019
0d985a2
Revert "Edit Post: Fix Block Manager "Show All" toggle checked as all…
mapk Mar 13, 2019
dca4049
Revert "Components: Add mirror prop support to CheckboxControl"
aduth Mar 14, 2019
40c7694
Edit Post: Display block manager entries as indented checklist
aduth Mar 14, 2019
22ad54b
Edit Post: Restore Block Manager toggle label association
aduth Mar 14, 2019
0b45148
Edit Post: Adjust mobile, margin styling for mixed checkbox
aduth Mar 14, 2019
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
Prev Previous commit
Next Next commit
Edit Post: Render Manage Blocks Visibility as checklist
  • Loading branch information
aduth committed Mar 12, 2019
commit c0b9a230b7ea0633a069587eaedeb652fb9b5f1a
46 changes: 10 additions & 36 deletions packages/block-editor/src/components/block-types-list/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { map } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -13,25 +8,15 @@ import { getBlockMenuDefaultClassName } from '@wordpress/blocks';
*/
import InserterListItem from '../inserter-list-item';

/**
* Stateless function component which renders its received `children` prop.
*
* @param {Object} props Props object.
*
* @return {WPElement} Rendered children.
*/
const RENDER_CHILDREN = ( props ) => props.children;

function BlockTypesList( {
items,
onSelect,
onHover = () => {},
renderItem: RenderItem = RENDER_CHILDREN,
children,
} ) {
items = map( items, ( item ) => {
return (
<RenderItem key={ item.id } item={ item }>
function BlockTypesList( { items, onSelect, onHover = () => {}, children } ) {
return (
/*
* Disable reason: The `list` ARIA role is redundant but
* Safari+VoiceOver won't announce the list otherwise.
*/
/* eslint-disable jsx-a11y/no-redundant-roles */
<ul role="list" className="editor-block-types-list">
{ items && items.map( ( item ) =>
<InserterListItem
key={ item.id }
className={ getBlockMenuDefaultClassName( item.id ) }
Expand All @@ -50,18 +35,7 @@ function BlockTypesList( {
isDisabled={ item.isDisabled }
title={ item.title }
/>
</RenderItem>
);
} );

return (
/*
* Disable reason: The `list` ARIA role is redundant but
* Safari+VoiceOver won't announce the list otherwise.
*/
/* eslint-disable jsx-a11y/no-redundant-roles */
<ul role="list" className="editor-block-types-list">
{ items }
) }
{ children }
</ul>
/* eslint-enable jsx-a11y/no-redundant-roles */
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export { default as BlockEdit } from './block-edit';
export { default as BlockFormatControls } from './block-format-controls';
export { default as BlockNavigationDropdown } from './block-navigation/dropdown';
export { default as BlockIcon } from './block-icon';
export { default as __experimentalBlockTypesList } from './block-types-list';
export { default as ColorPalette } from './color-palette';
export { default as withColorContext } from './color-palette/with-color-context';
export * from './colors';
Expand Down
6 changes: 0 additions & 6 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
## 7.2.0 (Unreleased)

### New Features

- `ToggleControl` now accepts a `className` prop to merge with its default-assigned class name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, on its own, it makes sense as well. We might want to add className prop to all reusable components located in @wordpress/components package.


## 7.1.0 (2019-03-06)

### New Features
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/toggle-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { isFunction } from 'lodash';
import classnames from 'classnames';

/**
* WordPress dependencies
Expand Down Expand Up @@ -30,7 +29,7 @@ class ToggleControl extends Component {
}

render() {
const { label, checked, help, instanceId, className } = this.props;
const { label, checked, help, instanceId } = this.props;
const id = `inspector-toggle-control-${ instanceId }`;

let describedBy, helpLabel;
Expand All @@ -43,7 +42,7 @@ class ToggleControl extends Component {
<BaseControl
id={ id }
help={ helpLabel }
className={ classnames( 'components-toggle-control', className ) }
className="components-toggle-control"
>
<FormToggle
id={ id }
Expand Down
90 changes: 40 additions & 50 deletions packages/edit-post/src/components/manage-blocks-modal/category.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,54 @@
/**
* External dependencies
*/
import { includes, map } from 'lodash';
import { without, map } from 'lodash';

/**
* WordPress dependencies
*/
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { cloneElement, Children } from '@wordpress/element';
import { ToggleControl, PanelBody } from '@wordpress/components';
import { __experimentalBlockTypesList as BlockTypesList } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import BlockManagerHideAll from './hide-all';
import BlockTypesChecklist from './checklist';

function BlockManagerCategory( {
category,
blockItems,
blockTypes,
hiddenBlockTypes,
opened,
onToggle,
showBlockTypes,
hideBlockTypes,
toggleVisible,
toggleAllHidden,
} ) {
if ( ! blockItems.length ) {
if ( ! blockTypes.length ) {
return null;
}

const isAllHidden = blockItems.every( ( blockItem ) => {
return hiddenBlockTypes.includes( blockItem.id );
} );
const checkedBlockNames = without(
map( blockTypes, 'name' ),
...hiddenBlockTypes
);

return (
<PanelBody
key={ category.slug }
title={ category.title }
icon={ category.icon }
opened={ opened }
onToggle={ onToggle }
>
<ToggleControl
label={ __( 'Hide all blocks' ) }
checked={ isAllHidden }
onChange={ toggleAllHidden }
className="edit-post-manage-blocks-modal__hide-all"
/>
<BlockTypesList
items={ blockItems }
onSelect={ ( item ) => (
includes( hiddenBlockTypes, item.id ) ?
showBlockTypes( item.id ) :
hideBlockTypes( item.id )
) }
renderItem={ ( { children, item } ) => {
const isHidden = includes( hiddenBlockTypes, item.id );
const child = Children.only( children );
return cloneElement( child, {
'aria-pressed': isHidden,
'aria-label': __( 'Hide block: %s' ),
'data-hidden': isHidden ? __( 'Hidden' ) : undefined,
} );
} }
<section className="edit-post-manage-blocks-modal__category">
<header className="edit-post-manage-blocks-modal__category-header">
<h2 className="edit-post-manage-blocks-modal__category-title">
{ category.title }
</h2>
<BlockManagerHideAll
category={ category }
checked={ ! checkedBlockNames.length }
onChange={ toggleAllHidden }
/>
</header>
<BlockTypesChecklist
blockTypes={ blockTypes }
value={ checkedBlockNames }
onItemChange={ toggleVisible }
/>
</PanelBody>
</section>
);
}

Expand All @@ -75,18 +61,22 @@ export default compose( [
};
} ),
withDispatch( ( dispatch, ownProps ) => {
const { blockItems } = ownProps;
const {
showBlockTypes,
hideBlockTypes,
} = dispatch( 'core/edit-post' );

return {
showBlockTypes,
hideBlockTypes,
toggleAllHidden( isToBeDisabled ) {
const blockNames = map( blockItems, 'id' );
if ( isToBeDisabled ) {
toggleVisible( blockName, nextIsChecked ) {
if ( nextIsChecked ) {
showBlockTypes( blockName );
} else {
hideBlockTypes( blockName );
}
},
toggleAllHidden( nextIsChecked ) {
const blockNames = map( ownProps.blockTypes, 'name' );
if ( nextIsChecked ) {
hideBlockTypes( blockNames );
} else {
showBlockTypes( blockNames );
Expand Down
37 changes: 37 additions & 0 deletions packages/edit-post/src/components/manage-blocks-modal/checklist.js
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>
<BlockIcon icon={ blockType.icon } />
{ blockType.title }
</Fragment>
) }
checked={ value.includes( blockType.name ) }
onChange={ partial( onItemChange, blockType.name ) }
/>
</li>
) ) }
</ul>
);
}

export default BlockTypesChecklist;
36 changes: 36 additions & 0 deletions packages/edit-post/src/components/manage-blocks-modal/hide-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* WordPress dependencies
*/
import { withInstanceId } from '@wordpress/compose';
import { FormToggle } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';

function BlockManagerHideAll( { instanceId, category, checked, onChange } ) {
const id = 'edit-post-manage-blocks-modal__hide-all-' + instanceId;

return (
<div className="edit-post-manage-blocks-modal__hide-all">
<label
htmlFor={ id }
className="edit-post-manage-blocks-modal__hide-all-label"
>
{
/* translators: Checkbox toggle label */
__( 'Hide all' )
}
</label>
<FormToggle
id={ id }
checked={ checked }
onChange={ ( event ) => onChange( event.target.checked ) }
aria-label={ sprintf(
/* translators: Block Visibility accessible checkbox toggle label */
__( 'Hide all blocks in category: %s' ),
category.title
) }
/>
</div>
);
}

export default withInstanceId( BlockManagerHideAll );
Loading