PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.9.0
GiveWP – Donation Plugin and Fundraising Platform v3.9.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / DonationForms / resources / app / form / Header.tsx
Header.tsx
75 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {useCallback} from 'react';
2 import {withTemplateWrapper} from '../templates';
3 import type {GoalType} from '@givewp/forms/propTypes';
4 import amountFormatter from '@givewp/forms/app/utilities/amountFormatter';
5 import DonationFormErrorBoundary from '@givewp/forms/app/errors/boundaries/DonationFormErrorBoundary';
6 import type {Form as DonationForm} from '@givewp/forms/types';
7
8 const formTemplates = window.givewp.form.templates;
9
10 const HeaderTemplate = withTemplateWrapper(formTemplates.layouts.header);
11 const HeaderTitleTemplate = withTemplateWrapper(formTemplates.layouts.headerTitle);
12 const HeaderDescriptionTemplate = withTemplateWrapper(formTemplates.layouts.headerDescription);
13 const GoalTemplate = withTemplateWrapper(formTemplates.layouts.goal);
14
15 const HeaderImageTemplate = withTemplateWrapper(formTemplates.layouts.headerImage);
16
17 /**
18 * @since 3.0.0
19 */
20 export default function Header({form}: {form: DonationForm}) {
21 const formatGoalAmount = useCallback((amount: number) => {
22 return amountFormatter(form.currency, {
23 maximumFractionDigits: 0,
24 }).format(amount);
25 }, []);
26
27 return (
28 <DonationFormErrorBoundary>
29 <HeaderTemplate
30 isMultiStep={form.design.isMultiStep}
31 HeaderImage={() =>
32 form.settings?.designSettingsImageUrl && (
33 <HeaderImageTemplate
34 url={form.settings?.designSettingsImageUrl}
35 alt={form.settings?.formTitle}
36 color={form.settings?.designSettingsImageColor}
37 opacity={form.settings?.designSettingsImageOpacity}
38 />
39 )
40 }
41 Title={() => form.settings?.showHeading && <HeaderTitleTemplate text={form.settings.heading} />}
42 Description={() =>
43 form.settings?.showDescription && <HeaderDescriptionTemplate text={form.settings.description} />
44 }
45 Goal={() =>
46 form.goal?.show && (
47 <GoalTemplate
48 currency={form.currency}
49 type={form.goal.type as GoalType}
50 goalLabel={form.goal.label}
51 progressPercentage={Math.round((form.goal.currentAmount / form.goal.targetAmount) * 100)}
52 currentAmount={form.goal.currentAmount}
53 currentAmountFormatted={
54 form.goal.typeIsMoney
55 ? formatGoalAmount(form.goal.currentAmount)
56 : form.goal.currentAmount.toString()
57 }
58 targetAmount={form.goal.targetAmount}
59 targetAmountFormatted={
60 form.goal.typeIsMoney
61 ? formatGoalAmount(form.goal.targetAmount)
62 : form.goal.targetAmount.toString()
63 }
64 totalRevenue={form.stats.totalRevenue}
65 totalRevenueFormatted={formatGoalAmount(form.stats.totalRevenue)}
66 totalCountValue={form.stats.totalCountValue}
67 totalCountLabel={form.stats.totalCountLabel}
68 />
69 )
70 }
71 />
72 </DonationFormErrorBoundary>
73 );
74 }
75