Skip to content

Commit

Permalink
Add optional prop to createTextLinkBlock function to set custom displ…
Browse files Browse the repository at this point in the history
…ayName
  • Loading branch information
VP-DS committed Oct 9, 2024
1 parent ec57e2d commit 24af64d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-tasks-tackle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-admin": minor
---

Add optional prop to `createTextLinkBlock` function to set a custom displayName
10 changes: 8 additions & 2 deletions packages/admin/cms-admin/src/blocks/createTextLinkBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ import {
withAdditionalBlockAttributes,
} from "@comet/blocks-admin";
import { Box } from "@mui/material";
import { ReactNode } from "react";
import { FormattedMessage } from "react-intl";

import { TextLinkBlockData, TextLinkBlockInput } from "../blocks.generated";

interface CreateTextLinkBlockOptions {
name?: string;
displayName?: ReactNode;
link: BlockInterface;
}

export function createTextLinkBlock({ link: LinkBlock, name = "TextLink" }: CreateTextLinkBlockOptions): BlockInterface {
export function createTextLinkBlock({
link: LinkBlock,
name = "TextLink",
displayName = <FormattedMessage {...messages.link} />,
}: CreateTextLinkBlockOptions): BlockInterface {
const { api: composedApi, block: composedBlock } = composeBlocks({ link: LinkBlock });

const block = withAdditionalBlockAttributes<Pick<TextLinkBlockData, "text">>({
Expand All @@ -33,7 +39,7 @@ export function createTextLinkBlock({ link: LinkBlock, name = "TextLink" }: Crea

name,

displayName: <FormattedMessage {...messages.link} />,
displayName,

category: BlockCategory.Navigation,

Expand Down

0 comments on commit 24af64d

Please sign in to comment.