Skip to content

Commit

Permalink
feat(SLB-292): horizontal separator gutenberg block
Browse files Browse the repository at this point in the history
  • Loading branch information
chindris committed Apr 29, 2024
1 parent 575ecf8 commit 07ec3af
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { registerBlockType } from 'wordpress__blocks';
import { compose, withState } from 'wordpress__compose';

declare const Drupal: { t: (s: string) => string };

const { t: __ } = Drupal;

// @ts-ignore
registerBlockType(`custom/horizontal-separator`, {
title: __('Horizontal separator'),
icon: 'minus',
category: 'text',
attributes: {},
// @ts-ignore
edit: compose(withState())(() => {
return <hr />;
}),
save() {
return null;
},
});
1 change: 1 addition & 0 deletions packages/drupal/gutenberg_blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ import './blocks/image-with-text';
import './filters/list';
import './blocks/cta';
import './blocks/quote';
import './blocks/horizontal-separator';
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ default:
<p>A standalone paragraph with <strong><em>markup</em></strong> and <a href="/node/0b45a665-286a-414e-a091-c13fa4e20eb2" data-type="Content: Basic page" data-id="0b45a665-286a-414e-a091-c13fa4e20eb2" data-entity-type="node">link</a></p>
<!-- /wp:paragraph -->
<!-- wp:custom/horizontal-separator /-->
<!-- wp:drupalmedia/drupal-media-entity {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"caption":"Media image"} /-->
<!-- wp:drupalmedia/drupal-media-entity {"mediaEntityIds":["478c4289-961d-4ce8-85d6-578ae05f3019"],"caption":"Media video"} /-->
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 @@ -35,6 +35,7 @@ fragment Page on Page {
...BlockCta
...BlockImageWithText
...BlockQuote
...BlockHorizontalSeparator
}
metaTags {
tag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fragment BlockHorizontalSeparator on BlockHorizontalSeparator {
# This is not really used, but until we have other real setting fields, we
# have to provide a dummy one.
markup
}
5 changes: 5 additions & 0 deletions packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ union PageContent @resolveEditorBlockType =
| BlockCta
| BlockImageWithText
| BlockQuote
| BlockHorizontalSeparator

type BlockForm @type(id: "custom/form") {
url: Url @resolveEditorBlockAttribute(key: "formId") @webformIdToUrl(id: "$")
Expand Down Expand Up @@ -270,6 +271,10 @@ type BlockQuote @type(id: "custom/quote") {
image: MediaImage @resolveEditorBlockMedia
}

type BlockHorizontalSeparator @type(id: "custom/horizontal-separator") {
markup: Markup! @resolveEditorBlockMarkup
}

input PaginationInput {
limit: Int!
offset: Int!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Meta, StoryObj } from '@storybook/react';

import { BlockHorizontalSeparator } from './BlockHorizontalSeparator';

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

export const HorizontalSeparator = {
args: {},
} satisfies StoryObj<typeof BlockHorizontalSeparator>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export function BlockHorizontalSeparator() {
return <hr />;
}
3 changes: 3 additions & 0 deletions packages/ui/src/components/Organisms/PageDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { UnreachableCaseError } from '../../utils/unreachable-case-error';
import { PageTransition } from '../Molecules/PageTransition';
import { BlockCta } from './PageContent/BlockCta';
import { BlockForm } from './PageContent/BlockForm';
import { BlockHorizontalSeparator } from './PageContent/BlockHorizontalSeparator';
import { BlockMarkup } from './PageContent/BlockMarkup';
import { BlockMedia } from './PageContent/BlockMedia';
import { BlockQuote } from './PageContent/BlockQuote';
Expand Down Expand Up @@ -60,6 +61,8 @@ export function PageDisplay(page: PageFragment) {
);
case 'BlockQuote':
return <BlockQuote key={index} {...block} />;
case 'BlockHorizontalSeparator':
return <BlockHorizontalSeparator key={index} {...block} />;
default:
throw new UnreachableCaseError(block);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/specs/drupal/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ test('All blocks are rendered', async ({ page }) => {
page.locator('a:text("link")[href="/en/architecture"]'),
).toHaveCount(1);

// Horizontal separator.
await expect(page.locator('hr')).toHaveCount(1);

// Image
await expect(
page.locator(
Expand Down
6 changes: 6 additions & 0 deletions tests/schema/specs/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ test('Blocks', async () => {
__typename
}
}
... on BlockHorizontalSeparator {
__typename
}
}
}
{
Expand Down Expand Up @@ -106,6 +109,9 @@ test('Blocks', async () => {
<p>A standalone paragraph with <strong><em>markup</em></strong> and <a href="/en/architecture" data-type="Content: Basic page" data-id="[numeric]" data-entity-type="node">link</a></p>
",
},
{
"__typename": "BlockHorizontalSeparator",
},
{
"__typename": "BlockMedia",
"caption": "Media image",
Expand Down

0 comments on commit 07ec3af

Please sign in to comment.