-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows specifying custom block categories in application code.
- Loading branch information
1 parent
0ff9b9b
commit a227388
Showing
10 changed files
with
174 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
"@comet/blocks-admin": minor | ||
--- | ||
|
||
Add support for custom block categories | ||
|
||
Allows specifying custom block categories in application code. | ||
|
||
**Example:** | ||
|
||
In `src/common/blocks/customBlockCategories.tsx`: | ||
|
||
```tsx | ||
import { BlockCategory, CustomBlockCategory } from "@comet/blocks-admin"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
const productsBlockCategory: CustomBlockCategory = { | ||
id: "Products", | ||
label: <FormattedMessage id="blocks.category.products" defaultMessage="Products" />, | ||
// Specify where category will be shown in drawer | ||
insertBefore: BlockCategory.Teaser, | ||
}; | ||
|
||
export { productsBlockCategory }; | ||
``` | ||
|
||
In `src/documents/pages/blocks/MyBlock.tsx`: | ||
|
||
```tsx | ||
import { productsBlockCategory } from "@src/common/blocks/customBlockCategories"; | ||
|
||
const MyBlock: BlockInterface = { | ||
category: productsBlockCategory, | ||
... | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { BlockCategory } from "@comet/blocks-admin"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
const customBlockCategory = { | ||
id: "Custom", | ||
label: <FormattedMessage id="blocks.category.custom" defaultMessage="Custom" />, | ||
insertBefore: BlockCategory.Media, | ||
}; | ||
|
||
export { customBlockCategory }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
import { createCompositeBlock, createListBlock } from "@comet/blocks-admin"; | ||
import { customBlockCategory } from "@src/common/blocks/customBlockCategories"; | ||
import { HeadlineBlock } from "@src/common/blocks/HeadlineBlock"; | ||
|
||
const TwoListsListBlock = createListBlock({ | ||
name: "TwoListsList", | ||
block: HeadlineBlock, | ||
}); | ||
|
||
export const TwoListsBlock = createCompositeBlock({ | ||
name: "TwoLists", | ||
displayName: "Two Lists", | ||
blocks: { | ||
list1: { | ||
block: TwoListsListBlock, | ||
title: "List 1", | ||
}, | ||
list2: { | ||
block: TwoListsListBlock, | ||
title: "List 2", | ||
export const TwoListsBlock = createCompositeBlock( | ||
{ | ||
name: "TwoLists", | ||
displayName: "Two Lists", | ||
blocks: { | ||
list1: { | ||
block: TwoListsListBlock, | ||
title: "List 1", | ||
}, | ||
list2: { | ||
block: TwoListsListBlock, | ||
title: "List 2", | ||
}, | ||
}, | ||
}, | ||
}); | ||
(block) => { | ||
block.category = customBlockCategory; | ||
return block; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters