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 TypeScript definitions for EuiRange and EuiRadio #1253

Merged
merged 2 commits into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

- Increased default font size of tabs in K6 theme ([#1244](https://github.com/elastic/eui/pull/1244))

**Bug fixes**

- Add TypeScript definitions for `EuiRange` and `EuiRadio`, and correct the definitions for `EuiRadioGroup` ([#1253](https://github.com/elastic/eui/pull/1253))

## [`4.5.2`](https://github.com/elastic/eui/tree/v4.5.2)

**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))
- 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)

Expand Down
1 change: 1 addition & 0 deletions src/components/form/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// <reference path="./form_label/index.d.ts" />
/// <reference path="./form_row/index.d.ts" />
/// <reference path="./radio/index.d.ts" />
/// <reference path="./range/index.d.ts" />
/// <reference path="./select/index.d.ts" />
/// <reference path="./switch/index.d.ts" />
/// <reference path="./text_area/index.d.ts" />
Expand Down
17 changes: 15 additions & 2 deletions src/components/form/radio/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="../../common.d.ts" />

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

declare module '@elastic/eui' {
/**
Expand All @@ -11,10 +11,12 @@ declare module '@elastic/eui' {
label?: ReactNode;
}

export type EuiRadioGroupChangeCallback = (id: string) => void;
export type EuiRadioGroupChangeCallback = (id: string, value: string) => void;

export type EuiRadioGroupProps = CommonProps &
Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> & {
disabled?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add disabled and name to the radio group's proptypes as well, so they're included in the documentation & runtime checks.

name?: string;
options?: EuiRadioGroupOption[];
idSelected?: string;
onChange: EuiRadioGroupChangeCallback;
Expand All @@ -23,4 +25,15 @@ declare module '@elastic/eui' {
export type x = EuiRadioGroupProps['onChange'];

export const EuiRadioGroup: SFC<EuiRadioGroupProps>;

export interface EuiRadioProps {
autoFocus?: boolean;
compressed?: boolean;
label?: ReactNode;
onChange: ChangeEventHandler<HTMLInputElement>; // overriding to make it required
}

export const EuiRadio: SFC<
CommonProps & InputHTMLAttributes<HTMLInputElement> & EuiRadioProps
Copy link
Contributor

Choose a reason for hiding this comment

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

EuiRadio applies its extra props to a div, not any kind of input. The props here need to reflect that with HTMLAttributes<HTMLDivElement>. This also means the input-related props (checked, value, disabled, autoFocus) on EuiRadio need to be added to EuiRadioProps. The onChange definition is correct as-is (other than not being an override after the other changes), because it is forwarded to the underlying input.

>;
}
28 changes: 28 additions & 0 deletions src/components/form/range/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference path="../../common.d.ts" />

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

declare module '@elastic/eui' {
/**
* @see './range.js'
*/

export type EuiRangeLevelColor = 'primary' | 'success' | 'warning' | 'danger';

export interface EuiRangeProps {
compressed?: boolean;
fullWidth?: boolean;
id?: string;
levels?: Array<{ min?: number; max?: number; color?: EuiRangeLevelColor }>;
showInput?: boolean;
showLabels?: boolean;
showRange?: boolean;
showTicks?: boolean;
showValue?: boolean;
tickInterval?: number;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

min and max are required in EuiRange but are optional in InputHTMLAttributes, so they must be overridden here. Also, our definition & usage of step requires it to be a number, whereas InputHTMLAttributes allows number or string values, so step requires an override too.


export const EuiRange: SFC<
CommonProps & InputHTMLAttributes<HTMLInputElement> & EuiRangeProps
>;
}