Skip to content

Commit

Permalink
Merge pull request #16 from chandlerprall/icon-tip-props-types
Browse files Browse the repository at this point in the history
Icon tip props types
  • Loading branch information
cchaos authored Jan 9, 2019
2 parents 22936c3 + 2e87482 commit e4782b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/components/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Component, FunctionComponent, SFC } from 'react';

export interface CommonProps {
className?: string;
'aria-label'?: string;
Expand All @@ -18,6 +20,12 @@ export function keysOf<T, K extends keyof T>(obj: T): K[] {
return Object.keys(obj) as K[];
}

export type PropsOf<C> =
C extends SFC<infer SFCProps> ? SFCProps :
C extends FunctionComponent<infer FunctionalProps> ? FunctionalProps :
C extends Component<infer ComponentProps> ? ComponentProps
: never;

/*
TypeScript's discriminated unions are overly permissive: as long as one type of the union is satisfied
the other types are not validated against. For example:
Expand Down
17 changes: 8 additions & 9 deletions src/components/tool_tip/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ReactElement, ReactNode, SFC } from 'react';
import { EuiIcon } from '../icon';
import { Omit, PropsOf } from '../common';

declare module '@elastic/eui' {
export type ToolTipPositions =
Expand All @@ -11,26 +13,23 @@ declare module '@elastic/eui' {
| 'regular'
| 'long';

export interface ToolTipProps {
export interface EuiToolTipProps {
children: ReactElement<any>;
className?: string;
content: ReactNode;
content?: ReactNode;
delay?: ToolTipDelay;
title?: ReactNode;
id?: string;
position?: ToolTipPositions;
}

export interface EuiToolTipProps {
children: ReactElement<any>;
}
export const EuiToolTip: SFC<ToolTipProps & EuiToolTipProps>;
export const EuiToolTip: SFC<EuiToolTipProps>;

export interface EuiIconTipProps {
color?: string;
type?: string;
size?: string;
'aria-label'?: string;
iconProps?: object;
iconProps?: PropsOf<typeof EuiIcon>;
}
export const EuiIconTip: SFC<ToolTipProps & EuiIconTipProps>;
export const EuiIconTip: SFC<Omit<EuiToolTipProps, 'children'> & EuiIconTipProps>;
}

0 comments on commit e4782b0

Please sign in to comment.