-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
472 additions
and
0 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,11 @@ | ||
import { createListBlock } from "@comet/blocks-admin"; | ||
import { AccordionItemBlock } from "@src/common/blocks/AccordionItemBlock"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
export const AccordionBlock = createListBlock({ | ||
name: "Accordion", | ||
displayName: <FormattedMessage id="accordionBlock.displayName" defaultMessage="Accordion" />, | ||
block: AccordionItemBlock, | ||
itemName: <FormattedMessage id="accordionBlock.itemName" defaultMessage="accordion item" />, | ||
itemsName: <FormattedMessage id="accordionBlock.itemsName" defaultMessage="accordion items" />, | ||
}); |
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,68 @@ | ||
import { SwitchField } from "@comet/admin"; | ||
import { | ||
BlockCategory, | ||
BlocksFinalForm, | ||
createBlocksBlock, | ||
createCompositeBlock, | ||
createCompositeBlockTextField, | ||
createCompositeSetting, | ||
} from "@comet/blocks-admin"; | ||
import { AccordionItemBlockData } from "@src/blocks.generated"; | ||
import { CallToActionListBlock } from "@src/common/blocks/CallToActionListBlock"; | ||
import { HeadingBlock } from "@src/common/blocks/HeadingBlock"; | ||
import { RichTextBlock } from "@src/common/blocks/RichTextBlock"; | ||
import { SpaceBlock } from "@src/common/blocks/SpaceBlock"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
const AccordionContentBlock = createBlocksBlock({ | ||
name: "AccordionContent", | ||
supportedBlocks: { | ||
richtext: RichTextBlock, | ||
space: SpaceBlock, | ||
heading: HeadingBlock, | ||
callToActionList: CallToActionListBlock, | ||
}, | ||
}); | ||
|
||
export const AccordionItemBlock = createCompositeBlock( | ||
{ | ||
name: "AccordionItem", | ||
displayName: <FormattedMessage id="accordionBlock.displayName" defaultMessage="Accordion Item" />, | ||
blocks: { | ||
title: { | ||
block: createCompositeBlockTextField({ | ||
fieldProps: { fullWidth: true, label: <FormattedMessage id="accordionBlock.accordionItem.title" defaultMessage="Title" /> }, | ||
}), | ||
hiddenInSubroute: true, | ||
}, | ||
content: { | ||
block: AccordionContentBlock, | ||
title: <FormattedMessage id="accordionBlock.accordionItem.content" defaultMessage="Content" />, | ||
}, | ||
openByDefault: { | ||
block: createCompositeSetting<AccordionItemBlockData["openByDefault"]>({ | ||
defaultValue: false, | ||
AdminComponent: ({ state, updateState }) => { | ||
return ( | ||
<BlocksFinalForm<{ openByDefault: typeof state }> | ||
onSubmit={({ openByDefault }) => updateState(openByDefault)} | ||
initialValues={{ openByDefault: state }} | ||
> | ||
<SwitchField | ||
name="openByDefault" | ||
label={<FormattedMessage id="accordionBlock.accordionItem.openByDefault" defaultMessage="Open by default" />} | ||
/> | ||
</BlocksFinalForm> | ||
); | ||
}, | ||
}), | ||
hiddenInSubroute: true, | ||
}, | ||
}, | ||
}, | ||
(block) => { | ||
block.category = BlockCategory.TextAndContent; | ||
block.previewContent = (state) => (state.title !== undefined ? [{ type: "text", content: state.title }] : []); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
BlockData, | ||
BlockDataInterface, | ||
BlockField, | ||
BlockInput, | ||
ChildBlock, | ||
ChildBlockInput, | ||
createBlock, | ||
createBlocksBlock, | ||
ExtractBlockInput, | ||
inputToData, | ||
} from "@comet/blocks-api"; | ||
import { IsUndefinable } from "@comet/cms-api"; | ||
import { CallToActionListBlock } from "@src/common/blocks/call-to-action-list.block"; | ||
import { HeadingBlock } from "@src/common/blocks/heading.block"; | ||
import { RichTextBlock } from "@src/common/blocks/rich-text.block"; | ||
import { SpaceBlock } from "@src/common/blocks/space.block"; | ||
import { IsBoolean, IsString } from "class-validator"; | ||
|
||
const AccordionContentBlock = createBlocksBlock( | ||
{ | ||
supportedBlocks: { | ||
richtext: RichTextBlock, | ||
heading: HeadingBlock, | ||
space: SpaceBlock, | ||
callToActionList: CallToActionListBlock, | ||
}, | ||
}, | ||
"AccordionContent", | ||
); | ||
|
||
class AccordionItemBlockData extends BlockData { | ||
@BlockField({ nullable: true }) | ||
title?: string; | ||
|
||
@ChildBlock(AccordionContentBlock) | ||
content: BlockDataInterface; | ||
|
||
@BlockField() | ||
openByDefault: boolean; | ||
} | ||
|
||
class AccordionItemBlockInput extends BlockInput { | ||
@IsUndefinable() | ||
@BlockField({ nullable: true }) | ||
@IsString() | ||
title?: string; | ||
|
||
@ChildBlockInput(AccordionContentBlock) | ||
content: ExtractBlockInput<typeof AccordionContentBlock>; | ||
|
||
@IsBoolean() | ||
@BlockField() | ||
openByDefault: boolean; | ||
|
||
transformToBlockData(): AccordionItemBlockData { | ||
return inputToData(AccordionItemBlockData, this); | ||
} | ||
} | ||
|
||
export const AccordionItemBlock = createBlock(AccordionItemBlockData, AccordionItemBlockInput, "AccordionItem"); |
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,4 @@ | ||
import { createListBlock } from "@comet/blocks-api"; | ||
import { AccordionItemBlock } from "@src/common/blocks/accordion-item.block"; | ||
|
||
export const AccordionBlock = createListBlock({ block: AccordionItemBlock }, "Accordion"); |
Oops, something went wrong.