Skip to content

Commit

Permalink
Expandable content -block (#1305)
Browse files Browse the repository at this point in the history
* Initial flip card block

* Improvements for flip card

* Added templateLock

* Initial expandable content -block

* Initial Revealable content -block

* Changed icon to button

* Little changes

* Little changes to revealable content block

* Changes to flipcard desing

* Changes to style of expandable content -block

* Changes to style of revealable content -block

* Small changes to style of the flip card block

* Small changes

* Changes to margin

* Seperated Inner card to back and front cards

* Small changes to Revealable content -block

* Little fixes

---------

Co-authored-by: Maija Y <[email protected]>
  • Loading branch information
Maijjay and Maija Y authored Oct 17, 2024
1 parent 7dfc3a9 commit 5861eb0
Show file tree
Hide file tree
Showing 34 changed files with 1,096 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { InnerBlocks } from "@wordpress/block-editor"
import { BlockEditProps } from "@wordpress/blocks"
import React from "react"
import { useTranslation } from "react-i18next"

import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper"

const ALLOWED_NESTED_BLOCKS = ["core/expandable-content-inner-block"]
const ExpandableContentEditor: React.FC<
React.PropsWithChildren<BlockEditProps<Record<string, never>>>
> = ({ clientId }) => {
const { t } = useTranslation()
return (
<BlockPlaceholderWrapper
id={clientId}
title={t("expandable-content-placeholder")}
explanation={t("expandable-content-explanation")}
>
<div>
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} />
</div>
</BlockPlaceholderWrapper>
)
}

export default ExpandableContentEditor
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable i18next/no-literal-string */
import { css } from "@emotion/css"
import { InnerBlocks } from "@wordpress/block-editor"
import { BlockEditProps } from "@wordpress/blocks"
import React from "react"
import { useTranslation } from "react-i18next"

import BlockPlaceholderWrapper from "../../BlockPlaceholderWrapper"

import { ExpandableContentConfigurationProps } from "."

import TextField from "@/shared-module/common/components/InputFields/TextField"

const ALLOWED_NESTED_BLOCKS = ["core/heading", "core/paragraph", "core/image", "core/list"]
const ExpandableContentInnerBlockEditor: React.FC<
React.PropsWithChildren<BlockEditProps<ExpandableContentConfigurationProps>>
> = ({ clientId, attributes, setAttributes }) => {
const { t } = useTranslation()
return (
<BlockPlaceholderWrapper
id={clientId}
title={"Expandable content"}
explanation={"Expandable content"}
>
<TextField
placeholder={t("label-title")}
value={attributes.name}
onChangeByValue={(value) => setAttributes({ name: value })}
className={css`
margin-bottom: 1rem !important;
`}
/>
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} />
</BlockPlaceholderWrapper>
)
}

export default ExpandableContentInnerBlockEditor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { InnerBlocks } from "@wordpress/block-editor"
import React from "react"

const ExpandableContentInnerBlockSave: React.FC<unknown> = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default ExpandableContentInnerBlockSave
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable i18next/no-literal-string */
import { BlockConfiguration } from "@wordpress/blocks"

import { MOOCFI_CATEGORY_SLUG } from "../../../utils/Gutenberg/modifyGutenbergCategories"

import ExpandableContentEditor from "./ExpandableContentInnerBlockEditor"
import ExpandableContentSave from "./ExpandableContentInnerBlockSave"

export interface ExpandableContentConfigurationProps {
name: string
}
const ExpandableContentInnerBlockConfiguration: BlockConfiguration<ExpandableContentConfigurationProps> =
{
title: "Expandable Content",
description: "One or more heading that has expandable/collapsible content",
category: MOOCFI_CATEGORY_SLUG,
attributes: { name: { type: "string", default: "" } },
parent: ["moocfi/expandable-content"],
edit: ExpandableContentEditor,
save: ExpandableContentSave,
}

export default ExpandableContentInnerBlockConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { InnerBlocks } from "@wordpress/block-editor"
import React from "react"

