-
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 gallery crop option in Inspector #1545
Changes from all commits
389fc17
3969523
09b6c41
3a60e05
20ce5d8
5ccb8ca
5ebb52f
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,6 +12,7 @@ import { registerBlockType, query as hpq } from '../../api'; | |
import MediaUploadButton from '../../media-upload-button'; | ||
import InspectorControls from '../../inspector-controls'; | ||
import RangeControl from '../../inspector-controls/range-control'; | ||
import ToggleControl from '../../inspector-controls/toggle-control'; | ||
import BlockControls from '../../block-controls'; | ||
import BlockAlignmentToolbar from '../../block-alignment-toolbar'; | ||
import GalleryImage from './gallery-image'; | ||
|
@@ -75,6 +76,8 @@ registerBlockType( 'core/gallery', { | |
const { images = [], columns = defaultColumnsNumber( attributes ), align = 'none' } = attributes; | ||
const setColumnsNumber = ( event ) => setAttributes( { columns: event.target.value } ); | ||
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } ); | ||
const { imageCrop = true } = attributes; | ||
const toggleImageCrop = () => setAttributes( { imageCrop: ! imageCrop } ); | ||
|
||
const controls = ( | ||
focus && ( | ||
|
@@ -121,16 +124,24 @@ registerBlockType( 'core/gallery', { | |
controls, | ||
focus && images.length > 1 && ( | ||
<InspectorControls key="inspector"> | ||
<p className="editor-block-inspector__description">Image galleries are a great way to share groups of pictures on your site.</p> | ||
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. just mind note: we should create a component for this 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 could create a PR for that if nobody is working on it yet. Sounds quite simple. 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. Go for it! |
||
<hr /> | ||
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. Is this something we want after every description? Perhaps we should do it with a CSS border in that case. 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. 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. Sounds good. |
||
<h3>{ __( 'Gallery Settings' ) }</h3> | ||
<RangeControl | ||
label={ __( 'Columns' ) } | ||
value={ columns } | ||
onChange={ setColumnsNumber } | ||
min="1" | ||
max={ Math.min( MAX_COLUMNS, images.length ) } | ||
/> | ||
<ToggleControl | ||
label={ __( 'Crop Images' ) } | ||
checked={ !! imageCrop } | ||
onChange={ toggleImageCrop } | ||
/> | ||
</InspectorControls> | ||
), | ||
<div key="gallery" className={ `${ className } align${ align } columns-${ columns }` }> | ||
<div key="gallery" className={ `${ className } align${ align } columns-${ columns } ${ imageCrop ? 'is-cropped' : '' }` }> | ||
{ images.map( ( img ) => ( | ||
<GalleryImage key={ img.url } img={ img } /> | ||
) ) } | ||
|
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 the description should be shown at all times, not just when there's more than 1 image. Of course, this check makes sense for the 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.
Wonder if we even need a description for this block.
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.
Responded in core slack, I think this is a great place to show contextual help. We want to ensure to have best practices in place that suggest no more than 2 lines, but it feels like it's worth using this spot to show this.