Skip to content

Commit

Permalink
BorderControl: Promote to stable (WordPress#65475)
Browse files Browse the repository at this point in the history
* Export without experimental prefix

* Update README

* Move Storybook stories and add redirect

* Add changelog entries

* Fix changelog.

* Fix changelog (for real?)

* Fix changelog

* Apply feedback.

* Fix changelog

* Remove alpha story.

* README fix.

* Fix default in README

* Fix changelog

* Remove `showDropdownHeader` prop and the header itself.

* Added `showDropdownHeader` as deprecated.

* Remove deprecation warning

* Add ignores to jsdocs.

Co-authored-by: DaniGuardiola <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: ciampo <[email protected]>
  • Loading branch information
8 people authored and huubl committed Oct 2, 2024
1 parent 47a3bb6 commit 17b0b92
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 89 deletions.
5 changes: 2 additions & 3 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@

- `ToolsPanel`: atomic one-step state update when (un)registering panels ([#65564](https://github.com/WordPress/gutenberg/pull/65564)).
- `Navigator`: fix `isInitial` logic ([#65527](https://github.com/WordPress/gutenberg/pull/65527)).
- `ToggleGroupControl`: Fix arrow key navigation in RTL ([#65735](https://github.com/WordPress/gutenberg/pull/65735)).

### Deprecations

- `__experimentalBorderControl` can now be imported as a stable `BorderControl` ([#65475](https://github.com/WordPress/gutenberg/pull/65475)).
- `__experimentalBorderBoxControl` can now be imported as a stable `BorderBoxControl` ([#65586](https://github.com/WordPress/gutenberg/pull/65586)).

### Enhancements

- `Tabs`: handle horizontal overflow and large tab lists gracefully ([#64371](https://github.com/WordPress/gutenberg/pull/64371)).
- `BorderControl`: promote to stable ([#65475](https://github.com/WordPress/gutenberg/pull/65475)).
- `BorderBoxControl`: promote to stable ([#65586](https://github.com/WordPress/gutenberg/pull/65586)).
- `MenuGroup`: Simplify the MenuGroup styles within dropdown menus. ([#65561](https://github.com/WordPress/gutenberg/pull/65561)).
- `DatePicker`: Use compact button size. ([#65653](https://github.com/WordPress/gutenberg/pull/65653)).
- `Navigator`: add support for exit animation ([#64777](https://github.com/WordPress/gutenberg/pull/64777)).
- `Guide`: Update finish button to use the new default size ([#65680](https://github.com/WordPress/gutenberg/pull/65680)).
- `BorderControl`: Use `__next40pxDefaultSize` prop for Reset button ([#65682](https://github.com/WordPress/gutenberg/pull/65682)).
- `Navigator`: stabilize APIs ([#64613](https://github.com/WordPress/gutenberg/pull/64613)).

## 28.8.0 (2024-09-19)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { CSSProperties } from 'react';
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { closeSmall } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -17,12 +16,10 @@ import Button from '../../button';
import ColorIndicator from '../../color-indicator';
import ColorPalette from '../../color-palette';
import Dropdown from '../../dropdown';
import { HStack } from '../../h-stack';
import { VStack } from '../../v-stack';
import type { WordPressComponentProps } from '../../context';
import { contextConnect } from '../../context';
import { useBorderControlDropdown } from './hook';
import { StyledLabel } from '../../base-control/styles/base-control-styles';
import DropdownContentWrapper from '../../dropdown/dropdown-content-wrapper';

import type { ColorObject } from '../../color-palette/types';
Expand Down Expand Up @@ -149,7 +146,6 @@ const BorderControlDropdown = (
popoverContentClassName,
popoverControlsClassName,
resetButtonClassName,
showDropdownHeader,
size,
__unstablePopoverProps,
...otherProps
Expand Down Expand Up @@ -197,17 +193,6 @@ const BorderControlDropdown = (
<>
<DropdownContentWrapper paddingSize="medium">
<VStack className={ popoverControlsClassName } spacing={ 6 }>
{ showDropdownHeader ? (
<HStack>
<StyledLabel>{ __( 'Border color' ) }</StyledLabel>
<Button
size="small"
label={ __( 'Close border color' ) }
icon={ closeSmall }
onClick={ onClose }
/>
</HStack>
) : undefined }
<ColorPalette
className={ popoverContentClassName }
value={ color }
Expand Down
62 changes: 26 additions & 36 deletions packages/components/src/border-control/border-control/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# BorderControl
# BorderControl

<div class="callout callout-alert">
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
</div>
<br />
This component provides control over a border's color, style, and width.
An input control for a border's color, style, and width.

## Development guidelines

Expand All @@ -21,7 +17,7 @@ a "shape" abstraction.

```jsx
import { useState } from 'react';
import { __experimentalBorderControl as BorderControl } from '@wordpress/components';
import { BorderControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

const colors = [
Expand Down Expand Up @@ -58,49 +54,49 @@ colors are organized by multiple origins.

Each color may be an object containing a `name` and `color` value.

- Required: No
- Default: `[]`
- Required: No
- Default: `[]`

### `disableCustomColors`: `boolean`

This toggles the ability to choose custom colors.

- Required: No
- Required: No

### `disableUnits`: `boolean`

This controls whether unit selection should be disabled.

- Required: No
- Required: No

### `enableAlpha`: `boolean`

This controls whether the alpha channel will be offered when selecting
custom colors.

- Required: No
- Default: `false`
- Required: No
- Default: `true`

### `enableStyle`: `boolean`

This controls whether to support border style selection.

- Required: No
- Default: `true`
- Required: No
- Default: `true`

### `hideLabelFromVision`: `boolean`

Provides control over whether the label will only be visible to screen readers.

- Required: No
- Required: No

### `isCompact`: `boolean`

This flags the `BorderControl` to render with a more compact appearance. It
restricts the width of the control and prevents it from expanding to take up
additional space.

- Required: No
- Required: No

### `label`: `string`

Expand All @@ -109,7 +105,7 @@ If provided, a label will be generated using this as the content.
_Whether it is visible only to screen readers is controlled via
`hideLabelFromVision`._

- Required: No
- Required: No

### `onChange`: `( value?: Object ) => void`

Expand All @@ -118,38 +114,32 @@ that selects or clears, border color, style, or width.

_Note: the value may be `undefined` if a user clears all border properties._

- Required: Yes
- Required: Yes

### `shouldSanitizeBorder`: `boolean`

If opted into, sanitizing the border means that if no width or color have been
selected, the border style is also cleared and `undefined` is returned as the
new border value.

- Required: No
- Default: true

### `showDropdownHeader`: `boolean`

Whether or not to render a header for the border color and style picker
dropdown. The header includes a label for the color picker and a close button.

- Required: No
- Required: No
- Default: `true`

### `size`: `string`

Size of the control.

- Required: No
- Default: `default`
- Allowed values: `default`, `__unstable-large`
- Required: No
- Default: `default`
- Allowed values: `default`, `__unstable-large`

### `value`: `Object`

An object representing a border or `undefined`. Used to set the current border
configuration for this component.

Example:

```js
{
color: '#72aee6',
Expand All @@ -158,25 +148,25 @@ Example:
}
```
- Required: No
- Required: No
### `width`: `CSSProperties[ 'width' ]`
Controls the visual width of the `BorderControl`. It has no effect if the
`isCompact` prop is set to `true`.
- Required: No
- Required: No
### `withSlider`: `boolean`
Flags whether this `BorderControl` should also render a `RangeControl` for
additional control over a border's width.

- Required: No
- Required: No

### `__next40pxDefaultSize`: `boolean`

Start opting into the larger default height that will become the default size in a future version.

- Required: No
- Default: `false`
- Required: No
- Default: `false`
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ const UnconnectedBorderControl = (
previousStyleSelection={
previousStyleSelection
}
showDropdownHeader={ showDropdownHeader }
__experimentalIsRenderedInSidebar={
__experimentalIsRenderedInSidebar
}
Expand Down Expand Up @@ -141,7 +140,7 @@ const UnconnectedBorderControl = (
* a "shape" abstraction.
*
* ```jsx
* import { __experimentalBorderControl as BorderControl } from '@wordpress/components';
* import { BorderControl } from '@wordpress/components';
* import { __ } from '@wordpress/i18n';
*
* const colors = [
Expand Down
14 changes: 4 additions & 10 deletions packages/components/src/border-control/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BorderControl } from '..';
import type { Border } from '../types';

const meta: Meta< typeof BorderControl > = {
title: 'Components (Experimental)/BorderControl',
title: 'Components/BorderControl',
component: BorderControl,
argTypes: {
onChange: {
Expand Down Expand Up @@ -93,6 +93,9 @@ export const Default = Template.bind( {} );
Default.args = {
colors,
label: 'Border',
enableAlpha: true,
enableStyle: true,
shouldSanitizeBorder: true,
};

/**
Expand Down Expand Up @@ -133,12 +136,3 @@ WithMultipleOrigins.args = {
...Default.args,
colors: multipleOriginColors,
};

/**
* Allow the alpha channel to be edited on each color.
*/
export const WithAlphaEnabled = Template.bind( {} );
WithAlphaEnabled.args = {
...Default.args,
enableAlpha: true,
};
17 changes: 2 additions & 15 deletions packages/components/src/border-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,6 @@ describe( 'BorderControl', () => {
expect( resetButton ).toBeInTheDocument();
} );

it( 'should render color and style popover header', async () => {
const user = userEvent.setup();
const props = createProps( { showDropdownHeader: true } );
render( <BorderControl { ...props } /> );
await openPopover( user );

const headerLabel = screen.getByText( 'Border color' );
const closeButton = getButton( 'Close border color' );

expect( headerLabel ).toBeInTheDocument();
expect( closeButton ).toBeInTheDocument();
} );

it( 'should not render style options when opted out of', async () => {
const user = userEvent.setup();
const props = createProps( { enableStyle: false } );
Expand Down Expand Up @@ -346,10 +333,10 @@ describe( 'BorderControl', () => {

it( 'should take no action when color and style popover is closed', async () => {
const user = userEvent.setup();
const props = createProps( { showDropdownHeader: true } );
const props = createProps();
render( <BorderControl { ...props } /> );
await openPopover( user );
await user.click( getButton( 'Close border color' ) );
await user.keyboard( 'Escape' );

expect( props.onChange ).not.toHaveBeenCalled();
} );
Expand Down
19 changes: 12 additions & 7 deletions packages/components/src/border-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ export type Border = {

export type ColorProps = Pick<
ColorPaletteProps,
'colors' | 'enableAlpha' | '__experimentalIsRenderedInSidebar'
'colors' | '__experimentalIsRenderedInSidebar'
> & {
/**
* This toggles the ability to choose custom colors.
*/
disableCustomColors?: boolean;
/**
* This controls whether the alpha channel will be offered when selecting
* custom colors.
*
* @default true
*/
enableAlpha?: boolean;
};

export type LabelProps = {
Expand Down Expand Up @@ -78,9 +85,8 @@ export type BorderControlProps = ColorProps &
*/
shouldSanitizeBorder?: boolean;
/**
* Whether or not to show the header for the border color and style
* picker dropdown. The header includes a label for the color picker
* and a close button.
* @deprecated This prop no longer has any effect.
* @ignore
*/
showDropdownHeader?: boolean;
/**
Expand Down Expand Up @@ -139,9 +145,8 @@ export type DropdownProps = ColorProps &
*/
previousStyleSelection?: string;
/**
* Whether or not to render a header for the border color and style picker
* dropdown. The header includes a label for the color picker and a
* close button.
* @deprecated This prop no longer has any effect.
* @ignore
*/
showDropdownHeader?: boolean;
};
Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export {
isDefinedBorder as __experimentalIsDefinedBorder,
isEmptyBorder as __experimentalIsEmptyBorder,
} from './border-box-control';
export { BorderControl as __experimentalBorderControl } from './border-control';
export {
/** @deprecated Import `BorderControl` instead. */
BorderControl as __experimentalBorderControl,
BorderControl,
} from './border-control';
export {
/** @deprecated Import `BoxControl` instead. */
default as __experimentalBoxControl,
Expand Down
1 change: 1 addition & 0 deletions storybook/manager-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const PREVIOUSLY_EXPERIMENTAL_COMPONENTS = [
'alignmentmatrixcontrol',
'borderboxcontrol',
'bordercontrol',
'boxcontrol',
'customselectcontrol-v2',
'dimensioncontrol',
Expand Down

0 comments on commit 17b0b92

Please sign in to comment.