Debian Codegraph @

node/@patternfly/react-core/src/components/SearchInput/examples/SearchInputWithNavigableOptions.tsx

raw
1 import { useState } from 'react';
2 import { SearchInput } from '@patternfly/react-core';
3
4 export const SearchInputWithNavigableOptions: React.FunctionComponent = () => {
5 const [value, setValue] = useState('');
6 const [resultsCount, setResultsCount] = useState(0);
7 const [currentResult, setCurrentResult] = useState(1);
8
9 const onChange = (value: string) => {
10 setValue(value);
11 setResultsCount(3);
12 };
13
14 const onClear = () => {
15 setValue('');
16 setResultsCount(0);
17 setCurrentResult(1);
18 };
19
20 const onNext = () => {
21 const newCurrentResult = currentResult + 1;
22 setCurrentResult(newCurrentResult > resultsCount ? resultsCount : newCurrentResult);
23 };
24
25 const onPrevious = () => {
26 const newCurrentResult = currentResult - 1;
27 setCurrentResult(newCurrentResult > 0 ? newCurrentResult : 1);
28 };
29
30 return (
31 <SearchInput
32 aria-label="Search match with navigable options example"
33 placeholder="Find by name"
34 value={value}
35 onChange={(_event, value) => onChange(value)}
36 onClear={onClear}
37 isNextNavigationButtonDisabled={currentResult === 3}
38 isPreviousNavigationButtonDisabled={currentResult === 1}
39 resultsCount={`${currentResult} / ${resultsCount}`}
40 onNextClick={onNext}
41 onPreviousClick={onPrevious}
42 />
43 );
44 };