Skip to content

Commit

Permalink
EuiSuggest: converted to Typescript (#2692)
Browse files Browse the repository at this point in the history
* Converts EuiSuggest to Typescript

* Adds PR number to CHANGELOG line

* Changes Object.keys() to keysOf()

* Changes icon type to IconType
  • Loading branch information
ffknob authored and chandlerprall committed Dec 30, 2019
1 parent 01a6c3f commit 772d2a8
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 327 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- 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 `EuiSuggest` to Typescript ([#2692](https://github.com/elastic/eui/pull/2692))
- Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690))

**Bug fixes**
Expand Down
5 changes: 0 additions & 5 deletions src/components/suggest/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/components/suggest/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { EuiSuggestInput, EuiSuggestInputProps } from './suggest_input';

export { EuiSuggestItem, EuiSuggestItemProps } from './suggest_item';

export { EuiSuggest, EuiSuggestProps } from './suggest';
81 changes: 0 additions & 81 deletions src/components/suggest/suggest.js

This file was deleted.

File renamed without changes.
63 changes: 63 additions & 0 deletions src/components/suggest/suggest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { FunctionComponent } from 'react';
import { CommonProps } from '../common';
import { EuiSuggestItem, EuiSuggestItemProps } from './suggest_item';
import { EuiSuggestInput, EuiSuggestInputProps } from './suggest_input';

export type EuiSuggestProps = CommonProps &
EuiSuggestInputProps & {
/**
* List of suggestions to display using 'suggestItem'.
*/
suggestions: EuiSuggestItemProps[];

/**
* Handler for click on a suggestItem.
*/
onItemClick?: (item: EuiSuggestItemProps) => void;

onInputChange?: (target: EventTarget) => void;
};

export const EuiSuggest: FunctionComponent<EuiSuggestProps> = (
props: EuiSuggestProps
) => {
const {
onItemClick,
onInputChange,
status,
append,
tooltipContent,
suggestions,
...rest
} = props;

const onChange = (e: React.FormEvent<HTMLDivElement>) => {
onInputChange ? onInputChange(e.target) : null;
};

const suggestionList = suggestions.map((item: EuiSuggestItemProps, index) => (
<EuiSuggestItem
type={item.type}
key={index}
label={item.label}
onClick={onItemClick ? () => onItemClick(item) : undefined}
description={item.description}
/>
));

const suggestInput = (
<EuiSuggestInput
status={status}
tooltipContent={tooltipContent}
append={append}
suggestions={suggestionList}
{...rest}
/>
);

return <div onChange={onChange}>{suggestInput}</div>;
};

EuiSuggestInput.defaultProps = {
status: 'unchanged',
};
134 changes: 0 additions & 134 deletions src/components/suggest/suggest_input.js

This file was deleted.

Loading

0 comments on commit 772d2a8

Please sign in to comment.