1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Paper, StyleRulesCallback, withStyles, WithStyles, List } from '@material-ui/core';
7 import { RecentQueriesItem } from '~/views-components/search-bar/search-bar-view';
8 import { GroupContentsResource } from '~/services/groups-service/groups-service';
9 import Highlighter from "react-highlight-words";
11 type CssRules = 'list' | 'searchView';
13 const styles: StyleRulesCallback<CssRules> = theme => {
19 borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px`
24 export interface SearchBarAutocompleteViewDataProps {
25 searchResults?: GroupContentsResource[];
29 type SearchBarAutocompleteViewProps = SearchBarAutocompleteViewDataProps & WithStyles<CssRules>;
31 export const SearchBarAutocompleteView = withStyles(styles)(
32 ({ classes, searchResults, searchValue }: SearchBarAutocompleteViewProps) =>
33 <Paper className={classes.searchView}>
34 {searchResults && <List component="nav" className={classes.list}>
35 {searchResults.map((item: GroupContentsResource) => {
36 return <RecentQueriesItem key={item.uuid} text={getFormattedText(item.name, searchValue)} />;
42 const getFormattedText = (textToHighlight: string, searchString = '') => {
43 return <Highlighter searchWords={[searchString]} autoEscape={true} textToHighlight={textToHighlight} />;