Skip to content

Commit

Permalink
Change prop name to labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Fichtner committed Sep 11, 2024
1 parent 7f6750c commit 0c38888
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .changeset/fluffy-points-think.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Add support for custom tab labels in OneOfBlock tabs

Usage:

- Add tabLabels to `createOneOfBlock` props
- Add labels to `createOneOfBlock` props
- ````ts
tabLabels: {
labels: {
image: (
<Tooltip trigger="hover" title={<FormattedMessage id="pages.blocks.media.image" defaultMessage="Image" />}>
<Image />
Expand All @@ -27,4 +27,4 @@ Usage:
}
```
````
- the keys in the tabLabels need to be the same as the `supportedBlocks`
- the keys in the labels need to be the same as the `supportedBlocks`
9 changes: 7 additions & 2 deletions demo/admin/src/pages/blocks/MediaBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tooltip } from "@comet/admin";
import { Image, Video, YouTube } from "@comet/admin-icons";
import { Image, Video, Vimeo, YouTube } from "@comet/admin-icons";
import { BlockCategory, createOneOfBlock } from "@comet/blocks-admin";
import { DamImageBlock, DamVideoBlock, VimeoVideoBlock, YouTubeVideoBlock } from "@comet/cms-admin";
import { FormattedMessage } from "react-intl";
Expand All @@ -11,7 +11,7 @@ export const MediaBlock = createOneOfBlock({
allowEmpty: false,
variant: "toggle",
supportedBlocks: { image: DamImageBlock, damVideo: DamVideoBlock, youTubeVideo: YouTubeVideoBlock, vimeoVideo: VimeoVideoBlock },
tabLabels: {
labels: {
image: (
<Tooltip trigger="hover" title={<FormattedMessage id="pages.blocks.media.image" defaultMessage="Image" />}>
<Image />
Expand All @@ -27,5 +27,10 @@ export const MediaBlock = createOneOfBlock({
<YouTube />
</Tooltip>
),
vimeoVideo: (
<Tooltip trigger="hover" title={<FormattedMessage id="pages.blocks.media.video.vimeo" defaultMessage="Video (Vimeo)" />}>
<Vimeo />
</Tooltip>
),
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export interface CreateOneOfBlockOptions<T extends boolean> {
name: string;
displayName?: ReactNode;
supportedBlocks: Record<BlockType, BlockInterface>;
tabLabels?: Record<BlockType, React.ReactNode>;
labels?: Record<BlockType, React.ReactNode>;
category?: BlockCategory | CustomBlockCategory;
variant?: "select" | "radio" | "toggle";
allowEmpty?: T;
}

export const createOneOfBlock = <T extends boolean = boolean>({
supportedBlocks,
tabLabels,
labels,
name,
displayName = "Switch",
category = BlockCategory.Other,
Expand Down Expand Up @@ -118,7 +118,7 @@ export const createOneOfBlock = <T extends boolean = boolean>({
Object.entries(supportedBlocks).forEach(([blockType, block]) => {
options.push({
value: blockType,
label: tabLabels && tabLabels[blockType] ? tabLabels[blockType] : block.displayName,
label: labels && labels[blockType] ? labels[blockType] : block.displayName,
});
});

Expand Down

0 comments on commit 0c38888

Please sign in to comment.