Skip to content

Commit

Permalink
Merge branch 'release' into SLB-308-cta-block-gutenberg
Browse files Browse the repository at this point in the history
  • Loading branch information
chindris committed Apr 15, 2024
2 parents fcb16e6 + aeea400 commit f3f8f8a
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 7 deletions.
119 changes: 119 additions & 0 deletions packages/drupal/gutenberg_blocks/src/blocks/image-teaser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {
// @ts-ignore
__experimentalLinkControl as LinkControl,
InnerBlocks,
InspectorControls,
RichText,
} from 'wordpress__block-editor';
import { registerBlockType } from 'wordpress__blocks';
import { PanelBody } from 'wordpress__components';
import { dispatch } from 'wordpress__data';

import { DrupalMediaEntity } from '../utils/drupal-media';

// @ts-ignore
const { t: __ } = Drupal;
// @ts-ignore
const { setPlainTextAttribute } = silverbackGutenbergUtils;

registerBlockType('custom/image-teaser', {
title: __('Image Teaser'),
parent: ['custom/image-teasers'],
icon: 'cover-image',
category: 'layout',
attributes: {
mediaEntityIds: {
type: 'array',
},
title: {
type: 'string',
},
ctaUrl: {
type: 'string',
},
ctaText: {
type: 'string',
},
},
edit: (props) => {
return (
<>
<InspectorControls>
<PanelBody title={__('CTA Link')}>
<LinkControl
placeholder={__('Link')}
value={{
url: props.attributes.ctaUrl,
}}
settings={{}}
onChange={(link: { url: string; opensInNewTab: boolean }) => {
props.setAttributes({
ctaUrl: link.url,
});
}}
/>
</PanelBody>
</InspectorControls>
<div>
<div>
<DrupalMediaEntity
classname={'w-full'}
attributes={{
...(props.attributes as any),
lockViewMode: true,
viewMode: 'gutenberg_header',
allowedTypes: ['image'],
}}
setAttributes={props.setAttributes}
isMediaLibraryEnabled={true}
onError={(error) => {
// @ts-ignore
error = typeof error === 'string' ? error : error[2];
dispatch('core/notices').createWarningNotice(error);
}}
/>
</div>

<div>
<div>
<RichText
className={'font-bold text-2xl mt-3'}
identifier="title"
tagName="div"
value={props.attributes.title as string}
allowedFormats={[]}
// @ts-ignore
disableLineBreaks={true}
placeholder={__('Title')}
keepPlaceholderOnFocus={true}
onChange={(title) => {
setPlainTextAttribute(props, 'title', title);
}}
/>
</div>
<div>
<RichText
identifier="ctaText"
tagName="div"
multiline={false}
value={props.attributes.ctaText as string}
allowedFormats={[]}
// @ts-ignore
disableLineBreaks={true}
placeholder={__('CTA text')}
keepPlaceholderOnFocus={true}
style={{
cursor: 'text',
}}
onChange={(ctaText) => {
setPlainTextAttribute(props, 'ctaText', ctaText);
}}
/>
</div>
</div>
</div>
</>
);
},
save: () => <InnerBlocks.Content />,
});
24 changes: 24 additions & 0 deletions packages/drupal/gutenberg_blocks/src/blocks/image-teasers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { InnerBlocks } from 'wordpress__block-editor';
import { registerBlockType } from 'wordpress__blocks';

// @ts-ignore
const { t: __ } = Drupal;

