| 1 |
import React from 'react'; |
| 2 |
import styles from './styles.module.scss'; |
| 3 |
|
| 4 |
/** |
| 5 |
* @since 4.4.0 |
| 6 |
*/ |
| 7 |
type HeaderProps = { |
| 8 |
children?: React.ReactNode; |
| 9 |
title: string; |
| 10 |
subtitle?: string; |
| 11 |
href?: string; |
| 12 |
actionText?: string; |
| 13 |
actionOnClick?: () => void; |
| 14 |
}; |
| 15 |
|
| 16 |
/** |
| 17 |
* @since 4.4.0 |
| 18 |
*/ |
| 19 |
export default function Header({title, subtitle, href, actionText, actionOnClick}: HeaderProps) { |
| 20 |
return ( |
| 21 |
<header className={styles.header}> |
| 22 |
<div> |
| 23 |
<HeaderText>{title}</HeaderText> |
| 24 |
{subtitle && <SubHeaderText>{subtitle}</SubHeaderText>} |
| 25 |
</div> |
| 26 |
{href && !actionOnClick && ( |
| 27 |
<a className={styles.action} href={href} rel={'noreferrer'} aria-label={`${actionText} for ${title}`}> |
| 28 |
{actionText} |
| 29 |
</a> |
| 30 |
)} |
| 31 |
{actionOnClick && !href && ( |
| 32 |
<button className={styles.action} onClick={actionOnClick} aria-label={`${actionText} for ${title}`}> |
| 33 |
{actionText} |
| 34 |
</button> |
| 35 |
)} |
| 36 |
</header> |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* @since 4.4.0 |
| 42 |
*/ |
| 43 |
export function HeaderText({children}: {children: React.ReactNode}) { |
| 44 |
return <h2 className={styles.headerText}>{children}</h2>; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* @since 4.4.0 |
| 49 |
*/ |
| 50 |
export function SubHeaderText({children}: {children: React.ReactNode}) { |
| 51 |
return <p className={styles.subHeaderText}>{children}</p>; |
| 52 |
} |
| 53 |
|