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 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
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
21 changes: 19 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, 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,19 @@ declare module '@elastic/eui' {
export type x = EuiRadioGroupProps['onChange'];

export const EuiRadioGroup: SFC<EuiRadioGroupProps>;

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

export const EuiRadio: SFC<
CommonProps & HTMLAttributes<HTMLDivElement> & EuiRadioProps
>;
}
2 changes: 2 additions & 0 deletions src/components/form/radio/radio_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const EuiRadioGroup = ({
);

EuiRadioGroup.propTypes = {
disabled: PropTypes.bool,
name: PropTypes.string,
options: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
Expand Down
35 changes: 35 additions & 0 deletions src/components/form/range/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <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 }>;
// `min` and `max` are optional in HTML but required for our component,
// so we override them.
max: number;
min: number;
// The spec allows string values for `step` but the component requires
// a number.
step?: number;
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
>;
}