symbol-palette-body.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { TabPanels, TabPanel } from '@reach/tabs'
  2. import { useTranslation } from 'react-i18next'
  3. import PropTypes from 'prop-types'
  4. import SymbolPaletteItems from './symbol-palette-items'
  5. export default function SymbolPaletteBody({
  6. categories,
  7. categorisedSymbols,
  8. filteredSymbols,
  9. handleSelect,
  10. focusInput,
  11. }) {
  12. const { t } = useTranslation()
  13. // searching with matches: show the matched symbols
  14. // searching with no matches: show a message
  15. // note: include empty tab panels so that aria-controls on tabs can still reference the panel ids
  16. if (filteredSymbols) {
  17. return (
  18. <>
  19. {filteredSymbols.length ? (
  20. <SymbolPaletteItems
  21. items={filteredSymbols}
  22. handleSelect={handleSelect}
  23. focusInput={focusInput}
  24. />
  25. ) : (
  26. <div className="symbol-palette-empty">{t('no_symbols_found')}</div>
  27. )}
  28. <TabPanels>
  29. {categories.map(category => (
  30. <TabPanel key={category.id} tabIndex={-1} />
  31. ))}
  32. </TabPanels>
  33. </>
  34. )
  35. }
  36. // not searching: show the symbols grouped by category
  37. return (
  38. <TabPanels>
  39. {categories.map(category => (
  40. <TabPanel key={category.id} tabIndex={-1}>
  41. <SymbolPaletteItems
  42. items={categorisedSymbols[category.id]}
  43. handleSelect={handleSelect}
  44. focusInput={focusInput}
  45. />
  46. </TabPanel>
  47. ))}
  48. </TabPanels>
  49. )
  50. }
  51. SymbolPaletteBody.propTypes = {
  52. categories: PropTypes.arrayOf(PropTypes.object).isRequired,
  53. categorisedSymbols: PropTypes.object,
  54. filteredSymbols: PropTypes.arrayOf(PropTypes.object),
  55. handleSelect: PropTypes.func.isRequired,
  56. focusInput: PropTypes.func.isRequired,
  57. }