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
Tidy up types
  • Loading branch information
ciampo committed Jun 7, 2023
commit 599f846c9f148383054e50af3bc27770a89fbc45
4 changes: 2 additions & 2 deletions packages/components/src/dropdown-menu-v2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type {
DropdownMenuRadioItemProps,
DropdownMenuSeparatorProps,
DropdownSubMenuTriggerProps,
DropdownMenuContext,
DropdownMenuInternalContext,
DropdownMenuPrivateContext as DropdownMenuPrivateContextType,
} from './types';

Expand Down Expand Up @@ -70,7 +70,7 @@ const UnconnectedDropdownMenu = ( props: DropdownMenuProps ) => {
variant,
} = useContextSystem<
// Adding `className` to the context type to avoid a TS error
DropdownMenuProps & DropdownMenuContext & { className?: string }
DropdownMenuProps & DropdownMenuInternalContext & { className?: string }
>( props, 'DropdownMenu' );

// Render the portal in the default slot used by the legacy Popover component.
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/dropdown-menu-v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export type DropdownMenuGroupProps = {

export type DropdownMenuSeparatorProps = {};

export type DropdownMenuContext = {
export type DropdownMenuInternalContext = {
/**
* This variant can be used to change the appearance of the component in
* specific contexts, ie. when rendered inside the `Toolbar` component.
Expand All @@ -258,7 +258,7 @@ export type DropdownMenuContext = {
};

export type DropdownMenuPrivateContext = Pick<
DropdownMenuContext,
DropdownMenuInternalContext,
'variant'
> & {
portalContainer: HTMLElement | null;
Expand Down
9 changes: 6 additions & 3 deletions packages/components/src/dropdown-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { contextConnectWithoutRef, useContextSystem } from '../ui/context';
import Button from '../button';
import Dropdown from '../dropdown';
import { NavigableMenu } from '../navigable-container';
import type { DropdownMenuProps, DropdownOption } from './types';
import type {
DropdownMenuProps,
DropdownOption,
DropdownMenuInternalContext,
} from './types';

function mergeProps<
T extends { className?: string; [ key: string ]: unknown }
Expand Down Expand Up @@ -55,8 +59,7 @@ function UnconnectedDropdownMenu( dropdownMenuProps: DropdownMenuProps ) {

// Context
variant,
// TODO: unify type with v2, consider adding unstyled?
} = useContextSystem< DropdownMenuProps & { variant?: 'toolbar' } >(
} = useContextSystem< DropdownMenuProps & DropdownMenuInternalContext >(
dropdownMenuProps,
'DropdownMenu'
);
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/dropdown-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,11 @@ export type DropdownMenuProps = {
*/
controls?: DropdownOption[] | DropdownOption[][];
};

export type DropdownMenuInternalContext = {
/**
* This variant can be used to change the appearance of the component in
* specific contexts, ie. when rendered inside the `Toolbar` component.
*/
variant?: 'toolbar';
};
5 changes: 2 additions & 3 deletions packages/components/src/dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import deprecated from '@wordpress/deprecated';
*/
import { contextConnect, useContextSystem } from '../ui/context';
import Popover from '../popover';
import type { DropdownProps } from './types';
import type { DropdownProps, DropdownInternalContext } from './types';

function useObservableState(
initialState: boolean,
Expand Down Expand Up @@ -56,8 +56,7 @@ const UnconnectedDropdown = (

// From context system
variant,
// TODO: unify type with v2, consider adding unstyled?
} = useContextSystem< DropdownProps & { variant?: 'toolbar' } >(
} = useContextSystem< DropdownProps & DropdownInternalContext >(
props,
'Dropdown'
);
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/dropdown/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ export type DropdownProps = {
*/
position?: PopoverProps[ 'position' ];
};

export type DropdownInternalContext = {
/**
* This variant can be used to change the appearance of the component in
* specific contexts, ie. when rendered inside the `Toolbar` component.
*/
variant?: 'toolbar';
};