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

Move gallery link controls to the block toolbar #62762

Merged
merged 28 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0e6cc04
Move link dropdown to toolbar in gallery block
akasunil Jun 22, 2024
cac26ab
Update e2e test for gallery block's setting
akasunil Jun 23, 2024
a0c3301
Fix e2e test for gallery block images link setting
akasunil Jun 23, 2024
ebd5a36
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jun 25, 2024
7e6f2c6
Fix unit test
akasunil Jun 25, 2024
5ea3de1
Synced with trunk and resolved conflicts
akasunil Jul 14, 2024
0c7a78b
Synced with trunk
akasunil Jul 20, 2024
ea17d8d
Added ToolbarDropdownMenu component instead of DropdownMenu
akasunil Jul 20, 2024
88b75ac
remove remove extra padding around link icon
akasunil Jul 20, 2024
cd83a3e
Remove unused components
akasunil Jul 20, 2024
6f40925
Revert "Synced with trunk"
akasunil Jul 20, 2024
c795bfa
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jul 20, 2024
694e665
Improve snackbar notices for gallery block link control select
akasunil Jul 22, 2024
8ad541b
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jul 24, 2024
b0f3339
Add constant for lightbox option in link control for gallery block
akasunil Jul 24, 2024
8107157
Update getHrefAndDestination function to handle Link control value ch…
akasunil Jul 24, 2024
eddabc7
Add lightbox option in link control of gallery block
akasunil Jul 24, 2024
3940299
Add info text for lightbox option in link control for gallery block
akasunil Jul 24, 2024
f3e8341
Set info text for lightbox option in single line
akasunil Jul 24, 2024
a321288
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jul 25, 2024
1228c00
reverting expand of click option changes
akasunil Jul 26, 2024
31dcc28
add change to resolve conflict
akasunil Jul 26, 2024
0bf1cac
fix: Avoid unsupported Gallery MenuGroup usage (#63953)
dcalhoun Jul 26, 2024
9456d3d
removing lightbox changes from edit component of gallery block
akasunil Jul 26, 2024
7976411
Removing unneccessory class
akasunil Jul 26, 2024
37a191b
Update link control lable in gallery block
akasunil Jul 27, 2024
893666c
Update label in unit test
akasunil Jul 27, 2024
16f87e7
Update text in snapshot
akasunil Jul 27, 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
88 changes: 75 additions & 13 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
ToggleControl,
RangeControl,
Spinner,
MenuGroup,
MenuItem,
ToolbarDropdownMenu,
withNotices,
} from '@wordpress/components';
import {
Expand All @@ -33,6 +36,12 @@ import { View } from '@wordpress/primitives';
import { createBlock } from '@wordpress/blocks';
import { createBlobURL } from '@wordpress/blob';
import { store as noticesStore } from '@wordpress/notices';
import {
link as linkIcon,
customLink,
image as imageIcon,
linkOff,
} from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -57,11 +66,23 @@ import GapStyles from './gap-styles';

const MAX_COLUMNS = 8;
const linkOptions = [
{ value: LINK_DESTINATION_ATTACHMENT, label: __( 'Attachment Page' ) },
{ value: LINK_DESTINATION_MEDIA, label: __( 'Media File' ) },
{
value: LINK_DESTINATION_NONE,
icon: customLink,
label: __( 'Link images to attachment pages' ),
value: LINK_DESTINATION_ATTACHMENT,
noticeText: __( 'Attachment Pages' ),
},
{
icon: imageIcon,
label: __( 'Link images to media files' ),
value: LINK_DESTINATION_MEDIA,
noticeText: __( 'Media Files' ),
},
{
icon: linkOff,
label: _x( 'None', 'Media item link option' ),
value: LINK_DESTINATION_NONE,
noticeText: __( 'None' ),
},
];
const ALLOWED_MEDIA_TYPES = [ 'image' ];
Expand Down Expand Up @@ -359,7 +380,7 @@ function GalleryEdit( props ) {
sprintf(
/* translators: %s: image size settings */
__( 'All gallery image links updated to: %s' ),
linkToText.label
linkToText.noticeText
),
{
id: 'gallery-attributes-linkTo',
Expand Down Expand Up @@ -552,15 +573,17 @@ function GalleryEdit( props ) {
size="__unstable-large"
/>
) }
<SelectControl
__nextHasNoMarginBottom
label={ __( 'Link to' ) }
value={ linkTo }
onChange={ setLinkTo }
options={ linkOptions }
hideCancelButton
size="__unstable-large"
/>
{ Platform.isNative ? (
<SelectControl
__nextHasNoMarginBottom
label={ __( 'Link to' ) }
value={ linkTo }
onChange={ setLinkTo }
options={ linkOptions }
hideCancelButton
size="__unstable-large"
/>
) : null }
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Crop images to fit' ) }
Expand Down Expand Up @@ -594,6 +617,45 @@ function GalleryEdit( props ) {
) }
</PanelBody>
</InspectorControls>
{ Platform.isWeb ? (
<BlockControls group="block">
<ToolbarDropdownMenu
icon={ linkIcon }
label={ __( 'Link To' ) }
>
{ ( { onClose } ) => (
<MenuGroup className="blocks-gallery__link-to-control">
madhusudhand marked this conversation as resolved.
Show resolved Hide resolved
{ linkOptions.map( ( linkItem ) => {
const isOptionSelected =
linkTo === linkItem.value;
return (
<MenuItem
key={ linkItem.value }
isSelected={ isOptionSelected }
className={ clsx(
'components-dropdown-menu__menu-item',
{
'is-active':
isOptionSelected,
}
) }
iconPosition="left"
icon={ linkItem.icon }
onClick={ () => {
setLinkTo( linkItem.value );
onClose();
} }
role="menuitemradio"
>
{ linkItem.label }
</MenuItem>
);
} ) }
</MenuGroup>
) }
</ToolbarDropdownMenu>
</BlockControls>
) : null }
{ Platform.isWeb && (
<>
{ ! multiGallerySelection && (
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/gallery/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ describe( 'Gallery block', () => {
// Set "Link to" setting via Gallery block settings
await openBlockSettings( screen );
fireEvent.press( getByText( 'Link to' ) );
fireEvent.press( getByText( 'Media File' ) );
fireEvent.press( getByText( 'Link images to media files' ) );

expect( getEditorHtml() ).toMatchSnapshot();
} );
Expand Down
Loading