const ExpendableContentSave: React.FC<unknown> = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default ExpendableContentSave
20 changes: 20 additions & 0 deletions services/cms/src/blocks/ExpandableContent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BlockConfiguration } from "@wordpress/blocks"

import { MOOCFI_CATEGORY_SLUG } from "../../utils/Gutenberg/modifyGutenbergCategories"

import ExpandableContentEditor from "./ExpandableContentEditor"
import ExpandableContentSave from "./ExpandableContentSave"

// eslint-disable-next-line i18next/no-literal-string
const ExpandableContent = "ExpandableContent"

const ExpandableContentConfiguration: BlockConfiguration = {
title: ExpandableContent,
description: ExpandableContent,
category: MOOCFI_CATEGORY_SLUG,
attributes: {},
edit: ExpandableContentEditor,
save: ExpandableContentSave,
}

export default ExpandableContentConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { InnerBlocks } from "@wordpress/block-editor"
import { BlockEditProps } from "@wordpress/blocks"
import React from "react"
import { useTranslation } from "react-i18next"

import BlockPlaceholderWrapper from "../../BlockPlaceholderWrapper"

const ALLOWED_NESTED_BLOCKS = ["core/image", "core/paragraph", "core/heading", "core/list"]

const BackFlipCardEditor: React.FC<BlockEditProps<Record<string, never>>> = ({ clientId }) => {
const { t } = useTranslation()

return (
<BlockPlaceholderWrapper
id={clientId}
title={t("back-card")}
explanation={t("back-card-explanation")}
>
<div>
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} templateLock={false} />
</div>
</BlockPlaceholderWrapper>
)
}
export default BackFlipCardEditor
11 changes: 11 additions & 0 deletions services/cms/src/blocks/FlipCard/BackFlipCard/BackFlipCardSave.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InnerBlocks } from "@wordpress/block-editor"

const BackFlipCardSave: React.FC = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default BackFlipCardSave
19 changes: 19 additions & 0 deletions services/cms/src/blocks/FlipCard/BackFlipCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable i18next/no-literal-string */
import { BlockConfiguration } from "@wordpress/blocks"

import BackFlipCardEditor from "./BackFlipCardEditor"
import InnerCardSave from "./BackFlipCardSave"

import { MOOCFI_CATEGORY_SLUG } from "@/utils/Gutenberg/modifyGutenbergCategories"

const BackFlipCardConfiguration: BlockConfiguration = {
title: "Back Flip Card",
description: "Back side for the flip card block",
category: MOOCFI_CATEGORY_SLUG,
parent: ["moocfi/flip-card"],
attributes: {},
edit: BackFlipCardEditor,
save: InnerCardSave,
}

export default BackFlipCardConfiguration
44 changes: 44 additions & 0 deletions services/cms/src/blocks/FlipCard/FlipCardEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { InnerBlocks, InspectorControls } from "@wordpress/block-editor"
import { BlockEditProps, TemplateArray } from "@wordpress/blocks"
import React from "react"
import { useTranslation } from "react-i18next"

import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper"

import { FlipCardAttributes } from "."

import FlipBoxSizeCustomizer from "@/components/blocks/FlipCardSizeCustomizer"

const ALLOWED_NESTED_BLOCKS = ["moocfi/front-card"]
const INNER_BLOCKS_TEMPLATE: TemplateArray = [
["moocfi/front-card", {}],
["moocfi/back-card", {}],
]

const FlipCardEditor: React.FC<React.PropsWithChildren<BlockEditProps<FlipCardAttributes>>> = ({
clientId,
attributes,
setAttributes,
}) => {
const { t } = useTranslation()

return (
<BlockPlaceholderWrapper
id={clientId}
title={t("flip-card-placeholder")}
explanation={t("flip-card-placeholder-explanation")}
>
<InspectorControls key="flip-card-settings">
<FlipBoxSizeCustomizer attributes={attributes} setAttributes={setAttributes} />
</InspectorControls>
<div>
<InnerBlocks
allowedBlocks={ALLOWED_NESTED_BLOCKS}
template={INNER_BLOCKS_TEMPLATE}
templateLock="all"
/>
</div>
</BlockPlaceholderWrapper>
)
}
export default FlipCardEditor
11 changes: 11 additions & 0 deletions services/cms/src/blocks/FlipCard/FlipCardSave.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InnerBlocks } from "@wordpress/block-editor"

