-
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
Try new gallery markup #3996
Try new gallery markup #3996
Changes from 3 commits
d8eaefb
4466445
3da0798
450f716
91b2504
d04b78d
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 |
---|---|---|
|
@@ -33,7 +33,7 @@ registerBlockType( 'core/gallery', { | |
type: 'array', | ||
default: [], | ||
source: 'query', | ||
selector: 'div.wp-block-gallery figure.blocks-gallery-image img', | ||
selector: 'ul.wp-block-gallery .blocks-gallery-item img', | ||
query: { | ||
url: { | ||
source: 'attribute', | ||
|
@@ -151,7 +151,7 @@ registerBlockType( 'core/gallery', { | |
save( { attributes } ) { | ||
const { images, columns = defaultColumnsNumber( attributes ), align, imageCrop, linkTo } = attributes; | ||
return ( | ||
<div className={ `align${ align } columns-${ columns } ${ imageCrop ? 'is-cropped' : '' }` } > | ||
<ul className={ `align${ align } columns-${ columns } ${ imageCrop ? 'is-cropped' : '' }` } > | ||
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. Can't review fully today but quick note here, we should add a "deprecated" section (see quote block as an example) to avoid invalidating existing galleries. |
||
{ images.map( ( image ) => { | ||
let href; | ||
|
||
|
@@ -167,13 +167,49 @@ registerBlockType( 'core/gallery', { | |
const img = <img src={ image.url } alt={ image.alt } data-id={ image.id } />; | ||
|
||
return ( | ||
<figure key={ image.id || image.url } className="blocks-gallery-image"> | ||
{ href ? <a href={ href }>{ img }</a> : img } | ||
</figure> | ||
<li key={ image.id || image.url } className="blocks-gallery-item"> | ||
<figure> | ||
{ href ? <a href={ href }>{ img }</a> : img } | ||
</figure> | ||
</li> | ||
); | ||
} ) } | ||
</div> | ||
</ul> | ||
); | ||
}, | ||
|
||
deprecated: [ | ||
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. In the deprecated section, you can just paste the old "attributes" and "save" functions before the change. 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. All of them, or just the changed attributes? |
||
{ | ||
save( { attributes } ) { | ||
const { images, columns = defaultColumnsNumber( attributes ), align, imageCrop, linkTo } = attributes; | ||
return ( | ||
<div className={ `align${ align } columns-${ columns } ${ imageCrop ? 'is-cropped' : '' }` } > | ||
{ images.map( ( image ) => { | ||
let href; | ||
|
||
switch ( linkTo ) { | ||
case 'media': | ||
href = image.url; | ||
break; | ||
case 'attachment': | ||
href = image.link; | ||
break; | ||
} | ||
|
||
const img = <img src={ image.url } alt={ image.alt } data-id={ image.id } />; | ||
|
||
return ( | ||
<li key={ image.id || image.url } className="blocks-gallery-item"> | ||
<figure> | ||
{ href ? <a href={ href }>{ img }</a> : img } | ||
</figure> | ||
</li> | ||
); | ||
} ) } | ||
</div> | ||
); | ||
}, | ||
}, | ||
], | ||
|
||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,29 @@ | |
.wp-block-gallery.aligncenter { | ||
display: flex; | ||
flex-wrap: wrap; | ||
list-style-type: none; | ||
|
||
.blocks-gallery-image { | ||
.blocks-gallery-item { | ||
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. Should we keep both classnames to avoid breaking old blocks styling? |
||
margin: 8px; | ||
display: flex; | ||
flex-grow: 1; | ||
flex-direction: column; | ||
justify-content: center; | ||
|
||
figure { | ||
height: 100%; | ||
margin: 0; | ||
} | ||
|
||
img { | ||
display: block; | ||
max-width: 100%; | ||
height: auto; | ||
} | ||
} | ||
|
||
// Cropped | ||
&.is-cropped .blocks-gallery-image { | ||
&.is-cropped .blocks-gallery-item { | ||
img { | ||
flex: 1; | ||
width: 100%; | ||
|
@@ -29,47 +36,26 @@ | |
} | ||
|
||
// Alas, IE11+ doesn't support object-fit | ||
_:-ms-lang(x), img { | ||
_:-ms-lang(x), figure { | ||
height: auto; | ||
width: auto; | ||
} | ||
} | ||
|
||
&.columns-1 figure { | ||
width: calc(100% / 1 - 16px); | ||
} | ||
&.columns-2 figure { | ||
width: calc(100% / 2 - 16px); | ||
// Responsive fallback value, 2 columns | ||
& .blocks-gallery-item { | ||
width: calc( 100% / 2 - 16px ); | ||
} | ||
|
||
// Responsive fallback value, 2 columns | ||
&.columns-3 figure, | ||
&.columns-4 figure, | ||
&.columns-5 figure, | ||
&.columns-6 figure, | ||
&.columns-7 figure, | ||
&.columns-8 figure { | ||
width: calc(100% / 2 - 16px); | ||
&.columns-1 .blocks-gallery-item { | ||
width: calc(100% / 1 - 16px); | ||
} | ||
|
||
@include break-small { | ||
&.columns-3 figure { | ||
width: calc(100% / 3 - 16px); | ||
} | ||
&.columns-4 figure { | ||
width: calc(100% / 4 - 16px); | ||
} | ||
&.columns-5 figure { | ||
width: calc(100% / 5 - 16px); | ||
} | ||
&.columns-6 figure { | ||
width: calc(100% / 6 - 16px); | ||
} | ||
&.columns-7 figure { | ||
width: calc(100% / 7 - 16px); | ||
} | ||
&.columns-8 figure { | ||
width: calc(100% / 8 - 16px); | ||
@for $i from 3 through 8 { | ||
&.columns-#{ $i } .blocks-gallery-item { | ||
width: calc(100% / #{ $i } - 16px ); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
<!-- wp:core/gallery --> | ||
<div class="wp-block-gallery alignnone columns-2 is-cropped"> | ||
<figure class="blocks-gallery-image"> | ||
<img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /> | ||
</figure> | ||
<figure class="blocks-gallery-image"> | ||
<img src="http://google.com/hi.png" alt="title" /> | ||
</figure> | ||
</div> | ||
<ul class="wp-block-gallery alignnone columns-2 is-cropped"> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /> | ||
</figure> | ||
</li> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="http://google.com/hi.png" alt="title" /> | ||
</figure> | ||
</li> | ||
</ul> | ||
<!-- /wp:core/gallery --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
<!-- wp:gallery --> | ||
<div class="wp-block-gallery alignnone columns-2 is-cropped"> | ||
<figure class="blocks-gallery-image"><img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /></figure> | ||
<figure class="blocks-gallery-image"><img src="http://google.com/hi.png" alt="title" /></figure> | ||
</div> | ||
<ul class="wp-block-gallery alignnone columns-2 is-cropped"> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /> | ||
</figure> | ||
</li> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="http://google.com/hi.png" alt="title" /> | ||
</figure> | ||
</li> | ||
</ul> | ||
<!-- /wp:gallery --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
<!-- wp:core/gallery {"columns":"1"} --> | ||
<div class="wp-block-gallery alignnone columns-1 is-cropped"> | ||
<figure class="blocks-gallery-image"> | ||
<img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /> | ||
</figure> | ||
<figure class="blocks-gallery-image"> | ||
<img src="http://google.com/hi.png" alt="title" /> | ||
</figure> | ||
</div> | ||
<ul class="wp-block-gallery columns-1 "> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /> | ||
</figure> | ||
</li> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="http://google.com/hi.png" alt="title" /> | ||
</figure> | ||
</li> | ||
</ul> | ||
<!-- /wp:core/gallery --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
<!-- wp:gallery {"columns":1} --> | ||
<div class="wp-block-gallery alignnone columns-1 is-cropped"> | ||
<figure class="blocks-gallery-image"><img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /></figure> | ||
<figure class="blocks-gallery-image"><img src="http://google.com/hi.png" alt="title" /></figure> | ||
</div> | ||
<ul class="wp-block-gallery columns-1 "> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /> | ||
</figure> | ||
</li> | ||
<li class="blocks-gallery-item"> | ||
<figure> | ||
<img src="http://google.com/hi.png" alt="title" /> | ||
</figure> | ||
</li> | ||
</ul> | ||
<!-- /wp:gallery --> |
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.
Is the classname change here intentional?
.blocks-gallery-item
? because this should reflect what's generated in thesave
function (not theedit
)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.
.blocks-gallery-item
is intentional because it's now in<li>
element, not in<figure>
element. Therefore.blocks-gallery-image
sounded weird for<li>
.