Skip to content
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 lightbox option in gallery block link control #64014

Merged
merged 30 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4dae199
Add link control as toolbar option in gallery
akasunil Jul 26, 2024
9284ea3
Add link option constant for lightbox
akasunil Jul 26, 2024
ba7b225
Add expand on lick option in link control
akasunil Jul 26, 2024
600c2a2
Add class into menugroup component for info text style
akasunil Jul 26, 2024
9342259
Add styles for info text in link control of popover of gallery block
akasunil Jul 26, 2024
624e1d5
Synced with trunk and resolved conflicts
akasunil Jul 30, 2024
f698871
Add info text for lightbox option in link control for gallery block
akasunil Jul 30, 2024
cf487dd
Add action for lightbox option in gallery block link control
akasunil Jul 31, 2024
f2ddb4d
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Aug 1, 2024
9f490b4
Show lightbox option only when lightbox UI is enabled
akasunil Aug 1, 2024
52934e0
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Aug 2, 2024
db15f40
Disable lightbox when other link option is selected in gallery block
akasunil Aug 2, 2024
bfd6bbd
Remove unneccessory constant
akasunil Aug 2, 2024
a3ce105
Conditionally apply the lightbox attribute based on defatult setting
akasunil Aug 2, 2024
9bdcd09
Fix lightbox default option issue for gallery block on page load
akasunil Aug 6, 2024
475a255
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Aug 6, 2024
aa70389
Highlight link to option in gallery block when selected
akasunil Aug 6, 2024
524ea5a
update condition to Highlight link to option
akasunil Aug 7, 2024
7fcd7ea
Fix lightbox attribute issue for default state of linkTo option
akasunil Aug 7, 2024
8bf2339
fix: Set empty default `block` settings value (#64448)
dcalhoun Aug 13, 2024
0ebdc1f
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Aug 13, 2024
20040eb
Change lightbox option lable and address other feedback
akasunil Aug 13, 2024
ac6c169
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Aug 16, 2024
a39977f
Move lightbox logic to getHrefAndDestination function
akasunil Aug 16, 2024
da0272f
Merge branch 'trunk' into update/gallery-block-image-link-control-opt…
t-hamano Aug 20, 2024
d2879cd
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Aug 21, 2024
d79d610
Remove highlight of LinkTo option in gallery block
akasunil Aug 21, 2024
655433b
Remove css for info text of lightbox option
akasunil Aug 21, 2024
0e2b6ec
Refactor getHrefAndDestination function to for lightbox additional at…
akasunil Aug 21, 2024
646e497
Merge branch 'trunk' of github.com:WordPress/gutenberg into update/ga…
akasunil Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-library/src/gallery/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const LINK_DESTINATION_NONE = 'none';
export const LINK_DESTINATION_MEDIA = 'media';
export const LINK_DESTINATION_LIGHTBOX = 'lightbox';
export const LINK_DESTINATION_ATTACHMENT = 'attachment';
export const LINK_DESTINATION_MEDIA_WP_CORE = 'file';
export const LINK_DESTINATION_ATTACHMENT_WP_CORE = 'post';
64 changes: 58 additions & 6 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
useInnerBlocksProps,
BlockControls,
MediaReplaceFlow,
useSettings,
} from '@wordpress/block-editor';
import { Platform, useEffect, useMemo } from '@wordpress/element';
import { __, _x, sprintf } from '@wordpress/i18n';
Expand All @@ -41,6 +42,7 @@ import {
customLink,
image as imageIcon,
linkOff,
fullscreen,
} from '@wordpress/icons';

