1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/ui/pages/swaps/searchable-item-list/searchable-item-list.js

84 lines
2.3 KiB
JavaScript
Raw Normal View History

import React, { useState, useRef } from 'react';
import PropTypes from 'prop-types';
import ItemList from './item-list';
import ListItemSearch from './list-item-search';
2020-10-06 20:28:38 +02:00
2020-11-03 00:41:28 +01:00
export default function SearchableItemList({
2020-10-06 20:28:38 +02:00
className,
defaultToAll,
fuseSearchKeys,
itemSelectorError,
itemsToSearch = [],
listTitle,
maxListItems,
onClickItem,
2021-06-03 18:08:37 +02:00
onOpenImportTokenModalClick,
2020-10-06 20:28:38 +02:00
Placeholder,
searchPlaceholderText,
hideRightLabels,
hideItemIf,
listContainerClassName,
2021-06-03 18:08:37 +02:00
shouldSearchForImports,
2020-10-06 20:28:38 +02:00
}) {
const itemListRef = useRef();
2020-10-06 20:28:38 +02:00
const [results, setResults] = useState(defaultToAll ? itemsToSearch : []);
const [searchQuery, setSearchQuery] = useState('');
2020-10-06 20:28:38 +02:00
return (
<div className={className}>
<ListItemSearch
listToSearch={itemsToSearch}
fuseSearchKeys={fuseSearchKeys}
2020-11-03 00:41:28 +01:00
onSearch={({
searchQuery: newSearchQuery = '',
results: newResults = [],
}) => {
setSearchQuery(newSearchQuery);
setResults(newResults);
2020-10-06 20:28:38 +02:00
}}
error={itemSelectorError}
searchPlaceholderText={searchPlaceholderText}
defaultToAll={defaultToAll}
2021-06-03 18:08:37 +02:00
shouldSearchForImports={shouldSearchForImports}
2020-10-06 20:28:38 +02:00
/>
<ItemList
searchQuery={searchQuery}
results={results}
onClickItem={onClickItem}
2021-06-03 18:08:37 +02:00
onOpenImportTokenModalClick={onOpenImportTokenModalClick}
2020-10-06 20:28:38 +02:00
Placeholder={Placeholder}
listTitle={listTitle}
maxListItems={maxListItems}
containerRef={itemListRef}
hideRightLabels={hideRightLabels}
hideItemIf={hideItemIf}
listContainerClassName={listContainerClassName}
/>
</div>
);
2020-10-06 20:28:38 +02:00
}
SearchableItemList.propTypes = {
itemSelectorError: PropTypes.string,
itemsToSearch: PropTypes.array,
onClickItem: PropTypes.func,
2021-06-03 18:08:37 +02:00
onOpenImportTokenModalClick: PropTypes.func,
2020-10-06 20:28:38 +02:00
Placeholder: PropTypes.func,
className: PropTypes.string,
searchPlaceholderText: PropTypes.string,
2020-11-03 00:41:28 +01:00
fuseSearchKeys: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
weight: PropTypes.number,
}),
),
2020-10-06 20:28:38 +02:00
listTitle: PropTypes.string,
defaultToAll: PropTypes.bool,
maxListItems: PropTypes.number,
hideRightLabels: PropTypes.bool,
hideItemIf: PropTypes.func,
listContainerClassName: PropTypes.string,
2021-06-03 18:08:37 +02:00
shouldSearchForImports: PropTypes.bool,
};