Aucune description

CapsuleSearchBar.tsx 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React, { useState } from 'react';
  2. import {
  3. IonItem,
  4. IonList,
  5. IonSearchbar,
  6. IonCard,
  7. IonCardHeader,
  8. IonCardTitle,
  9. } from '@ionic/react';
  10. import capsules from '../data/Capsule.json'
  11. function SearchBar() {
  12. let [results, setResults] = useState([...capsules]);
  13. const filterSearch = (ev: Event) => {
  14. let query = "";
  15. const target = ev.target as HTMLIonSearchbarElement;
  16. if (target) query = target.value!.toLowerCase();
  17. setResults(capsules.filter(cap => {
  18. return cap.title.toLowerCase().indexOf(query) > -1;
  19. })
  20. )
  21. }
  22. return (
  23. <>
  24. <IonSearchbar debounce={500} onIonChange={(ev) => filterSearch(ev)}></IonSearchbar>
  25. <IonList inset={true}>
  26. { results.map(result => (
  27. <IonCard>
  28. <IonItem button routerLink={`/Capsule/${result.id}`}>
  29. <IonCardHeader>
  30. <IonCardTitle>{result.title}</IonCardTitle>
  31. </IonCardHeader>
  32. </IonItem>
  33. </IonCard>
  34. ))}
  35. </IonList>
  36. </>
  37. );
  38. }
  39. export default SearchBar;
  40. /*
  41. <>
  42. <IonCard>
  43. <IonItem routerLink={`/Biography/${listbio.id}`}>
  44. <IonImg style={{ height: 300, width: 600 }} src={RobertoClemente} alt='Logo'></IonImg>
  45. <IonCardHeader>
  46. <IonCardTitle>{listbio.title}</IonCardTitle>
  47. <IonCardSubtitle>{listbio.tags}</IonCardSubtitle>
  48. </IonCardHeader><IonCardContent>
  49. {listbio.content}
  50. </IonCardContent>
  51. </IonItem>
  52. <IonItem routerLink={`/Question`} detail={true}>
  53. <IonIcon icon={square} />Tomar quiz
  54. </IonItem>
  55. </IonCard>
  56. </>
  57. */