/**
Expand All @@ -58,14 +60,15 @@ import {
LINK_DESTINATION_ATTACHMENT,
LINK_DESTINATION_MEDIA,
LINK_DESTINATION_NONE,
LINK_DESTINATION_LIGHTBOX,
} from './constants';
import useImageSizes from './use-image-sizes';
import useGetNewImages from './use-get-new-images';
import useGetMedia from './use-get-media';
import GapStyles from './gap-styles';

const MAX_COLUMNS = 8;
const linkOptions = [
let linkOptions = [
{
icon: customLink,
label: __( 'Link images to attachment pages' ),
Expand All @@ -78,6 +81,13 @@ const linkOptions = [
value: LINK_DESTINATION_MEDIA,
noticeText: __( 'Media Files' ),
},
{
icon: fullscreen,
label: __( 'Expand on click' ),
value: LINK_DESTINATION_LIGHTBOX,
noticeText: __( 'Lightbox effect' ),
infoText: __( 'Scales the image with a lightbox effect' ),
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
},
{
icon: linkOff,
label: _x( 'None', 'Media item link option' ),
Expand Down Expand Up @@ -110,6 +120,20 @@ function GalleryEdit( props ) {
onFocus,
} = props;

const [ blockSetting ] = useSettings( 'blocks' );

const lightboxSetting = blockSetting.hasOwnProperty( 'core/image' )
? blockSetting[ 'core/image' ]?.lightbox
: false;
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

useEffect( () => {
if ( ! lightboxSetting?.allowEditing ) {
linkOptions = linkOptions.filter(
( option ) => option.value !== LINK_DESTINATION_LIGHTBOX
);
}
}, [ lightboxSetting?.allowEditing ] );
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

const { columns, imageCrop, randomOrder, linkTarget, linkTo, sizeSlug } =
attributes;

Expand Down Expand Up @@ -366,10 +390,34 @@ function GalleryEdit( props ) {
const image = block.attributes.id
? imageData.find( ( { id } ) => id === block.attributes.id )
: null;
changedAttributes[ block.clientId ] = getHrefAndDestination(
image,
value
);

let hrefAndDestination = getHrefAndDestination( image, value );

if (
value === LINK_DESTINATION_LIGHTBOX &&
! lightboxSetting?.enabled
) {
hrefAndDestination = {
...hrefAndDestination,
lightbox: { enabled: true },
};
} else if (
value !== LINK_DESTINATION_NONE &&
value !== LINK_DESTINATION_LIGHTBOX &&
lightboxSetting?.enabled
) {
hrefAndDestination = {
...hrefAndDestination,
lightbox: { enabled: false },
};
} else {
hrefAndDestination = {
...hrefAndDestination,
lightbox: undefined,
};
}
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

changedAttributes[ block.clientId ] = hrefAndDestination;
} );
updateBlockAttributes( blocks, changedAttributes, true );
const linkToText = [ ...linkOptions ].find(
Expand Down Expand Up @@ -622,9 +670,12 @@ function GalleryEdit( props ) {
<ToolbarDropdownMenu
icon={ linkIcon }
label={ __( 'Link' ) }
toggleProps={ {
isPressed: hasLinkTo,
} }
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
>
{ ( { onClose } ) => (
<MenuGroup>
<MenuGroup className="blocks-gallery__link-to-control">
{ linkOptions.map( ( linkItem ) => {
const isOptionSelected =
linkTo === linkItem.value;
Expand All @@ -646,6 +697,7 @@ function GalleryEdit( props ) {
onClose();
} }
role="menuitemradio"
info={ linkItem.infoText ?? false }
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
>
{ linkItem.label }
</MenuItem>
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/gallery/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,11 @@
justify-content: flex-end;
gap: $grid-unit-15;
}

.blocks-gallery__link-to-control {
.components-menu-item__item {
.components-menu-item__info {
white-space: nowrap;
}
}
}
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions packages/block-library/src/gallery/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LINK_DESTINATION_NONE,
LINK_DESTINATION_MEDIA_WP_CORE,
LINK_DESTINATION_ATTACHMENT_WP_CORE,
LINK_DESTINATION_LIGHTBOX,
} from './constants';
import {
LINK_DESTINATION_ATTACHMENT as IMAGE_LINK_DESTINATION_ATTACHMENT,
Expand Down Expand Up @@ -43,6 +44,12 @@ export function getHrefAndDestination(
href: image?.link,
linkDestination: IMAGE_LINK_DESTINATION_ATTACHMENT,
};
case LINK_DESTINATION_LIGHTBOX:
return {
href: undefined,
lightbox: { enabled: true },
linkDestination: IMAGE_LINK_DESTINATION_NONE,
};
case LINK_DESTINATION_NONE:
return {
href: undefined,
Expand Down
Loading