Skip to content

Commit

Permalink
chore(SLB-332): added the icon and icon placement properties on CTA
Browse files Browse the repository at this point in the history
  • Loading branch information
chindris committed Apr 22, 2024
1 parent d332581 commit 3bb8443
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 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',
},
iconPlacement: {
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 placement')}
value={props.attributes.iconPlacement}
options={[
{ label: __('After button text'), value: 'AFTER' },
{ label: __('Before button text'), value: 'BEFORE' },
]}
onChange={(iconPlacement) => {
props.setAttributes({
iconPlacement,
});
}}
/>
)}
</PanelBody>
</InspectorControls>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ 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","icon":"ARROW","iconPlacement":"BEFORE"} /-->
<!-- wp:custom/cta {"url":"/media/1","text":"CTA with link to media","data-id":"b998ae5e-8b56-40ca-8f80-fd4404e7e716","data-entity-type":"media"} /-->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
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
iconPlacement
}
13 changes: 13 additions & 0 deletions packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,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")
iconPlacement: CTAIconPlacement
@resolveEditorBlockAttribute(key: "iconPlacement")
}

enum CTAIconType {
NONE
ARROW
}

enum CTAIconPlacement {
AFTER
BEFORE
}

input PaginationInput {
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
iconPlacement
}
}
}
Expand Down Expand Up @@ -145,18 +147,24 @@ test('Blocks', async () => {
},
{
"__typename": "BlockCta",
"icon": null,
"iconPlacement": null,
"openInNewTab": null,
"text": "Internal CTA",
"url": "/en/drupal",
},
{
"__typename": "BlockCta",
"icon": "ARROW",
"iconPlacement": null,
"openInNewTab": true,
"text": "External CTA",
"url": "https://www.google.com",
},
{
"__typename": "BlockCta",
"icon": "ARROW",
"iconPlacement": "BEFORE",
"openInNewTab": null,
"text": "CTA with link to media",
"url": "/media/[numeric]",
Expand Down Expand Up @@ -205,6 +213,8 @@ test('Blocks', async () => {
},
{
"__typename": "BlockCta",
"icon": null,
"iconPlacement": null,
"openInNewTab": null,
"text": null,
"url": null,
Expand Down

0 comments on commit 3bb8443

Please sign in to comment.