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

Add types for EuiEmptyPrompt, EuiCode(Block), EuiCallOut #1010

Merged
merged 8 commits into from
Jul 13, 2018
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Make some proprties of `EuiFlyout` optional ([#1003](https://github.com/elastic/eui/pull/1003))
- Add typings for `EuiFlyout`, `EuiFlyoutBody`, `EuiFlyoutHeader`, and `EuiFlyoutFooter` ([#1001](https://github.com/elastic/eui/pull/1001))
- Gave `EuiFlyout` close button a data-test-subj ([#1000](https://github.com/elastic/eui/pull/1000))
- Add typings for `EuiEmptyPrompt`, `EuiCode`, `EuiCodeBlock`, and `EuiCallOut` ([#1010](https://github.com/elastic/eui/pull/1010))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to use past-tense in the changelog.


**Breaking changes**

Expand Down
26 changes: 26 additions & 0 deletions src/components/call_out/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference path="../common.d.ts" />
/// <reference path="../icon/index.d.ts" />

import { SFC, ReactNode, HTMLAttributes } from 'react';

declare module '@elastic/eui' {
/**
* EuiCallOut type defs
*
* @see './code.js'
*/

type Color = 'primary' | 'success' | 'warning' | 'danger';
type Size = 's' | 'm';

export interface EuiCallOutProps {
title?: ReactNode,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the title prop collides with the title attribute from HTMLAttributes<HTMLDivElement>, so TypeScript seems to be requiring that values in that prop meet both ReactNode and string which is weird... Experimenting...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I just removed HTMLAttributes<HTMLDivElement> from the prop types signature for now, we can always add specific properties down the road if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can keep using HTMLAttributes and use Omit (defined in common.d.ts) to omit the original title prop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I figured there must be a way to do that, couldn't figure it out.

iconType?: IconType,
color?: Color,
size?: Size,
}

export const EuiCallOut: SFC<
CommonProps & EuiCallOutProps & HTMLAttributes<HTMLDivElement>
>;
}
57 changes: 57 additions & 0 deletions src/components/code/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/// <reference path="../common.d.ts" />

import { SFC, HTMLAttributes } from 'react';

declare module '@elastic/eui' {
type FontSize = 's' | 'm' | 'l';
type PaddingSize = 'none' | 's' | 'm' | 'l';

// there isn't a specific type for the <code> element, and MDN
// says that it only supports the HTMLElement interface
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code
type HTMLCodeElement = HTMLElement

interface EuiCodeSharedProps {
paddingSize?: PaddingSize;

/**
* Sets the syntax highlighting for a specific language
* See http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html#language-names-and-aliases
* for options
*/
language?: string;

overflowHeight?: number;
fontSize?: FontSize;
transparentBackground?: boolean;
}


/**
* EuiCode type defs
*
* @see './code.js'
*/

export interface EuiCodeProps extends EuiCodeSharedProps {
inline?: true
}

export const EuiCode: SFC<
CommonProps & EuiCodeProps & HTMLAttributes<HTMLCodeElement>
>;

/**
* EuiCodeBlock type defs
*
* @see './code_block.js'
*/

export interface EuiCodeBlockProps extends EuiCodeSharedProps {
inline?: false
}

export const EuiCodeBlock: SFC<
CommonProps & EuiCodeBlockProps & HTMLAttributes<HTMLCodeElement>
>;
}
26 changes: 26 additions & 0 deletions src/components/empty_prompt/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference path="../common.d.ts" />
/// <reference path="../icon/index.d.ts" />
/// <reference path="../title/index.d.ts" />

import { SFC, ReactNode, HTMLAttributes } from 'react';

declare module '@elastic/eui' {
/**
* EuiEmptyPrompt type defs
*
* @see './empty_prompt.js'
*/

export interface EuiEmptyPromptProps {
iconType?: IconType;
iconColor?: IconColor;
title?: ReactNode;
titleSize?: EuiTitleSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, eventually it looks like we'll need to align our naming. Some of these are prefixed and some are not.

body?: ReactNode;
actions?: ReactNode;
}

export const EuiEmptyPrompt: SFC<
CommonProps & EuiEmptyPromptProps & HTMLAttributes<HTMLDivElement>
>;
}
3 changes: 3 additions & 0 deletions src/components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
/// <reference path="./horizontal_rule/index.d.ts" />
/// <reference path="./page/index.d.ts" />
/// <reference path="./flyout/index.d.ts" />
/// <reference path="./empty_prompt/index.d.ts" />
/// <reference path="./code/index.d.ts" />
/// <reference path="./call_out/index.d.ts" />