Skip to content

Commit

Permalink
Remove Controls/NormalizedControls abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed May 17, 2023
1 parent c2a9ee7 commit 0f925c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/components/src/dropdown-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { menu } from '@wordpress/icons';
import Button from '../button';
import Dropdown from '../dropdown';
import { NavigableMenu } from '../navigable-container';
import type { Controls, DropdownMenuProps, NormalizedControls } from './types';
import type { DropdownMenuProps, DropdownOption } from './types';

function mergeProps<
T extends { className?: string; [ key: string ]: unknown }
Expand Down Expand Up @@ -139,15 +139,15 @@ function DropdownMenu( dropdownMenuProps: DropdownMenuProps ) {
}

// Normalize controls to nested array of objects (sets of controls)
let controlSets: NormalizedControls;
let controlSets: DropdownOption[][];
if ( controls?.length ) {
// @ts-expect-error The check below is needed because `DropdownMenus`
// rendered by `ToolBarGroup` receive controls as a nested array.
controlSets = controls;
if ( ! Array.isArray( controlSets[ 0 ] ) ) {
// This is not ideal, but at this point we know that `controls` is
// not a nested array, even if TypeScript doesn't.
controlSets = [ controls as Controls ];
controlSets = [ controls as DropdownOption[] ];
}
}

Expand Down
7 changes: 2 additions & 5 deletions packages/components/src/dropdown-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { DropdownProps } from '../dropdown/types';
import type { Props as IconProps } from '../icon';
import type { NavigableMenuProps } from '../navigable-container/types';

type DropdownOption = {
export type DropdownOption = {
/**
* The Dashicon icon slug to be shown for the option.
*/
Expand Down Expand Up @@ -44,9 +44,6 @@ type DropdownOption = {
role?: HTMLElement[ 'role' ];
};

export type Controls = DropdownOption[];
export type NormalizedControls = DropdownOption[][];

type DropdownCallbackProps = {
isOpen: boolean;
onToggle: () => void;
Expand Down Expand Up @@ -142,5 +139,5 @@ export type DropdownMenuProps = {
*
* A valid DropdownMenu must specify a `controls` or `children` prop, or both.
*/
controls?: Controls | NormalizedControls;
controls?: DropdownOption[] | DropdownOption[][];
};

0 comments on commit 0f925c1

Please sign in to comment.