-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Blocks: Refactor blocks to use supports align #5099
Changes from all commits
b4ebda2
baaa079
9b1d5ae
e19d12b
ddad84d
3a32e1c
f903bb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ import './editor.scss'; | |
import './style.scss'; | ||
import RichText from '../../rich-text'; | ||
import UrlInput from '../../url-input'; | ||
import BlockControls from '../../block-controls'; | ||
import BlockAlignmentToolbar from '../../block-alignment-toolbar'; | ||
import ColorPalette from '../../color-palette'; | ||
import ContrastChecker from '../../contrast-checker'; | ||
import InspectorControls from '../../inspector-controls'; | ||
|
@@ -67,18 +65,12 @@ class ButtonBlock extends Component { | |
text, | ||
url, | ||
title, | ||
align, | ||
color, | ||
textColor, | ||
clear, | ||
} = attributes; | ||
|
||
return [ | ||
isSelected && ( | ||
<BlockControls key="controls"> | ||
<BlockAlignmentToolbar value={ align } onChange={ this.updateAlignment } /> | ||
</BlockControls> | ||
), | ||
<span key="button" className={ className } title={ title } ref={ this.bindRef }> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this will no longer need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my previous comment. |
||
<RichText | ||
tagName="span" | ||
|
@@ -157,10 +149,6 @@ const blockAttributes = { | |
source: 'children', | ||
selector: 'a', | ||
}, | ||
align: { | ||
type: 'string', | ||
default: 'none', | ||
}, | ||
color: { | ||
type: 'string', | ||
}, | ||
|
@@ -182,13 +170,13 @@ export const settings = { | |
|
||
attributes: blockAttributes, | ||
|
||
getEditWrapperProps( attributes ) { | ||
const { align, clear } = attributes; | ||
const props = { 'data-resized': true }; | ||
supports: { | ||
align: true, | ||
alignWide: false, | ||
}, | ||
|
||
if ( 'left' === align || 'right' === align || 'center' === align ) { | ||
props[ 'data-align' ] = align; | ||
} | ||
getEditWrapperProps( { clear } ) { | ||
const props = { 'data-resized': true }; | ||
|
||
if ( clear ) { | ||
props[ 'data-clear' ] = 'true'; | ||
|
@@ -200,7 +188,7 @@ export const settings = { | |
edit: ButtonBlock, | ||
|
||
save( { attributes } ) { | ||
const { url, text, title, align, color, textColor } = attributes; | ||
const { url, text, title, color, textColor } = attributes; | ||
|
||
const buttonStyle = { | ||
backgroundColor: color, | ||
|
@@ -210,7 +198,7 @@ export const settings = { | |
const linkClass = 'wp-block-button__link'; | ||
|
||
return ( | ||
<div className={ `align${ align }` }> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only unfortunate thing about these "magic" supports. It becomes very non-obvious why we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this might have up to 3 class names inserted in here :) |
||
<div> | ||
<a className={ linkClass } href={ url } title={ title } style={ buttonStyle }> | ||
{ text } | ||
</a> | ||
|
@@ -219,7 +207,13 @@ export const settings = { | |
}, | ||
|
||
deprecated: [ { | ||
attributes: blockAttributes, | ||
attributes: { | ||
...blockAttributes, | ||
align: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it will work. The |
||
type: 'string', | ||
default: 'none', | ||
}, | ||
}, | ||
|
||
save( { attributes } ) { | ||
const { url, text, title, align, color, textColor } = attributes; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer needs to be returned as an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an optional
form
in line 117: https://github.com/WordPress/gutenberg/blob/a3ceee55afbe0200a1567945e14de6f3b3f14f61/blocks/library/button/index.js#L117. It only seems that you can omit array structure here :)