2020-03-07 10:20:38 -05:00
|
|
|
import React from "react";
|
|
|
|
import { t } from "../i18n";
|
|
|
|
|
|
|
|
interface SectionProps extends React.HTMLProps<HTMLElement> {
|
|
|
|
heading: string;
|
|
|
|
children: React.ReactNode | ((header: React.ReactNode) => React.ReactNode);
|
|
|
|
}
|
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const Section = ({ heading, children, ...props }: SectionProps) => {
|
2020-03-07 10:20:38 -05:00
|
|
|
const header = (
|
|
|
|
<h2 className="visually-hidden" id={`${heading}-title`}>
|
|
|
|
{t(`headings.${heading}`)}
|
|
|
|
</h2>
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
<section {...props} aria-labelledby={`${heading}-title`}>
|
|
|
|
{typeof children === "function" ? (
|
|
|
|
children(header)
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{header}
|
|
|
|
{children}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</section>
|
|
|
|
);
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|