Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expandable content -block #1305

Merged
merged 20 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]

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} />
</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
40 changes: 40 additions & 0 deletions services/cms/src/blocks/FlipCard/FlipCardEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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} />
</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"]

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} />
</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
Loading