Skip to content

Commit

Permalink
Feature: Two Panel (steps) form layout (#7180)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Waldstein <[email protected]>
Co-authored-by: Paulo Iankoski <[email protected]>
Co-authored-by: Jon Waldstein <[email protected]>
Co-authored-by: Joshua Dinh <[email protected]>
Co-authored-by: Joshua Dinh <[email protected]>
Co-authored-by: Jon Waldstein <[email protected]>
  • Loading branch information
7 people authored Mar 6, 2024
1 parent 829ffa8 commit e56cd37
Show file tree
Hide file tree
Showing 25 changed files with 234 additions and 34 deletions.
1 change: 1 addition & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare module '*.svg';
declare module '*.module.css';
declare module '*.module.scss';
declare module '*.png';
// this makes the wp or window.wp global variable available in the eyes of TypeScript
declare var wp;
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
*/
class MultiStepFormDesign extends FormDesign
{
/**
* @since 3.0.0
*/
protected $isMultiStep = true;

/**
* @unreleased
*/
protected $includeHeaderInMultiStep = true;

/**
* @since 3.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Give\DonationForms\FormDesigns\TwoPanelStepsFormLayout;

use Give\Framework\FormDesigns\FormDesign;

/**
* @unreleased
*/
class TwoPanelStepsFormLayout extends FormDesign
{
protected $isMultiStep = true;

/**
* @unreleased
*/
public static function id(): string
{
return 'two-panel-steps';
}

/**
* @unreleased
*/
public static function name(): string
{
return __('Two Panel (Steps)', 'give');
}

/**
* @unreleased
*/
public function css(): string
{
return GIVE_PLUGIN_URL . 'build/twoPanelStepsFormLayoutCss.css';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.givewp-donation-form {
--two-panel-header-width: 42.5rem;

align-items: flex-start;
gap: var(--givewp-spacing-2);
display: flex;
flex-direction: row;
margin: auto;
max-width: calc(var(--two-panel-header-width) + 35.5rem);
padding: 0;
width: 100%;

@media screen and (max-width: 71.5rem) {
border: solid 1px var(--givewp-grey-25);
border-radius: var(--givewp-rounded-8);
box-shadow: var(--givewp-shadow-sm);
flex-direction: column;
gap: 0;
max-width: 35rem;
}

@media screen and (max-width: 36rem) {
margin: 0.5rem;
max-width: calc(100% - 1rem);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.givewp-layouts {
&-header {
max-width: var(--two-panel-header-width);
text-align: center;
width: 100%;

@media screen and (min-width: 71.5rem) {
border: solid 1px var(--givewp-grey-25);
border-radius: var(--givewp-rounded-8);
box-shadow: var(--givewp-shadow-sm);
}
}

&-headerTitle {
margin-bottom: var(--givewp-spacing-3);
}

&-headerDescription {
margin-bottom: var(--givewp-spacing-10);
}

.givewp-layouts-header__templates-ms {
padding-bottom: 2rem;

&--background {
.givewp-layouts-header__content {
position: static;
margin-bottom: 0;
}

.givewp-layouts-headerImage {

img {
position: absolute;
left: 0;
bottom: 0;
height: 100%;
min-height: 100%;
border-radius: var(--givewp-rounded-8);
}
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.givewp-donation-form__steps {
@media screen and (max-width: 71.5rem) {
border-radius: 0;
box-shadow: none;
}
}

.givewp-layouts-section {
margin-bottom: 0;

&__fieldset {
display: flex;
flex-direction: column;
gap: var(--givewp-spacing-6);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@layer form-design {
@import 'container';
@import 'sections';
@import 'header';
}
2 changes: 2 additions & 0 deletions src/DonationForms/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Give\DonationForms\DataTransferObjects\DonationFormPreviewRouteData;
use Give\DonationForms\DataTransferObjects\DonationFormViewRouteData;
use Give\DonationForms\FormDesigns\ClassicFormDesign\ClassicFormDesign;
use Give\DonationForms\FormDesigns\TwoPanelStepsFormLayout\TwoPanelStepsFormLayout;
use Give\DonationForms\FormDesigns\MultiStepFormDesign\MultiStepFormDesign;
use Give\DonationForms\FormPage\TemplateHandler;
use Give\DonationForms\Migrations\CleanMultipleSlashesOnDB;
Expand Down Expand Up @@ -161,6 +162,7 @@ private function registerFormDesigns()
try {
$formDesignRegistrar->registerDesign(ClassicFormDesign::class);
$formDesignRegistrar->registerDesign(MultiStepFormDesign::class);
$formDesignRegistrar->registerDesign(TwoPanelStepsFormLayout::class);
} catch (Exception $e) {
Log::error('Error registering form designs', [
'message' => $e->getMessage(),
Expand Down
2 changes: 2 additions & 0 deletions src/DonationForms/ViewModels/DonationFormViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private function formStatsData(): array
}

/**
* @unreleased added includeHeaderInMultiStep to form design export
* @since 3.0.0
*/
public function exports(): array
Expand Down Expand Up @@ -227,6 +228,7 @@ public function exports(): array
'id' => $formDesign::id(),
'name' => $formDesign::name(),
'isMultiStep' => $formDesign->isMultiStep(),
'includeHeaderInMultiStep' => $formDesign->shouldIncludeHeaderInMultiStep(),
] : null,
]),
'previewMode' => $this->previewMode,
Expand Down
1 change: 1 addition & 0 deletions src/DonationForms/resources/app/DonationFormApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function App({form}: { form: DonationForm }) {
return (
<DonationFormSettingsProvider value={{...form.settings, ...donationFormNodeSettings}}>
<DonationFormStateProvider initialState={initialState}>
{!form.design?.includeHeaderInMultiStep && form.settings.showHeader && <Header form={form} />}
<MultiStepForm form={form} />
</DonationFormStateProvider>
</DonationFormSettingsProvider>
Expand Down
4 changes: 3 additions & 1 deletion src/DonationForms/resources/app/form/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {withTemplateWrapper} from '../templates';
import type {GoalType} from '@givewp/forms/propTypes';
import amountFormatter from '@givewp/forms/app/utilities/amountFormatter';
import DonationFormErrorBoundary from '@givewp/forms/app/errors/boundaries/DonationFormErrorBoundary';
import type {Form as DonationForm} from '@givewp/forms/types';

const formTemplates = window.givewp.form.templates;

Expand All @@ -16,7 +17,7 @@ const HeaderImageTemplate = withTemplateWrapper(formTemplates.layouts.headerImag
/**
* @since 3.0.0
*/
export default function Header({form}) {
export default function Header({form}: {form: DonationForm}) {
const formatGoalAmount = useCallback((amount: number) => {
return amountFormatter(form.currency, {
maximumFractionDigits: 0,
Expand All @@ -26,6 +27,7 @@ export default function Header({form}) {
return (
<DonationFormErrorBoundary>
<HeaderTemplate
isMultiStep={form.design.isMultiStep}
HeaderImage={() =>
form.settings?.designSettingsImageUrl && (
<HeaderImageTemplate
Expand Down
6 changes: 4 additions & 2 deletions src/DonationForms/resources/app/form/MultiStepForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ const convertSectionsToSteps = (sections: Section[], hasFirstStep: boolean) => {
};

/**
* @unreleased updated to use includeHeaderInMultiStep
* @since 3.0.0
*/
export default function MultiStepForm({form}: {form: Form}) {
const steps = convertSectionsToSteps(form.nodes, form.settings?.showHeader);
const shouldIncludeHeaderInSteps = form.design?.includeHeaderInMultiStep && form.settings?.showHeader;
const steps = convertSectionsToSteps(form.nodes, shouldIncludeHeaderInSteps);

if (form.settings?.showHeader) {
if (shouldIncludeHeaderInSteps) {
steps.unshift({
id: 0,
title: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PropTypes = {
donateButtonCaption: string;
multiStepNextButtonText: string;
multiStepFirstButtonText: string;
showHeader: boolean;
};
children: ReactNode;
};
Expand Down
1 change: 1 addition & 0 deletions src/DonationForms/resources/propTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export interface HeaderProps {
Title: FC<HeaderTitleProps | {}>;
Description: FC<HeaderDescriptionProps | {}>;
Goal: FC<GoalProps | {}>;
isMultiStep: boolean
}

export interface HeaderImageProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import type {HeaderProps} from '@givewp/forms/propTypes';
import cx from 'classnames';

/**
* @since 3.5.0 add HeaderImage
* @since 3.0.0
*/
export default function Header({HeaderImage, Title, Description, Goal}: HeaderProps) {
const {designSettingsImageStyle, designSettingsImageUrl} = window.givewp.form.hooks.useDonationFormSettings();
export default function Header({ HeaderImage, Title, Description, Goal, isMultiStep }: HeaderProps) {
const { designSettingsImageStyle, designSettingsImageUrl } = window.givewp.form.hooks.useDonationFormSettings();

if (!designSettingsImageUrl) {
return (
<div className={`givewp-layouts-header__templates-ms`}>
<div className={
cx({
'givewp-layouts-header__templates': !isMultiStep,
'givewp-layouts-header__templates-ms': isMultiStep
}
)}>
<Title />
<Description />
<Goal />
Expand All @@ -19,7 +25,12 @@ export default function Header({HeaderImage, Title, Description, Goal}: HeaderPr

return (
<div
className={`givewp-layouts-header__templates-ms givewp-layouts-header__templates-ms--${designSettingsImageStyle}`}
className={cx({
'givewp-layouts-header__templates': !isMultiStep,
[`givewp-layouts-header__templates--${designSettingsImageStyle}`]: !isMultiStep,
'givewp-layouts-header__templates-ms': isMultiStep,
[`givewp-layouts-header__templates-ms--${designSettingsImageStyle}`]: isMultiStep
})}
>
<HeaderImageTemplates
imagePosition={designSettingsImageStyle}
Expand All @@ -32,7 +43,7 @@ export default function Header({HeaderImage, Title, Description, Goal}: HeaderPr
);
}

function HeaderImageTemplates({imagePosition, HeaderImage, Title, Description, Goal}) {
function HeaderImageTemplates({ imagePosition, HeaderImage, Title, Description, Goal }) {
switch (imagePosition) {
case 'background':
return (
Expand Down
32 changes: 17 additions & 15 deletions src/DonationForms/resources/styles/design-settings/image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
img {
object-fit: cover;
min-width: 100%;
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
border-top-left-radius: var(--givewp-rounded-8);
border-top-right-radius: var(--givewp-rounded-8);
}
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@
}

.givewp-layouts-goal {
margin-top: -1.35rem;
margin-top: -1.25rem;
}
}
}
Expand All @@ -107,8 +107,9 @@
}

/* Multi Step */
.givewp-donation-form__steps-body {
.givewp-donation-form__steps-body, .givewp-donation-form > .givewp-layouts-header {
padding: 0;
background: #fff;

.givewp-layouts-multiStepForm, .givewp-layouts-header__templates-ms {
padding: 2rem 2rem 0 2rem;
Expand All @@ -125,13 +126,6 @@
}
}

.givewp-layouts-headerTitle {
color: var(--givewp-grey-900);
}

.givewp-layouts-headerDescription {
color: var(--givewp-grey-700);
}

.givewp-layouts-header__templates-ms {
.givewp-layouts-headerImage {
Expand All @@ -140,11 +134,19 @@
img {
object-fit: cover;
min-width: 100%;
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
border-top-left-radius: var(--givewp-rounded-8);
border-top-right-radius: var(--givewp-rounded-8);
}
}

.givewp-layouts-headerTitle {
color: var(--givewp-grey-900);
}

.givewp-layouts-headerDescription {
color: var(--givewp-grey-700);
}


&--background {
padding: 0;
Expand All @@ -167,7 +169,7 @@
}


div:not(.givewp-layouts-headerImage), aside {
div:not(.givewp-layouts-headerImage, .givewp-layouts-header__content), aside {
position: relative;
z-index: 999;
}
Expand Down Expand Up @@ -205,7 +207,7 @@
.givewp-layouts-headerImage {
img {
border-radius: var(--givewp-rounded-4);

max-height: 320px;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/DonationForms/resources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export interface Form extends Group {
id: string;
name: string;
isMultiStep: boolean;
includeHeaderInMultiStep: boolean;
};
nodes: Section[];
currencySwitcherSettings?: CurrencySwitcherSetting[];
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e56cd37

Please sign in to comment.