File size: 1,567 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
64
65
66
67
import { Flex, FlexBlock, FlexItem, Card, CardBody, Icon } from '@wordpress/components';
import { chevronRight } from '@wordpress/icons';
import clsx from 'clsx';
import Badge from '../badge';
import type { BadgeType } from '../badge';
import './style.scss';

interface FlowQuestionProps {
	icon?: JSX.Element;
	onClick: () => void;
	text: string;
	title: string;
	disabled?: boolean;
	badge?: {
		type: BadgeType;
		text: string;
	};
	className?: string;
}

const bemElement = ( customClassName?: string ) => ( element: string ) =>
	customClassName ? `${ customClassName }__${ element }` : undefined;

const FlowQuestion = ( {
	icon,
	onClick,
	text,
	title,
	disabled = false,
	badge,
	className,
}: FlowQuestionProps ) => {
	const bem = bemElement( className );

	return (
		<Card
			className={ clsx( 'flow-question', className ) }
			as="button"
			size="small"
			onClick={ onClick }
			disabled={ disabled }
		>
			<CardBody>
				<Flex>
					{ icon && (
						<FlexItem className={ clsx( 'flow-question__icon', bem( 'icon' ) ) }>
							<Icon icon={ icon } size={ 24 } />
						</FlexItem>
					) }
					<FlexBlock>
						<h3 className={ clsx( 'flow-question__heading', bem( 'heading' ) ) }>
							{ title }
							{ badge && <Badge type={ badge.type }>{ badge.text }</Badge> }
						</h3>
						<p className={ clsx( 'flow-question__description', bem( 'description' ) ) }>{ text }</p>
					</FlexBlock>
					<FlexItem>
						<Icon icon={ chevronRight } size={ 24 } />
					</FlexItem>
				</Flex>
			</CardBody>
		</Card>
	);
};

export default FlowQuestion;