Skip to content

Commit

Permalink
Merge branch 'feat/SLB-314' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
chindris committed Apr 23, 2024
2 parents ea949a9 + 3d740df commit 037d19e
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 52 deletions.
39 changes: 38 additions & 1 deletion packages/drupal/gutenberg_blocks/src/blocks/cta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RichText,
} from 'wordpress__block-editor';
import { registerBlockType } from 'wordpress__blocks';
import { PanelBody, ToggleControl } from 'wordpress__components';
import { PanelBody, SelectControl, ToggleControl } from 'wordpress__components';
import { compose, withState } from 'wordpress__compose';

// @ts-ignore
Expand Down Expand Up @@ -37,6 +37,14 @@ registerBlockType('custom/cta', {
openInNewTab: {
type: 'boolean',
},
icon: {
type: 'string',
default: 'NONE',
},
iconPosition: {
type: 'string',
default: 'AFTER',
},
},
// @ts-ignore
edit: compose(withState({}))((props) => {
Expand Down Expand Up @@ -116,6 +124,35 @@ registerBlockType('custom/cta', {
});
}}
/>
<SelectControl
label={__('Icon')}
value={props.attributes.icon}
options={[
{ label: __('- None -'), value: 'NONE' },
{ label: __('Arrow'), value: 'ARROW' },
]}
onChange={(icon) => {
props.setAttributes({
icon,
});
}}
/>
{typeof props.attributes.icon !== 'undefined' &&
props.attributes.icon !== 'NONE' && (
<SelectControl
label={__('Icon position')}
value={props.attributes.iconPosition}
options={[
{ label: __('After button text'), value: 'AFTER' },
{ label: __('Before button text'), value: 'BEFORE' },
]}
onChange={(iconPosition) => {
props.setAttributes({
iconPosition,
});
}}
/>
)}
</PanelBody>
</InspectorControls>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,31 @@ _meta:
5dfc1856-e9e4-4f02-9cd6-9d888870ce1a: media
default:
revision_uid:
-
target_id: 1
- target_id: 1
status:
-
value: true
- value: true
uid:
-
target_id: 1
- target_id: 1
title:
-
value: 'Blocks: complete'
- value: 'Blocks: complete'
created:
-
value: 1686759493
- value: 1686759493
promote:
-
value: false
- value: false
sticky:
-
value: false
- value: false
moderation_state:
-
value: published
- value: published
path:
-
alias: /blocks-complete
- alias: /blocks-complete
langcode: en
pathauto: 0
content_translation_source:
-
value: und
- value: und
content_translation_outdated:
-
value: false
- value: false
body:
-
value: |-
- value: |-
<!-- wp:custom/hero {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"headline":"All kinds of blocks with maximum data","lead":"Lead text","ctaUrl":"https://example.com","ctaText":"CTA text","formId":"contact"} /-->
<!-- wp:custom/content -->
Expand Down Expand Up @@ -111,9 +99,9 @@ default:
<!-- wp:custom/cta {"url":"/en/drupal","text":"Internal CTA","data-id":"f1f827c9-ed06-4e7d-b89d-a169e70a459c","data-entity-type":"node"} /-->
<!-- 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":"https://www.google.com","text":"External CTA","data-id":"https://www.google.com","data-entity-type":"","openInNewTab":true,"icon":"ARROW"} /-->
<!-- 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/cta {"url":"/media/1","text":"CTA with link to media","data-id":"b998ae5e-8b56-40ca-8f80-fd4404e7e716","data-entity-type":"media","icon":"ARROW","iconPosition":"BEFORE"} /-->
<!-- wp:custom/quote {"quote":"Lorem ipsum dolor sit amet, \u003cstrong\u003econsectetur\u003c/strong\u003e adipiscing elit. Vivamus sagittis nisi nec neque porta, a ornare ligula efficitur.","author":"John Doe","role":"Project manager","mediaEntityIds":["5dfc1856-e9e4-4f02-9cd6-9d888870ce1a"]} /-->
Expand All @@ -126,40 +114,29 @@ default:
translations:
de:
status:
-
value: true
- value: true
uid:
-
target_id: 1
- target_id: 1
title:
-
value: 'Blocks: complete DE'
- value: 'Blocks: complete DE'
created:
-
value: 1687338353
- value: 1687338353
promote:
-
value: false
- value: false
sticky:
-
value: false
- value: false
moderation_state:
-
value: published
- value: published
path:
-
alias: /blocks-complete
- alias: /blocks-complete
langcode: de
pathauto: 0
content_translation_source:
-
value: en
- value: en
content_translation_outdated:
-
value: false
- value: false
body:
-
value: |-
- value: |-
<!-- wp:custom/hero {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"headline":"All kinds of blocks with maximum data DE","lead":"Lead text DE"} /-->
<!-- wp:custom/content -->
Expand Down
2 changes: 2 additions & 0 deletions packages/schema/src/fragments/PageContent/BlockCta.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ fragment BlockCta on BlockCta {
url
text
openInNewTab
icon
iconPosition
}
13 changes: 13 additions & 0 deletions packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ type BlockCta @type(id: "custom/cta") {
url: Url @resolveEditorBlockAttribute(key: "url")
text: String @resolveEditorBlockAttribute(key: "text")
openInNewTab: Boolean @resolveEditorBlockAttribute(key: "openInNewTab")
icon: CTAIconType @resolveEditorBlockAttribute(key: "icon")
iconPosition: CTAIconPosition
@resolveEditorBlockAttribute(key: "iconPosition")
}

enum CTAIconType {
NONE
ARROW
}

enum CTAIconPosition {
AFTER
BEFORE
}

type BlockImageWithText @type(id: "custom/image-with-text") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { CtaIconPosition, Url } from '@custom/schema';
import { Meta, StoryObj } from '@storybook/react';

import { BlockCta } from './BlockCta';

export default {
component: BlockCta,
} satisfies Meta<typeof BlockCta>;

export const BlockCtaDefault = {
args: {
text: 'Support center',
url: 'https://example.com' as Url,
openInNewTab: false,
icon: 'ARROW',
iconPosition: CtaIconPosition.After,
},
} satisfies StoryObj<typeof BlockCta>;

export const BlockCtaStoryIconLeft = {
args: {
text: 'Support center',
url: 'https://example.com' as Url,
openInNewTab: false,
icon: 'ARROW',
iconPosition: CtaIconPosition.Before,
},
} satisfies StoryObj<typeof BlockCta>;

export const BlockCtaStoryNoIcon = {
args: {
text: 'Support center',
url: 'https://example.com' as Url,
openInNewTab: false,
},
} satisfies StoryObj<typeof BlockCta>;
36 changes: 33 additions & 3 deletions packages/ui/src/components/Organisms/PageContent/BlockCta.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
import { BlockCtaFragment } from '@custom/schema';
import { BlockCtaFragment, CtaIconPosition, CtaIconType } from '@custom/schema';
import clsx from 'clsx';
import React from 'react';

export function BlockCta(props: BlockCtaFragment) {
console.log(props);
return <div />;
return (
<a
className={clsx(
{ 'flex-row-reverse': props.iconPosition === CtaIconPosition.Before },
'text-blue-600 hover:text-white border border-blue-600 hover:bg-blue-600 focus:ring-4 focus:outline-none focus:ring-blue-300 rounded-lg py-2 px-3 gap-2 flex flex-row items-center text-xs font-medium text-center w-fit transition-all duration-200 ease-in-out group',
)}
href={props.url}
target={props.openInNewTab ? '_blank' : '_self'}
rel="noreferrer"
>
{props.text}
{!!props.icon && props.icon === CtaIconType.Arrow && <ArrowRightIcon />}
</a>
);
}

const ArrowRightIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 16 15"
fill="none"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M9.83401 4.23435C9.98403 4.08437 10.1875 4.00012 10.3996 4.00012C10.6117 4.00012 10.8152 4.08437 10.9652 4.23435L14.1652 7.43435C14.3152 7.58437 14.3994 7.78782 14.3994 7.99995C14.3994 8.21208 14.3152 8.41553 14.1652 8.56555L10.9652 11.7656C10.8143 11.9113 10.6122 11.9919 10.4025 11.9901C10.1927 11.9883 9.99208 11.9041 9.84375 11.7558C9.69543 11.6075 9.61129 11.4068 9.60947 11.1971C9.60765 10.9873 9.68828 10.7852 9.83401 10.6344L11.6684 8.79995H2.39961C2.18744 8.79995 1.98395 8.71567 1.83392 8.56564C1.68389 8.41561 1.59961 8.21212 1.59961 7.99995C1.59961 7.78778 1.68389 7.5843 1.83392 7.43427C1.98395 7.28424 2.18744 7.19995 2.39961 7.19995H11.6684L9.83401 5.36555C9.68403 5.21553 9.59978 5.01208 9.59978 4.79995C9.59978 4.58782 9.68403 4.38437 9.83401 4.23435Z"
className=" fill-blue-600 group-hover:fill-white transition-all duration-200 ease-in-out"
/>
</svg>
);
5 changes: 5 additions & 0 deletions tests/e2e/specs/drupal/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ test('All blocks are rendered', async ({ page }) => {
page.locator('blockquote img[alt="The silverback"]'),
).toHaveCount(1);

// CTA blocks
await expect(page.locator('a:text("Internal CTA")')).toHaveCount(1);
await expect(page.locator('a:text("External CTA")')).toHaveCount(1);
await expect(page.locator('a:text("CTA with link to media")')).toHaveCount(1);

// Form
await expect(
page.locator('.silverback-iframe iframe').last(),
Expand Down
10 changes: 10 additions & 0 deletions tests/schema/specs/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ test('Blocks', async () => {
url
text
openInNewTab
icon
iconPosition
}
... on BlockImageWithText {
image {
Expand Down Expand Up @@ -182,18 +184,24 @@ test('Blocks', async () => {
},
{
"__typename": "BlockCta",
"icon": null,
"iconPosition": null,
"openInNewTab": null,
"text": "Internal CTA",
"url": "/en/drupal",
},
{
"__typename": "BlockCta",
"icon": "ARROW",
"iconPosition": null,
"openInNewTab": true,
"text": "External CTA",
"url": "https://www.google.com",
},
{
"__typename": "BlockCta",
"icon": "ARROW",
"iconPosition": "BEFORE",
"openInNewTab": null,
"text": "CTA with link to media",
"url": "/media/[numeric]",
Expand Down Expand Up @@ -249,6 +257,8 @@ test('Blocks', async () => {
},
{
"__typename": "BlockCta",
"icon": null,
"iconPosition": null,
"openInNewTab": null,
"text": null,
"url": null,
Expand Down

0 comments on commit 037d19e

Please sign in to comment.