-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Implement image alignment controls #416
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,26 @@ | ||
| .editor-visual-editor__block[data-type="core/image"] { | ||
| &[data-align="left"], | ||
| &[data-align="right"] { | ||
| // Without z-index, won't be clickable as "above" adjacent content | ||
| z-index: 10; | ||
| max-width: 370px; | ||
| } | ||
|
|
||
| &[data-align="left"] { | ||
| float: left; | ||
| margin-right: 15px; | ||
| } | ||
|
|
||
| &[data-align="right"] { | ||
| float: right; | ||
| margin-left: 15px; | ||
| } | ||
| } | ||
|
|
||
| .blocks-image { | ||
| margin: 0; | ||
|
|
||
| img { | ||
| display: block; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,30 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { expect } from 'chai'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getBlockAttributesAsProps } from '../block'; | ||
|
|
||
| describe( 'block', () => { | ||
| describe( 'getBlockAttributesAsProps()', () => { | ||
| it( 'should return an object of data-* attribute props', () => { | ||
| const props = getBlockAttributesAsProps( { | ||
| string: 'string', | ||
| number: 10, | ||
| bool: true, | ||
| object: {}, | ||
| array: [], | ||
| undef: undefined | ||
| } ); | ||
|
|
||
| expect( props ).to.eql( { | ||
| 'data-string': 'string', | ||
| 'data-number': '10', | ||
| 'data-bool': 'true' | ||
| } ); | ||
| } ); | ||
| } ); | ||
| } ); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice workaround :)
I think we should propose an opt-in behaviour (maybe leave it undocumented until needed) and use it in core blocks. I'm a bit concerned with the too many
data-*attributes we'll end up with.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.
In all cases, blocks should be aware of the existence of a wrapper div, thus, I think we should move the
getBlockAttributesAsPropsfunction to the block API. Each block could decide to add any attribute to its parent div.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.
Yeah, I considered that, and it makes more sense now that I reflect on how the styles already make it clear that the block must be aware of the wrapper element. Your suggestion also addresses worries of computing and assigning attributes unnecessarily, dealing with complex attribute types (more accurately, not dealing with), and lends more flexibility to the block to define different / additional props to apply.
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.
I bounced back and forth on a few names, or whether this could somehow be integrated into the
editfunction itself (via callback, or a special shaped return value including metadata).How does
getEditWrapperPropssound to you?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.
It's a good name for now but could be changed later if we settle on changing the
editname