Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Hook Dropdown into context system, update DropdownMenu and CircularOp…
…tionPicker
  • Loading branch information
ciampo committed Jun 7, 2023
commit 69576a00182377e21cfe44bfb237dd795c0dd7ae
7 changes: 2 additions & 5 deletions packages/components/src/circular-option-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Icon } from '@wordpress/icons';
* Internal dependencies
*/
import type { ButtonAsButtonProps } from '../button/types';
import type Dropdown from '../dropdown';
import type { DropdownProps } from '../dropdown/types';
import type { WordPressComponentProps } from '../ui/context';

export type CircularOptionPickerProps = {
Expand Down Expand Up @@ -44,10 +44,7 @@ export type DropdownLinkActionProps = {
'children'
>;
linkText: string;
dropdownProps: Omit<
React.ComponentProps< typeof Dropdown >,
'className' | 'renderToggle'
>;
dropdownProps: Omit< DropdownProps, 'className' | 'renderToggle' >;
className?: string;
};

Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/dropdown-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function UnconnectedDropdownMenu( dropdownMenuProps: DropdownMenuProps ) {

// Context
variant,
// TODO: unify type with v2, consider adding unstyled?
} = useContextSystem< DropdownMenuProps & { variant?: 'toolbar' } >(
dropdownMenuProps,
'DropdownMenu'
Expand All @@ -80,7 +81,9 @@ function UnconnectedDropdownMenu( dropdownMenuProps: DropdownMenuProps ) {
const mergedPopoverProps = mergeProps(
{
className: 'components-dropdown-menu__popover',
variant,
// Do not add a `variant` prop if it's not defined, to avoid overriding
// values from internal context system.
...( !! variant ? { variant } : {} ),
},
popoverProps
);
Expand Down
27 changes: 19 additions & 8 deletions packages/components/src/dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import type { ForwardedRef } from 'react';
/**
* WordPress dependencies
*/
import { forwardRef, useEffect, useRef, useState } from '@wordpress/element';
import { useEffect, useRef, useState } from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
*/
import { contextConnect, useContextSystem } from '../ui/context';
import Popover from '../popover';
import type { DropdownProps } from './types';

Expand All @@ -33,8 +34,11 @@ function useObservableState(
] as const;
}

function UnforwardedDropdown(
{
const UnconnectedDropdown = (
props: DropdownProps,
forwardedRef: ForwardedRef< any >
) => {
const {
renderContent,
renderToggle,
className,
Expand All @@ -49,9 +53,15 @@ function UnforwardedDropdown(

// Deprecated props
position,
}: DropdownProps,
forwardedRef: ForwardedRef< any >
) {

// From context system
variant,
// TODO: unify type with v2, consider adding unstyled?
} = useContextSystem< DropdownProps & { variant?: 'toolbar' } >(
props,
'Dropdown'
);

if ( position !== undefined ) {
deprecated( '`position` prop in wp.components.Dropdown', {
since: '6.2',
Expand Down Expand Up @@ -149,6 +159,7 @@ function UnforwardedDropdown(
? fallbackPopoverAnchor
: undefined
}
variant={ variant }
{ ...popoverProps }
className={ classnames(
'components-dropdown__content',
Expand All @@ -161,7 +172,7 @@ function UnforwardedDropdown(
) }
</div>
);
}
};

/**
* Renders a button that opens a floating content modal when clicked.
Expand All @@ -188,6 +199,6 @@ function UnforwardedDropdown(
* );
* ```
*/
export const Dropdown = forwardRef( UnforwardedDropdown );
export const Dropdown = contextConnect( UnconnectedDropdown, 'Dropdown' );

export default Dropdown;