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

Add call to action (and list) block #249

Merged
merged 24 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e7d1430
api/admin add cta button and list block
SebiVPS May 22, 2024
5a5a983
add site implementation
SebiVPS May 24, 2024
5b3d3bc
remove link list block
SebiVPS May 31, 2024
80c88a0
add disabled state to button component
SebiVPS May 31, 2024
0e795d4
refactor: remove button from name
SebiVPS Jun 3, 2024
66cd5f5
remove user-select none
SebiVPS Jun 4, 2024
1224461
theme: revert changes to the grey palette
SebiVPS Jun 5, 2024
864660d
rename call to action list item and items
SebiVPS Jun 5, 2024
28988c0
add forward ref for button component
SebiVPS Jun 5, 2024
bd405d6
use ListBlock helper
SebiVPS Jun 5, 2024
c44f6f9
add site TextLinkBlock again
SebiVPS Jun 5, 2024
01647fe
add @ts-expect-error for ref in button instead of two casts
SebiVPS Jun 5, 2024
f4ea61d
remove single call to action block from api page-content-block
SebiVPS Jun 5, 2024
7bf0b0e
reworked button component to split up styled components to have right…
SebiVPS Jun 6, 2024
16b6e75
remove box-sizing: border-box;
SebiVPS Jun 6, 2024
7061d15
remove button props which are already in html attributes
SebiVPS Jun 6, 2024
70f6d2c
use button variant type from api generated data
SebiVPS Jun 6, 2024
0f4cb62
change transition to specific prop (background-color)
SebiVPS Jun 6, 2024
43e8231
Merge branch 'main' into cta-button-block
SebiVPS Jun 10, 2024
d70faf1
move variant to commonStyle
SebiVPS Jun 11, 2024
932c2da
add color and border color to transition
SebiVPS Jun 11, 2024
6b5737f
only set change border-color on hover
SebiVPS Jun 11, 2024
db90a12
Update css transition
SebiVPS Jun 11, 2024
da9869c
add button variant map
SebiVPS Jun 11, 2024
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
33 changes: 33 additions & 0 deletions admin/src/common/blocks/CallToActionBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { BlockCategory, createCompositeBlock, createCompositeBlockSelectField } from "@comet/blocks-admin";
import { CallToActionBlockData } from "@src/blocks.generated";
import { FormattedMessage } from "react-intl";

import { TextLinkBlock } from "./TextLinkBlock";

export const CallToActionBlock = createCompositeBlock(
{
name: "CallToAction",
displayName: <FormattedMessage id="callToActionBlock.displayName" defaultMessage="Call To Action" />,
blocks: {
textLink: {
block: TextLinkBlock,
title: <FormattedMessage id="callToActionBlock.link.displayName" defaultMessage="Link" />,
},
variant: {
block: createCompositeBlockSelectField<CallToActionBlockData["variant"]>({
defaultValue: "Contained",
options: [
{ value: "Contained", label: <FormattedMessage id="callToActionBlock.variant.contained" defaultMessage="Contained" /> },
{ value: "Outlined", label: <FormattedMessage id="callToActionBlock.variant.outlined" defaultMessage="Outlined" /> },
{ value: "Text", label: <FormattedMessage id="callToActionBlock.variant.text" defaultMessage="Text" /> },
],
fieldProps: { label: <FormattedMessage id="callToActionBlock.variant" defaultMessage="Variant" />, fullWidth: true },
}),
},
},
},
(block) => {
block.category = BlockCategory.Navigation;
return block;
},
);
11 changes: 11 additions & 0 deletions admin/src/common/blocks/CallToActionListBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createListBlock } from "@comet/blocks-admin";
import { CallToActionBlock } from "@src/common/blocks/CallToActionBlock";
import { FormattedMessage } from "react-intl";

