Skip to content

Commit

Permalink
Replace internal Tooltip usage of position with placement
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp committed Sep 13, 2023
1 parent 727ddaa commit 0ea691c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function BoxInputControls( {
: selectedUnits[ corner ] || selectedUnits.flat;

return (
<Tooltip text={ label } position="top" key={ corner }>
<Tooltip text={ label } placement="top" key={ corner }>
<div className="components-border-radius-control__tooltip-wrapper">
<UnitControl
{ ...props }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const MediaReplaceFlow = ( {
{ __( 'Current media URL:' ) }
</span>

<Tooltip text={ mediaURL } position="bottom">
<Tooltip text={ mediaURL }>
<div>
<LinkControl
value={ { url: mediaURL } }
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/box-control/unit-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Tooltip( {
* https://github.com/WordPress/gutenberg/pull/24966#issuecomment-685875026
*/
return (
<BaseTooltip text={ text } position="top">
<BaseTooltip text={ text } placement="top">
<div>{ children }</div>
</BaseTooltip>
);
Expand Down
10 changes: 9 additions & 1 deletion packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Tooltip from '../tooltip';
import Icon from '../icon';
import { VisuallyHidden } from '../visually-hidden';
import type { ButtonProps, DeprecatedButtonProps } from './types';
import { positionToPlacement } from '../popover/utils';

const disabledEventsOnDisabledButton = [ 'onMouseDown', 'onClick' ] as const;

Expand Down Expand Up @@ -225,6 +226,13 @@ export function UnforwardedButton(
</button>
);

// use floating-ui's `placement` instead of legacy `position`
let computedPlacement;
// if `tooltipPosition` is defined, compute value to `placement`
if ( tooltipPosition !== undefined ) {
computedPlacement = positionToPlacement( tooltipPosition );
}

if ( ! shouldShowTooltip ) {
return (
<>
Expand All @@ -248,7 +256,7 @@ export function UnforwardedButton(
: label
}
shortcut={ shortcut }
position={ tooltipPosition }
placement={ computedPlacement }
>
{ element }
</Tooltip>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/date-time/time/timezone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const TimeZone = () => {
: `(${ zoneAbbr }) ${ timezone.string.replace( '_', ' ' ) }`;

return (
<Tooltip position="top center" text={ timezoneDetail }>
<Tooltip placement="top" text={ timezoneDetail }>
<StyledComponent className="components-datetime__timezone">
{ zoneAbbr }
</StyledComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const LAYOUT_ID = 'toggle-group-backdrop-shared-layout-id';
const WithToolTip = ( { showTooltip, text, children }: WithToolTipProps ) => {
if ( showTooltip && text ) {
return (
<Tooltip text={ text } position="top center">
<Tooltip text={ text } placement="top">
{ children }
</Tooltip>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/page-patterns/grid-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function GridItem( { categoryId, item, ...props } ) {
>
{ itemIcon && ! isNonUserPattern && (
<Tooltip
position="top center"
placement="top"
text={ __(
'Editing this pattern will also update anywhere it is used'
) }
Expand Down Expand Up @@ -210,7 +210,7 @@ function GridItem( { categoryId, item, ...props } ) {
) }
{ item.type === PATTERNS && (
<Tooltip
position="top center"
placement="top"
text={ __( 'This pattern cannot be edited.' ) }
>
<span className="edit-site-patterns__pattern-lock-icon">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function ThemePatternsGroup( { categories, currentCategory, currentType } ) {
<Flex justify="left" align="center" gap={ 0 }>
{ category.label }
<Tooltip
position="top center"
placement="top"
text={ sprintf(
// translators: %s: The pattern category name.
'"%s" patterns cannot be edited.',
Expand Down

0 comments on commit 0ea691c

Please sign in to comment.