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

Interface: Use plugin context hook instead of HoC #66362

Merged
merged 1 commit into from
Oct 23, 2024
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*/
import { Button } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { usePluginContext } from '@wordpress/plugins';

/**
* Internal dependencies
*/
import { store as interfaceStore } from '../../store';
import complementaryAreaContext from '../complementary-area-context';

/**
* Whether the role supports checked state.
Expand All @@ -29,17 +29,20 @@ function roleSupportsCheckedState( role ) {
].includes( role );
}

function ComplementaryAreaToggle( {
export default function ComplementaryAreaToggle( {
as = Button,
scope,
identifier,
icon,
identifier: identifierProp,
icon: iconProp,
selectedIcon,
name,
shortcut,
...props
} ) {
const ComponentToUse = as;
const context = usePluginContext();
const icon = iconProp || context.icon;
const identifier = identifierProp || `${ context.name }/${ name }`;
const isSelected = useSelect(
( select ) =>
select( interfaceStore ).getActiveComplementaryArea( scope ) ===
Expand Down Expand Up @@ -70,5 +73,3 @@ function ComplementaryAreaToggle( {
/>
);
}

export default complementaryAreaContext( ComplementaryAreaToggle );
17 changes: 9 additions & 8 deletions packages/interface/src/components/complementary-area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import {
useViewportMatch,
usePrevious,
} from '@wordpress/compose';
import { usePluginContext } from '@wordpress/plugins';

/**
* Internal dependencies
*/
import ComplementaryAreaHeader from '../complementary-area-header';
import ComplementaryAreaMoreMenuItem from '../complementary-area-more-menu-item';
import ComplementaryAreaToggle from '../complementary-area-toggle';
import withComplementaryAreaContext from '../complementary-area-context';
import PinnedItems from '../pinned-items';
import { store as interfaceStore } from '../../store';

Expand Down Expand Up @@ -171,10 +171,10 @@ function ComplementaryArea( {
children,
className,
closeLabel = __( 'Close plugin' ),
identifier,
identifier: identifierProp,
header,
headerClassName,
icon,
icon: iconProp,
isPinnable = true,
panelClassName,
scope,
Expand All @@ -183,6 +183,10 @@ function ComplementaryArea( {
toggleShortcut,
isActiveByDefault,
} ) {
const context = usePluginContext();
const icon = iconProp || context.icon;
const identifier = identifierProp || `${ context.name }/${ name }`;

// This state is used to delay the rendering of the Fill
// until the initial effect runs.
// This prevents the animation from running on mount if
Expand Down Expand Up @@ -344,9 +348,6 @@ function ComplementaryArea( {
);
}

const ComplementaryAreaWrapped =
withComplementaryAreaContext( ComplementaryArea );

ComplementaryAreaWrapped.Slot = ComplementaryAreaSlot;
ComplementaryArea.Slot = ComplementaryAreaSlot;

export default ComplementaryAreaWrapped;
export default ComplementaryArea;
Loading