Skip to content

Commit

Permalink
EuiGlobalToastListItem code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo committed Apr 29, 2019
1 parent 5d52ec4 commit 9c72666
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type RefCallback<Element extends HTMLElement> = (

// utility types:

export type Filter<T, U> = T extends U ? T : never; // Remove types from T that are not assignable to U
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

/**
Expand Down
23 changes: 10 additions & 13 deletions src/components/toast/global_toast_list_item.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import {
cloneElement,
FunctionComponent,
ReactElement,
ReactNode,
Children,
} from 'react';
import { cloneElement, FunctionComponent, ReactElement } from 'react';
import classNames from 'classnames';
import { CommonProps, Filter } from '../common';
import { CommonProps } from '../common';

export interface EuiGlobalToastListItemProps {
isDismissed?: boolean;
children?: Filter<{ props: ReactNode }, ReactNode>;
children?: ReactElement;
}

export const EuiGlobalToastListItem: FunctionComponent<
CommonProps & EuiGlobalToastListItemProps
> = ({ children, isDismissed }) => {
if (!children) {
return null;
}
const classes = classNames(
'euiGlobalToastListItem',
children!.props.className,
children.props.className,
{
'euiGlobalToastListItem-isDismissed': isDismissed,
}
);
const child = Children.only(children);
return cloneElement(child as ReactElement<any>, {
...children!.props,

return cloneElement(children, {
...children.props,
...{ className: classes },
});
};
8 changes: 5 additions & 3 deletions src/components/toast/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export {
EuiGlobalToastListItemProps,
EuiGlobalToastListItem,
import {
EuiGlobalToastListItemProps as ToastListItemProps,
EuiGlobalToastListItem as ToastListItem,
} from './global_toast_list_item';
import { CommonProps } from '../common';
import { IconType } from '../icon';
Expand Down Expand Up @@ -28,6 +28,8 @@ declare module '@elastic/eui' {
}

export const EuiToast: FunctionComponent<EuiToastProps>;
export interface EuiGlobalToastListItem extends ToastListItemProps {}
export const EuiGlobalToastListItem: typeof ToastListItem;

/**
* EuiGlobalToastList type def
Expand Down

0 comments on commit 9c72666

Please sign in to comment.