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

EuiFieldNumber: converted to Typescript #2685

Merged
merged 6 commits into from
Dec 19, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Converted `EuiFieldNumber` to Typescript ([#2685](https://github.com/elastic/eui/pull/2685))
- Converted `EuiFieldPassword` to Typescript ([#2683](https://github.com/elastic/eui/pull/2683))
- Converted `EuiHighlight` to Typescript ([#2681](https://github.com/elastic/eui/pull/2681))
- Converted `EuiTextArea` to Typescript ([#2695](https://github.com/elastic/eui/pull/2695))
Expand Down
138 changes: 0 additions & 138 deletions src/components/form/field_number/field_number.js

This file was deleted.

107 changes: 107 additions & 0 deletions src/components/form/field_number/field_number.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { InputHTMLAttributes, Ref, FunctionComponent } from 'react';
import { CommonProps } from '../../common';
import classNames from 'classnames';

import { EuiFormControlLayout } from '../form_control_layout';

import { EuiValidatableControl } from '../validatable_control';

export type EuiFieldNumberProps = InputHTMLAttributes<HTMLInputElement> &
ffknob marked this conversation as resolved.
Show resolved Hide resolved
CommonProps & {
value?: number | '';
icon?: string;
isInvalid?: boolean;
fullWidth?: boolean;
isLoading?: boolean;
readOnly?: boolean;
min?: number;
max?: number;
step?: number;
inputRef?: Ref<HTMLInputElement>;

/**
* Creates an input group with element(s) coming before input
*/
prepend?: JSX.Element | JSX.Element[];

/**
* Creates an input group with element(s) coming after input
*/
append?: string;

/**
* Completely removes form control layout wrapper and ignores
* icon, prepend, and append. Best used inside EuiFormControlLayoutDelimited.
*/
controlOnly?: boolean;

/**
* when `true` creates a shorter height input
*/
compressed?: boolean;
};

export const EuiFieldNumber: FunctionComponent<EuiFieldNumberProps> = ({
className,
icon,
id,
placeholder,
name,
min,
max,
value,
isInvalid,
fullWidth = false,
isLoading = false,
compressed = false,
prepend,
append,
inputRef,
readOnly,
controlOnly,
...rest
}) => {
const classes = classNames('euiFieldNumber', className, {
'euiFieldNumber--withIcon': icon,
'euiFieldNumber--fullWidth': fullWidth,
'euiFieldNumber--compressed': compressed,
'euiFieldNumber--inGroup': prepend || append,
'euiFieldNumber-isLoading': isLoading,
});

const control = (
<EuiValidatableControl isInvalid={isInvalid}>
<input
type="number"
id={id}
min={min}
max={max}
name={name}
value={value}
placeholder={placeholder}
readOnly={readOnly}
className={classes}
ref={inputRef}
{...rest}
/>
</EuiValidatableControl>
);

if (controlOnly) {
return control;
}

return (
<EuiFormControlLayout
icon={icon}
fullWidth={fullWidth}
isLoading={isLoading}
compressed={compressed}
readOnly={readOnly}
prepend={prepend}
append={append}
inputId={id}>
{control}
</EuiFormControlLayout>
);
};
27 changes: 0 additions & 27 deletions src/components/form/field_number/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/components/form/field_number/index.js

This file was deleted.

1 change: 1 addition & 0 deletions src/components/form/field_number/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EuiFieldNumber, EuiFieldNumberProps } from './field_number';
1 change: 0 additions & 1 deletion src/components/form/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CommonProps } from '../common';
/// <reference path="./field_number/index.d.ts" />
/// <reference path="./field_search/index.d.ts" />
/// <reference path="./field_text/index.d.ts" />
/// <reference path="./form_row/index.d.ts" />
Expand Down