You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
4 years ago
|
import React, { useState, useRef } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import ItemList from './item-list';
|
||
|
import ListItemSearch from './list-item-search';
|
||
4 years ago
|
|
||
4 years ago
|
export default function SearchableItemList({
|
||
4 years ago
|
className,
|
||
|
defaultToAll,
|
||
|
fuseSearchKeys,
|
||
|
itemSelectorError,
|
||
|
itemsToSearch = [],
|
||
|
listTitle,
|
||
|
maxListItems,
|
||
|
onClickItem,
|
||
|
Placeholder,
|
||
|
searchPlaceholderText,
|
||
|
hideRightLabels,
|
||
|
hideItemIf,
|
||
|
listContainerClassName,
|
||
|
}) {
|
||
4 years ago
|
const itemListRef = useRef();
|
||
4 years ago
|
|
||
4 years ago
|
const [results, setResults] = useState(defaultToAll ? itemsToSearch : []);
|
||
|
const [searchQuery, setSearchQuery] = useState('');
|
||
4 years ago
|
|
||
|
return (
|
||
|
<div className={className}>
|
||
|
<ListItemSearch
|
||
|
listToSearch={itemsToSearch}
|
||
|
fuseSearchKeys={fuseSearchKeys}
|
||
4 years ago
|
onSearch={({
|
||
|
searchQuery: newSearchQuery = '',
|
||
|
results: newResults = [],
|
||
|
}) => {
|
||
4 years ago
|
setSearchQuery(newSearchQuery);
|
||
|
setResults(newResults);
|
||
4 years ago
|
}}
|
||
|
error={itemSelectorError}
|
||
|
searchPlaceholderText={searchPlaceholderText}
|
||
|
defaultToAll={defaultToAll}
|
||
|
/>
|
||
|
<ItemList
|
||
|
searchQuery={searchQuery}
|
||
|
results={results}
|
||
|
onClickItem={onClickItem}
|
||
|
Placeholder={Placeholder}
|
||
|
listTitle={listTitle}
|
||
|
maxListItems={maxListItems}
|
||
|
containerRef={itemListRef}
|
||
|
hideRightLabels={hideRightLabels}
|
||
|
hideItemIf={hideItemIf}
|
||
|
listContainerClassName={listContainerClassName}
|
||
|
/>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
|
|
||
|
SearchableItemList.propTypes = {
|
||
|
itemSelectorError: PropTypes.string,
|
||
|
itemsToSearch: PropTypes.array,
|
||
|
onClickItem: PropTypes.func,
|
||
|
Placeholder: PropTypes.func,
|
||
|
className: PropTypes.string,
|
||
|
searchPlaceholderText: PropTypes.string,
|
||
4 years ago
|
fuseSearchKeys: PropTypes.arrayOf(
|
||
|
PropTypes.shape({
|
||
|
name: PropTypes.string,
|
||
|
weight: PropTypes.number,
|
||
|
}),
|
||
|
),
|
||
4 years ago
|
listTitle: PropTypes.string,
|
||
|
defaultToAll: PropTypes.bool,
|
||
|
maxListItems: PropTypes.number,
|
||
|
hideRightLabels: PropTypes.bool,
|
||
|
hideItemIf: PropTypes.func,
|
||
|
listContainerClassName: PropTypes.string,
|
||
4 years ago
|
};
|