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

Fix: Ensure consistency in editor tools for navigation buttons and delete options #67253

Merged
merged 8 commits into from
Dec 20, 2024
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;
67 changes: 63 additions & 4 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,16 @@ import {
Button,
Flex,
FlexItem,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { plus, shadow as shadowIcon } from '@wordpress/icons';
import {
plus,
shadow as shadowIcon,
chevronRight,
moreVertical,
} from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -21,6 +27,10 @@ import Subtitle from './subtitle';
import { NavigationButtonAsItem } from './navigation-button';
import ScreenHeader from './header';
import { getNewIndexFromPresets } from './utils';
import { IconWithCurrentColor } from './icon-with-current-color';
const { Menu } = unlock( componentsPrivateApis );
sarthaknagoshe2002 marked this conversation as resolved.
Show resolved Hide resolved
import { useState } from '@wordpress/element';
import ConfirmResetShadowDialog from './confirm-reset-shadow-dialog';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );

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,23 @@ function ShadowList( { label, shadows, category, canCreate, onCreate } ) {
/>
</FlexItem>
) }
{ !! shadows?.length && category === 'custom' && (
<Menu
trigger={
<Button
size="small"
icon={ moreVertical }
label={ __( 'shadow options' ) }
sarthaknagoshe2002 marked this conversation as resolved.
Show resolved Hide resolved
/>
}
>
<Menu.Item onClick={ onReset }>
<Menu.ItemLabel>
{ __( 'Remove all shadows' ) }
sarthaknagoshe2002 marked this conversation as resolved.
Show resolved Hide resolved
</Menu.ItemLabel>
</Menu.Item>
</Menu>
) }
</HStack>
{ shadows.length > 0 && (
<ItemGroup isBordered isSeparated>
Expand All @@ -135,9 +189,14 @@ function ShadowItem( { shadow, category } ) {
return (
<NavigationButtonAsItem
path={ `/shadows/edit/${ category }/${ shadow.slug }` }
icon={ shadowIcon }
>
{ shadow.name }
<HStack justify="space-between">
sarthaknagoshe2002 marked this conversation as resolved.
Show resolved Hide resolved
<HStack justify="flex-start">
<IconWithCurrentColor icon={ shadowIcon } />
sarthaknagoshe2002 marked this conversation as resolved.
Show resolved Hide resolved
<FlexItem> { shadow.name } </FlexItem>
</HStack>
<IconWithCurrentColor icon={ chevronRight } />
mikachan marked this conversation as resolved.
Show resolved Hide resolved
</HStack>
</NavigationButtonAsItem>
);
}
Loading