export const CallToActionListBlock = createListBlock({
name: "CallToActionList",
displayName: <FormattedMessage id="callToActionListBlock.displayName" defaultMessage="Call To Action List" />,
block: CallToActionBlock,
itemName: <FormattedMessage id="callToActionListBlock.itemName" defaultMessage="action" />,
itemsName: <FormattedMessage id="callToActionListBlock.itemsName" defaultMessage="actions" />,
});
12 changes: 0 additions & 12 deletions admin/src/common/blocks/LinkListBlock.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions admin/src/documents/pages/blocks/PageContentBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createBlocksBlock, YouTubeVideoBlock } from "@comet/blocks-admin";
import { AnchorBlock, DamImageBlock, DamVideoBlock } from "@comet/cms-admin";
import { CallToActionListBlock } from "@src/common/blocks/CallToActionListBlock";
import { HeadingBlock } from "@src/common/blocks/HeadingBlock";
import { LinkListBlock } from "@src/common/blocks/LinkListBlock";
import { RichTextBlock } from "@src/common/blocks/RichTextBlock";
import { SpaceBlock } from "@src/common/blocks/SpaceBlock";
import { TextImageBlock } from "@src/common/blocks/TextImageBlock";
Expand All @@ -17,6 +17,6 @@ export const PageContentBlock = createBlocksBlock({
textImage: TextImageBlock,
damVideo: DamVideoBlock,
youTubeVideo: YouTubeVideoBlock,
links: LinkListBlock,
callToActionList: CallToActionListBlock,
},
});
157 changes: 98 additions & 59 deletions api/block-meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,102 @@
}
]
},
{
"name": "CallToAction",
"fields": [
{
"name": "textLink",
"kind": "Block",
"block": "TextLink",
"nullable": false
},
{
"name": "variant",
"kind": "Enum",
"enum": [
"Contained",
"Outlined",
"Text"
],
"nullable": false
}
],
"inputFields": [
{
"name": "textLink",
"kind": "Block",
"block": "TextLink",
"nullable": false
},
{
"name": "variant",
"kind": "Enum",
"enum": [
"Contained",
"Outlined",
"Text"
],
"nullable": false
}
]
},
{
"name": "CallToActionList",
"fields": [
{
"name": "blocks",
"kind": "NestedObjectList",
"object": {
"fields": [
{
"name": "key",
"kind": "String",
"nullable": false
},
{
"name": "visible",
"kind": "Boolean",
"nullable": false
},
{
"name": "props",
"kind": "Block",
"block": "CallToAction",
"nullable": false
}
]
},
"nullable": false
}
],
"inputFields": [
{
"name": "blocks",
"kind": "NestedObjectList",
"object": {
"fields": [
{
"name": "key",
"kind": "String",
"nullable": false
},
{
"name": "visible",
"kind": "Boolean",
"nullable": false
},
{
"name": "props",
"kind": "Block",
"block": "CallToAction",
"nullable": false
}
]
},
"nullable": false
}
]
},
{
"name": "DamImage",
"fields": [
Expand Down Expand Up @@ -406,63 +502,6 @@
}
]
},
{
"name": "LinkList",
"fields": [
{
"name": "blocks",
"kind": "NestedObjectList",
"object": {
"fields": [
{
"name": "key",
"kind": "String",
"nullable": false
},
{
"name": "visible",
"kind": "Boolean",
"nullable": false
},
{
"name": "props",
"kind": "Block",
"block": "TextLink",
"nullable": false
}
]
},
"nullable": false
}
],
"inputFields": [
{
"name": "blocks",
"kind": "NestedObjectList",
"object": {
"fields": [
{
"name": "key",
"kind": "String",
"nullable": false
},
{
"name": "visible",
"kind": "Boolean",
"nullable": false
},
{
"name": "props",
"kind": "Block",
"block": "TextLink",
"nullable": false
}
]
},
"nullable": false
}
]
},
{
"name": "OptionalPixelImage",
"fields": [
Expand Down Expand Up @@ -527,7 +566,7 @@
"textImage": "TextImage",
"damVideo": "DamVideo",
"youTubeVideo": "YouTubeVideo",
"links": "LinkList"
"callToActionList": "CallToActionList"
},
"nullable": false
}
Expand Down Expand Up @@ -569,7 +608,7 @@
"textImage": "TextImage",
"damVideo": "DamVideo",
"youTubeVideo": "YouTubeVideo",
"links": "LinkList"
"callToActionList": "CallToActionList"
},
"nullable": false
}
Expand Down
4 changes: 4 additions & 0 deletions api/src/common/blocks/call-to-action-list.block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createListBlock } from "@comet/blocks-api";
import { CallToActionBlock } from "@src/common/blocks/call-to-action.block";

export const CallToActionListBlock = createListBlock({ block: CallToActionBlock }, "CallToActionList");
43 changes: 43 additions & 0 deletions api/src/common/blocks/call-to-action.block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
BlockData,
BlockDataInterface,
BlockField,
BlockInput,
ChildBlock,
ChildBlockInput,
createBlock,
ExtractBlockInput,
inputToData,
} from "@comet/blocks-api";
import { IsEnum } from "class-validator";

import { TextLinkBlock } from "./text-link.block";

enum Variant {
Contained = "Contained",
Outlined = "Outlined",
Text = "Text",
}

class CallToActionBlockData extends BlockData {
@ChildBlock(TextLinkBlock)
textLink: BlockDataInterface;

@BlockField({ type: "enum", enum: Variant })
variant: Variant;
}

class CallToActionBlockInput extends BlockInput {
@ChildBlockInput(TextLinkBlock)
textLink: ExtractBlockInput<typeof TextLinkBlock>;

@IsEnum(Variant)
@BlockField({ type: "enum", enum: Variant })
variant: Variant;

transformToBlockData(): CallToActionBlockData {
return inputToData(CallToActionBlockData, this);
}
}

export const CallToActionBlock = createBlock(CallToActionBlockData, CallToActionBlockInput, "CallToAction");
5 changes: 0 additions & 5 deletions api/src/common/blocks/link-list.block.ts

This file was deleted.

4 changes: 2 additions & 2 deletions api/src/documents/pages/blocks/page-content.block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createBlocksBlock, YouTubeVideoBlock } from "@comet/blocks-api";
import { AnchorBlock, DamImageBlock, DamVideoBlock } from "@comet/cms-api";
import { CallToActionListBlock } from "@src/common/blocks/call-to-action-list.block";
import { HeadingBlock } from "@src/common/blocks/heading.block";
import { LinkListBlock } from "@src/common/blocks/link-list.block";
import { RichTextBlock } from "@src/common/blocks/rich-text.block";
import { SpaceBlock } from "@src/common/blocks/space.block";
import { TextImageBlock } from "@src/common/blocks/text-image.block";
Expand All @@ -17,7 +17,7 @@ export const PageContentBlock = createBlocksBlock(
textImage: TextImageBlock,
damVideo: DamVideoBlock,
youTubeVideo: YouTubeVideoBlock,
links: LinkListBlock,
callToActionList: CallToActionListBlock,
},
},
"PageContent",
Expand Down
17 changes: 17 additions & 0 deletions site/src/common/blocks/CallToActionBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client";
import { PropsWithData, withPreview } from "@comet/cms-site";
import { CallToActionBlockData } from "@src/blocks.generated";
import { LinkBlock } from "@src/common/blocks/LinkBlock";
import { HiddenIfInvalidLink } from "@src/common/helpers/HiddenIfInvalidLink";
import { Button } from "@src/components/common/Button";

export const CallToActionBlock = withPreview(
({ data: { textLink, variant } }: PropsWithData<CallToActionBlockData>) => (
<HiddenIfInvalidLink link={textLink.link}>
<LinkBlock data={textLink.link}>
<Button variant={variant}>{textLink.text}</Button>
</LinkBlock>
</HiddenIfInvalidLink>
),
{ label: "Call To Action" },
);
25 changes: 25 additions & 0 deletions site/src/common/blocks/CallToActionListBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use client";
import { ListBlock, PropsWithData, withPreview } from "@comet/cms-site";
import { CallToActionListBlockData } from "@src/blocks.generated";
import { CallToActionBlock } from "@src/common/blocks/CallToActionBlock";
import styled from "styled-components";

export const CallToActionListBlock = withPreview(
({ data }: PropsWithData<CallToActionListBlockData>) => (
<Root>
<ListBlock data={data} block={(block) => <CallToActionBlock data={block} />} />
</Root>
),
{ label: "Call To Action List" },
);

const Root = styled.div`
display: flex;
flex-wrap: wrap;
flex-direction: row;
gap: ${({ theme }) => theme.spacing.S300};

${({ theme }) => theme.breakpoints.sm.mediaQuery} {
gap: ${({ theme }) => theme.spacing.S400};
}
`;
4 changes: 2 additions & 2 deletions site/src/common/blocks/LinkBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExternalLinkBlock, InternalLinkBlock, OneOfBlock, PropsWithData, SupportedBlocks, withPreview } from "@comet/cms-site";
import { LinkBlockData } from "@src/blocks.generated";
import * as React from "react";
import { ReactElement } from "react";

const supportedBlocks: SupportedBlocks = {
internal: ({ children, title, ...props }) => (
Expand All @@ -16,7 +16,7 @@ const supportedBlocks: SupportedBlocks = {
};

interface LinkBlockProps extends PropsWithData<LinkBlockData> {
children: React.ReactElement;
children: ReactElement;
}

export const LinkBlock = withPreview(
Expand Down
Loading
Loading