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 reset button to color control #50989

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
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 @@ -69,6 +69,7 @@ $swatch-gap: 12px;
* with the `:last-child` styles.
*/
.block-editor-tools-panel-color-gradient-settings__item {
position: relative;
padding: 0;
max-width: 100%;

Expand Down Expand Up @@ -99,7 +100,7 @@ $swatch-gap: 12px;
display: block;
padding: 0;

> button {
> .block-editor-panel-color-gradient-settings__dropdown {
height: auto;
padding-top: $grid-unit * 1.25;
padding-bottom: $grid-unit * 1.25;
Expand All @@ -125,3 +126,32 @@ $swatch-gap: 12px;
flex-shrink: 0;
}
}

.block-editor-panel-color-gradient-settings__reset {
position: absolute;
display: inline-flex;
right: 0;
top: 0;
bottom: 0;
margin: auto $grid-unit auto;
height: 24px;
width: 24px;
opacity: 0;
transition: opacity 0.1s ease-in-out;

// Override the button style.
&.components-button.has-icon {
padding: 0;
min-width: 0;
border-radius: 0;
}

.block-editor-panel-color-gradient-settings__dropdown:hover + & {
opacity: 1;
}

&:focus,
&:hover {
opacity: 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { reset } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -238,12 +239,25 @@ function ColorPanelDropdown( {
};

return (
<Button { ...toggleProps }>
<LabeledColorIndicators
indicators={ indicators }
label={ label }
<>
<Button { ...toggleProps }>
<LabeledColorIndicators
indicators={ indicators }
label={ label }
/>
</Button>
<Button
label={ __( 'Reset' ) }
aria-label={
/* translators: %s is the type of color property, e.g., "background" */
__( 'Reset %s color' )
}
className="block-editor-panel-color-gradient-settings__reset"
icon={ reset }
onClick={ resetValue }
showTooltip
/>
</Button>
</>
);
} }
renderContent={ () => (
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/circular-option-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Example = () => {
<CircularOptionPicker.ButtonAction
onClick={ () => setCurrentColor( undefined ) }
>
{ 'Clear' }
{ 'Reset' }
</CircularOptionPicker.ButtonAction>
}
/>
Expand Down Expand Up @@ -136,6 +136,6 @@ Inherits all of the [`Dropdown` props](/packages/components/src/dropdown/README.

Props for the underlying `Button` component.

Inherits all of the [`Button` props](/packages/components/src/button/README.md#props), except for `href`, `target`, and `children`.
Inherits all of the [`Button` props](/packages/components/src/button/README.md#props), except for `href`, `target`, and `children`.

- Required: No
2 changes: 1 addition & 1 deletion packages/components/src/circular-option-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function ButtonAction( {
* <CircularOptionPicker.ButtonAction
* onClick={ () => setCurrentColor( undefined ) }
* >
* { 'Clear' }
* { 'Reset' }
* </CircularOptionPicker.ButtonAction>
* }
* />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const DefaultActions = () => {
<CircularOptionPicker.ButtonAction
onClick={ () => setCurrentColor?.( undefined ) }
>
{ 'Clear' }
{ 'Reset' }
</CircularOptionPicker.ButtonAction>
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/color-palette/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function UnforwardedColorPalette(
value,
actions: !! clearable && (
<CircularOptionPicker.ButtonAction onClick={ clearColor }>
{ __( 'Clear' ) }
{ __( 'Reset' ) }
</CircularOptionPicker.ButtonAction>
),
headingLevel,
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/color-palette/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe( 'ColorPalette', () => {
/>
);

await user.click( screen.getByRole( 'button', { name: 'Clear' } ) );
await user.click( screen.getByRole( 'button', { name: 'Reset' } ) );

expect( onChange ).toHaveBeenCalledTimes( 1 );
expect( onChange ).toHaveBeenCalledWith( undefined );
Expand Down Expand Up @@ -188,7 +188,7 @@ describe( 'ColorPalette', () => {
);

expect(
screen.getByRole( 'button', { name: 'Clear' } )
screen.getByRole( 'button', { name: 'Reset' } )
).toBeInTheDocument();
} );

Expand All @@ -198,7 +198,7 @@ describe( 'ColorPalette', () => {
render( <ColorPalette colors={ [] } onChange={ onChange } /> );

expect(
screen.getByRole( 'button', { name: 'Clear' } )
screen.getByRole( 'button', { name: 'Reset' } )
).toBeInTheDocument();
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function DuotonePicker( {
<CircularOptionPicker.ButtonAction
onClick={ () => onChange( undefined ) }
>
{ __( 'Clear' ) }
{ __( 'Reset' ) }
</CircularOptionPicker.ButtonAction>
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/gradient-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function GradientPicker( {
<CircularOptionPicker.ButtonAction
onClick={ clearGradient }
>
{ __( 'Clear' ) }
{ __( 'Reset' ) }
</CircularOptionPicker.ButtonAction>
)
}
Expand Down