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

EuiTextArea: converted to Typescript #2695

Merged
merged 3 commits into from
Dec 18, 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,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Converted `EuiHighlight` to Typescript ([#2681](https://github.com/elastic/eui/pull/2681))
- Converted `EuiTextArea` to Typescript ([#2695](https://github.com/elastic/eui/pull/2695))
- Converted `EuiPage` and related child components to TypeScript ([#2669](https://github.com/elastic/eui/pull/2669))

**Bug fixes**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { TextareaHTMLAttributes, Ref, FunctionComponent } from 'react';
import { CommonProps } from '../../common';
import classNames from 'classnames';

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

export type EuiTextAreaProps = TextareaHTMLAttributes<HTMLTextAreaElement> &
CommonProps & {
isInvalid?: boolean;
fullWidth?: boolean;
compressed?: boolean;

/**
* Which direction, if at all, should the textarea resize
*/
resize?: keyof typeof resizeToClassNameMap;

inputRef?: Ref<HTMLTextAreaElement>;
};

const resizeToClassNameMap = {
vertical: 'euiTextArea--resizeVertical',
horizontal: 'euiTextArea--resizeHorizontal',
Expand All @@ -13,17 +26,17 @@ const resizeToClassNameMap = {

export const RESIZE = Object.keys(resizeToClassNameMap);

export const EuiTextArea = ({
export const EuiTextArea: FunctionComponent<EuiTextAreaProps> = ({
children,
className,
compressed,
fullWidth,
fullWidth = false,
id,
inputRef,
isInvalid,
name,
placeholder,
resize,
resize = 'vertical',
rows,
...rest
}) => {
Expand All @@ -37,7 +50,7 @@ export const EuiTextArea = ({
className
);

let definedRows;
let definedRows: number;

if (rows) {
definedRows = rows;
Expand All @@ -62,23 +75,3 @@ export const EuiTextArea = ({
</EuiValidatableControl>
);
};

EuiTextArea.propTypes = {
name: PropTypes.string,
id: PropTypes.string,
placeholder: PropTypes.string,
rows: PropTypes.number,
isInvalid: PropTypes.bool,
fullWidth: PropTypes.bool,
compressed: PropTypes.bool,

/**
* Which direction, if at all, should the textarea resize
*/
resize: PropTypes.oneOf(RESIZE),
};

EuiTextArea.defaultProps = {
fullWidth: false,
resize: 'vertical',
};