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 3 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))

**Bug fixes**

Expand Down
File renamed without changes.
81 changes: 0 additions & 81 deletions src/components/suggest/suggest.js

This file was deleted.

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

export type EuiSuggestProps = CommonProps & {
ffknob marked this conversation as resolved.
Show resolved Hide resolved
tooltipContent?: string;

/**
* Status of the current query 'notYetSaved', 'saved', 'unchanged' or 'loading'.
*/
status?: 'unsaved' | 'saved' | 'unchanged' | 'loading';

/**
* Element to be appended to the input bar (e.g. hashtag popover).
*/
append?: JSX.Element;

/**
* List of suggestions to display using 'suggestItem'.
*/
suggestions: EuiSuggestItemProps[];

/**
* Handler for click on a suggestItem.
*/
onItemClick?: Function;
ffknob marked this conversation as resolved.
Show resolved Hide resolved

onInputChange?: Function;
ffknob marked this conversation as resolved.
Show resolved Hide resolved
};

export const EuiSuggest: FunctionComponent<EuiSuggestProps> = (
props: EuiSuggestProps
) => {
const setValue = useState<string>('')[1];
ffknob marked this conversation as resolved.
Show resolved Hide resolved

const {
onItemClick,
onInputChange,
status,
append,
tooltipContent,
suggestions,
...rest
} = props;

const getValue = (val: string) => {
setValue(val);
};

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}
sendValue={getValue}
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