Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLB-304: Hero form #181

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export const Error = {
args: {
url: 'webforms/error/index.html' as Url,
cssStylesToInject: cmsCss,
className: 'mt-16',
},
} satisfies StoryObj<typeof BlockForm>;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { SilverbackIframe } from '@amazeelabs/silverback-iframe';
import { BlockFormFragment, Url, useLocation } from '@custom/schema';
import clsx from 'clsx';
import React from 'react';

import { buildMessages, storeMessages } from '../../Molecules/Messages';

export function BlockForm(
props: BlockFormFragment & {
className?: string;
// For Storybook.
cssStylesToInject?: string;
},
Expand All @@ -17,7 +19,7 @@ export function BlockForm(
}

return (
<div className="mt-16 mx-auto max-w-3xl">
<div className={clsx('mx-auto max-w-3xl', props.className)}>
<SilverbackIframe
src={props.url}
buildMessages={buildMessages}
Expand Down
54 changes: 52 additions & 2 deletions packages/ui/src/components/Organisms/PageHero.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Image, Link, PageFragment } from '@custom/schema';
import React from 'react';

import { BlockForm } from './PageContent/BlockForm';

export function PageHero(props: NonNullable<PageFragment['hero']>) {
return props.formUrl ? <FormHero {...props} /> : <DefaultHero {...props} />;
}

function DefaultHero(props: NonNullable<PageFragment['hero']>) {
return (
<div className="relative isolate overflow-hidden bg-gray-900 py-24 sm:py-32">
<section className="relative isolate overflow-hidden bg-gray-900 py-24 sm:py-32">
{props.image ? (
<Image
alt={props.image.alt}
Expand Down Expand Up @@ -57,6 +63,50 @@ export function PageHero(props: NonNullable<PageFragment['hero']>) {
) : null}
</div>
</div>
</div>
</section>
);
}

function FormHero(props: NonNullable<PageFragment['hero']>) {
return (
<section>
<div className="relative isolate overflow-hidden bg-gray-900 py-24">
{props.image ? (
<Image
alt={props.image.alt}
source={props.image.source}
priority={true}
className="absolute inset-0 -z-10 h-full w-full object-cover"
data-test-id={'hero-image'}
/>
) : null}

<div className="px-4 lg:pt-24 pt-8 pb-72 lg:pb-80 mx-auto max-w-screen-sm text-center lg:px-6 ">
<h1 className="mb-4 text-4xl tracking-tight font-extrabold text-white">
{props.headline}
</h1>
{props.lead ? (
<p className="mt-6 text-lg leading-4 text-gray-300">{props.lead}</p>
) : null}
{props.ctaText && props.ctaUrl ? (
<Link
href={props.ctaUrl}
className={
'mt-7 inline-block text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800'
}
>
{props.ctaText}
</Link>
) : null}
</div>
</div>
{props.formUrl ? (
<div className="px-4 mx-auto -mt-[22rem] lg:-mt-96 max-w-screen-xl lg:px-6 relative">
<div className="p-6 mx-auto max-w-screen-md bg-white rounded-lg border border-gray-200 shadow-sm">
<BlockForm url={props.formUrl} />
</div>
</div>
) : null}
</section>
);
}
21 changes: 21 additions & 0 deletions packages/ui/src/components/Routes/Page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,24 @@ export const FullHero = {
},
},
} satisfies StoryObj<ViewPageQuery>;

export const FormHero = {
...Default,
args: {
...Default.args,
page: {
...Default.args.page,
hero: {
headline: 'Page Hero Headline',
lead: 'A longer lead text that even might break into multiple lines.',
image: {
source: image(Landscape, { width: 2000 }),
alt: 'Stock photo landscape hero.',
},
ctaUrl: '/test' as Url,
ctaText: 'Call to action',
formUrl: 'webforms/error/index.html' as Url,
},
},
},
} satisfies StoryObj<ViewPageQuery>;
7 changes: 3 additions & 4 deletions tests/e2e/specs/drupal/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ test('All blocks are rendered', async ({ page }) => {
);

// Form
await expect(page.locator('.silverback-iframe iframe')).toHaveAttribute(
'src',
'http://127.0.0.1:8000/en/form/contact?iframe=true',
);
await expect(
page.locator('.silverback-iframe iframe').last(),
).toHaveAttribute('src', 'http://127.0.0.1:8000/en/form/contact?iframe=true');
});
2 changes: 2 additions & 0 deletions tests/e2e/specs/drupal/webforms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test('Webforms work', async ({ page }) => {
// Webform can be submitted.
await page
.frameLocator('.silverback-iframe iframe')
.last()
.getByRole('button', { name: 'Send message' })
.click();

Expand All @@ -29,6 +30,7 @@ test('Webforms work', async ({ page }) => {
await page.goto(websiteUrl('/de/blocks-complete'));
await page
.frameLocator('.silverback-iframe iframe')
.last()
.getByRole('button', { name: 'Send message' })
.click();
// TODO: Find out why it does not work.
Expand Down
Loading