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 a popover variant prop and refactor popovers to use it, deprecate isAlternate #45137

Merged
merged 2 commits into from
Oct 30, 2022
Merged
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 @@ -30,7 +30,7 @@ const DEFAULT_ALIGNMENT_CONTROLS = [

const POPOVER_PROPS = {
position: 'bottom right',
isAlternate: true,
variant: 'toolbar',
};

function AlignmentUI( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export const BLOCK_ALIGNMENTS_CONTROLS = {
export const DEFAULT_CONTROL = 'none';

export const POPOVER_PROPS = {
isAlternate: true,
variant: 'toolbar',
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function BlockAlignmentMatrixControl( props ) {
return (
<Dropdown
position="bottom right"
popoverProps={ { isAlternate: true } }
popoverProps={ { variant: 'toolbar' } }
renderToggle={ ( { onToggle, isOpen } ) => {
const openOnArrowDown = ( event ) => {
if ( ! isOpen && event.keyCode === DOWN ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ function BlockPopoverInbetween( {
resize={ false }
flip={ false }
placement="bottom-start"
variant="unstyled"
>
<div
className="block-editor-block-popover__inbetween-container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function BlockPopover(
'block-editor-block-popover',
props.className
) }
variant="unstyled"
>
{ __unstableCoverTarget && <div style={ style }>{ children }</div> }
{ ! __unstableCoverTarget && children }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
margin: 0 !important;
min-width: auto;
width: max-content;
background: none;
border: none;
outline: none;
box-shadow: none;
overflow-y: visible;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const noop = () => {};
const POPOVER_PROPS = {
className: 'block-editor-block-settings-menu__popover',
position: 'bottom right',
isAlternate: true,
variant: 'toolbar',
};

function CopyMenuItem( { blocks, onCopy } ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
label={ blockSwitcherLabel }
popoverProps={ {
position: 'bottom right',
isAlternate: true,
variant: 'toolbar',
className: 'block-editor-block-switcher__popover',
} }
icon={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const DEFAULT_CONTROLS = [ 'top', 'center', 'bottom' ];
const DEFAULT_CONTROL = 'top';

const POPOVER_PROPS = {
isAlternate: true,
variant: 'toolbar',
};

function BlockVerticalAlignmentUI( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function DuotoneControl( {
popoverProps={ {
className: 'block-editor-duotone-control__popover',
headerTitle: __( 'Duotone' ),
isAlternate: true,
variant: 'toolbar',
} }
renderToggle={ ( { isOpen, onToggle } ) => {
const openOnArrowDown = ( event ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export const MIN_ZOOM = 100;
export const MAX_ZOOM = 300;
export const POPOVER_PROPS = {
position: 'bottom right',
isAlternate: true,
variant: 'toolbar',
};
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default function ListViewDropIndicator( {
anchor={ popoverAnchor }
focusOnMount={ false }
className="block-editor-list-view-drop-indicator"
variant="unstyled"
>
<div
style={ style }
Expand Down
8 changes: 0 additions & 8 deletions packages/block-editor/src/components/list-view/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,6 @@ $block-navigation-max-indent: 8;
}
}

// Reset some popover defaults for the drop indicator.
.block-editor-list-view-drop-indicator > .components-popover__content {
margin-left: 0;
talldan marked this conversation as resolved.
Show resolved Hide resolved
border: none;
box-shadow: none;
outline: none;
}

.block-editor-list-view-placeholder {
padding: 0;
margin: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const MediaReplaceFlow = ( {
const gallery = multiple && onlyAllowsImages();

const POPOVER_PROPS = {
isAlternate: true,
variant: 'toolbar',
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { chevronDown } from '@wordpress/icons';

const POPOVER_PROPS = {
position: 'bottom right',
isAlternate: true,
variant: 'toolbar',
};

const FormatToolbar = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function FlexLayoutJustifyContentControl( {
onChange={ onJustificationChange }
popoverProps={ {
position: 'bottom right',
isAlternate: true,
variant: 'toolbar',
} }
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/buttons/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default function ButtonsEdit( {
}
popoverProps={ {
position: 'bottom right',
isAlternate: true,
variant: 'toolbar',
} }
/>
</BlockControls>
Expand Down
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
### Deprecations

- `Popover`: the deprecation messages for anchor-related props (`anchorRef`, `anchorRect`, `getAnchorRect`) have been updated. ([#45195](https://github.com/WordPress/gutenberg/pull/45195)).
- `Popover`: The `isAlternate` prop has been replaced with a `variant` prop that can be called with the `'toolbar'` string ([#45137](https://github.com/WordPress/gutenberg/pull/45137)).

### New Feature

- `BoxControl` & `CustomSelectControl`: Add `onMouseOver` and `onMouseOut` callback props to allow handling of these events by parent components ([#44955](https://github.com/WordPress/gutenberg/pull/44955))
- `Popover`: A `variant` prop has been added to style popovers, with `'unstyled'` and `'toolbar'` possible values ([#45137](https://github.com/WordPress/gutenberg/pull/45137)).

### Enhancements

Expand Down
15 changes: 13 additions & 2 deletions packages/components/src/popover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ Used to customize the header text shown when the popover is toggled to fullscree

### `isAlternate`: `boolean`

_Note: this prop is deprecated. Please use the `variant` prop with the `'toolbar'` values instead._

Used to enable a different visual style for the popover.

- Required: No
Expand Down Expand Up @@ -212,8 +214,7 @@ Possible values:
- `yAxis`: `'top' | 'middle' | 'bottom'`
- `xAxis`: `'left' | 'center' | 'right'`
- `corner`: `'top' | 'right' | 'bottom' | 'left'`


<!-- Break into two separate lists using an HTML comment -->
- Required: No

### `resize`: `boolean`
Expand All @@ -222,3 +223,13 @@ Adjusts the size of the popover to prevent its contents from going out of view w

- Required: No
- Default: `true`

### `variant`: `'toolbar' | 'unstyled'`

Specifies the popover's style.

Leave undefined for the default style. Possible values are:
- `unstyled`: The popover is essentially without any visible style, it has no background, border, outline or drop shadow, but the popover contents are still displayed.
- `toolbar`: A style that has no elevation, but a high contrast with other elements. This matches the style of the [`Toolbar` component](/packages/components/toolbar/README.md).
<!-- Break into two separate lists using an HTML comment -->
- Required: No
20 changes: 17 additions & 3 deletions packages/components/src/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ const UnforwardedPopover = (
children,
className,
noArrow = true,
isAlternate,
position,
placement: placementProp = 'bottom-start',
offset: offsetProp = 0,
Expand All @@ -181,12 +180,14 @@ const UnforwardedPopover = (
flip = true,
resize = true,
shift = false,
variant,

// Deprecated props
__unstableForcePosition,
anchorRef,
anchorRect,
getAnchorRect,
isAlternate,

// Rest
...contentProps
Expand All @@ -195,7 +196,7 @@ const UnforwardedPopover = (
let computedFlipProp = flip;
let computedResizeProp = resize;
if ( __unstableForcePosition !== undefined ) {
deprecated( '`__unstableForcePosition` prop wp.components.Popover', {
deprecated( '`__unstableForcePosition` prop in wp.components.Popover', {
since: '6.1',
version: '6.3',
alternative: '`flip={ false }` and `resize={ false }`',
Expand Down Expand Up @@ -228,6 +229,14 @@ const UnforwardedPopover = (
} );
}

const computedVariant = isAlternate ? 'toolbar' : variant;
if ( isAlternate !== undefined ) {
deprecated( '`isAlternate` prop in wp.components.Popover', {
since: '6.2',
alternative: "`variant` prop with the `'toolbar'` value",
} );
}

const arrowRef = useRef< HTMLElement | null >( null );

const [ fallbackReferenceElement, setFallbackReferenceElement ] =
Expand Down Expand Up @@ -452,7 +461,12 @@ const UnforwardedPopover = (
placement={ computedPlacement }
className={ classnames( 'components-popover', className, {
'is-expanded': isExpanded,
'is-alternate': isAlternate,
// Use the 'alternate' classname for 'toolbar' variant for back compat.
[ `is-${
computedVariant === 'toolbar'
? 'alternate'
: computedVariant
}` ]: computedVariant,
} ) }
{ ...contentProps }
ref={ mergedFloatingRef }
Expand Down
30 changes: 29 additions & 1 deletion packages/components/src/popover/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const PopoverWithAnchor = ( args: PopoverProps ) => {
);
};

export const Default: ComponentStory< typeof Popover > = ( args ) => {
const Template: ComponentStory< typeof Popover > = ( args ) => {
const [ isVisible, setIsVisible ] = useState( false );
const toggleVisible = () => {
setIsVisible( ( state ) => ! state );
Expand Down Expand Up @@ -114,6 +114,8 @@ export const Default: ComponentStory< typeof Popover > = ( args ) => {
</div>
);
};

export const Default: ComponentStory< typeof Popover > = Template.bind( {} );
Default.args = {
children: (
<div style={ { width: '280px', whiteSpace: 'normal' } }>
Expand All @@ -125,6 +127,32 @@ Default.args = {
),
};

export const Toolbar: ComponentStory< typeof Popover > = Template.bind( {} );
Toolbar.args = {
children: (
<div style={ { width: '280px', whiteSpace: 'normal' } }>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
</div>
),
variant: 'toolbar',
};

export const Unstyled: ComponentStory< typeof Popover > = Template.bind( {} );
Unstyled.args = {
children: (
<div style={ { width: '280px', whiteSpace: 'normal' } }>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
</div>
),
variant: 'unstyled',
};

export const AllPlacements: ComponentStory< typeof Popover > = ( {
children,
...args
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/popover/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ $arrow-triangle-base-size: 14px;
box-shadow: none;
}

// A style that gives the popover no visible ui.
.is-unstyled & {
background: none;
border: none;
border-radius: 0;
outline: none;
box-shadow: none;
}

.components-popover.is-expanded & {
position: static;
height: calc(100% - #{ $panel-header-height });
Expand Down
27 changes: 22 additions & 5 deletions packages/components/src/popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ export type PopoverProps = {
* fullscreen on mobile viewports (see the `expandOnMobile` prop).
*/
headerTitle?: string;
/**
* Used to enable a different visual style for the popover.
*/
isAlternate?: boolean;
/**
* Used to show/hide the arrow that points at the popover's anchor.
*
Expand Down Expand Up @@ -138,7 +134,20 @@ export type PopoverProps = {
* @default false
*/
shift?: boolean;

/**
* Specifies the popover's style.
*
* Leave undefined for the default style. Other values are:
* - 'unstyled': The popover is essentially without any visible style, it
* has no background, border, outline or drop shadow, but
* the popover contents are still displayed.
* - 'toolbar': A style that has no elevation, but a high contrast with
* other elements. This is matches the style of the
* `Toolbar` component.
*
* @default undefined
*/
talldan marked this conversation as resolved.
Show resolved Hide resolved
variant?: 'unstyled' | 'toolbar';
// Deprecated props
/**
* Prevent the popover from flipping and resizing when meeting the viewport
Expand Down Expand Up @@ -176,4 +185,12 @@ export type PopoverProps = {
getAnchorRect?: (
fallbackReferenceElement: Element | null
) => DomRectWithOwnerDocument;
/**
* Used to enable a different visual style for the popover.
* _Note: this prop is deprecated. Use the `variant` prop with the
* 'toolbar' value instead._
*
* @deprecated
*/
isAlternate?: boolean;
};
2 changes: 1 addition & 1 deletion packages/components/src/toolbar-dropdown-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ToolbarDropdownMenu( props, ref ) {
<DropdownMenu
{ ...props }
popoverProps={ {
isAlternate: true,
variant: 'toolbar',
...props.popoverProps,
} }
toggleProps={ toolbarItemProps }
Expand Down