From a397d61c44cbae9de0d7451f32b11735520d74ae Mon Sep 17 00:00:00 2001 From: Rory Hunter Date: Thu, 18 Oct 2018 06:36:48 +0100 Subject: [PATCH] TypeScript definition changes (#1247) * TypeScript definition changes Add definitions for `EuiAccordion`, `EuiDescriptionList`, `EuiForm`, `EuiFormHelpText` and the accessibility services, and fix a number of small TS issues. * Fix EuiCheckbox TS def --- CHANGELOG.md | 4 ++- src/components/accordion/index.d.ts | 18 +++++++++++ src/components/button/index.d.ts | 1 + src/components/combo_box/index.d.ts | 2 +- src/components/description_list/index.d.ts | 31 +++++++++++++++++++ src/components/form/checkbox/index.d.ts | 4 +-- src/components/form/form_help_text/index.d.ts | 17 ++++++++++ src/components/form/form_row/index.d.ts | 2 +- src/components/form/index.d.ts | 17 ++++++++++ src/components/index.d.ts | 2 ++ src/components/text/index.d.ts | 1 + src/components/tool_tip/index.d.ts | 3 +- src/services/accessibility/index.d.ts | 6 ++++ src/services/index.d.ts | 1 + 14 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 src/components/accordion/index.d.ts create mode 100644 src/components/description_list/index.d.ts create mode 100644 src/components/form/form_help_text/index.d.ts create mode 100644 src/services/accessibility/index.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 79d03b76ec4..e9258533024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## [`master`](https://github.com/elastic/eui/tree/master) -No public interface changes since `4.5.1`. +**Bug fixes** + +* TypeScript definition changes for `EuiAccordion`, `EuiDescriptionList`, `EuiForm`, `EuiFormHelpText` and the accessibility services, plus a number of other TS fixes ([#1247](https://github.com/elastic/eui/pull/1247)) ## [`4.5.1`](https://github.com/elastic/eui/tree/v4.5.1) diff --git a/src/components/accordion/index.d.ts b/src/components/accordion/index.d.ts new file mode 100644 index 00000000000..2a66e5867b6 --- /dev/null +++ b/src/components/accordion/index.d.ts @@ -0,0 +1,18 @@ +import { HTMLAttributes, Component, ReactNode } from 'react'; + +declare module '@elastic/eui' { + export type EuiAccordionSize = 'none' | 'xs' | 's' | 'm' | 'l' | 'xl'; + + export interface EuiAccordionProps { + id: string; + buttonContentClassName?: string; + buttonContent?: ReactNode; + extraAction?: ReactNode; + initialIsOpen?: boolean; + paddingSize?: EuiAccordionSize; + } + + export class EuiAccordion extends Component< + CommonProps & HTMLAttributes & EuiAccordionProps + > {} +} diff --git a/src/components/button/index.d.ts b/src/components/button/index.d.ts index a67acfe3b1b..fe10d678721 100644 --- a/src/components/button/index.d.ts +++ b/src/components/button/index.d.ts @@ -57,6 +57,7 @@ declare module '@elastic/eui' { 'aria-label'?: string; 'aria-labelledby'?: string; isDisabled?: boolean; + size?: ButtonSize; } export const EuiButtonIcon: SFC< EuiButtonPropsForButtonOrLink diff --git a/src/components/combo_box/index.d.ts b/src/components/combo_box/index.d.ts index a16de82c280..3fb61c90a57 100644 --- a/src/components/combo_box/index.d.ts +++ b/src/components/combo_box/index.d.ts @@ -10,7 +10,7 @@ import { declare module '@elastic/eui' { export type EuiComboBoxOptionProps = ButtonHTMLAttributes & { label: string, - isGroupLabelOption: boolean, + isGroupLabelOption?: boolean, } export type EuiComboBoxOptionsListPosition = 'top' | 'bottom' diff --git a/src/components/description_list/index.d.ts b/src/components/description_list/index.d.ts new file mode 100644 index 00000000000..cd1d7db6cef --- /dev/null +++ b/src/components/description_list/index.d.ts @@ -0,0 +1,31 @@ +import { HTMLAttributes, Component, ReactNode } from 'react'; + +declare module '@elastic/eui' { + export type EuiDescriptionListType = 'row' | 'column' | 'inline'; + export type EuiDescriptionListAlignment = 'center' | 'left'; + export type EuiDescriptionListTextStyle = 'normal' | 'reverse'; + + export interface EuiDescriptionListProps { + listItems?: Array<{ title: ReactNode, description: ReactNode }>; + align?: EuiDescriptionListAlignment; + compressed?: boolean; + textStyle?: EuiDescriptionListTextStyle; + type?: EuiDescriptionListType; + } + + export class EuiDescriptionList extends Component< + CommonProps & HTMLAttributes & EuiDescriptionListProps + > {} + + export interface EuiDescriptionListTitleProps {} + + export class EuiDescriptionListTitle extends Component< + CommonProps & HTMLAttributes & EuiDescriptionListTitleProps + > {} + + export interface EuiDescriptionListDescriptionProps {} + + export class EuiDescriptionListDescription extends Component< + CommonProps & HTMLAttributes & EuiDescriptionListDescriptionProps + > {} +} diff --git a/src/components/form/checkbox/index.d.ts b/src/components/form/checkbox/index.d.ts index aa44db8ccb4..93997a6e504 100644 --- a/src/components/form/checkbox/index.d.ts +++ b/src/components/form/checkbox/index.d.ts @@ -1,6 +1,6 @@ /// -import { SFC, ReactNode, HTMLAttributes, ChangeEventHandler } from 'react'; +import { SFC, ReactNode, HTMLAttributes, ChangeEventHandler, InputHTMLAttributes } from 'react'; declare module '@elastic/eui' { /** @@ -22,7 +22,7 @@ declare module '@elastic/eui' { } export const EuiCheckbox: SFC< - CommonProps & HTMLAttributes & EuiCheckboxProps + CommonProps & InputHTMLAttributes & EuiCheckboxProps >; /** diff --git a/src/components/form/form_help_text/index.d.ts b/src/components/form/form_help_text/index.d.ts new file mode 100644 index 00000000000..0c3c51e7065 --- /dev/null +++ b/src/components/form/form_help_text/index.d.ts @@ -0,0 +1,17 @@ +/// +/// + +import { ReactNode, SFC, HTMLAttributes } from 'react'; + +declare module '@elastic/eui' { + + /** + * @see './field_help_text.js' + */ + export interface EuiFormHelpTextProps { + } + + export const EuiFormHelpText: SFC< + CommonProps & HTMLAttributes & EuiFormHelpTextProps + >; +} diff --git a/src/components/form/form_row/index.d.ts b/src/components/form/form_row/index.d.ts index b2eb7becdf3..e957c909870 100644 --- a/src/components/form/form_row/index.d.ts +++ b/src/components/form/form_row/index.d.ts @@ -9,7 +9,7 @@ declare module '@elastic/eui' { export type EuiFormRowProps = CommonProps & HTMLAttributes & { - error?: string | string[]; + error?: ReactNode | ReactNode[]; fullWidth?: boolean; hasEmptyLabelSpace?: boolean; helpText?: ReactNode; diff --git a/src/components/form/index.d.ts b/src/components/form/index.d.ts index f5cf502b1c4..03e77287856 100644 --- a/src/components/form/index.d.ts +++ b/src/components/form/index.d.ts @@ -1,10 +1,27 @@ +/// /// /// /// /// +/// /// /// /// /// /// /// + +import { SFC, FormHTMLAttributes, ReactNode } from 'react'; + +declare module '@elastic/eui' { + /** + * @see './form.js' + */ + export type EuiFormProps = CommonProps & + FormHTMLAttributes & { + isInvalid?: boolean; + error?: ReactNode | ReactNode[]; + }; + + export const EuiForm: SFC; +} diff --git a/src/components/index.d.ts b/src/components/index.d.ts index 3d48abf511e..c971f057e6a 100644 --- a/src/components/index.d.ts +++ b/src/components/index.d.ts @@ -1,8 +1,10 @@ /// +/// /// /// /// /// +/// /// /// /// diff --git a/src/components/text/index.d.ts b/src/components/text/index.d.ts index cb90f56fdf5..990c4b8a79a 100644 --- a/src/components/text/index.d.ts +++ b/src/components/text/index.d.ts @@ -24,6 +24,7 @@ declare module '@elastic/eui' { HTMLAttributes & { size?: SIZES; color?: COLORS; + grow?: boolean; }; type EuiTextColorProps = CommonProps & diff --git a/src/components/tool_tip/index.d.ts b/src/components/tool_tip/index.d.ts index 0ae40a15bfa..8572335f233 100644 --- a/src/components/tool_tip/index.d.ts +++ b/src/components/tool_tip/index.d.ts @@ -1,7 +1,7 @@ import { ReactElement, ReactNode, SFC } from 'react'; declare module '@elastic/eui' { - export type ToolTipPositions = + export type ToolTipPositions = | 'top' | 'right' | 'bottom' @@ -22,6 +22,7 @@ declare module '@elastic/eui' { type?: string; size?: string; 'aria-label'?: string; + content: ReactNode; } export const EuiIconTip: SFC; } diff --git a/src/services/accessibility/index.d.ts b/src/services/accessibility/index.d.ts new file mode 100644 index 00000000000..5e6fb3784a3 --- /dev/null +++ b/src/services/accessibility/index.d.ts @@ -0,0 +1,6 @@ +declare module '@elastic/eui' { + export const accessibleClickKeys: { [keyCode: number]: string }; + export const cascadingMenuKeyCodes: { [keyCodeName: string]: keyCodes }; + export const comboBoxKeyCodes: { [keyCodeName: string]: keyCodes }; + export const htmlIdGenerator: (prefix?: string) => (suffix?: string) => string; +} diff --git a/src/services/index.d.ts b/src/services/index.d.ts index 37e4b505c3f..68b0e81d836 100644 --- a/src/services/index.d.ts +++ b/src/services/index.d.ts @@ -1,3 +1,4 @@ +/// /// /// ///