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

Bring consistency to block toolbar for text blocks #15964

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 13 additions & 8 deletions packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,24 @@ function HeadingEdit( {
return (
<>
<BlockControls>
<HeadingToolbar minLevel={ 2 } maxLevel={ 5 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />
<HeadingToolbar
isCollapsed
minLevel={ 1 }
maxLevel={ 7 }
selectedLevel={ level }
onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) }
/>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Heading Settings' ) }>
<p>{ __( 'Level' ) }</p>
<HeadingToolbar minLevel={ 1 } maxLevel={ 7 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />
<p>{ __( 'Text Alignment' ) }</p>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
</PanelBody>
<HeadingColorUI
setTextColor={ setTextColor }
Expand Down
9 changes: 7 additions & 2 deletions packages/block-library/src/heading/heading-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ class HeadingToolbar extends Component {
}

render() {
const { minLevel, maxLevel, selectedLevel, onChange } = this.props;
const { isCollapsed, minLevel, maxLevel, selectedLevel, onChange } = this.props;

return (
<Toolbar controls={ range( minLevel, maxLevel ).map( ( index ) => this.createLevelControl( index, selectedLevel, onChange ) ) } />
<Toolbar
controls={ range( minLevel, maxLevel ).map( ( index ) => this.createLevelControl( index, selectedLevel, onChange ) ) }
icon="heading"
isCollapsed={ isCollapsed }
/>
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/list/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "core/list",
"category": "common",
"attributes": {
"align": {
"type": "string"
},
"ordered": {
"type": "boolean",
"default": false
Expand Down
54 changes: 36 additions & 18 deletions packages/block-library/src/list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
import { __ } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
import { RichText } from '@wordpress/block-editor';
import {
AlignmentToolbar,
BlockControls,
RichText,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -17,24 +21,38 @@ export default function ListEdit( {
onReplace,
className,
} ) {
const { ordered, values } = attributes;
const { align, ordered, values } = attributes;

return (
<RichText
identifier="values"
multiline="li"
tagName={ ordered ? 'ol' : 'ul' }
onChange={ ( nextValues ) => setAttributes( { values: nextValues } ) }
value={ values }
wrapperClassName="block-library-list"
className={ className }
placeholder={ __( 'Write list…' ) }
onMerge={ mergeBlocks }
onSplit={ ( value ) => createBlock( name, { ordered, values: value } ) }
__unstableOnSplitMiddle={ () => createBlock( 'core/paragraph' ) }
onReplace={ onReplace }
onRemove={ () => onReplace( [] ) }
onTagNameChange={ ( tag ) => setAttributes( { ordered: tag === 'ol' } ) }
/>
<>
<BlockControls>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
</BlockControls>
<RichText
identifier="values"
multiline="li"
tagName={ ordered ? 'ol' : 'ul' }
onChange={ ( nextValues ) => setAttributes( { values: nextValues } ) }
value={ values }
wrapperClassName="block-library-list"
className={ className }
placeholder={ __( 'Write list…' ) }
onMerge={ mergeBlocks }
onSplit={ ( value ) => createBlock( name, { ordered, values: value } ) }
__unstableOnSplitMiddle={ () => createBlock( 'core/paragraph' ) }
onReplace={ onReplace }
onRemove={ () => onReplace( [] ) }
onTagNameChange={ ( tag ) => setAttributes( { ordered: tag === 'ol' } ) }
style={ {
textAlign: align,
listStylePosition: 'inside',
} }
/>
</>
);
}
8 changes: 6 additions & 2 deletions packages/block-library/src/list/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import { RichText } from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { ordered, values } = attributes;
const { align, ordered, values } = attributes;
const tagName = ordered ? 'ol' : 'ul';
const styles = {
textAlign: align,
listStylePosition: 'inside',
gziolo marked this conversation as resolved.
Show resolved Hide resolved
};

return (
<RichText.Content tagName={ tagName } value={ values } multiline="li" />
<RichText.Content tagName={ tagName } style={ styles } value={ values } multiline="li" />
);
}
2 changes: 2 additions & 0 deletions packages/block-library/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@
}

.has-text-align-left {
/*rtl:ignore*/
text-align: left;
}

.has-text-align-right {
/*rtl:ignore*/
text-align: right;
}

Expand Down