Skip to content
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 @@ -109,6 +109,7 @@ export function Actions(): React.ReactNode {
label: __( 'Layout settings' ),
onClick: openLayoutSettings,
disabled: editMode,
disabledTooltip: __( 'Disabled while editing widgets' ),
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { moreVertical } from '@wordpress/icons';
// eslint-disable-next-line @wordpress/use-recommended-components
import { Button, IconButton } from '@wordpress/ui';
import { Button, IconButton, Tooltip } from '@wordpress/ui';

/**
* Internal dependencies
Expand All @@ -18,12 +18,54 @@ export interface MoreActionsDropdownItem {
label: string;
onClick: () => void;
disabled?: boolean;
/**
* Shown on hover when the item is disabled (for example, to explain
* why the action is unavailable).
*/
disabledTooltip?: string;
}

interface MoreActionsDropdownProps {
items: MoreActionsDropdownItem[];
}

function MoreActionsMenuItem( { item }: { item: MoreActionsDropdownItem } ) {
const showDisabledTooltip = item.disabled && item.disabledTooltip;

const menuItem = (
<Menu.Item
disabled={ item.disabled }
onClick={ item.onClick }
render={ <Button variant="minimal" tone="neutral" /> }
>
{ item.label }
</Menu.Item>
);

if ( ! showDisabledTooltip ) {
return menuItem;
}

return (
<Tooltip.Root>
<Tooltip.Trigger
render={
<Menu.Item
disabled={ item.disabled }
onClick={ item.onClick }
render={ <Button variant="minimal" tone="neutral" /> }
/>
}
>
{ item.label }
</Tooltip.Trigger>
<Tooltip.Popup positioner={ <Tooltip.Positioner side="bottom" /> }>
{ item.disabledTooltip }
</Tooltip.Popup>
</Tooltip.Root>
);
}

/**
* Renders a vertical-three-dots dropdown that surfaces secondary
* actions for the dashboard. Each entry in `items` becomes a menu
Expand Down Expand Up @@ -62,20 +104,13 @@ export function MoreActionsDropdown( {
}
/>
<Menu.Popover>
<Menu.Group>
{ items.map( ( item, index ) => (
<Menu.Item
key={ index }
disabled={ item.disabled }
onClick={ item.onClick }
render={
<Button variant="minimal" tone="neutral" />
}
>
{ item.label }
</Menu.Item>
) ) }
</Menu.Group>
<Tooltip.Provider delay={ 0 }>
<Menu.Group>
{ items.map( ( item, index ) => (
<MoreActionsMenuItem key={ index } item={ item } />
) ) }
</Menu.Group>
</Tooltip.Provider>
</Menu.Popover>
</Menu>
);
Expand Down
Loading