const FlipCardSave: React.FC = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default FlipCardSave
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { InnerBlocks } from "@wordpress/block-editor"
import { BlockEditProps } from "@wordpress/blocks"
import React from "react"
import { useTranslation } from "react-i18next"

import BlockPlaceholderWrapper from "../../BlockPlaceholderWrapper"

const ALLOWED_NESTED_BLOCKS = ["core/image", "core/paragraph", "core/heading", "core/list"]

const FrontFlipCardEditor: React.FC<BlockEditProps<Record<string, never>>> = ({ clientId }) => {
const { t } = useTranslation()

return (
<BlockPlaceholderWrapper
id={clientId}
title={t("front-card")}
explanation={t("front-card-explanation")}
>
<div>
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} templateLock={false} />
</div>
</BlockPlaceholderWrapper>
)
}
export default FrontFlipCardEditor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InnerBlocks } from "@wordpress/block-editor"

const FrontFlipCardSave: React.FC = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default FrontFlipCardSave
19 changes: 19 additions & 0 deletions services/cms/src/blocks/FlipCard/FrontFlipCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable i18next/no-literal-string */
import { BlockConfiguration } from "@wordpress/blocks"

import FrontFlipCardEditor from "./FrontFlipCardEditor"
import FrontFlipCardSave from "./FrontFlipCardSave"

import { MOOCFI_CATEGORY_SLUG } from "@/utils/Gutenberg/modifyGutenbergCategories"

const FrontFlipCardConfiguration: BlockConfiguration = {
title: "Inner Card",
description: "Front side for the flip card block",
category: MOOCFI_CATEGORY_SLUG,
parent: ["moocfi/flip-card"],
attributes: {},
edit: FrontFlipCardEditor,
save: FrontFlipCardSave,
}

export default FrontFlipCardConfiguration
26 changes: 26 additions & 0 deletions services/cms/src/blocks/FlipCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable i18next/no-literal-string */
import { BlockConfiguration } from "@wordpress/blocks"

import FlipCardEditor from "./FlipCardEditor"
import FlipCardSave from "./FlipCardSave"

import { MOOCFI_CATEGORY_SLUG } from "@/utils/Gutenberg/modifyGutenbergCategories"

export interface FlipCardAttributes {
size: string
}
const FlipCardConfiguration: BlockConfiguration<FlipCardAttributes> = {
title: "Flip Card",
description: "A two sided flip card that can be flipped by clicking the card",
category: MOOCFI_CATEGORY_SLUG,
attributes: {
size: {
type: "string",
default: "xl",
},
},
edit: FlipCardEditor,
save: FlipCardSave,
}

export default FlipCardConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { InnerBlocks } from "@wordpress/block-editor"
import { BlockEditProps } from "@wordpress/blocks"
import { t } from "i18next"
import React from "react"

import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper"

import { ConditionAttributes } from "."

const ALLOWED_NESTED_BLOCKS = [
"core/heading",
"core/paragraph",
"core/image",
"core/list",
"moocfi/revealable-hidden-content",
]

const ConditionalBlockEditor: React.FC<
React.PropsWithChildren<BlockEditProps<ConditionAttributes>>
> = ({ clientId }) => {
return (
<BlockPlaceholderWrapper
id={clientId}
title={t("revealable-content-placeholder")}
explanation={t("revealable-content-explanation")}
>
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} />
</BlockPlaceholderWrapper>
)
}

export default ConditionalBlockEditor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InnerBlocks } from "@wordpress/block-editor"

const RevealableContentSave: React.FC = () => {
return (
<div>
<InnerBlocks.Content />
</div>
)
}

export default RevealableContentSave
Loading

0 comments on commit 5861eb0

Please sign in to comment.