File size: 1,847 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {
	__experimentalVStack as VStack,
	__experimentalHStack as HStack,
	__experimentalText as Text,
} from '@wordpress/components';
import clsx from 'clsx';
import type { SectionHeaderProps } from './types';

import './style.scss';

/**
 * The SectionHeader component provides a consistently structured introduction
 * to a section of content, combining a title, optional description/decoration,
 * and contextual actions. It is used to add hierarchy and clarity within page
 * content or nested in composite components such as SummaryButtonList, or DataFormFields.
 */
export const SectionHeader = ( {
	title,
	description,
	actions,
	decoration,
	headingId,
	prefix,
	className,
	level = 2,
}: SectionHeaderProps ) => {
	const HeadingTag = `h${ level }` as keyof JSX.IntrinsicElements;
	return (
		<VStack className={ clsx( 'dashboard-section-header', `is-level-${ level }`, className ) }>
			{ prefix && <div className="dashboard-section-header__prefix">{ prefix }</div> }
			<HStack
				justify="flex-start"
				alignment="center"
				className="dashboard-section-header__heading-row"
			>
				{ decoration && (
					<span className="dashboard-section-header__decoration">{ decoration }</span>
				) }
				<HStack justify="space-between" alignment="center" spacing={ 3 }>
					<HeadingTag className="dashboard-section-header__heading" id={ headingId }>
						{ title }
					</HeadingTag>
					{ /* The wrapper is always needed for view transitions. */ }
					<HStack
						justify="flex-end"
						expanded={ false }
						alignment="center"
						className="dashboard-section-header__actions"
						spacing={ 3 }
					>
						{ actions }
					</HStack>
				</HStack>
			</HStack>
			{ description && (
				<Text variant="muted" className="dashboard-section-header__description">
					{ description }
				</Text>
			) }
		</VStack>
	);
};