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

EuiFieldText: converted to Typescript #2688

Merged
merged 7 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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 `EuiFieldText` to Typescript ([#2688](https://github.com/elastic/eui/pull/2688))
- Added `nested` glyph to `EuiIcon` ([#2707](https://github.com/elastic/eui/pull/2707))
- Added `tableLayout` prop to `EuiTable`, `EuiBasicTable` and `EuiInMemoryTable` to provide the option of auto layout ([#2697](https://github.com/elastic/eui/pull/2697))
- Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690))
Expand Down
3 changes: 1 addition & 2 deletions src/components/color_picker/color_picker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {
FunctionComponent,
HTMLAttributes,
ReactChild,
ReactElement,
cloneElement,
useEffect,
Expand Down Expand Up @@ -324,7 +323,7 @@ export const EuiColorPicker: FunctionComponent<EuiColorPickerProps> = ({
'Press the escape key to close the popover',
'Press the down key to open a popover containing color options',
]}>
{([openLabel, closeLabel]: ReactChild[]) => (
{([openLabel, closeLabel]: string[]) => (
<EuiFieldText
className="euiColorPicker__input"
onClick={handleInputActivity}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

exports[`EuiFieldText is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
icon="foo"
inputid="1"
isloading="false"
>
<eui-validatable-control>
<input
Expand Down Expand Up @@ -34,9 +32,7 @@ exports[`EuiFieldText props controlOnly is rendered 1`] = `

exports[`EuiFieldText props fullWidth is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="true"
isloading="false"
>
<eui-validatable-control>
<input
Expand All @@ -49,9 +45,7 @@ exports[`EuiFieldText props fullWidth is rendered 1`] = `

exports[`EuiFieldText props isInvalid is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
isloading="false"
>
<eui-validatable-control
isinvalid="true"
Expand All @@ -66,7 +60,6 @@ exports[`EuiFieldText props isInvalid is rendered 1`] = `

exports[`EuiFieldText props isLoading is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
isloading="true"
>
Expand All @@ -81,9 +74,7 @@ exports[`EuiFieldText props isLoading is rendered 1`] = `

exports[`EuiFieldText props readOnly is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
isloading="false"
readonly="true"
>
<eui-validatable-control>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { InputHTMLAttributes, Ref, FunctionComponent } from 'react';
import { CommonProps } from '../../common';
import classNames from 'classnames';

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

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

export const EuiFieldText = ({
export type EuiFieldTextProps = InputHTMLAttributes<HTMLInputElement> &
CommonProps & {
icon?: EuiFormControlLayoutProps['icon'];
isInvalid?: boolean;
fullWidth?: boolean;
isLoading?: boolean;
readOnly?: boolean;
inputRef?: Ref<HTMLInputElement>;

/**
* Creates an input group with element(s) coming before input
*/
prepend?: EuiFormControlLayoutProps['prepend'];

/**
* Creates an input group with element(s) coming after input
*/
append?: EuiFormControlLayoutProps['append'];

/**
* 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 EuiFieldText: FunctionComponent<EuiFieldTextProps> = ({
id,
name,
placeholder,
Expand All @@ -15,7 +49,7 @@ export const EuiFieldText = ({
icon,
isInvalid,
inputRef,
fullWidth,
fullWidth = false,
isLoading,
compressed,
prepend,
Expand Down Expand Up @@ -64,46 +98,3 @@ export const EuiFieldText = ({
</EuiFormControlLayout>
);
};

EuiFieldText.propTypes = {
name: PropTypes.string,
id: PropTypes.string,
placeholder: PropTypes.string,
value: PropTypes.string,
icon: PropTypes.string,
isInvalid: PropTypes.bool,
inputRef: PropTypes.func,
fullWidth: PropTypes.bool,
isLoading: PropTypes.bool,
readOnly: PropTypes.bool,
/**
* when `true` creates a shorter height input
*/
compressed: PropTypes.bool,
/**
* Creates an input group with element(s) coming before input
*/
prepend: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
/**
* Creates an input group with element(s) coming after input
*/
append: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
/**
* Completely removes form control layout wrapper and ignores
* icon, prepend, and append. Best used inside EuiFormControlLayoutDelimited.
*/
controlOnly: PropTypes.bool,
};

EuiFieldText.defaultProps = {
value: undefined,
fullWidth: false,
isLoading: false,
compressed: false,
};
1 change: 0 additions & 1 deletion src/components/form/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CommonProps } from '../common';
/// <reference path="./field_search/index.d.ts" />
/// <reference path="./field_text/index.d.ts" />
/// <reference path="./form_row/index.d.ts" />
/// <reference path="./range/index.d.ts" />
/// <reference path="./select/index.d.ts" />
Expand Down