Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon tip props types #16

Merged
merged 3 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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>;
}