registerBlockType('custom/image-teasers', {
title: __('Image Teasers'),
icon: 'format-image',
category: 'layout',
attributes: {},
edit: () => {
return (
<>
<InnerBlocks
templateLock={false}
allowedBlocks={['custom/image-teaser']}
template={[['custom/image-teaser']]}
/>
</>
);
},
save: () => <InnerBlocks.Content />,
});
2 changes: 2 additions & 0 deletions packages/drupal/gutenberg_blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ import './blocks/content';
import './blocks/heading';
import './blocks/form';
import './blocks/cta';
import './blocks/image-teaser';
import './blocks/image-teasers';
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _meta:
depends:
3a0fe860-a6d6-428a-9474-365bd57509aa: media
478c4289-961d-4ce8-85d6-578ae05f3019: media
72187a1f-3e48-4b45-a9b7-189c6fd7ee26: media
default:
revision_uid:
-
Expand Down Expand Up @@ -84,6 +85,15 @@ default:
<!-- wp:custom/cta {"url":"https://www.google.com","text":"External CTA","data-id":"https://www.google.com","data-entity-type":"","openInNewTab":true} /-->
<!-- wp:custom/cta {"url":"/media/1","text":"CTA with link to media","data-id":"b998ae5e-8b56-40ca-8f80-fd4404e7e716","data-entity-type":"media"} /-->
<!-- wp:custom/image-teasers -->
<!-- wp:custom/image-teaser {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"title":"Teaser 1","ctaUrl":"https://google.com","ctaText":"Foo"} /-->
<!-- wp:custom/image-teaser {"mediaEntityIds":["72187a1f-3e48-4b45-a9b7-189c6fd7ee26"],"title":"Teaser 2","ctaUrl":"https://google.com","ctaText":"Bar"} /-->
<!-- /wp:custom/image-teasers -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:custom/content -->
format: gutenberg
summary: ''
Expand Down
1 change: 1 addition & 0 deletions packages/schema/src/fragments/Page.gql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fragment Page on Page {
...BlockMedia
...BlockForm
...BlockCta
...BlockImageTeasers
}
metaTags {
tag
Expand Down
11 changes: 11 additions & 0 deletions packages/schema/src/fragments/PageContent/BlockImageTeasers.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fragment BlockImageTeasers on BlockImageTeasers {
teasers {
image {
source(width: 1536, sizes: [[768, 768], [1536, 1536]])
alt
}
title
ctaText
ctaUrl
}
}
24 changes: 18 additions & 6 deletions packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,7 @@ union PageContent @resolveEditorBlockType =
| BlockMedia
| BlockForm
| BlockCta

type BlockCta @type(id: "custom/cta") {
url: Url @resolveEditorBlockAttribute(key: "url")
text: String @resolveEditorBlockAttribute(key: "text")
openInNewTab: Boolean @resolveEditorBlockAttribute(key: "openInNewTab")
}
| BlockImageTeasers

type BlockForm @type(id: "custom/form") {
url: Url @resolveEditorBlockAttribute(key: "formId") @webformIdToUrl(id: "$")
Expand Down Expand Up @@ -232,6 +227,23 @@ type BlockMedia @type(id: "drupalmedia/drupal-media-entity") {
caption: Markup @resolveEditorBlockAttribute(key: "caption")
}

type BlockCta @type(id: "custom/cta") {
url: Url @resolveEditorBlockAttribute(key: "url")
text: String @resolveEditorBlockAttribute(key: "text")
openInNewTab: Boolean @resolveEditorBlockAttribute(key: "openInNewTab")
}

type BlockImageTeasers @type(id: "custom/image-teasers") {
teasers: [BlockImageTeaser!]! @resolveEditorBlockChildren
}

type BlockImageTeaser @default @value {
image: MediaImage @resolveEditorBlockMedia
title: String @resolveEditorBlockAttribute(key: "title")
ctaText: String @resolveEditorBlockAttribute(key: "ctaText")
ctaUrl: Url @resolveEditorBlockAttribute(key: "ctaUrl")
}

input PaginationInput {
limit: Int!
offset: Int!
Expand Down
15 changes: 15 additions & 0 deletions packages/ui/src/components/Organisms/PageDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ export function PageDisplay(page: PageFragment) {
return <BlockForm key={index} {...block} />;
case 'BlockCta':
return <BlockCta key={index} {...block} />;
case 'BlockImageTeasers':
return (
// TODO: Implement BlockImageTeasers
<div
style={{
color: 'red',
border: 'solid 3px red',
padding: '3px',
margin: '5px 0',
}}
// eslint-disable-next-line react/jsx-no-literals
>
BlockImageTeasers goes here
</div>
);
default:
throw new UnreachableCaseError(block);
}
Expand Down
12 changes: 11 additions & 1 deletion packages/ui/src/components/Organisms/PageHero.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Image, PageFragment } from '@custom/schema';
import { Image, Link, PageFragment } from '@custom/schema';
import React from 'react';

export function PageHero(props: NonNullable<PageFragment['hero']>) {
Expand Down Expand Up @@ -45,6 +45,16 @@ export function PageHero(props: NonNullable<PageFragment['hero']>) {
{props.lead ? (
<p className="mt-6 text-lg leading-8 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>
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/components/Routes/Page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export const FullHero = {
source: image(Landscape, { width: 2000 }),
alt: 'Stock photo landscape hero.',
},
ctaUrl: '/test' as Url,
ctaText: 'Call to action',
},
},
},
Expand Down
40 changes: 40 additions & 0 deletions tests/schema/specs/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ test('Blocks', async () => {
text
openInNewTab
}
... on BlockImageTeasers {
teasers {
__typename
image {
__typename
}
title
ctaText
ctaUrl
}
}
}
}
{
Expand Down Expand Up @@ -127,6 +138,35 @@ test('Blocks', async () => {
"text": "CTA with link to media",
"url": "/media/[numeric]",
},
{
"__typename": "BlockImageTeasers",
"teasers": [
{
"__typename": "BlockImageTeaser",
"ctaText": "Foo",
"ctaUrl": "https://google.com",
"image": {
"__typename": "MediaImage",
},
"title": "Teaser 1",
},
{
"__typename": "BlockImageTeaser",
"ctaText": "Bar",
"ctaUrl": "https://google.com",
"image": {
"__typename": "MediaImage",
},
"title": "Teaser 2",
},
],
},
{
"__typename": "BlockMarkup",
"markup": "
<p></p>
",
},
],
"hero": {
"__typename": "Hero",
Expand Down

0 comments on commit f3f8f8a

Please sign in to comment.