Skip to content

Commit

Permalink
Fix: Ensure consistency in editor tools for navigation buttons and de…
Browse files Browse the repository at this point in the history
…lete options (#67253)

* fix: ensure consistency in editor tools for navigation buttons and delete options

* Fix: remove shadow icon

* Fix: remove redandunt styling

* Fix: use lower case in confirmation message

Co-authored-by: Sarah Norris <[email protected]>

---------

Co-authored-by: Sarah Norris <[email protected]>
Co-authored-by: sarthaknagoshe2002 <[email protected]>
Co-authored-by: mikachan <[email protected]>
Co-authored-by: madhusudhand <[email protected]>
  • Loading branch information
5 people authored Dec 20, 2024
1 parent 12f7764 commit 9297500
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* WordPress dependencies
*/
import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

function ConfirmResetShadowDialog( {
text,
confirmButtonText,
isOpen,
toggleOpen,
onConfirm,
} ) {
const handleConfirm = async () => {
toggleOpen();
onConfirm();
};

const handleCancel = () => {
toggleOpen();
};

return (
<ConfirmDialog
isOpen={ isOpen }
cancelButtonText={ __( 'Cancel' ) }
confirmButtonText={ confirmButtonText }
onCancel={ handleCancel }
onConfirm={ handleConfirm }
size="medium"
>
{ text }
</ConfirmDialog>
);
}

export default ConfirmResetShadowDialog;
65 changes: 60 additions & 5 deletions packages/edit-site/src/components/global-styles/shadows-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ import {
Button,
Flex,
FlexItem,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { __, sprintf, isRTL } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { plus, Icon, chevronLeft, chevronRight } from '@wordpress/icons';
import {
plus,
Icon,
chevronLeft,
chevronRight,
moreVertical,
} from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -21,8 +28,11 @@ import Subtitle from './subtitle';
import { NavigationButtonAsItem } from './navigation-button';
import ScreenHeader from './header';
import { getNewIndexFromPresets } from './utils';
import { useState } from '@wordpress/element';
import ConfirmResetShadowDialog from './confirm-reset-shadow-dialog';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );
const { Menu } = unlock( componentsPrivateApis );

export const defaultShadow = '6px 6px 9px rgba(0, 0, 0, 0.2)';

Expand All @@ -40,8 +50,27 @@ export default function ShadowsPanel() {
setCustomShadows( [ ...( customShadows || [] ), shadow ] );
};

const handleResetShadows = () => {
setCustomShadows( [] );
};

const [ isResetDialogOpen, setIsResetDialogOpen ] = useState( false );

const toggleResetDialog = () => setIsResetDialogOpen( ! isResetDialogOpen );

return (
<>
{ isResetDialogOpen && (
<ConfirmResetShadowDialog
text={ __(
'Are you sure you want to remove all custom shadows?'
) }
confirmButtonText={ __( 'Remove' ) }
isOpen={ isResetDialogOpen }
toggleOpen={ toggleResetDialog }
onConfirm={ handleResetShadows }
/>
) }
<ScreenHeader
title={ __( 'Shadows' ) }
description={ __(
Expand Down Expand Up @@ -73,14 +102,22 @@ export default function ShadowsPanel() {
category="custom"
canCreate
onCreate={ onCreateShadow }
onReset={ toggleResetDialog }
/>
</VStack>
</div>
</>
);
}

function ShadowList( { label, shadows, category, canCreate, onCreate } ) {
function ShadowList( {
label,
shadows,
category,
canCreate,
onCreate,
onReset,
} ) {
const handleAddShadow = () => {
const newIndex = getNewIndexFromPresets( shadows, 'shadow-' );
onCreate( {
Expand Down Expand Up @@ -115,6 +152,26 @@ function ShadowList( { label, shadows, category, canCreate, onCreate } ) {
/>
</FlexItem>
) }
{ !! shadows?.length && category === 'custom' && (
<Menu>
<Menu.TriggerButton
render={
<Button
size="small"
icon={ moreVertical }
label={ __( 'Shadow options' ) }
/>
}
/>
<Menu.Popover>
<Menu.Item onClick={ onReset }>
<Menu.ItemLabel>
{ __( 'Remove all custom shadows' ) }
</Menu.ItemLabel>
</Menu.Item>
</Menu.Popover>
</Menu>
) }
</HStack>
{ shadows.length > 0 && (
<ItemGroup isBordered isSeparated>
Expand All @@ -138,9 +195,7 @@ function ShadowItem( { shadow, category } ) {
>
<HStack>
<FlexItem>{ shadow.name }</FlexItem>
<FlexItem display="flex">
<Icon icon={ isRTL() ? chevronLeft : chevronRight } />
</FlexItem>
<Icon icon={ isRTL() ? chevronLeft : chevronRight } />
</HStack>
</NavigationButtonAsItem>
);
Expand Down

1 comment on commit 9297500

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 9297500.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12432926285
📝 Reported issues:

Please sign in to comment.