SearchMethodMenuItem.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import { useCurrentPagePath } from '~/stores/page';
  4. type MenuItemProps = {
  5. children: React.ReactNode
  6. onClick: () => void
  7. }
  8. const MenuItem = (props: MenuItemProps): JSX.Element => {
  9. const { children, onClick } = props;
  10. return (
  11. <tr>
  12. <div className="text-muted ps-1 d-flex">
  13. <span className="material-symbols-outlined fs-4 me-3">search</span>
  14. { children }
  15. </div>
  16. </tr>
  17. );
  18. };
  19. type SearchMethodMenuItemProps = {
  20. searchKeyword: string
  21. }
  22. export const SearchMethodMenuItem = (props: SearchMethodMenuItemProps): JSX.Element => {
  23. const { t } = useTranslation('commons');
  24. const { data: currentPagePath } = useCurrentPagePath();
  25. const { searchKeyword } = props;
  26. const shouldShowButton = searchKeyword.length > 0;
  27. return (
  28. <table className="table">
  29. <tbody>
  30. { shouldShowButton && (
  31. <MenuItem onClick={() => {}}>
  32. <span>{searchKeyword}</span>
  33. <div className="ms-auto">
  34. <span>{t('search_buttons.search_in_all')}</span>
  35. </div>
  36. </MenuItem>
  37. )}
  38. <MenuItem onClick={() => {}}>
  39. <code>prefix: {currentPagePath}</code>
  40. <span className="ms-2">{searchKeyword}</span>
  41. <div className="ms-auto">
  42. <span>{t('search_buttons.only_children_of_this_tree')}</span>
  43. </div>
  44. </MenuItem>
  45. { shouldShowButton && (
  46. <MenuItem onClick={() => {}}>
  47. <span>{`"${searchKeyword}"`}</span>
  48. <div className="ms-auto">
  49. <span>{t('search_buttons.exact_mutch')}</span>
  50. </div>
  51. </MenuItem>
  52. ) }
  53. </tbody>
  54. </table>
  55. );
  56. };