Skip to content

Commit

Permalink
Updates types and null to undefined in toolbar-group
Browse files Browse the repository at this point in the history
  • Loading branch information
margolisj committed Sep 14, 2023
1 parent 3c7f827 commit 4ab80d2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/toolbar/toolbar-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function ToolbarGroup( {
containerClassName={
indexOfSet > 0 && indexOfControl === 0
? 'has-left-divider'
: null
: undefined
}
{ ...control }
/>
Expand Down
104 changes: 79 additions & 25 deletions packages/components/src/toolbar/toolbar-group/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import type { ReactNode } from 'react';
/**
* Internal dependencies
*/
import type { DropdownOption } from '../../dropdown-menu/types';
import type {
DropdownMenuProps,
DropdownOption,
} from '../../dropdown-menu/types';

export type ToolbarGroupControls = DropdownOption & {
/**
Expand All @@ -15,44 +18,95 @@ export type ToolbarGroupControls = DropdownOption & {
subscript?: string;
};

export type ToolbarGroupProps = {
type ToolbarGroupPropsBase = {
/**
* The controls to render in this toolbar.
*/
controls?: ToolbarGroupControls[];

/**
* Any other things to render inside the toolbar besides the controls.
*/
children?: ReactNode;
controls?: ToolbarGroupControls[] | ToolbarGroupControls[][];

/**
* Class to set on the container div.
*/
className?: string;

/**
* Turns ToolbarGroup into a dropdown menu.
*/
isCollapsed?: boolean;

/**
* ARIA label for dropdown menu if is collapsed.
* Any other things to render inside the toolbar besides the controls.
*/
title?: string;
children?: ReactNode;
};

export type ToolbarGroupCollapsedProps = Omit< ToolbarGroupProps, 'props' > & {
/**
* Props to be passed to the drop down.
*/
toggleProps?: Record< string, any >;
// export type ToolbarGroupProps = {
// /**
// * The controls to render in this toolbar.
// */
// controls?: ToolbarGroupControls[] | ToolbarGroupControls[][];

/**
* Props to be passed.
*/
props?: any;
};
// /**
// * Any other things to render inside the toolbar besides the controls.
// */
// children?: ReactNode;

// /**
// * Class to set on the container div.
// */
// className?: string;

// /**
// * Turns ToolbarGroup into a dropdown menu.
// */
// isCollapsed?: boolean;

// /**
// * ARIA label for dropdown menu if is collapsed.
// */
// title?: string;

// // TODO: Looks like this was needed, should the group be sharing other props?
// icon?: string;
// };

export type ToolbarGroupProps = ToolbarGroupPropsBase &
(
| {
/**
* When true, turns `ToolbarGroup` into a dropdown menu.
*/
isCollapsed?: false;
/**
* Any other things to render inside the toolbar besides the controls.
*/
children?: ReactNode;
title?: never;
}
| {
/**
* When true, turns `ToolbarGroup` into a dropdown menu.
*/
isCollapsed: true;
/**
* Any other things to render inside the toolbar besides the controls.
*/
children?: ToolbarGroupCollapsedProps[ 'children' ];
/**
* ARIA label for dropdown menu if is collapsed.
*/
title: string;
}
);

// export type ToolbarGroupCollapsedProps = ToolbarGroupProps & {
// /**
// * Props to be passed to the drop down.
// */
// toggleProps?: Record< string, any >;

// /**
// * Props to be passed.
// */
// props?: any;
// };

export type ToolbarGroupCollapsedProps = DropdownMenuProps;

export type ToolbarGroupContainerProps = {
/**
Expand Down

0 comments on commit 4ab80d2

Please sign in to comment.