-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add cover image #879
Add cover image #879
Conversation
post-content.js
Outdated
'<!-- /wp:core/cover-image -->', | ||
|
||
'<!-- wp:core/heading -->', | ||
'<h1>Welcome to the Gutenberg Editor</h1>', |
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 is no longer part of the demo content.
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.
Thanks, must have been a merge conflict.
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.
Thanks for your help on this block. I left some small notes
blocks/library/cover-image/index.js
Outdated
</div> | ||
<Button isLarge> | ||
{ wp.i18n.__( 'Insert from Media Library' ) } | ||
</Button> |
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.
The media library integration is already available through the MediaUploadButton
. see https://github.com/WordPress/gutenberg/blob/master/blocks/library/image/index.js#L89
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.
We need to start thinking about documenting these (editable, media button, the iframe thing).
blocks/library/cover-image/index.js
Outdated
title: wp.i18n.__( 'Change Image' ), | ||
isActive: ( { align } ) => 'left' === align, | ||
onClick: toggleAlignment( 'left' ), | ||
}, |
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.
What is this control for? should we drop it?
blocks/library/cover-image/index.js
Outdated
category: 'common', | ||
|
||
attributes: { | ||
url: attr( 'section', 'data-url' ), |
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.
FWIW, it's possible to drop the url
attribute here and the url will be saved in the block opening comment.
blocks/library/cover-image/index.js
Outdated
import { registerBlock, query } from '../../api'; | ||
import Editable from '../../editable'; | ||
// TODO: Revisit when we have a common components solution | ||
import Dashicon from '../../../components/dashicon'; |
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.
Should we move this to the WordPress dependencies import Dashicon from 'components/dashicon';
?
@mtias and @youknowriad thank you for the 👀 , the feedback is really helpful for me (as someone less familiar with the project). I'm still getting the block working, and after that I'll work on cleaning everything up. |
b174020
to
ed8fb8e
Compare
@jasmussen would you kindly try this block out and let me know how it feels? I'm still working on a parallax setting but the core functionality should be there |
I like it! I have a bunch of small things, including a different UI for adding/changing the image, but I think we might want to try and keep things minimal for the first merge, then iterate. There isn't any |
@jasmussen I wanted to make sure I was on the right path before going too far down it. I'm going to play with a few settings for |
@youknowriad could you take another look at this? I'm ready to merge |
|
@mkaz thanks, I'll check out the backspace. For alignment vs pin I see the argument for allowing something to be both aligned and pinned. I'll try out a few CSS tweaks to see how they look. |
blocks/library/cover-image/index.js
Outdated
/** | ||
* WordPress dependencies | ||
*/ | ||
import Placeholder from 'components/placeholder'; |
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.
We should use import { Placeholder } from 'components';
to avoid duplication in the built files. (We should probably make this clearer in our dev docs)
blocks/library/cover-image/index.js
Outdated
title: text( 'h2' ), | ||
}, | ||
|
||
controls: [ |
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.
If you rebase master, you'll notice this property doesn't work anymore and I suggest using <BlockAlignmentToolbar>
for alignment controls. See #1019 for examples.
blocks/library/cover-image/index.js
Outdated
}; | ||
|
||
registerBlockType( 'core/cover-image', { | ||
title: wp.i18n.__( 'Cover Image' ), |
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.
We're trying to avoid using the wp
global variable as much as we can in favor of import { __ } from 'i18n
. See #1332 for context on this.
blocks/library/cover-image/index.js
Outdated
|
||
editFrame.on( 'insert', updateFn ); | ||
editFrame.open( 'cover-image' ); | ||
}; |
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 is the second block allowing to edit a media. I wonder if should try to factorize this in MediaUploadButton
or similar. This could be done in a separate PR.
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'm going to remove this for now but I think it may make sense as a follow-up as it's own InspectorControl
.
blocks/library/cover-image/index.js
Outdated
buttonProps={ uploadButtonProps } | ||
onSelect={ setMediaUrl } | ||
type="image" | ||
auto-open |
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.
auto-open has been rename autoOpen
@georgeh we should try to use |
@@ -25,6 +25,10 @@ const BLOCK_ALIGNMENTS_CONTROLS = { | |||
icon: 'align-full-width', | |||
title: __( 'Full width' ), | |||
}, | |||
fixed: { |
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 think this should be a toggle in the inspector, not a shared alignment.
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'm going to make a CheckboxControl
to use in the inspector
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.
Should probably just use the existing toggle component for this (see the drop cap setting for text). cc @jasmussen
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.
Looking at the code for TextboxControl
it looks like I can pass type="checkbox"
- how do you feel about me renaming that to InputControl
?
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.
Yes if we were to make a toggle for this it should just be the existing switch:
But I think it's okay to actually remove this advanced property for now to just get the PR merged, if that's simpler.
Alternately, I feel pretty strongly that the fixed background should be applied by default. And it should not be a data-align
value. It should be something you can toggle in addition to the image alignment.
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.
Yes, it's not an alignment, just an extra attribute.
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 gave George the go-ahead to merge this without this fixed position toggle (which we just removed). I think it's good to merge this block, and we can add the toggle separately if we desire it.
Thanks to @mkaz for the pairing session to get it done
Now using the new `<BlockControls>` to manage the image position. Also removed the ability to change the picture pending moving it into the inspector Also addressed changes in the PR to remove `wp` global and fix autoOpen the MediaUploadButton
- Make background attachment fixed by default. Let's either remove the option to pin it entirely, or move it to the inspector and make it something that's on by default. - Added gray scrim, removed text shadow, reduced font size - Removed alignments because these are now inherited Future improvements we should also consider: add the full-wide button that images have now, and make it so the dark scrim is only present when there's text.
cb1f6ac
to
6985c7b
Compare
Okay I think this is good to go! 👍 👍 |
Addresses #487
TODO
Pre-select image in image chooser when replacing the image