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

BorderControl: always show Reset button #69066

Merged
merged 11 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -256,6 +256,7 @@ export default function BorderPanel( {
<BorderBoxControl
colors={ colors }
enableAlpha
showClearButton
enableStyle={ showBorderStyle }
onChange={ onBorderChange }
popoverOffset={ 40 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const MyBorderBoxControl = () => {
return (
<BorderBoxControl
__next40pxDefaultSize
showClearButton
colors={ colors }
label={ __( 'Borders' ) }
onChange={ onChange }
Expand Down Expand Up @@ -89,6 +90,13 @@ custom colors.
- Required: No
- Default: `false`

### `showClearButton`: `boolean`

Select whether to display the Clear button.

- Required: No
- Default: `undefined`

### `enableStyle`: `boolean`

This controls whether to support border style selections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const UnconnectedBorderBoxControl = (
disableCustomColors,
disableUnits,
enableAlpha,
showClearButton,
enableStyle,
hasMixedBorders,
hideLabelFromVision,
Expand Down Expand Up @@ -103,6 +104,7 @@ const UnconnectedBorderBoxControl = (
disableUnits={ disableUnits }
disableCustomColors={ disableCustomColors }
enableAlpha={ enableAlpha }
showClearButton={ showClearButton }
enableStyle={ enableStyle }
onChange={ onLinkedChange }
placeholder={
Expand Down Expand Up @@ -177,6 +179,7 @@ const UnconnectedBorderBoxControl = (
* return (
* <BorderBoxControl
* __next40pxDefaultSize
* showClearButton
* colors={ colors }
* label={ __( 'Borders' ) }
* onChange={ onChange }
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/border-box-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type BorderSide = keyof Borders;

export type BorderBoxControlProps = ColorProps &
LabelProps &
Pick< BorderControlProps, 'enableStyle' | 'size' > & {
Pick< BorderControlProps, 'showClearButton' | 'enableStyle' | 'size' > & {
/**
* A callback function invoked when any border value is changed. The value
* received may be a "flat" border object, one that has properties defining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { CSSProperties } from 'react';
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -152,17 +153,27 @@ const BorderControlDropdown = (
indicatorClassName,
indicatorWrapperClassName,
isStyleSettable,
showClearButton,
onReset,
onColorChange,
onStyleChange,
popoverContentClassName,
popoverControlsClassName,
resetButtonClassName,
clearButtonClassName,
size,
__unstablePopoverProps,
...otherProps
} = useBorderControlDropdown( props );

if ( showClearButton === undefined ) {
deprecated( `Clear button styles for wp.components.BorderBoxControl`, {
since: '6.8',
version: '7.1',
hint: 'Set the `showClearButton` prop to true to start opting into the new styles, which will become the default in a future version.',
} );
}

const { color, style } = border || {};
const colorObject = getColorObject( color, colors );

Expand Down Expand Up @@ -224,8 +235,23 @@ const BorderControlDropdown = (
/>
) }
</VStack>
{ showClearButton && (
<div className={ clearButtonClassName }>
<Button
variant="tertiary"
onClick={ () => {
onReset();
} }
disabled={ ! showResetButton }
accessibleWhenDisabled
__next40pxDefaultSize
>
{ __( 'Clear' ) }
</Button>
</div>
) }
</DropdownContentWrapper>
{ showResetButton && (
{ ! showClearButton && showResetButton && (
<DropdownContentWrapper paddingSize="none">
<Button
className={ resetButtonClassName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export function useBorderControlDropdown(
return cx( styles.borderControlPopoverContent );
}, [ cx ] );

const clearButtonClassName = useMemo( () => {
return cx( styles.clearButton );
}, [ cx ] );

const resetButtonClassName = useMemo( () => {
return cx( styles.resetButton );
}, [ cx ] );
Expand All @@ -94,6 +98,7 @@ export function useBorderControlDropdown(
onReset,
popoverContentClassName,
popoverControlsClassName,
clearButtonClassName,
resetButtonClassName,
size,
__experimentalIsRenderedInSidebar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const UnconnectedBorderControl = (
innerWrapperClassName,
inputWidth,
isStyleSettable,
showClearButton,
label,
onBorderChange,
onSliderChange,
Expand Down Expand Up @@ -89,6 +90,7 @@ const UnconnectedBorderControl = (
enableAlpha={ enableAlpha }
enableStyle={ enableStyle }
isStyleSettable={ isStyleSettable }
showClearButton={ showClearButton }
onChange={ onBorderChange }
previousStyleSelection={
previousStyleSelection
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/border-control/border-control/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function useBorderControl(
enableAlpha = true,
enableStyle = true,
shouldSanitizeBorder = true,
showClearButton,
size = 'default',
value: border,
width,
Expand Down Expand Up @@ -160,6 +161,7 @@ export function useBorderControl(
innerWrapperClassName,
inputWidth: wrapperWidth,
isStyleSettable,
showClearButton,
onBorderChange,
onSliderChange,
onWidthChange,
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/border-control/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ export const borderControlPopoverControls = css`
export const borderControlPopoverContent = css``;
export const borderColorIndicator = css``;

export const clearButton = css`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reference

.components-circular-option-picker__custom-clear-wrapper {
display: flex;
justify-content: flex-end;
margin-top: $grid-unit-15;
}

display: flex;
justify-content: flex-end;
margin-top: 12px;
`;

export const resetButton = css`
justify-content: center;
width: 100%;
Expand Down
10 changes: 10 additions & 0 deletions packages/components/src/border-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export type BorderControlProps = ColorProps &
* @default true
*/
enableStyle?: boolean;
/**
* ShowClearButton
*
* @default undefined
*/
showClearButton?: boolean | undefined;
/**
* This flags the `BorderControl` to render with a more compact
* appearance. It restricts the width of the control and prevents it
Expand Down Expand Up @@ -137,6 +143,10 @@ export type DropdownProps = ColorProps &
* Whether a border style can be set, based on the border sanitization settings.
*/
isStyleSettable: boolean;
/**
* Show Clear Button
*/
showClearButton?: boolean;
/**
* An internal prop used to control the visibility of the dropdown.
*/
Expand Down
Loading