Section.tsx 733 B

12345678910111213141516171819202122232425262728
  1. import React from "react";
  2. import { t } from "../i18n";
  3. import { useExcalidrawContainer } from "./App";
  4. export const Section: React.FC<{
  5. heading: string;
  6. children?: React.ReactNode | ((heading: React.ReactNode) => React.ReactNode);
  7. className?: string;
  8. }> = ({ heading, children, ...props }) => {
  9. const { id } = useExcalidrawContainer();
  10. const header = (
  11. <h2 className="visually-hidden" id={`${id}-${heading}-title`}>
  12. {t(`headings.${heading}`)}
  13. </h2>
  14. );
  15. return (
  16. <section {...props} aria-labelledby={`${id}-${heading}-title`}>
  17. {typeof children === "function" ? (
  18. children(header)
  19. ) : (
  20. <>
  21. {header}
  22. {children}
  23. </>
  24. )}
  25. </section>
  26. );
  27. };