| 1 |
import styles from '@patternfly/react-styles/css/components/Form/form'; |
| 2 |
import { css } from '@patternfly/react-styles'; |
| 3 |
import { GenerateId } from '../../helpers/GenerateId/GenerateId'; |
| 4 |
|
| 5 |
export interface FormSectionProps extends Omit<React.HTMLProps<HTMLDivElement>, 'title'> { |
| 6 |
/** Content rendered inside the section */ |
| 7 |
children?: React.ReactNode; |
| 8 |
/** Additional classes added to the section */ |
| 9 |
className?: string; |
| 10 |
/** Title for the section */ |
| 11 |
title?: React.ReactNode; |
| 12 |
/** Element to wrap the section title*/ |
| 13 |
titleElement?: 'div' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; |
| 14 |
} |
| 15 |
|
| 16 |
export const FormSection: React.FunctionComponent<FormSectionProps> = ({ |
| 17 |
className = '', |
| 18 |
children, |
| 19 |
title = '', |
| 20 |
titleElement: TitleElement = 'div', |
| 21 |
...props |
| 22 |
}: FormSectionProps) => ( |
| 23 |
<GenerateId prefix="pf-form-section-title"> |
| 24 |
{(sectionId) => ( |
| 25 |
<section |
| 26 |
className={css(styles.formSection, className)} |
| 27 |
role="group" |
| 28 |
{...(title && { 'aria-labelledby': sectionId })} |
| 29 |
{...props} |
| 30 |
> |
| 31 |
{title && ( |
| 32 |
<TitleElement id={sectionId} className={css(styles.formSectionTitle, className)}> |
| 33 |
{title} |
| 34 |
</TitleElement> |
| 35 |
)} |
| 36 |
{children} |
| 37 |
</section> |
| 38 |
)} |
| 39 |
</GenerateId> |
| 40 |
); |
| 41 |
FormSection.displayName = 'FormSection'; |