File size: 1,341 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
import { PremiumBadge } from '@automattic/components';
import clsx from 'clsx';
import { RefObject } from 'react';
import { preventWidows } from 'calypso/lib/formatting';

import './style.scss';

type PatternsSectionProps = {
	title: string;
	id?: string;
	forwardRef?: RefObject< HTMLDivElement >;
	description: string;
	theme?: 'blue' | 'dark' | 'gray';
	bodyFullWidth?: boolean;
	children: React.ReactNode;
	isPremium?: boolean;
};

export const PatternsSection = ( {
	title,
	forwardRef,
	id,
	description,
	theme,
	bodyFullWidth,
	children,
	isPremium,
}: PatternsSectionProps ) => {
	const sectionProps = id ? { id } : {};
	return (
		<section
			ref={ forwardRef }
			{ ...sectionProps }
			className={ clsx( 'patterns-section', {
				'patterns-section--blue': theme === 'blue',
				'patterns-section--dark': theme === 'dark',
				'patterns-section--gray': theme === 'gray',
				'patterns-section--full-width-body': bodyFullWidth,
			} ) }
		>
			{ isPremium && (
				<div className="patterns-section__premium-badge">
					<PremiumBadge shouldHideTooltip />
				</div>
			) }
			<div className="patterns-section__header">
				<h2>{ title }</h2>
				<div className="patterns-section__header-description">{ preventWidows( description ) }</div>
			</div>
			<div className="patterns-section__body">{ children }</div>
		</section>
	);
};