Skip to content

Commit

Permalink
Blocks: Remove obsolete isSelected usage (part 3) (#6280)
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 20, 2018
1 parent 3b8f242 commit cb1b92e
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 208 deletions.
10 changes: 4 additions & 6 deletions blocks/library/preformatted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ export const settings = {
],
},

edit( { attributes, setAttributes, className, isSelected } ) {
edit( { attributes, setAttributes, className } ) {
const { content } = attributes;

return [
return (
<RichText
key="block"
tagName="pre"
value={ content }
onChange={ ( nextContent ) => {
Expand All @@ -73,9 +72,8 @@ export const settings = {
} }
placeholder={ __( 'Write preformatted text…' ) }
wrapperClassName={ className }
isSelected={ isSelected }
/>,
];
/>
);
},

save( { attributes } ) {
Expand Down
63 changes: 32 additions & 31 deletions blocks/library/pullquote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { map } from 'lodash';
*/
import { __ } from '@wordpress/i18n';
import { withState } from '@wordpress/components';
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -72,47 +73,47 @@ export const settings = {
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } );
const onSetActiveEditable = ( newEditable ) => () => setState( { editable: newEditable } );

return [
isSelected && (
<BlockControls key="controls">
return (
<Fragment>
<BlockControls>
<BlockAlignmentToolbar
value={ align }
onChange={ updateAlignment }
/>
</BlockControls>
),
<blockquote key="quote" className={ className }>
<RichText
multiline="p"
value={ toRichTextValue( value ) }
onChange={
( nextValue ) => setAttributes( {
value: fromRichTextValue( nextValue ),
} )
}
/* translators: the text of the quotation */
placeholder={ __( 'Write quote…' ) }
wrapperClassName="blocks-pullquote__content"
isSelected={ isSelected && editable === 'content' }
onFocus={ onSetActiveEditable( 'content' ) }
/>
{ ( citation || isSelected ) && (
<blockquote className={ className }>
<RichText
tagName="cite"
value={ citation }
/* translators: the individual or entity quoted */
placeholder={ __( 'Write citation…' ) }
multiline="p"
value={ toRichTextValue( value ) }
onChange={
( nextCitation ) => setAttributes( {
citation: nextCitation,
( nextValue ) => setAttributes( {
value: fromRichTextValue( nextValue ),
} )
}
isSelected={ isSelected && editable === 'cite' }
onFocus={ onSetActiveEditable( 'cite' ) }
/* translators: the text of the quotation */
placeholder={ __( 'Write quote…' ) }
wrapperClassName="blocks-pullquote__content"
isSelected={ isSelected && editable === 'content' }
onFocus={ onSetActiveEditable( 'content' ) }
/>
) }
</blockquote>,
];
{ ( citation || isSelected ) && (
<RichText
tagName="cite"
value={ citation }
/* translators: the individual or entity quoted */
placeholder={ __( 'Write citation…' ) }
onChange={
( nextCitation ) => setAttributes( {
citation: nextCitation,
} )
}
isSelected={ isSelected && editable === 'cite' }
onFocus={ onSetActiveEditable( 'cite' ) }
/>
) }
</blockquote>
</Fragment>
);
} ),

save( { attributes } ) {
Expand Down
82 changes: 41 additions & 41 deletions blocks/library/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import classnames from 'classnames';
*/
import { __, sprintf } from '@wordpress/i18n';
import { Toolbar, withState } from '@wordpress/components';
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -171,9 +172,9 @@ export const settings = {
setState( { editable: newEditable } );
};

return [
isSelected && (
<BlockControls key="controls">
return (
<Fragment>
<BlockControls>
<Toolbar controls={ [ 1, 2 ].map( ( variation ) => ( {
icon: 1 === variation ? 'format-quote' : 'testimonial',
title: sprintf( __( 'Quote style %d' ), variation ),
Expand All @@ -189,49 +190,48 @@ export const settings = {
} }
/>
</BlockControls>
),
<blockquote
key="quote"
className={ containerClassname }
style={ { textAlign: align } }
>
<RichText
multiline="p"
value={ toRichTextValue( value ) }
onChange={
( nextValue ) => setAttributes( {
value: fromRichTextValue( nextValue ),
} )
}
onMerge={ mergeBlocks }
onRemove={ ( forward ) => {
const hasEmptyCitation = ! citation || citation.length === 0;
if ( ! forward && hasEmptyCitation ) {
onReplace( [] );
}
} }
/* translators: the text of the quotation */
placeholder={ __( 'Write quote…' ) }
isSelected={ isSelected && editable === 'content' }
onFocus={ onSetActiveEditable( 'content' ) }
/>
{ ( ( citation && citation.length > 0 ) || isSelected ) && (
<blockquote
className={ containerClassname }
style={ { textAlign: align } }
>
<RichText
tagName="cite"
value={ citation }
multiline="p"
value={ toRichTextValue( value ) }
onChange={
( nextCitation ) => setAttributes( {
citation: nextCitation,
( nextValue ) => setAttributes( {
value: fromRichTextValue( nextValue ),
} )
}
/* translators: the individual or entity quoted */
placeholder={ __( 'Write citation…' ) }
isSelected={ isSelected && editable === 'cite' }
onFocus={ onSetActiveEditable( 'cite' ) }
onMerge={ mergeBlocks }
onRemove={ ( forward ) => {
const hasEmptyCitation = ! citation || citation.length === 0;
if ( ! forward && hasEmptyCitation ) {
onReplace( [] );
}
} }
/* translators: the text of the quotation */
placeholder={ __( 'Write quote…' ) }
isSelected={ isSelected && editable === 'content' }
onFocus={ onSetActiveEditable( 'content' ) }
/>
) }
</blockquote>,
];
{ ( ( citation && citation.length > 0 ) || isSelected ) && (
<RichText
tagName="cite"
value={ citation }
onChange={
( nextCitation ) => setAttributes( {
citation: nextCitation,
} )
}
/* translators: the individual or entity quoted */
placeholder={ __( 'Write citation…' ) }
isSelected={ isSelected && editable === 'cite' }
onFocus={ onSetActiveEditable( 'cite' ) }
/>
) }
</blockquote>
</Fragment>
);
} ),

save( { attributes } ) {
Expand Down
4 changes: 1 addition & 3 deletions blocks/library/subhead/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ export const settings = {
],
},

edit( { attributes, setAttributes, isSelected, className } ) {
edit( { attributes, setAttributes, className } ) {
const { content, placeholder } = attributes;

return (
<RichText
tagName="p"
key="editable"
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
Expand All @@ -72,7 +71,6 @@ export const settings = {
} }
className={ className }
placeholder={ placeholder || __( 'Write subhead…' ) }
isSelected={ isSelected }
/>
);
},
Expand Down
32 changes: 18 additions & 14 deletions blocks/library/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import { __ } from '@wordpress/i18n';

/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -56,25 +61,24 @@ export const settings = {
edit( { attributes, setAttributes, isSelected, className } ) {
const { content } = attributes;
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } );
return [
isSelected && (
<BlockControls key="toolbar">
return (
<Fragment>
<BlockControls>
<BlockAlignmentToolbar
value={ attributes.align }
onChange={ updateAlignment }
/>
</BlockControls>
),
<TableBlock
key="editor"
onChange={ ( nextContent ) => {
setAttributes( { content: nextContent } );
} }
content={ content }
className={ className }
isSelected={ isSelected }
/>,
];
<TableBlock
onChange={ ( nextContent ) => {
setAttributes( { content: nextContent } );
} }
content={ content }
className={ className }
isSelected={ isSelected }
/>
</Fragment>
);
},

save( { attributes } ) {
Expand Down
38 changes: 18 additions & 20 deletions blocks/library/table/table-block.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { Component, Fragment } from '@wordpress/element';
import { Toolbar, DropdownMenu } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -94,23 +94,21 @@ export default class TableBlock extends Component {
render() {
const { content, onChange, className, isSelected } = this.props;

return [
<RichText
key="editor"
tagName="table"
wrapperClassName={ className }
getSettings={ ( settings ) => ( {
...settings,
plugins: ( settings.plugins || [] ).concat( 'table' ),
table_tab_navigation: false,
} ) }
onSetup={ ( editor ) => this.handleSetup( editor, isSelected ) }
onChange={ onChange }
value={ content }
isSelected={ isSelected }
/>,
isSelected && (
<BlockControls key="menu">
return (
<Fragment>
<RichText
tagName="table"
wrapperClassName={ className }
getSettings={ ( settings ) => ( {
...settings,
plugins: ( settings.plugins || [] ).concat( 'table' ),
table_tab_navigation: false,
} ) }
onSetup={ ( editor ) => this.handleSetup( editor, isSelected ) }
onChange={ onChange }
value={ content }
/>
<BlockControls>
<Toolbar>
<DropdownMenu
icon="editor-table"
Expand All @@ -123,7 +121,7 @@ export default class TableBlock extends Component {
/>
</Toolbar>
</BlockControls>
),
];
</Fragment>
);
}
}
Loading

0 comments on commit cb1b92e

Please sign in to comment.