-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
79 lines (74 loc) · 1.92 KB
/
index.js
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
68
69
70
71
72
73
74
75
76
77
78
79
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Panel, PanelBody, PanelRow } from '@wordpress/components';
import classnames from 'classnames';
/**
* Internal dependencies
*/
import { recordGlaEvent } from '~/utils/tracks';
import './index.scss';
const getPanelToggleHandler = ( trackName, id, context ) => ( isOpened ) => {
recordGlaEvent( trackName, {
id,
action: isOpened ? 'expand' : 'collapse',
context,
} );
};
/**
* Clicking on faq item to collapse or expand it.
*
* @event gla_faq
* @property {string} id FAQ identifier
* @property {string} action (`expand`|`collapse`)
* @property {string} context Indicates which page / module the FAQ is in
*/
/**
* @typedef {Object} FaqItem
* @property {string} trackId Track ID of this FAQ.
* @property {JSX.Element} question The question of this FAQ.
* @property {JSX.Element} answer The answer of this FAQ.
*/
/**
* Renders a toggleable FAQs by the Panel layout
*
* @param {Object} props React props.
* @param {string} props.trackName The track event name to be recorded when toggling on FAQ items.
* @param {Array<FaqItem>} props.faqItems FAQ items for rendering.
* @param {string} [props.className] The class name for this component.
* @param {string} props.context The track event property to be recorded when toggling on FAQ items.
*/
export default function FaqsPanel( {
trackName,
faqItems,
className,
context,
} ) {
return (
<Panel
className={ classnames( 'gla-faqs-panel', className ) }
header={ __(
'Frequently asked questions',
'google-listings-and-ads'
) }
>
{ faqItems.map( ( { trackId, question, answer } ) => {
return (
<PanelBody
key={ trackId }
title={ question }
initialOpen={ false }
onToggle={ getPanelToggleHandler(
trackName,
trackId,
context
) }
>
<PanelRow>{ answer }</PanelRow>
</PanelBody>
);
} ) }
</Panel>
);
}