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

Shadow Panel: Add reset button #68981

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { __ } from '@wordpress/i18n';
import {
__experimentalVStack as VStack,
__experimentalHeading as Heading,
__experimentalHStack as HStack,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
Button,
FlexItem,
Dropdown,
Composite,
Tooltip,
} from '@wordpress/components';
import { useMemo } from '@wordpress/element';
import { shadow as shadowIcon, Icon, check } from '@wordpress/icons';
import { shadow as shadowIcon, Icon, check, reset } from '@wordpress/icons';

/**
* External dependencies
Expand Down Expand Up @@ -119,7 +117,7 @@ export function ShadowPopover( { shadow, onShadowChange, settings } ) {
<Dropdown
popoverProps={ popoverProps }
className="block-editor-global-styles__shadow-dropdown"
renderToggle={ renderShadowToggle() }
renderToggle={ renderShadowToggle( shadow, onShadowChange ) }
renderContent={ () => (
<DropdownContentWrapper paddingSize="medium">
<ShadowPopoverContainer
Expand All @@ -133,25 +131,46 @@ export function ShadowPopover( { shadow, onShadowChange, settings } ) {
);
}

function renderShadowToggle() {
function renderShadowToggle( shadow, onShadowChange ) {
return ( { onToggle, isOpen } ) => {
const toggleProps = {
onClick: onToggle,
className: clsx( { 'is-open': isOpen } ),
'aria-expanded': isOpen,
};

const removeButtonProps = {
onClick: () => {
if ( isOpen ) {
onToggle();
}
onShadowChange( undefined );
},
className: clsx(
'block-editor-global-styles__shadow-editor__remove-button',
{ 'is-open': isOpen }
),
label: __( 'Remove shadow' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
label: __( 'Remove shadow' ),
label: __( 'Reset' ),

Keep wording consistent with other similar UI.

};

return (
<Button __next40pxDefaultSize { ...toggleProps }>
<HStack justify="flex-start">
<Icon
className="block-editor-global-styles__toggle-icon"
icon={ shadowIcon }
size={ 24 }
<>
<Button
__next40pxDefaultSize
icon={ shadowIcon }
{ ...toggleProps }
>
{ __( 'Drop shadow' ) }
</Button>
{ !! shadow && (
<Button
__next40pxDefaultSize
size="small"
icon={ reset }
{ ...removeButtonProps }
/>
<FlexItem>{ __( 'Drop shadow' ) }</FlexItem>
</HStack>
</Button>
) }
</>
);
};
}
Expand Down
32 changes: 28 additions & 4 deletions packages/block-editor/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.block-editor-global-styles__toggle-icon {
fill: currentColor;
}

// @todo Ideally, popover, swatch size, and gap values should be CSS variables
// to apply precise grid layouts.
// https://github.com/WordPress/gutenberg/blob/954ecae571abbddc113d3a4bd8e1a72230180554/packages/block-editor/src/components/duotone-control/style.scss#L3-L9
Expand All @@ -24,6 +20,7 @@
.block-editor-global-styles__shadow-dropdown {
display: block;
padding: 0;
position: relative;

button {
width: 100%;
Expand All @@ -35,6 +32,33 @@
}
}

.block-editor-global-styles__shadow-dropdown {
> .components-button.has-icon.has-text:first-child {
gap: $grid-unit-10;
}
}
Comment on lines +36 to +38
Copy link
Contributor

Choose a reason for hiding this comment

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

CSS selectors with the .components- prefix should be avoided as much as possible. Can we use the HStack component inside the Button component as in the previous implementation?


.block-editor-global-styles__shadow-editor__remove-button {
position: absolute;
right: 0;
top: $grid-unit;
margin: auto $grid-unit auto;
opacity: 0;
transition: opacity 0.1s ease-in-out;
@include reduce-motion("transition");

Comment on lines +47 to +48
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
transition: opacity 0.1s ease-in-out;
@include reduce-motion("transition");
@media not ( prefers-reduced-motion ) {
transition: opacity 0.1s ease-in-out;
}

See #68282

.block-editor-global-styles__shadow-dropdown:hover &,
&:focus,
&:hover {
opacity: 1;
}

@media (hover: none) {
// Show reset button on devices that do not support hover.
opacity: 1;
}
}

// These styles are similar to the color palette.
.block-editor-global-styles__shadow-indicator {
appearance: none;
Expand Down
Loading