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

EuiSuggest: converted to Typescript #2692

Merged
merged 7 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -2,6 +2,7 @@

- 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.

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