ButtonsTabbed.jsx 865 B

1234567891011121314151617181920212223242526272829
  1. import { h } from 'preact';
  2. import { useCallback } from 'preact/hooks';
  3. export default function ButtonsTabbed({ titles = [], viewMode, setViewMode }) {
  4. const className = 'text-gray-600 py-0 px-4 block hover:text-gray-500';
  5. const handleClick = useCallback((i) => {
  6. setViewMode(titles[i]);
  7. }, [viewMode]); // eslint-disable-line react-hooks/exhaustive-deps
  8. return (
  9. <nav className="flex justify-end">
  10. {titles.map((title, i) => {
  11. return (
  12. <button
  13. autoFocus={!i}
  14. onClick={() => handleClick(i)}
  15. className={viewMode === title
  16. ? `${className} focus:outline-none border-b-2 font-medium border-gray-500`
  17. : className
  18. }
  19. >
  20. {`${title.charAt(0).toUpperCase()}${title.slice(1)}`}
  21. </button>
  22. );
  23. })}
  24. </nav>
  25. );
  26. }